Cheetah
ChStoreSearchResult.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbTwigSearchResult');
9 
11 {
12  var $aCurrent = array(
13  'name' => 'ch_store',
14  'title' => '_ch_store_page_title_browse',
15  'table' => 'ch_store_products',
16  'ownFields' => array('id', 'title', 'uri', 'created', 'author_id', 'thumb', 'price_range', 'rate', 'desc'),
17  'searchFields' => array('title', 'desc', 'tags', 'categories'),
18  'join' => array(
19  'profile' => array(
20  'type' => 'left',
21  'table' => 'Profiles',
22  'mainField' => 'author_id',
23  'onField' => 'ID',
24  'joinFields' => array('NickName'),
25  ),
26  ),
27  'restriction' => array(
28  'activeStatus' => array('value' => 'approved', 'field'=>'status', 'operator'=>'='),
29  'owner' => array('value' => '', 'field' => 'author_id', 'operator' => '='),
30  'tag' => array('value' => '', 'field' => 'tags', 'operator' => 'against'),
31  'category' => array('value' => '', 'field' => 'Category', 'operator' => '=', 'table' => 'sys_categories'),
32  'category_type' => array('value' => '', 'field' => 'Type', 'operator' => '=', 'table' => 'sys_categories'),
33  'public' => array('value' => '', 'field' => 'allow_view_product_to', 'operator' => '='),
34  ),
35  'paginate' => array('perPage' => 14, 'page' => 1, 'totalNum' => 0, 'totalPages' => 1),
36  'sorting' => 'last',
37  'rss' => array(
38  'title' => '',
39  'link' => '',
40  'image' => '',
41  'profile' => 0,
42  'fields' => array (
43  'Link' => '',
44  'Title' => 'title',
45  'DateTimeUTS' => 'created',
46  'Desc' => 'desc',
47  'Image' => 'thumb',
48  ),
49  ),
50  'ident' => 'id'
51  );
52 
53  function __construct($sMode = '', $sValue = '', $sValue2 = '', $sValue3 = '')
54  {
55  switch ($sMode) {
56 
57  case 'pending':
58  if (false !== ch_get('ch_store_filter'))
59  $this->aCurrent['restriction']['keyword'] = array('value' => process_db_input(ch_get('ch_store_filter'), CH_TAGS_STRIP), 'field' => '','operator' => 'against');
60  $this->aCurrent['restriction']['activeStatus']['value'] = 'pending';
61  $this->sBrowseUrl = "administration";
62  $this->aCurrent['title'] = _t('_ch_store_page_title_pending_approval');
63  unset($this->aCurrent['rss']);
64  break;
65 
66  case 'my_pending':
67  $oMain = $this->getMain();
68  $this->aCurrent['restriction']['owner']['value'] = $oMain->_iProfileId;
69  $this->aCurrent['restriction']['activeStatus']['value'] = 'pending';
70  $this->sBrowseUrl = "browse/user/" . getNickName($oMain->_iProfileId);
71  $this->aCurrent['title'] = _t('_ch_store_page_title_pending_approval');
72  unset($this->aCurrent['rss']);
73  break;
74 
75  case 'search':
76  if ($sValue)
77  $this->aCurrent['restriction']['keyword'] = array('value' => $sValue,'field' => '','operator' => 'against');
78 
79  if ($sValue2) {
80 
81  $this->aCurrent['join']['category'] = array(
82  'type' => 'inner',
83  'table' => 'sys_categories',
84  'mainField' => 'id',
85  'onField' => 'ID',
86  'joinFields' => '',
87  );
88 
89  $this->aCurrent['restriction']['category_type']['value'] = $this->aCurrent['name'];
90  $this->aCurrent['restriction']['category']['value'] = $sValue2;
91  if (is_array($sValue2)) {
92  $this->aCurrent['restriction']['category']['operator'] = 'in';
93  }
94  }
95  $sValue = $GLOBALS['MySQL']->unescape($sValue);
96  $sValue2 = $GLOBALS['MySQL']->unescape($sValue2);
97  $this->sBrowseUrl = "search/$sValue/" . (is_array($sValue2) ? implode(',',$sValue2) : $sValue2);
98  $this->aCurrent['title'] = _t('_ch_store_page_title_search_results') . ' ' . (is_array($sValue2) ? implode(', ',$sValue2) : $sValue2) . ' ' . $sValue;
99  unset($this->aCurrent['rss']);
100  break;
101 
102  case 'user':
103  $iProfileId = $GLOBALS['oChStoreModule']->_oDb->getProfileIdByNickName ($sValue, false);
104  $GLOBALS['oTopMenu']->setCurrentProfileID($iProfileId); // select profile subtab, instead of module tab
105  if (!$iProfileId)
106  $this->isError = true;
107  else
108  $this->aCurrent['restriction']['owner']['value'] = $iProfileId;
109  $sValue = $GLOBALS['MySQL']->unescape($sValue);
110  $this->sBrowseUrl = "browse/user/$sValue";
111 
112  $iProfileId = getID($sValue);
113  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_by_author', $iProfileId ? getNickName($iProfileId) : $sValue);
114 
115  if (ch_get('rss')) {
116  $aData = getProfileInfo($iProfileId);
117  if ($aData['Avatar']) {
118  $a = array ('ID' => $aData['author_id'], 'Avatar' => $aData['thumb']);
119  $aImage = ChWsbService::call('photos', 'get_image', array($a, 'browse'), 'Search');
120  if (!$aImage['no_image'])
121  $this->aCurrent['rss']['image'] = $aImage['file'];
122  }
123  }
124  break;
125 
126  case 'admin':
127  $this->aCurrent['restriction']['owner']['value'] = 0;
128  $this->sBrowseUrl = "browse/admin";
129  $this->aCurrent['title'] = _t('_ch_store_page_title_admin_products');
130  break;
131 
132  case 'category':
133  $this->aCurrent['join']['category'] = array(
134  'type' => 'inner',
135  'table' => 'sys_categories',
136  'mainField' => 'id',
137  'onField' => 'ID',
138  'joinFields' => '',
139  );
140  $this->aCurrent['restriction']['category_type']['value'] = $this->aCurrent['name'];
141  $this->aCurrent['restriction']['category']['value'] = $sValue;
142  $sValue = $GLOBALS['MySQL']->unescape($sValue);
143  $this->sBrowseUrl = "browse/category/" . title2uri($sValue);
144  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_by_category', $sValue);
145  break;
146 
147  case 'tag':
148  $this->aCurrent['restriction']['tag']['value'] = $sValue;
149  $sValue = $GLOBALS['MySQL']->unescape($sValue);
150  $this->sBrowseUrl = "browse/tag/" . title2uri($sValue);
151  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_by_tag', $sValue);
152  break;
153 
154  case 'free':
155  $this->aCurrent['restriction']['price'] = array('value' => 'Free', 'field' => 'price_range', 'operator' => '=');
156  $this->sBrowseUrl = "browse/free";
157  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_free_products') . ' ' . $sValue;
158  break;
159 
160  case 'recent':
161  $this->sBrowseUrl = 'browse/recent';
162  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_recent');
163  break;
164 
165  case 'top':
166  $this->sBrowseUrl = 'browse/top';
167  $this->aCurrent['sorting'] = 'top';
168  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_top_rated');
169  break;
170 
171  case 'popular':
172  $this->sBrowseUrl = 'browse/popular';
173  $this->aCurrent['sorting'] = 'popular';
174  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_popular');
175  break;
176 
177  case 'featured':
178  $this->aCurrent['restriction']['featured'] = array('value' => 1, 'field' => 'featured', 'operator' => '=');
179  $this->sBrowseUrl = 'browse/featured';
180  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_featured');
181  break;
182 
183  case 'calendar':
184  $this->aCurrent['restriction']['calendar-min'] = array('value' => "UNIX_TIMESTAMP('{$sValue}-{$sValue2}-{$sValue3} 00:00:00')", 'field' => 'created', 'operator' => '>=', 'no_quote_value' => true);
185  $this->aCurrent['restriction']['calendar-max'] = array('value' => "UNIX_TIMESTAMP('{$sValue}-{$sValue2}-{$sValue3} 23:59:59')", 'field' => 'created', 'operator' => '<=', 'no_quote_value' => true);
186  $this->sEventsBrowseUrl = "browse/calendar/{$sValue}/{$sValue2}/{$sValue3}";
187  $this->aCurrent['title'] = _t('_ch_store_page_title_browse_by_day', getLocaleDate(strtotime("{$sValue}-{$sValue2}-{$sValue3}"), CH_WSB_LOCALE_DATE_SHORT));
188  break;
189 
190  case '':
191  $this->sBrowseUrl = 'browse/';
192  $this->aCurrent['title'] = _t('_ch_store');
193  unset($this->aCurrent['rss']);
194  break;
195 
196  default:
197  $this->isError = true;
198  }
199 
200  $oMain = $this->getMain();
201 
202  $this->aCurrent['paginate']['perPage'] = $oMain->_oDb->getParam('ch_store_perpage_browse');
203 
204  if (isset($this->aCurrent['rss']))
205  $this->aCurrent['rss']['link'] = CH_WSB_URL_ROOT . $oMain->_oConfig->getBaseUri() . $this->sBrowseUrl;
206 
207  if (ch_get('rss')) {
208  $this->aCurrent['ownFields'][] = 'desc';
209  $this->aCurrent['ownFields'][] = 'created';
210  $this->aCurrent['paginate']['perPage'] = $oMain->_oDb->getParam('ch_store_max_rss_num');
211  }
212 
213  ch_store_import('Voting', $this->getModuleArray());
214  $oVotingView = new ChStoreVoting ('ch_store', 0);
215  $this->oVotingView = $oVotingView->isEnabled() ? $oVotingView : null;
216 
217  $this->sFilterName = 'ch_store_filter';
218 
219  parent::__construct();
220  }
221 
222  function getAlterOrder()
223  {
224  if ($this->aCurrent['sorting'] == 'last') {
225  $aSql = array();
226  $aSql['order'] = " ORDER BY `ch_store_products`.`created` DESC";
227  return $aSql;
228  } elseif ($this->aCurrent['sorting'] == 'top') {
229  $aSql = array();
230  $aSql['order'] = " ORDER BY `ch_store_products`.`rate` DESC, `ch_store_products`.`rate_count` DESC";
231  return $aSql;
232  } elseif ($this->aCurrent['sorting'] == 'popular') {
233  $aSql = array();
234  $aSql['order'] = " ORDER BY `ch_store_products`.`views` DESC";
235  return $aSql;
236  }
237  return array();
238  }
239 
240  function displayResultBlock ()
241  {
243  $s = parent::displayResultBlock ();
244  if($s) {
245  $s = $oFunctions->centerContent ($s, '.ch_store_unit');
246 
247  $oMain = $this->getMain();
248  $GLOBALS['oSysTemplate']->addDynamicLocation($oMain->_oConfig->getHomePath(), $oMain->_oConfig->getHomeUrl());
249  $GLOBALS['oSysTemplate']->addCss(array('unit.css', 'twig.css'));
250  return $GLOBALS['oSysTemplate']->parseHtmlByName('default_padding.html', array('content' => $s));
251  }
252  return '';
253  }
254 
255  function getModuleArray()
256  {
257  return db_arr ("SELECT * FROM `sys_modules` WHERE `title` = 'Store' AND `class_prefix` = 'ChStore' LIMIT 1");
258  }
259 
260  function getMain()
261  {
262  if ($GLOBALS['oChStoreModule']) {
263  return $GLOBALS['oChStoreModule'];
264  } else {
266  ch_import ('Module', $aModule);
267  ch_import ('Template', $aModule);
268  ch_import ('Config', $aModule);
269  $GLOBALS['oChStoreModule'] = new ChStoreModule($aModule);
270  return $GLOBALS['oChStoreModule'];
271  }
272  }
273 
274  function getRssUnitLink (&$a)
275  {
276  $oMain = $this->getMain();
277  return CH_WSB_URL_ROOT . $oMain->_oConfig->getBaseUri() . 'view/' . $a['uri'];
278  }
279 
280  function _getPseud ()
281  {
282  return array(
283  'id' => 'id',
284  'title' => 'title',
285  'uri' => 'uri',
286  'created' => 'created',
287  'author_id' => 'author_id',
288  'NickName' => 'NickName',
289  'thumb' => 'thumb',
290  'price_range' => 'price_range',
291  );
292  }
293 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChStoreModule
Definition: ChStoreModule.php:119
ChStoreSearchResult\__construct
__construct($sMode='', $sValue='', $sValue2='', $sValue3='')
Definition: ChStoreSearchResult.php:53
$sMode
else $sMode
Definition: antispam.php:362
$aModule
$aModule
Definition: classifieds.php:21
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
php
ChStoreSearchResult\displayResultBlock
displayResultBlock()
Definition: ChStoreSearchResult.php:240
ChWsbTwigSearchResult\$oVotingView
$oVotingView
Definition: ChWsbTwigSearchResult.php:15
ch_store_import
ch_store_import($sClassPostfix, $aModuleOverwright=array())
Definition: ChStoreModule.php:8
$oFunctions
$oFunctions
Definition: ChTemplFunctions.php:20
ChStoreSearchResult\getRssUnitLink
getRssUnitLink(&$a)
Definition: ChStoreSearchResult.php:274
db_arr
db_arr($query, $bindings=[])
Definition: db.inc.php:76
ChStoreSearchResult\getModuleArray
getModuleArray()
Definition: ChStoreSearchResult.php:255
ChStoreSearchResult
Definition: ChStoreSearchResult.php:11
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
title2uri
title2uri($sValue)
Definition: utils.inc.php:42
ChWsbTwigSearchResult
Definition: ChWsbTwigSearchResult.php:14
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChStoreSearchResult\getMain
getMain()
Definition: ChStoreSearchResult.php:260
CH_WSB_LOCALE_DATE_SHORT
const CH_WSB_LOCALE_DATE_SHORT
Definition: utils.inc.php:15
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
ChStoreSearchResult\_getPseud
_getPseud()
Definition: ChStoreSearchResult.php:280
$s
$s
Definition: embed.php:13
ChStoreSearchResult\$aCurrent
$aCurrent
Definition: ChStoreSearchResult.php:12
getID
getID( $str, $with_email=1)
Definition: admin.inc.php:139
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
ChStoreVoting
Definition: ChStoreVoting.php:11
ChWsbTwigSearchResult\$sBrowseUrl
$sBrowseUrl
Definition: ChWsbTwigSearchResult.php:17
ChStoreSearchResult\getAlterOrder
getAlterOrder()
Definition: ChStoreSearchResult.php:222
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
getLocaleDate
getLocaleDate($sTimestamp='', $iCode=CH_WSB_LOCALE_DATE_SHORT)
Definition: utils.inc.php:70
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10