source: extensions/UserCollections/include/display_collections.inc.php @ 23361

Last change on this file since 23361 was 23361, checked in by mistic100, 11 years ago

all collections are "active", display a menu when adding to a collection

File size: 3.2 KB
Line 
1<?php
2defined('USER_COLLEC_PATH') or die('Hacking attempt!');
3
4
5// collections orders
6if (isset($_GET['uc_collection_order']))
7{
8  if ( (int)$_GET['uc_collection_order'] > 0)
9  {
10    pwg_set_session_var('uc_collection_order', (int)$_GET['uc_collection_order']);
11  }
12  else
13  {
14    pwg_unset_session_var('uc_collection_order');
15  }
16  redirect(USER_COLLEC_PUBLIC);
17}
18
19$col_order_id = pwg_get_session_var('uc_collection_order', 0);
20$orders = get_collections_preferred_orders();
21
22// get sorted collections
23$query = '
24SELECT *
25  FROM '.COLLECTIONS_TABLE.'
26  WHERE user_id = '.$user['id'].'
27  ORDER BY '.$orders[$col_order_id][1].'
28';
29$categories = hash_from_query($query, 'id');
30
31$template->assign('COLLECTIONS_COUNT', count($categories));
32
33// order menu
34if (count($categories))
35{
36  $url = add_url_params(USER_COLLEC_PUBLIC, array('uc_collection_order' => ''));
37 
38  foreach ($orders as $order_id => $order)
39  {
40    if ($order[2])
41    {
42      $template->append(
43        'image_orders',
44        array(
45          'DISPLAY' => $order[0],
46          'URL' => $url.$order_id,
47          'SELECTED' => ($col_order_id == $order_id ? true:false),
48          )
49        );
50    }
51  }
52}
53
54
55if (count($categories))
56{
57  $query = '
58SELECT * FROM (
59  SELECT
60      i.*,
61      ci.col_id
62    FROM '.IMAGES_TABLE.' AS i
63    INNER JOIN '.COLLECTION_IMAGES_TABLE.' AS ci
64      ON i.id = ci.image_id
65    WHERE col_id IN('.implode(',', array_keys($categories)).')
66    ORDER BY ci.add_date DESC
67  ) AS t
68  GROUP BY col_id
69;';
70  $thumbnails = hash_from_query($query, 'col_id');
71 
72  $thumbnails[0] = array(
73    'id' => 0,
74    'path' => 'themes/default/icon/img_small.png',
75    'picture_ext' => 'png',
76    'width' => 32,
77    'height' => 32,
78    'rotation' => 0,
79    );
80 
81  foreach ($thumbnails as &$info)
82  {
83    $info['src_image'] = new SrcImage($info);
84  }
85  unset($info);
86 
87  $tpl_thumbnails_var = array();
88
89  foreach ($categories as $category)
90  {
91    $thumb = empty($thumbnails[ $category['id'] ]) ? $thumbnails[0] : $thumbnails[ $category['id'] ];
92    $counter = get_display_images_count($category['nb_images'], $category['nb_images'], 0);
93   
94    $tpl_var = array_merge( $category, array(
95      'representative'   => $thumb,
96      'TN_ALT'   => strip_tags($category['name']),
97      'URL'   => USER_COLLEC_PUBLIC.'edit/'.$category['id'],
98      'CAPTION_NB_IMAGES' => empty($counter) ? sprintf(l10n('%d photo'), 0) : $counter,
99      'NAME'  => $category['name'],
100      'INFO_DATES' => format_date($category['date_creation'], true),
101     
102      // 'U_ACTIVE' => add_url_params(USER_COLLEC_PUBLIC, array('action'=>'toggle_active','col_id'=>$category['id'])),
103      'U_DELETE' => add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$category['id'])),
104      ));
105
106    $tpl_thumbnails_var[] = $tpl_var;
107  }
108 
109  $derivative_params = trigger_event('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_THUMB) );
110  $template->assign(array(
111    'maxRequests' =>$conf['max_requests'],
112    'category_thumbnails' => $tpl_thumbnails_var,
113    'derivative_params' => $derivative_params,
114    ));
115 
116  $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
117  $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
118}
119
120?>
Note: See TracBrowser for help on using the repository browser.