Changeset 11827 for trunk/admin/include/functions.php
- Timestamp:
- Jul 25, 2011, 8:04:50 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r11753 r11827 1052 1052 1053 1053 /** 1054 * update images.average_rate field1055 * param int $element_id optional, otherwise applies to all1056 * @return void1057 */1058 function update_average_rate( $element_id=-1 )1059 {1060 $query = '1061 SELECT element_id,1062 ROUND(AVG(rate),2) AS average_rate1063 FROM '.RATE_TABLE;1064 if ( $element_id != -1 )1065 {1066 $query .= ' WHERE element_id=' . $element_id;1067 }1068 $query .= ' GROUP BY element_id;';1069 1070 $result = pwg_query($query);1071 1072 $datas = array();1073 1074 while ($row = pwg_db_fetch_assoc($result))1075 {1076 array_push(1077 $datas,1078 array(1079 'id' => $row['element_id'],1080 'average_rate' => $row['average_rate']1081 )1082 );1083 }1084 1085 mass_updates(1086 IMAGES_TABLE,1087 array(1088 'primary' => array('id'),1089 'update' => array('average_rate')1090 ),1091 $datas1092 );1093 1094 $query='1095 SELECT id FROM '.IMAGES_TABLE .'1096 LEFT JOIN '.RATE_TABLE.' ON id=element_id1097 WHERE element_id IS NULL AND average_rate IS NOT NULL';1098 if ( $element_id != -1 )1099 {1100 $query .= ' AND id=' . $element_id;1101 }1102 $to_update = array_from_query( $query, 'id');1103 1104 if ( !empty($to_update) )1105 {1106 $query='1107 UPDATE '.IMAGES_TABLE .'1108 SET average_rate=NULL1109 WHERE id IN (' . implode(',',$to_update) . ')';1110 pwg_query($query);1111 }1112 }1113 1114 /**1115 1054 * change the parent category of the given categories. The categories are 1116 1055 * supposed virtual.
Note: See TracChangeset
for help on using the changeset viewer.