8 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbTags.php');
10 define(
"CATEGORIES_DIVIDER",
';');
18 parent::__construct();
19 $this->iViewer = (int)$iPossOwner > 0 ? (
int)$iPossOwner :
$this->iViewer;
20 $this->sCacheFile =
'sys_objects_categories';
21 $this->sNonParseParams =
'tags_non_parsable';
22 $this->sCacheTable =
'sys_objects_categories';
23 $this->sTagTable =
'sys_categories';
24 $this->aTagFields = array(
32 $this->sAutoApprovePrefix =
'category_auto_app_';
33 $this->bToLower =
false;
39 $a = array(
'' =>
_t(
'_Please_Select_')) + (is_array($a) ? $a : array());
41 $aCustomValues = $this->
explodeTags($sCustomValues);
42 foreach($aCustomValues
as $iIndex => $sValue)
43 $a[$sValue] = $sValue;
46 'type' =>
'select_box',
47 'name' =>
'Categories',
48 'caption' =>
_t(
'_Categories'),
53 'error' =>
_t (
'_sys_err_categories'),
56 'pass' =>
'Categories',
65 $iOwnerId = (int)$iOwnerId;
66 $sqlQuery =
"SELECT `cat`.`{$this->aTagFields['tag']}`
67 FROM `{$this->sTagTable}` `cat`
68 WHERE (`cat`.`{$this->aTagFields['owner']}` = 0 OR `cat`.`{$this->aTagFields['owner']}` = $iOwnerId)
69 AND `cat`.`{$this->aTagFields['type']}` = '$sType' AND `cat`.`{$this->aTagFields['status']}` = 'active'
71 GROUP BY `cat`.`{$this->aTagFields['tag']}`";
78 $aAddSql[] =
" AND `cat`.`{$this->aTagFields['status']}` = 'active'";
81 foreach ($aAddSql
as $sValue)
84 $sqlQuery = str_replace(
'__sqlAdd__', $sqlAdd, $sqlQuery);
85 return $bForm ? $this->oDb->getPairs($sqlQuery, $this->aTagFields[
'tag'], $this->aTagFields[
'tag']) : $this->oDb->getColumn($sqlQuery);
92 $aTotalTags = array();
93 $sGroupBy =
"GROUP BY `{$this->aTagFields['tag']}`";
95 if (isset($aParam[
'limit'])) {
97 if (isset($aParam[
'start']))
98 $sLimit .= (int)$aParam[
'start'] .
', ';
99 $sLimit .= (int)$aParam[
'limit'];
104 if (isset($aParam[
'orderby'])) {
105 if ($aParam[
'orderby'] ==
'popular')
106 $sGroupBy .=
" ORDER BY `count` DESC, `{$this->aTagFields['tag']}` ASC";
107 else if ($aParam[
'orderby'] ==
'recent')
108 $sGroupBy .=
" ORDER BY `{$this->aTagFields['date']}` DESC, `{$this->aTagFields['tag']}` ASC";
114 `tgs`.`{$this->aTagFields['tag']}` as `{$this->aTagFields['tag']}`,
115 `tgs`.`{$this->aTagFields['date']}` as `{$this->aTagFields['date']}`,
116 COUNT(`tgs`.`{$this->aTagFields['id']}`) AS `count`
117 FROM `{$this->sTagTable}` `tgs` $sCondition $sGroupBy $sLimit";
119 $aTags = $this->oDb->getAll($sqlQuery);
120 if (count($aTags) > 0) {
121 foreach($aTags
as $aTag) {
122 if ((
int)$aTag[
'count'] > 0)
123 $aTotalTags[$aTag[$this->aTagFields[
'tag']]] = $aTag[
'count'];
132 $sqlQuery =
"SELECT count(DISTINCT `tgs`.`{$this->aTagFields['tag']}`) AS `count` FROM
133 `{$this->sTagTable}` `tgs` {$sCondition}";
135 return (
int)$this->oDb->getOne($sqlQuery);
140 $sCondition =
"WHERE `tgs`.`{$this->aTagFields['owner']}` != 0";
145 if (isset($aParam[
'common'])) {
148 if (is_array($aUnitsCommon)) {
149 foreach ($aUnitsCommon
as $sUnit)
151 $sCatsList = substr($sCatsList, 0, -3);
153 $sCondition .=
" AND `tgs`.`{$this->aTagFields['tag']}` " . (!$aParam[
'common'] ?
'NOT' :
'') .
154 " IN ('" . $sCatsList .
"')";
157 if (isset($aParam[
'type']) && $aParam[
'type'])
158 $sCondition .=
" AND `tgs`.`{$this->aTagFields['type']}` = '{$aParam['type']}'";
160 if (isset($aParam[
'status']) && $aParam[
'status'])
161 $sCondition .=
" AND tgs.`{$this->aTagFields['status']}` = '{$aParam['status']}'";
163 $sCondition .=
" AND tgs.`{$this->aTagFields['status']}` = 'active'";
165 if (isset($aParam[
'filter']) && $aParam[
'filter'])
166 $sCondition .=
" AND `tgs`.`{$this->aTagFields['tag']}` LIKE '%{$aParam['filter']}%'";
168 if (isset($aParam[
'date']) && $aParam[
'date'])
169 $sCondition .=
" AND DATE(`tgs`.`{$this->aTagFields['date']}`) = DATE('{$aParam['date']['year']}-{$aParam['date']['month']}-{$aParam['date']['day']}')";
176 $sCondModule = strlen(
$sModule) > 0 ?
"AND `Type` = '$sModule'" :
'';
177 return $this->oDb->getColumn(
"SELECT `Category` FROM `sys_categories` WHERE `Owner` = 0 $sCondModule");
182 $aTags = $this->
explodeTags($aTagsSet[
'tagString']);
186 foreach ($this->aTagFields
as $sKey => $sValue)
187 $sFields .= $sValue .
', ';
190 $bAutoApprove =
getParam($this->sAutoApprovePrefix . $aTagsSet[
'type']) ==
'on';
192 $sFields = trim($sFields,
', ');
194 foreach( $aTags
as $sTag ) {
196 $aTagsSet[
'status'] = $bAutoApprove || in_array($aTagsSet[
'tag'], $aCommonCat) ?
'active' :
'passive';
197 $sValues .=
"('{$aTagsSet['id']}', '{$aTagsSet['type']}', '{$aTagsSet['tag']}', '{$aTagsSet['owner']}', '{$aTagsSet['status']}', CURRENT_TIMESTAMP), ";
199 $sValues = trim($sValues,
', ');
201 $sqlQuery =
"INSERT INTO `{$this->sTagTable}` ($sFields) VALUES $sValues";
202 $this->oDb->query($sqlQuery);