Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiAction
  • cApiActionCollection
  • cApiActionlog
  • cApiActionlogCollection
  • cApiArea
  • cApiAreaCollection
  • cApiArticle
  • cApiArticleCollection
  • cApiArticleLanguage
  • cApiArticleLanguageCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiDbfs
  • cApiDbfsCollection
  • cApiFile
  • cApiFileCollection
  • cApiFileInformation
  • cApiFileInformationCollection
  • cApiFrameFile
  • cApiFrameFileCollection
  • cApiFrontendGroup
  • cApiFrontendGroupCollection
  • cApiFrontendGroupMember
  • cApiFrontendGroupMemberCollection
  • cApiFrontendPermission
  • cApiFrontendPermissionCollection
  • cApiFrontendUser
  • cApiFrontendUserCollection
  • cApiGroup
  • cApiGroupCollection
  • cApiGroupMember
  • cApiGroupMemberCollection
  • cApiGroupProperty
  • cApiGroupPropertyCollection
  • cApiInUse
  • cApiInUseCollection
  • cApiIso3166
  • cApiIso3166Collection
  • cApiIso6392
  • cApiIso6392Collection
  • cApiKeyword
  • cApiKeywordCollection
  • cApiLanguage
  • cApiLanguageCollection
  • cApiLayout
  • cApiLayoutCollection
  • cApiMailLog
  • cApiMailLogCollection
  • cApiMailLogSuccess
  • cApiMailLogSuccessCollection
  • cApiMetaTag
  • cApiMetaTagCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the category article collection and item class.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       GenericDB_Model
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Timo Hummel
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Category article collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiCategoryArticleCollection extends ItemCollection {
 25: 
 26:     public function __construct($select = false) {
 27:         global $cfg;
 28:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
 29:         $this->_setItemClass('cApiCategoryArticle');
 30: 
 31:         // set the join partners so that joins can be used via link() method
 32:         $this->_setJoinPartner('cApiCategoryCollection');
 33:         $this->_setJoinPartner('cApiArticleCollection');
 34: 
 35:         if ($select !== false) {
 36:             $this->select($select);
 37:         }
 38:     }
 39: 
 40:     /**
 41:      * Creates an article item entry
 42:      *
 43:      * @param int $idcat
 44:      * @param int $idart
 45:      * @param int $status
 46:      * @param string $author
 47:      * @param string $created
 48:      * @param string $lastmodified
 49:      * @param int $createcode
 50:      * @return cApiCategoryArticle
 51:      */
 52:     public function create($idcat, $idart, $status = 0, $author = "", $created = "", $lastmodified = "", $createcode = 1) {
 53:         global $auth;
 54: 
 55:         if (empty($author)) {
 56:             $author = $auth->auth['uname'];
 57:         }
 58:         if (empty($created)) {
 59:             $created = date('Y-m-d H:i:s');
 60:         }
 61:         if (empty($lastmodified)) {
 62:             $lastmodified = date('Y-m-d H:i:s');
 63:         }
 64: 
 65:         $item = parent::createNewItem();
 66: 
 67:         $item->set('idcat', (int) $idcat);
 68:         $item->set('idart', (int) $idart);
 69:         $item->set('status', (int) $status);
 70:         $item->set('author', $this->escape($author));
 71:         $item->set('created', $this->escape($created));
 72:         $item->set('lastmodified', $this->escape($lastmodified));
 73:         $item->set('createcode', ($createcode == 1)? 1 : 0);
 74: 
 75:         $item->store();
 76:         return $item;
 77:     }
 78: 
 79:     /**
 80:      * Returns the first category article available entry from category tree by
 81:      * client id and language id.
 82:      * Build a complex query trough several tables to get a ordered tree
 83:      * structure
 84:      * and returns first available category article item.
 85:      *
 86:      * @param int $client
 87:      * @param int $lang
 88:      * @return cApiCategoryArticle null
 89:      */
 90:     public function fetchFirstFromTreeByClientIdAndLangId($client, $lang) {
 91:         global $cfg;
 92: 
 93:         $sql = "SELECT A.* FROM `:cat_art` AS A, `:cat_tree` AS B, `:cat` AS C, `:cat_lang` AS D, `:art_lang` AS E " . "WHERE A.idcat = B.idcat AND B.idcat = C.idcat AND D.startidartlang = E.idartlang AND D.idlang = :lang AND E.idart = A.idart AND E.idlang = :lang AND idclient = :client " . "ORDER BY idtree ASC LIMIT 1";
 94: 
 95:         $params = array(
 96:             'cat_art' => $this->table,
 97:             'cat_tree' => $cfg['tab']['cat_tree'],
 98:             'cat' => $cfg['tab']['cat'],
 99:             'cat_lang' => $cfg['tab']['cat_lang'],
100:             'art_lang' => $cfg['tab']['art_lang'],
101:             'lang' => (int) $lang,
102:             'client' => (int) $client
103:         );
104: 
105:         $sql = $this->db->prepare($sql, $params);
106:         $this->db->query($sql);
107:         if ($this->db->nextRecord()) {
108:             $oItem = new cApiCategoryArticle();
109:             $oItem->loadByRecordSet($this->db->toArray());
110:             return $oItem;
111:         }
112:         return null;
113:     }
114: 
115:     /**
116:      * Returns a category article entry by category id and article id.
117:      *
118:      * @param int $idcat
119:      * @param int $idart
120:      * @return cApiCategoryArticle|null
121:      */
122:     public function fetchByCategoryIdAndArticleId($idcat, $idart) {
123:         $aProps = array(
124:             'idcat' => $idcat,
125:             'idart' => $idart
126:         );
127:         $aRecordSet = $this->_oCache->getItemByProperties($aProps);
128:         if ($aRecordSet) {
129:             // entry in cache found, load entry from cache
130:             $oItem = new cApiCategoryArticle();
131:             $oItem->loadByRecordSet($aRecordSet);
132:             return $oItem;
133:         } else {
134:             $this->select('idcat = ' . (int) $idcat . ' AND idart = ' . (int) $idart);
135:             return $this->next();
136:         }
137:     }
138: 
139:     /**
140:      * Returns a category article id by category id and article id.
141:      *
142:      * @param int $idcat
143:      * @param int $idart
144:      * @return int|null
145:      */
146:     public function getIdByCategoryIdAndArticleId($idcat, $idart) {
147:         $where = "idcat = %d AND idart = %d";
148:         $where = $this->db->prepare("idcat = %d AND idart = %d", $idcat, $idart);
149:         $aIds = $this->getIdsByWhereClause($where);
150:         return (count($aIds) > 0)? $aIds[0] : null;
151:     }
152: 
153:     /**
154:      * Returns all category article ids by client id.
155:      *
156:      * @param int $idclient
157:      * @return array
158:      */
159:     public function getAllIdsByClientId($idclient) {
160:         global $cfg;
161: 
162:         $aIds = array();
163: 
164:         $sql = "SELECT A.idcatart FROM `%s` as A, `%s` as B WHERE B.idclient = %d AND B.idcat = A.idcat";
165:         $this->db->query($sql, $this->table, $cfg['tab']['cat'], $idclient);
166:         while ($this->db->nextRecord()) {
167:             $aIds[] = $this->db->f('idcatart');
168:         }
169: 
170:         return $aIds;
171:     }
172: 
173:     /**
174:      * Returns all available category ids of entries having a secific article id
175:      *
176:      * @param int $idart
177:      * @return array
178:      */
179:     public function getCategoryIdsByArticleId($idart) {
180:         $aIdCats = array();
181: 
182:         $sql = "SELECT idcat FROM `:cat_art` WHERE idart=:idart";
183:         $sql = $this->db->prepare($sql, array(
184:             'cat_art' => $this->table,
185:             'idart' => (int) $idart
186:         ));
187:         $this->db->query($sql);
188: 
189:         while ($this->db->nextRecord()) {
190:             $aIdCats[] = $this->db->f('idcat');
191:         }
192: 
193:         return $aIdCats;
194:     }
195: 
196:     /**
197:      * Checks, if passed category contains any articles in specified language.
198:      *
199:      * @param int $idcat Category id
200:      * @param int $idlang Language id
201:      * @return bool
202:      */
203:     public function getHasArticles($idcat, $idlang) {
204:         global $cfg;
205: 
206:         $sql = "SELECT b.idartlang AS idartlang FROM `:cat_art` AS a, `:art_lang` AS b " . "WHERE a.idcat = :idcat AND a.idart = b.idart AND b.idlang = :idlang";
207:         $sql = $this->db->prepare($sql, array(
208:             'cat_art' => $this->table,
209:             'art_lang' => $cfg['tab']['art_lang'],
210:             'idcat' => $idcat,
211:             'idlang' => $idlang
212:         ));
213:         $this->db->query($sql);
214: 
215:         return ($this->db->nextRecord())? true : false;
216:     }
217: 
218:     /**
219:      * Sets 'createcode' flag for one or more category articles.
220:      *
221:      * @param int|array $idcatart One category article id or list of category
222:      *        article ids
223:      * @param int $createcode Create code state, either 1 or 0.
224:      * @return int Number of updated entries
225:      */
226:     public function setCreateCodeFlag($idcatart, $createcode = 1) {
227:         $createcode = ($createcode == 1)? 1 : 0;
228:         if (is_array($idcatart)) {
229:             // Multiple ids
230:             if (count($idcatart) == 0) {
231:                 return;
232:             }
233:             foreach ($idcatart as $pos => $id) {
234:                 $idcatart[$pos] = (int) $id;
235:             }
236:             $inSql = implode(', ', $idcatart);
237:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart IN (" . $inSql . ")";
238:             $sql = $this->db->prepare($sql, $this->table, $createcode);
239:         } else {
240:             // Single id
241:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart = %d";
242:             $sql = $this->db->prepare($sql, $this->table, $createcode, $idcatart);
243:         }
244:         $this->db->query($sql);
245:         return $this->db->affectedRows();
246:     }
247: 
248: }
249: 
250: /**
251:  * Category article item
252:  *
253:  * @package Core
254:  * @subpackage GenericDB_Model
255:  */
256: class cApiCategoryArticle extends Item {
257: 
258:     /**
259:      * Constructor Function
260:      *
261:      * @param mixed $mId Specifies the ID of item to load
262:      */
263:     public function __construct($mId = false) {
264:         global $cfg;
265:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
266:         $this->setFilters(array(), array());
267:         if ($mId !== false) {
268:             $this->loadByPrimaryKey($mId);
269:         }
270:     }
271: }
272: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0