Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • 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
  • cApiArticleLanguageVersion
  • cApiArticleLanguageVersionCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiContentVersion
  • cApiContentVersionCollection
  • 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
  • cApiMetaTagVersion
  • cApiMetaTagVersionCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiSearchTracking
  • cApiSearchTrackingCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserPasswordRequest
  • cApiUserPasswordRequestCollection
  • 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:  * @author Timo Hummel
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Category article collection
 18:  *
 19:  * @package Core
 20:  * @subpackage GenericDB_Model
 21:  */
 22: class cApiCategoryArticleCollection extends ItemCollection {
 23:     /**
 24:      * Constructor to create an instance of this class.
 25:      *
 26:      * @param bool $select [optional]
 27:      *                     where clause to use for selection (see ItemCollection::select())
 28:      *
 29:      * @throws cDbException
 30:      * @throws cInvalidArgumentException
 31:      */
 32:     public function __construct($select = false) {
 33:         global $cfg;
 34:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
 35:         $this->_setItemClass('cApiCategoryArticle');
 36: 
 37:         // set the join partners so that joins can be used via link() method
 38:         $this->_setJoinPartner('cApiCategoryCollection');
 39:         $this->_setJoinPartner('cApiArticleCollection');
 40: 
 41:         if ($select !== false) {
 42:             $this->select($select);
 43:         }
 44:     }
 45: 
 46:     /**
 47:      * Creates an article item entry
 48:      *
 49:      * @param int    $idcat
 50:      * @param int    $idart
 51:      * @param int    $status       [optional]
 52:      * @param string $author       [optional]
 53:      * @param string $created      [optional]
 54:      * @param string $lastmodified [optional]
 55:      * @param int    $createcode   [optional]
 56:      *
 57:      * @return cApiCategoryArticle
 58:      *
 59:      * @throws cDbException
 60:      * @throws cException
 61:      * @throws cInvalidArgumentException
 62:      */
 63:     public function create($idcat, $idart, $status = 0, $author = "", $created = "", $lastmodified = "", $createcode = 1) {
 64:         global $auth;
 65: 
 66:         if (empty($author)) {
 67:             $author = $auth->auth['uname'];
 68:         }
 69:         if (empty($created)) {
 70:             $created = date('Y-m-d H:i:s');
 71:         }
 72:         if (empty($lastmodified)) {
 73:             $lastmodified = date('Y-m-d H:i:s');
 74:         }
 75: 
 76:         $item = $this->createNewItem();
 77: 
 78:         $item->set('idcat', $idcat);
 79:         $item->set('idart', $idart);
 80:         $item->set('status', $status);
 81:         $item->set('author', $author);
 82:         $item->set('created', $created);
 83:         $item->set('lastmodified', $lastmodified);
 84:         $item->set('createcode', $createcode);
 85: 
 86:         $item->store();
 87:         return $item;
 88:     }
 89: 
 90:     /**
 91:      * Returns the first category article available entry from category tree by
 92:      * client id and language id.
 93:      * Build a complex query trough several tables to get a ordered tree
 94:      * structure
 95:      * and returns first available category article item.
 96:      *
 97:      * @param int $client
 98:      * @param int $lang
 99:      *
100:      * @return cApiCategoryArticle|NULL
101:      * 
102:      * @throws cDbException
103:      */
104:     public function fetchFirstFromTreeByClientIdAndLangId($client, $lang) {
105:         global $cfg;
106: 
107:         $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";
108: 
109:         $params = array(
110:             'cat_art' => $this->table,
111:             'cat_tree' => $cfg['tab']['cat_tree'],
112:             'cat' => $cfg['tab']['cat'],
113:             'cat_lang' => $cfg['tab']['cat_lang'],
114:             'art_lang' => $cfg['tab']['art_lang'],
115:             'lang' => (int) $lang,
116:             'client' => (int) $client
117:         );
118: 
119:         $sql = $this->db->prepare($sql, $params);
120:         $this->db->query($sql);
121:         if ($this->db->nextRecord()) {
122:             $oItem = new cApiCategoryArticle();
123:             $oItem->loadByRecordSet($this->db->toArray());
124:             return $oItem;
125:         }
126:         return NULL;
127:     }
128: 
129:     /**
130:      * Returns a category article entry by category id and article id.
131:      *
132:      * @param int $idcat
133:      * @param int $idart
134:      *
135:      * @return cApiCategoryArticle|NULL
136:      *
137:      * @throws cDbException
138:      * @throws cException
139:      */
140:     public function fetchByCategoryIdAndArticleId($idcat, $idart) {
141:         $aProps = array(
142:             'idcat' => $idcat,
143:             'idart' => $idart
144:         );
145:         $aRecordSet = $this->_oCache->getItemByProperties($aProps);
146:         if ($aRecordSet) {
147:             // entry in cache found, load entry from cache
148:             $oItem = new cApiCategoryArticle();
149:             $oItem->loadByRecordSet($aRecordSet);
150:             return $oItem;
151:         } else {
152:             $this->select('idcat = ' . (int) $idcat . ' AND idart = ' . (int) $idart);
153:             return $this->next();
154:         }
155:     }
156: 
157:     /**
158:      * Returns a category article id by category id and article id.
159:      *
160:      * @param int $idcat
161:      * @param int $idart
162:      *
163:      * @return int|NULL
164:      *
165:      * @throws cDbException
166:      */
167:     public function getIdByCategoryIdAndArticleId($idcat, $idart) {
168:         $where = $this->db->prepare("idcat = %d AND idart = %d", $idcat, $idart);
169:         $aIds = $this->getIdsByWhereClause($where);
170:         return (count($aIds) > 0) ? $aIds[0] : NULL;
171:     }
172: 
173:     /**
174:      * Returns all category article ids by client id.
175:      *
176:      * @param int $idclient
177:      *
178:      * @return array
179:      *
180:      * @throws cDbException
181:      */
182:     public function getAllIdsByClientId($idclient) {
183:         global $cfg;
184: 
185:         $aIds = array();
186: 
187:         $sql = "SELECT A.idcatart FROM `%s` as A, `%s` as B WHERE B.idclient = %d AND B.idcat = A.idcat";
188:         $this->db->query($sql, $this->table, $cfg['tab']['cat'], $idclient);
189:         while ($this->db->nextRecord()) {
190:             $aIds[] = $this->db->f('idcatart');
191:         }
192: 
193:         return $aIds;
194:     }
195: 
196:     /**
197:      * Returns all available category ids of entries having a secific article id
198:      *
199:      * @param int $idart
200:      * 
201:      * @return array
202:      * 
203:      * @throws cDbException
204:      */
205:     public function getCategoryIdsByArticleId($idart) {
206:         $aIdCats = array();
207: 
208:         $sql = "SELECT idcat FROM `:cat_art` WHERE idart=:idart";
209:         $sql = $this->db->prepare($sql, array(
210:             'cat_art' => $this->table,
211:             'idart' => (int) $idart
212:         ));
213:         $this->db->query($sql);
214: 
215:         while ($this->db->nextRecord()) {
216:             $aIdCats[] = $this->db->f('idcat');
217:         }
218: 
219:         return $aIdCats;
220:     }
221: 
222:     /**
223:      * Checks, if passed category contains any articles in specified language.
224:      *
225:      * @param int $idcat
226:      *         Category id
227:      * @param int $idlang
228:      *         Language id
229:      * 
230:      * @return bool
231:      * 
232:      * @throws cDbException
233:      */
234:     public function getHasArticles($idcat, $idlang) {
235:         global $cfg;
236: 
237:         $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";
238:         $sql = $this->db->prepare($sql, array(
239:             'cat_art' => $this->table,
240:             'art_lang' => $cfg['tab']['art_lang'],
241:             'idcat' => $idcat,
242:             'idlang' => $idlang
243:         ));
244:         $this->db->query($sql);
245: 
246:         return ($this->db->nextRecord()) ? true : false;
247:     }
248: 
249:     /**
250:      * Sets 'createcode' flag for one or more category articles.
251:      *
252:      * @param int|array $idcatart
253:      *                              One category article id or list of category article ids
254:      * @param int       $createcode [optional]
255:      *                              Create code state, either 1 or 0.
256:      *
257:      * @return int
258:      *                              Number of updated entries
259:      *
260:      * @throws cDbException
261:      */
262:     public function setCreateCodeFlag($idcatart, $createcode = 1) {
263:         $createcode = ($createcode == 1) ? 1 : 0;
264:         if (is_array($idcatart)) {
265:             // Multiple ids
266:             if (count($idcatart) == 0) {
267:                 return;
268:             }
269:             foreach ($idcatart as $pos => $id) {
270:                 $idcatart[$pos] = (int) $id;
271:             }
272:             $inSql = implode(', ', $idcatart);
273:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart IN (" . $inSql . ")";
274:             $sql = $this->db->prepare($sql, $this->table, $createcode);
275:         } else {
276:             // Single id
277:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart = %d";
278:             $sql = $this->db->prepare($sql, $this->table, $createcode, $idcatart);
279:         }
280:         $this->db->query($sql);
281:         return $this->db->affectedRows();
282:     }
283: }
284: 
285: /**
286:  * Category article item
287:  *
288:  * @package Core
289:  * @subpackage GenericDB_Model
290:  */
291: class cApiCategoryArticle extends Item
292: {
293:     /**
294:      * Constructor to create an instance of this class.
295:      *
296:      * @param mixed $mId [optional]
297:      *                   Specifies the ID of item to load
298:      *
299:      * @throws cDbException
300:      * @throws cException
301:      */
302:     public function __construct($mId = false) {
303:         global $cfg;
304:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
305:         $this->setFilters(array(), array());
306:         if ($mId !== false) {
307:             $this->loadByPrimaryKey($mId);
308:         }
309:     }
310: 
311:     /**
312:      * Userdefined setter for category article fields.
313:      *
314:      * @param string $name
315:      * @param mixed $value
316:      * @param bool $bSafe [optional]
317:      *         Flag to run defined inFilter on passed value
318:      * @return bool
319:      */
320:     public function setField($name, $value, $bSafe = true) {
321:         switch ($name) {
322:             case 'idcat':
323:                 $value = cSecurity::toInteger($value);
324:                 break;
325:             case 'idart':
326:                 $value = cSecurity::toInteger($value);
327:                 break;
328:             case 'status':
329:                 $value = cSecurity::toInteger($value);
330:                 break;
331:             case 'createcode':
332:                 $value = ($value == 1) ? 1 : 0;
333:                 break;
334:         }
335: 
336:         return parent::setField($name, $value, $bSafe);
337:     }
338: 
339: }
340: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0