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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • 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:     /**
 25:      * Create a new collection of items.
 26:      *
 27:      * @param string $select [optional]
 28:      *         where clause to use for selection (see ItemCollection::select())
 29:      */
 30:     public function __construct($select = false) {
 31:         global $cfg;
 32:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
 33:         $this->_setItemClass('cApiCategoryArticle');
 34: 
 35:         // set the join partners so that joins can be used via link() method
 36:         $this->_setJoinPartner('cApiCategoryCollection');
 37:         $this->_setJoinPartner('cApiArticleCollection');
 38: 
 39:         if ($select !== false) {
 40:             $this->select($select);
 41:         }
 42:     }
 43: 
 44:     /**
 45:      * Creates an article item entry
 46:      *
 47:      * @param int $idcat
 48:      * @param int $idart
 49:      * @param int $status [optional]
 50:      * @param string $author [optional]
 51:      * @param string $created [optional]
 52:      * @param string $lastmodified [optional]
 53:      * @param int $createcode [optional]
 54:      * @return cApiCategoryArticle
 55:      */
 56:     public function create($idcat, $idart, $status = 0, $author = "", $created = "", $lastmodified = "", $createcode = 1) {
 57:         global $auth;
 58: 
 59:         if (empty($author)) {
 60:             $author = $auth->auth['uname'];
 61:         }
 62:         if (empty($created)) {
 63:             $created = date('Y-m-d H:i:s');
 64:         }
 65:         if (empty($lastmodified)) {
 66:             $lastmodified = date('Y-m-d H:i:s');
 67:         }
 68: 
 69:         $item = $this->createNewItem();
 70: 
 71:         $item->set('idcat', $idcat);
 72:         $item->set('idart', $idart);
 73:         $item->set('status', $status);
 74:         $item->set('author', $author);
 75:         $item->set('created', $created);
 76:         $item->set('lastmodified', $lastmodified);
 77:         $item->set('createcode', $createcode);
 78: 
 79:         $item->store();
 80:         return $item;
 81:     }
 82: 
 83:     /**
 84:      * Returns the first category article available entry from category tree by
 85:      * client id and language id.
 86:      * Build a complex query trough several tables to get a ordered tree
 87:      * structure
 88:      * and returns first available category article item.
 89:      *
 90:      * @param int $client
 91:      * @param int $lang
 92:      * @return cApiCategoryArticle|NULL
 93:      */
 94:     public function fetchFirstFromTreeByClientIdAndLangId($client, $lang) {
 95:         global $cfg;
 96: 
 97:         $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";
 98: 
 99:         $params = array(
100:             'cat_art' => $this->table,
101:             'cat_tree' => $cfg['tab']['cat_tree'],
102:             'cat' => $cfg['tab']['cat'],
103:             'cat_lang' => $cfg['tab']['cat_lang'],
104:             'art_lang' => $cfg['tab']['art_lang'],
105:             'lang' => (int) $lang,
106:             'client' => (int) $client
107:         );
108: 
109:         $sql = $this->db->prepare($sql, $params);
110:         $this->db->query($sql);
111:         if ($this->db->nextRecord()) {
112:             $oItem = new cApiCategoryArticle();
113:             $oItem->loadByRecordSet($this->db->toArray());
114:             return $oItem;
115:         }
116:         return NULL;
117:     }
118: 
119:     /**
120:      * Returns a category article entry by category id and article id.
121:      *
122:      * @param int $idcat
123:      * @param int $idart
124:      * @return cApiCategoryArticle|NULL
125:      */
126:     public function fetchByCategoryIdAndArticleId($idcat, $idart) {
127:         $aProps = array(
128:             'idcat' => $idcat,
129:             'idart' => $idart
130:         );
131:         $aRecordSet = $this->_oCache->getItemByProperties($aProps);
132:         if ($aRecordSet) {
133:             // entry in cache found, load entry from cache
134:             $oItem = new cApiCategoryArticle();
135:             $oItem->loadByRecordSet($aRecordSet);
136:             return $oItem;
137:         } else {
138:             $this->select('idcat = ' . (int) $idcat . ' AND idart = ' . (int) $idart);
139:             return $this->next();
140:         }
141:     }
142: 
143:     /**
144:      * Returns a category article id by category id and article id.
145:      *
146:      * @param int $idcat
147:      * @param int $idart
148:      * @return int|NULL
149:      */
150:     public function getIdByCategoryIdAndArticleId($idcat, $idart) {
151:         $where = "idcat = %d AND idart = %d";
152:         $where = $this->db->prepare("idcat = %d AND idart = %d", $idcat, $idart);
153:         $aIds = $this->getIdsByWhereClause($where);
154:         return (count($aIds) > 0) ? $aIds[0] : NULL;
155:     }
156: 
157:     /**
158:      * Returns all category article ids by client id.
159:      *
160:      * @param int $idclient
161:      * @return array
162:      */
163:     public function getAllIdsByClientId($idclient) {
164:         global $cfg;
165: 
166:         $aIds = array();
167: 
168:         $sql = "SELECT A.idcatart FROM `%s` as A, `%s` as B WHERE B.idclient = %d AND B.idcat = A.idcat";
169:         $this->db->query($sql, $this->table, $cfg['tab']['cat'], $idclient);
170:         while ($this->db->nextRecord()) {
171:             $aIds[] = $this->db->f('idcatart');
172:         }
173: 
174:         return $aIds;
175:     }
176: 
177:     /**
178:      * Returns all available category ids of entries having a secific article id
179:      *
180:      * @param int $idart
181:      * @return array
182:      */
183:     public function getCategoryIdsByArticleId($idart) {
184:         $aIdCats = array();
185: 
186:         $sql = "SELECT idcat FROM `:cat_art` WHERE idart=:idart";
187:         $sql = $this->db->prepare($sql, array(
188:             'cat_art' => $this->table,
189:             'idart' => (int) $idart
190:         ));
191:         $this->db->query($sql);
192: 
193:         while ($this->db->nextRecord()) {
194:             $aIdCats[] = $this->db->f('idcat');
195:         }
196: 
197:         return $aIdCats;
198:     }
199: 
200:     /**
201:      * Checks, if passed category contains any articles in specified language.
202:      *
203:      * @param int $idcat
204:      *         Category id
205:      * @param int $idlang
206:      *         Language id
207:      * @return bool
208:      */
209:     public function getHasArticles($idcat, $idlang) {
210:         global $cfg;
211: 
212:         $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";
213:         $sql = $this->db->prepare($sql, array(
214:             'cat_art' => $this->table,
215:             'art_lang' => $cfg['tab']['art_lang'],
216:             'idcat' => $idcat,
217:             'idlang' => $idlang
218:         ));
219:         $this->db->query($sql);
220: 
221:         return ($this->db->nextRecord()) ? true : false;
222:     }
223: 
224:     /**
225:      * Sets 'createcode' flag for one or more category articles.
226:      *
227:      * @param int|array $idcatart
228:      *         One category article id or list of category article ids
229:      * @param int $createcode [optional]
230:      *         Create code state, either 1 or 0.
231:      * @return int
232:      *         Number of updated entries
233:      */
234:     public function setCreateCodeFlag($idcatart, $createcode = 1) {
235:         $createcode = ($createcode == 1) ? 1 : 0;
236:         if (is_array($idcatart)) {
237:             // Multiple ids
238:             if (count($idcatart) == 0) {
239:                 return;
240:             }
241:             foreach ($idcatart as $pos => $id) {
242:                 $idcatart[$pos] = (int) $id;
243:             }
244:             $inSql = implode(', ', $idcatart);
245:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart IN (" . $inSql . ")";
246:             $sql = $this->db->prepare($sql, $this->table, $createcode);
247:         } else {
248:             // Single id
249:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart = %d";
250:             $sql = $this->db->prepare($sql, $this->table, $createcode, $idcatart);
251:         }
252:         $this->db->query($sql);
253:         return $this->db->affectedRows();
254:     }
255: }
256: 
257: /**
258:  * Category article item
259:  *
260:  * @package Core
261:  * @subpackage GenericDB_Model
262:  */
263: class cApiCategoryArticle extends Item {
264: 
265:     /**
266:      * Constructor Function
267:      *
268:      * @param mixed $mId [optional]
269:      *         Specifies the ID of item to load
270:      */
271:     public function __construct($mId = false) {
272:         global $cfg;
273:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
274:         $this->setFilters(array(), array());
275:         if ($mId !== false) {
276:             $this->loadByPrimaryKey($mId);
277:         }
278:     }
279: 
280:     /**
281:      * Userdefined setter for category article fields.
282:      *
283:      * @param string $name
284:      * @param mixed $value
285:      * @param bool $bSafe [optional]
286:      *         Flag to run defined inFilter on passed value
287:      * @return bool
288:      */
289:     public function setField($name, $value, $bSafe = true) {
290:         switch ($name) {
291:             case 'idcat':
292:                 $value = cSecurity::toInteger($value);
293:                 break;
294:             case 'idart':
295:                 $value = cSecurity::toInteger($value);
296:                 break;
297:             case 'status':
298:                 $value = cSecurity::toInteger($value);
299:                 break;
300:             case 'createcode':
301:                 $value = ($value == 1) ? 1 : 0;
302:                 break;
303:         }
304: 
305:         return parent::setField($name, $value, $bSafe);
306:     }
307: 
308: }
309: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0