Cheetah
ChBaseCategories.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbCategories.php');
9 
11 {
15 
16  function __construct ()
17  {
18  parent::__construct();
19 
20  $this->_sCategTmplName = 'view_categ.html';
21  $this->_sCategTmplContent = '';
22  $this->_aOrderValues = array('none' => _t('_categ_order_none'), 'popular' => _t('_categ_order_popular'), 'recent' => _t('_categ_order_recent'));
23  }
24 
25  function getCategoriesView ($aTotalCategories, $sHrefTempl, $iColumns)
26  {
28 
29  if (empty($aTotalCategories))
30  return MsgBox(_t( '_Empty' ));
31 
32  if (!$iColumns)
33  $iColumns = 1;
34 
35  $iCount = count($aTotalCategories);
36  $iRowCount = floor($iCount / $iColumns) + (($iCount % $iColumns) ? 1 : 0);
37  $iWidthPr = floor(100 / $iColumns);
38  $i = 0;
39  $sCode = '<div class="categories_wrapper ch-def-bc-margin ch-def-font-large">';
40 
41  foreach( $aTotalCategories as $sCategory => $iCatCount ) {
42  if (!($i % $iRowCount)) {
43  if ($i)
44  $sCode .= '</div>';
45  $sCode .= '<div class="categories_col" style="width: ' . $iWidthPr . '%">';
46  }
47 
48  $aUnit['catHref'] = str_replace( '{tag}', rawurlencode(title2uri($sCategory)), $sHrefTempl);
49  $aUnit['category'] = htmlspecialchars_adv($sCategory );
50  $aUnit['count'] = $iCatCount;
51 
52  if ($this->_sCategTmplContent)
53  $sCode .= $oSysTemplate->parseHtmlByContent($this->_sCategTmplContent, $aUnit);
54  else
55  $sCode .= $oSysTemplate->parseHtmlByName($this->_sCategTmplName, $aUnit);
56 
57  $i++;
58  }
59 
60  $sCode .= '</div></div>';
61 
62  return $sCode;
63  }
64 
65  function getCategTopMenu ($aParam, $sAction = '')
66  {
67  $aTopMenu = array();
68  $aParamTmp = $aParam;
69 
70  foreach ($this->aTagObjects as $sKey => $aTagUnit) {
71  $sName = _t($aTagUnit['LangKey']);
72  $sHref = ch_html_attribute($_SERVER['PHP_SELF']) . "?tags_mode=$sKey" . ($sAction ? '&action=' . $sAction : '');
73 
74  if (isset($aParam['filter']) && $aParam['filter']) {
75  $aParamTmp['type'] = $sKey;
76  $sName .= '(' . $this->getTagsCount($aParamTmp) . ')';
77  $sHref .= '&filter=' . $aParam['filter'];
78  }
79 
80  if (isset($aParam['date']) && $aParam['date'])
81  $sHref .= '&year=' . $aParam['date']['year'] .
82  '&month=' . $aParam['date']['month'] .
83  '&day=' . $aParam['date']['day'];
84 
85  $aTopMenu[$sName] = array('href' => $sHref, 'dynamic' => true, 'active' => ( $sKey == $aParam['type']));
86  }
87 
88  return $aTopMenu;
89  }
90 
91  function getCategTopMenuHtml($aParam, $iBoxId, $sAction = '')
92  {
93  $aItems = array();
94 
95  $aTopMenu = $this->getCategTopMenu($aParam, $sAction);
96  foreach ($aTopMenu as $sName => $aItem) {
97  $aItems[$sName] = array(
98  'dynamic' => true,
99  'active' => $aItem['active'],
100  'href' => $aItem['href']
101  );
102  }
103  return ChWsbPageView::getBlockCaptionItemCode($iBoxId, $aItems);
104  }
105 
106  function display($aParam, $iBoxId, $sAction = '', $bOrderPanel = false, $iColumns, $sUrl = '')
107  {
108  if (!isset($aParam['type']) || !$aParam['type'])
109  return MsgBox(_t( '_Empty' ));
110 
111  $sPaginate = '';
112  $sCode = '';
113  $sPageUrl = $sUrl ? $sUrl : ch_html_attribute($_SERVER['PHP_SELF']);
114  $sPageUrl .= '?tags_mode=' . $aParam['type'];
115 
116  if (!isset($aParam['orderby']) && isset($_REQUEST['orderby']) && $_REQUEST['orderby'] && isset($this->_aOrderValues[$_REQUEST['orderby']]))
117  $aParam['orderby'] = $_REQUEST['orderby'];
118 
119  if (isset($aParam['filter']) && $aParam['filter'])
120  $sPageUrl .= '&filter=' . $aParam['filter'];
121  if (isset($aParam['orderby']) && $aParam['orderby'])
122  $sPageUrl .= '&orderby=' . $aParam['orderby'];
123  if ($sAction)
124  $sPageUrl .= '&action=' . $sAction;
125  if (isset($aParam['date']) && $aParam['date']) {
126  $sPageUrl .= '&year=' . $aParam['date']['year'] .
127  '&month=' . $aParam['date']['month'] .
128  '&day=' . $aParam['date']['day'];
129  }
130 
131  if (isset($aParam['pagination']) && $aParam['pagination']) {
132  ch_import('ChWsbPaginate');
133 
134  $aPaginate = array(
135  'page_url' => $sPageUrl . '&page={page}&per_page={per_page}',
136  'info' => true,
137  'page_links' => true,
138  'on_change_page' => "!loadDynamicBlock($iBoxId, this.href)"
139  );
140 
141  $aParam['limit'] = $aPaginate['per_page'] = $aParam['pagination'];
142  $aPaginate['count'] = $this->getTagsCount($aParam);
143  $aPaginate['page'] = isset($_REQUEST['page']) ? (int)$_REQUEST['page'] : 1;
144  $aParam['start'] = $aParam['limit'] * ($aPaginate['page'] - 1);
145  if ($aParam['start'] <=0)
146  $aParam['start'] = 0;
147 
148  $oPaginate = new ChWsbPaginate($aPaginate);
149  $sPaginate = '<div class="clear_both"></div>'.$oPaginate->getPaginate();
150  }
151 
152  $sHrefTmpl = $this->getHrefWithType($aParam['type']);
153  $aTotalTags = $this->getTagList($aParam);
154 
155  if ($aTotalTags) {
156  if ($bOrderPanel)
157  $sCode .= $this->_getTopBox($aParam, $iBoxId, $sPageUrl);
158  $sCode .= $this->getCategoriesView($aTotalTags, $sHrefTmpl, $iColumns) . $sPaginate;
159  } else
160  return MsgBox(_t( '_Empty' ));
161 
162  return $sCode;
163  }
164 
165  function setTemplateName($sTmplName)
166  {
167  $this->_sCategTmplName = $sTmplName;
168  }
169 
170  function setTemplateContent($sTmplContent)
171  {
172  $this->_sCategTmplContent = $sTmplContent;
173  }
174 
175  function _getTopBox($aParam, $iBoxId, $sPageUrl)
176  {
178 
179  $aTmplVars = array(
180  'block_id' => $iBoxId,
181  'page_url' => $sPageUrl,
182  'ch_repeat:options' => array()
183  );
184 
185  foreach ($this->_aOrderValues as $sKey => $sVal)
186  $aTmplVars['ch_repeat:options'][] = array(
187  'key' => $sKey,
188  'ch_if:show_selected' => array(
189  'condition' => $sKey == $aParam['orderby'],
190  'content' => array()
191  ),
192  'value' => $sVal
193  );
194  $sTopControls = $oSysTemplate->parseHtmlByName('categories_top_controls.html', $aTmplVars);
195 
196  return $oSysTemplate->parseHtmlByName('designbox_top_controls.html', array('top_controls' => $sTopControls));
197  }
198 }
ChBaseCategories
Definition: ChBaseCategories.php:11
ChBaseCategories\setTemplateContent
setTemplateContent($sTmplContent)
Definition: ChBaseCategories.php:170
ChWsbPageView\getBlockCaptionItemCode
static getBlockCaptionItemCode( $iBlockID, $aLinks)
Definition: ChWsbPageView.php:502
ChWsbCategories\getTagsCount
getTagsCount($aParam)
Definition: ChWsbCategories.php:129
ChBaseCategories\getCategTopMenu
getCategTopMenu($aParam, $sAction='')
Definition: ChBaseCategories.php:65
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
$aUnit
$aUnit
Definition: short_profile_info.php:31
$sCode
$sCode
Definition: explanation.php:19
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChBaseCategories\$_aOrderValues
$_aOrderValues
Definition: ChBaseCategories.php:14
ChBaseCategories\__construct
__construct()
Definition: ChBaseCategories.php:16
$sUrl
$sUrl
Definition: cart.php:15
php
ChBaseCategories\$_sCategTmplContent
$_sCategTmplContent
Definition: ChBaseCategories.php:13
ChBaseCategories\$_sCategTmplName
$_sCategTmplName
Definition: ChBaseCategories.php:12
ChWsbCategories
Definition: ChWsbCategories.php:13
ch_html_attribute
ch_html_attribute($mixedInput)
Definition: utils.inc.php:1324
ChBaseCategories\getCategTopMenuHtml
getCategTopMenuHtml($aParam, $iBoxId, $sAction='')
Definition: ChBaseCategories.php:91
ChWsbTags\getHrefWithType
getHrefWithType($sType)
Definition: ChWsbTags.php:185
htmlspecialchars_adv
htmlspecialchars_adv($string)
Definition: utils.inc.php:302
title2uri
title2uri($sValue)
Definition: utils.inc.php:42
$_REQUEST
$_REQUEST['action']
Definition: cmd.php:11
ChWsbPaginate
Definition: ChWsbPaginate.php:69
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
ChBaseCategories\_getTopBox
_getTopBox($aParam, $iBoxId, $sPageUrl)
Definition: ChBaseCategories.php:175
ChBaseCategories\setTemplateName
setTemplateName($sTmplName)
Definition: ChBaseCategories.php:165
ChWsbCategories\getTagList
getTagList($aParam)
Definition: ChWsbCategories.php:88
ChBaseCategories\getCategoriesView
getCategoriesView($aTotalCategories, $sHrefTempl, $iColumns)
Definition: ChBaseCategories.php:25
$sAction
$sAction
Definition: categories.php:274
$oSysTemplate
$oSysTemplate
Definition: params.inc.php:22
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChBaseCategories\display
display($aParam, $iBoxId, $sAction='', $bOrderPanel=false, $iColumns, $sUrl='')
Definition: ChBaseCategories.php:106