Changeset 11333 for extensions/SmartAlbums/include/functions.inc.php
- Timestamp:
- Jun 12, 2011, 5:56:09 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmartAlbums/include/functions.inc.php
r10980 r11333 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 pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'); 12 12 13 13 $images = smart_get_pictures($cat_id); … … 21 21 'category_id' => $cat_id, 22 22 'smart' => true, 23 );23 ); 24 24 } 25 25 mass_inserts_ignore( … … 27 27 array_keys($datas[0]), 28 28 $datas 29 );29 ); 30 30 set_random_representant(array($cat_id)); 31 31 } … … 48 48 if ($filters == null) 49 49 { 50 $filters = pwg_query("SELECT * FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id." ORDER BY type ASC, cond ASC;"); 50 $query = ' 51 SELECT * 52 FROM '.CATEGORY_FILTERS_TABLE.' 53 WHERE category_id = '.$cat_id.' 54 ORDER BY type ASC, cond ASC 55 ;'; 56 $filters = pwg_query($query); 57 51 58 if (!pwg_db_num_rows($filters)) return array(); 52 59 … … 57 64 'cond' => $filter['cond'], 58 65 'value' => $filter['value'], 59 );66 ); 60 67 } 61 68 … … 78 85 foreach($tags_arr as $value) 79 86 { 80 $join[] = "".IMAGE_TAG_TABLE." AS it_$i_tags ON i.id = it_$i_tags.image_id";81 $where[] = "it_$i_tags.tag_id = ".$value."";87 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 88 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 82 89 $i_tags++; 83 90 } … … 85 92 else if ($filter['cond'] == 'one') 86 93 { 87 $join[] = "".IMAGE_TAG_TABLE." AS it_$i_tags ON i.id = it_$i_tags.image_id";88 $where[] = "it_$i_tags.tag_id IN (".$filter['value'].")";94 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 95 $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')'; 89 96 $i_tags++; 90 97 } 91 98 else if ($filter['cond'] == 'none') 92 99 { 93 $sub_query = "SELECT it_$i_tags.image_id 94 FROM ".IMAGE_TAG_TABLE." AS it_$i_tags 95 WHERE it_$i_tags.image_id = i.id 96 AND it_$i_tags.tag_id IN (".$filter['value'].") 97 GROUP BY it_$i_tags.image_id"; 98 $where[] = "NOT EXISTS (".$sub_query.")"; 100 $sub_query = ' 101 SELECT it_'.$i_tags.'.image_id 102 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' 103 WHERE 104 it_'.$i_tags.'.image_id = i.id AND 105 it_'.$i_tags.'.tag_id IN ('.$filter['value'].') 106 GROUP BY it_'.$i_tags.'.image_id 107 '; 108 $where[] = 'NOT EXISTS ('.$sub_query.')'; 99 109 $i_tags++; 100 110 } 101 111 else if ($filter['cond'] == 'only') 102 112 { 103 $sub_query = "SELECT it_$i_tags.image_id 104 FROM ".IMAGE_TAG_TABLE." AS it_$i_tags 105 WHERE it_$i_tags.image_id = i.id 106 AND it_$i_tags.tag_id NOT IN (".$filter['value'].") 107 GROUP BY it_$i_tags.image_id"; 108 $where[] = "NOT EXISTS (".$sub_query.")"; 113 $sub_query = ' 114 SELECT it_'.$i_tags.'.image_id 115 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' 116 WHERE 117 it_'.$i_tags.'.image_id = i.id AND 118 it_'.$i_tags.'.tag_id NOT IN ('.$filter['value'].') 119 GROUP BY it_'.$i_tags.'.image_id 120 '; 121 $where[] = 'NOT EXISTS ('.$sub_query.')'; 109 122 110 123 $i_tags++; … … 113 126 foreach($tags_arr as $value) 114 127 { 115 $join[] = "".IMAGE_TAG_TABLE." AS it_$i_tags ON i.id = it_$i_tags.image_id";116 $where[] = "it_$i_tags.tag_id = ".$value."";128 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 129 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 117 130 $i_tags++; 118 131 } … … 122 135 else if ($filter['type'] == 'date') 123 136 { 124 if ($filter['cond'] == 'the') $where[] = "date_available BETWEEN '".$filter['value']." 00:00:00' AND '".$filter['value']." 23:59:59'";125 else if ($filter['cond'] == 'before') $where[] = "date_available < '".$filter['value']." 00:00:00'";126 else if ($filter['cond'] == 'after') $where[] = "date_available > '".$filter['value']." 23:59:59'";137 if ($filter['cond'] == 'the') $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"'; 138 else if ($filter['cond'] == 'before') $where[] = 'date_available < "'.$filter['value'].' 00:00:00"'; 139 else if ($filter['cond'] == 'after') $where[] = 'date_available > "'.$filter['value'].' 23:59:59"'; 127 140 } 128 141 // limit 129 142 else if ($filter['type'] == 'limit') 130 143 { 131 $limit = "0, ".$filter['value'];144 $limit = '0, '.$filter['value']; 132 145 } 133 146 } 134 147 135 148 /* bluid query */ 136 $MainQuery = "SELECT i.id 137 FROM ( 138 SELECT i.id 139 FROM ".IMAGES_TABLE." AS i"."\n"; 140 141 if (isset($join)) 142 { 143 foreach ($join as $query) 144 { 145 $MainQuery .= "LEFT JOIN ".$query."\n"; 146 } 147 } 148 if (isset($where)) 149 { 150 $MainQuery .= "WHERE"."\n"; 151 $i = 0; 152 foreach ($where as $query) 153 { 154 if ($i != 0) $MainQuery .= "AND "; 155 $MainQuery .= $query."\n"; 156 $i++; 157 } 158 } 159 160 $MainQuery .= "GROUP BY i.id 161 ".$conf['order_by']." 162 ".(isset($limit) ? "LIMIT ".$limit : null)." 163 ) AS i 164 "; 165 149 $MainQuery = ' 150 SELECT i.id 151 FROM '.IMAGES_TABLE.' AS i'; 152 153 if (isset($join)) 154 { 155 foreach ($join as $query) 156 { 157 $MainQuery .= ' 158 LEFT JOIN '.$query; 159 } 160 } 161 if (isset($where)) 162 { 163 $MainQuery .= ' 164 WHERE'; 165 $i = 0; 166 foreach ($where as $query) 167 { 168 if ($i != 0) $MainQuery .= ' AND'; 169 $MainQuery .= ' 170 '.$query; 171 $i++; 172 } 173 } 174 175 $MainQuery .= ' 176 GROUP BY i.id 177 '.$conf['order_by_inside_category'].' 178 '.(isset($limit) ? "LIMIT ".$limit : null).' 179 ;'; 180 166 181 return array_from_query($MainQuery, 'id'); 167 182 } … … 189 204 else 190 205 { 191 $filter['value'] = implode(',', get_ fckb_tag_ids($filter['value']));206 $filter['value'] = implode(',', get_tag_ids($filter['value'])); 192 207 } 193 208 }
Note: See TracChangeset
for help on using the changeset viewer.