Changeset 11546 for extensions/SmartAlbums/include/functions.inc.php
- Timestamp:
- Jun 28, 2011, 3:19:44 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmartAlbums/include/functions.inc.php
r11381 r11546 9 9 function smart_make_associations($cat_id) 10 10 { 11 pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'); 11 $query = ' 12 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 13 WHERE 14 category_id = '.$cat_id.' 15 AND smart = true 16 ;'; 17 pwg_query($query); 12 18 13 19 $images = smart_get_pictures($cat_id); … … 30 36 } 31 37 32 if (!function_exists('set_random_representant')) 33 { 34 include(PHPWG_ROOT_PATH.'admin/include/functions.php'); 35 } 36 set_random_representant(array($cat_id)); 38 // represantant, try to not overwrite if still in images list 39 $query = ' 40 SELECT representative_picture_id 41 FROM '.CATEGORIES_TABLE.' 42 WHERE id = '.$cat_id.' 43 ;'; 44 list($rep_id) = pwg_db_fetch_row(pwg_query($query)); 45 46 if ( !in_array($rep_id, $images) ) 47 { 48 if (!function_exists('set_random_representant')) 49 { 50 include(PHPWG_ROOT_PATH.'admin/include/functions.php'); 51 } 52 set_random_representant(array($cat_id)); 53 } 37 54 38 55 return $images; … … 79 96 if ($filters == null) 80 97 { 98 $filters = array(); 99 81 100 $query = ' 82 101 SELECT * … … 85 104 ORDER BY type ASC, cond ASC 86 105 ;'; 87 $ filters= pwg_query($query);88 89 if (!pwg_db_num_rows($ filters)) return array();90 91 while ($ filter = pwg_db_fetch_assoc($filters))92 { 93 $ temp[] = array(94 'type' => $ filter['type'],95 'cond' => $ filter['cond'],96 'value' => $ filter['value'],106 $result = pwg_query($query); 107 108 if (!pwg_db_num_rows($result)) return $filters; 109 110 while ($row = pwg_db_fetch_assoc($result)) 111 { 112 $filters[] = array( 113 'type' => $row['type'], 114 'cond' => $row['cond'], 115 'value' => $row['value'], 97 116 ); 98 117 } 99 100 $filters = $temp;101 118 } 102 119 … … 110 127 if ($filter['type'] == 'tags') 111 128 { 112 if($filter['cond'] == "all") 113 { 114 $tags_arr = explode(',', $filter['value']); 115 116 foreach($tags_arr as $value) 117 { 118 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 119 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 120 $i_tags++; 121 } 122 } 123 else if ($filter['cond'] == 'one') 129 if($filter['cond'] == "all") 130 { 131 $tags_arr = explode(',', $filter['value']); 132 133 foreach($tags_arr as $value) 124 134 { 125 135 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 126 $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';136 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 127 137 $i_tags++; 128 138 } 129 else if ($filter['cond'] == 'none') 130 { 131 $sub_query = ' 139 } 140 else if ($filter['cond'] == 'one') 141 { 142 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 143 $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')'; 144 $i_tags++; 145 } 146 else if ($filter['cond'] == 'none') 147 { 148 $sub_query = ' 132 149 SELECT it_'.$i_tags.'.image_id 133 150 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' … … 137 154 GROUP BY it_'.$i_tags.'.image_id 138 155 '; 139 140 141 142 143 144 156 $where[] = 'NOT EXISTS ('.$sub_query.')'; 157 $i_tags++; 158 } 159 else if ($filter['cond'] == 'only') 160 { 161 $sub_query = ' 145 162 SELECT it_'.$i_tags.'.image_id 146 163 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' … … 150 167 GROUP BY it_'.$i_tags.'.image_id 151 168 '; 152 $where[] = 'NOT EXISTS ('.$sub_query.')'; 169 $where[] = 'NOT EXISTS ('.$sub_query.')'; 170 171 $i_tags++; 172 $tags_arr = explode(',', $filter['value']); 153 173 174 foreach($tags_arr as $value) 175 { 176 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 177 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 154 178 $i_tags++; 155 $tags_arr = explode(',', $filter['value']); 156 157 foreach($tags_arr as $value) 158 { 159 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 160 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 161 $i_tags++; 162 } 163 } 179 } 180 } 164 181 } 165 182 // date … … 234 251 /** 235 252 * Check if the filter is proper 236 *237 253 * @param array filter 238 254 * @return array or false … … 246 262 if ($filter['type'] == 'tags') 247 263 { 248 if ($filter['value'] == null) // tags fields musn't be null264 if ($filter['value'] == null) 249 265 { 250 266 $error = true; … … 259 275 else if ($filter['type'] == 'date') 260 276 { 261 if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) // dates must be proper277 if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) 262 278 { 263 279 $error = true; … … 268 284 else if ($filter['type'] == 'limit') 269 285 { 270 if (!preg_match('#([0-9]{1,})#', $filter['value'])) // limit must be an integer286 if (!preg_match('#([0-9]{1,})#', $filter['value'])) 271 287 { 272 288 $error = true; … … 298 314 /** 299 315 * inserts multiple lines in a table, ignore duplicate entries 300 *301 316 * @param string table_name 302 317 * @param array dbfields
Note: See TracChangeset
for help on using the changeset viewer.