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
    • 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: /**
  4:  * This file contains the group property collection and item class.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       GenericDB_Model
  8:  * @author           Murat Purc <murat@purc.de>
  9:  * @copyright        four for business AG <www.4fb.de>
 10:  * @license          http://www.contenido.org/license/LIZENZ.txt
 11:  * @link             http://www.4fb.de
 12:  * @link             http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: /**
 18:  * Group property collection.
 19:  *
 20:  * The cApiGroupPropertyCollection class keeps also track of changed and deleted
 21:  * properties and synchronizes them with cached values, as long as you use the
 22:  * interface of cApiGroupPropertyCollection to manage the properties.
 23:  *
 24:  * @package Core
 25:  * @subpackage GenericDB_Model
 26:  */
 27: class cApiGroupPropertyCollection extends ItemCollection {
 28: 
 29:     /**
 30:      * Groups id (usually the current logged in users group)
 31:      *
 32:      * @var string
 33:      */
 34:     protected $_groupId = '';
 35: 
 36:     /**
 37:      * List of cached entries
 38:      *
 39:      * @var array
 40:      */
 41:     protected static $_entries;
 42: 
 43:     /**
 44:      * Flag to enable caching.
 45:      *
 46:      * @var bool
 47:      */
 48:     protected static $_enableCache;
 49: 
 50:     /**
 51:      * Number of max groups to cache proerties from.
 52:      *
 53:      * @var int
 54:      */
 55:     protected static $_maxGroups = 3;
 56: 
 57:     /**
 58:      * Constructor to create an instance of this class.
 59:      *
 60:      * @param string $groupId
 61:      *
 62:      * @throws cDbException
 63:      * @throws cException
 64:      * @throws cInvalidArgumentException
 65:      */
 66:     public function __construct($groupId) {
 67:         global $cfg;
 68:         parent::__construct($cfg['tab']['group_prop'], 'idgroupprop');
 69:         $this->_setItemClass('cApiGroupProperty');
 70: 
 71:         // set the join partners so that joins can be used via link() method
 72:         $this->_setJoinPartner('cApiGroupCollection');
 73: 
 74:         if (!isset(self::$_enableCache)) {
 75:             if (isset($cfg['properties']) && isset($cfg['properties']['group_prop']) && isset($cfg['properties']['group_prop']['enable_cache'])) {
 76:                 self::$_enableCache = (bool) $cfg['properties']['group_prop']['enable_cache'];
 77: 
 78:                 if (isset($cfg['properties']['group_prop']['max_groups'])) {
 79:                     self::$_maxGroups = (int) $cfg['properties']['group_prop']['max_groups'];
 80:                     // if caching is enabled, there is no need to set max cache
 81:                     // value to lower than 1
 82:                     if (self::$_maxGroups < 1) {
 83:                         self::$_maxGroups = 1;
 84:                     }
 85:                 }
 86:             } else {
 87:                 self::$_enableCache = false;
 88:             }
 89:         }
 90: 
 91:         $this->setGroupId($groupId);
 92:     }
 93: 
 94:     /**
 95:      * Resets the states of static properties.
 96:      */
 97:     public static function reset() {
 98:         self::$_enableCache = null;
 99:         self::$_entries = null;
100:         self::$_maxGroups = 3;
101:     }
102: 
103:     /**
104:      * Group id setter
105:      *
106:      * @param string $groupId
107:      *
108:      * @throws cDbException
109:      * @throws cException
110:      * @throws cInvalidArgumentException If passed group id is empty
111:      */
112:     public function setGroupId($groupId) {
113:         if (empty($groupId)) {
114:             throw new cInvalidArgumentException("Empty group id");
115:         }
116:         $this->_groupId = $groupId;
117:         if (self::$_enableCache) {
118:             $this->_loadFromCache();
119:         }
120:     }
121: 
122:     /**
123:      * Updatess a existing group property entry or creates it.
124:      *
125:      * @param string $type
126:      * @param string $name
127:      * @param string $value
128:      * @param int    $idcatlang [optional]
129:      *
130:      * @return cApiGroupProperty
131:      * 
132:      * @throws cDbException
133:      * @throws cException
134:      * @throws cInvalidArgumentException
135:      */
136:     public function setValueByTypeName($type, $name, $value, $idcatlang = 0) {
137:         $item = $this->fetchByGroupIdTypeName($type, $name);
138:         if ($item) {
139:             $item->set('value', $value);
140:             $item->store();
141:         } else {
142:             $item = $this->create($type, $name, $value, $idcatlang);
143:         }
144: 
145:         if (self::$_enableCache) {
146:             $this->_addToCache($item);
147:         }
148: 
149:         return $item;
150:     }
151: 
152:     /**
153:      * Creates a group property entry.
154:      *
155:      * @param string $type
156:      * @param string $name
157:      * @param string $value
158:      * @param int    $idcatlang [optional]
159:      * @return cApiGroupProperty
160:      * @throws cDbException
161:      * @throws cException
162:      * @throws cInvalidArgumentException
163:      */
164:     public function create($type, $name, $value, $idcatlang = 0) {
165:         $item = $this->createNewItem();
166: 
167:         $item->set('group_id', $this->_groupId);
168:         $item->set('type', $type);
169:         $item->set('name', $name);
170:         $item->set('value', $value);
171:         $item->set('idcatlang', $idcatlang);
172:         $item->store();
173: 
174:         if (self::$_enableCache) {
175:             $this->_addToCache($item);
176:         }
177: 
178:         return $item;
179:     }
180: 
181:     /**
182:      * Returns group property by groupid, type and name.
183:      *
184:      * @param string $type
185:      * @param string $name
186:      *
187:      * @return cApiGroupProperty|NULL
188:      *
189:      * @throws cDbException
190:      * @throws cException
191:      */
192:     public function fetchByGroupIdTypeName($type, $name) {
193:         if (self::$_enableCache) {
194:             return $this->_fetchByGroupIdTypeNameFromCache($type, $name);
195:         }
196: 
197:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s' AND name = '%s'", $this->_groupId, $type, $name);
198:         $this->select($sql);
199:         if (($property = $this->next()) !== false) {
200:             return $property;
201:         }
202:         return NULL;
203:     }
204: 
205:     /**
206:      * Returns all group properties by groupid and type.
207:      *
208:      * @param string $type
209:      *
210:      * @return array
211:      *
212:      * @throws cDbException
213:      * @throws cException
214:      */
215:     public function fetchByGroupIdType($type) {
216:         if (self::$_enableCache) {
217:             return $this->_fetchByGroupIdTypeFromCache($type);
218:         }
219: 
220:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s'", $this->_groupId, $type);
221:         $this->select($sql);
222:         $props = array();
223:         while (($property = $this->next()) !== false) {
224:             $props[] = clone $property;
225:         }
226:         return $props;
227:     }
228: 
229:     /**
230:      * Returns all group properties by groupid.
231:      *
232:      * @return array
233:      *
234:      * @throws cDbException
235:      * @throws cException
236:      */
237:     public function fetchByGroupId() {
238:         if (self::$_enableCache) {
239:             return $this->_fetchByGroupIdFromCache();
240:         }
241: 
242:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
243:         $this->select($sql);
244:         $props = array();
245:         while (($property = $this->next()) !== false) {
246:             $props[] = clone $property;
247:         }
248:         return $props;
249:     }
250: 
251:     /**
252:      * Deletes group property by groupid, type and name.
253:      *
254:      * @param string $type
255:      * @param string $name
256:      *
257:      * @return bool
258:      *
259:      * @throws cDbException
260:      * @throws cException
261:      * @throws cInvalidArgumentException
262:      */
263:     public function deleteByGroupIdTypeName($type, $name) {
264:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s' AND name = '%s'", $this->_groupId, $type, $name);
265:         $this->select($sql);
266:         return $this->_deleteSelected();
267:     }
268: 
269:     /**
270:      * Deletes group properties by groupid and type.
271:      *
272:      * @param string $type
273:      *
274:      * @return bool
275:      *
276:      * @throws cDbException
277:      * @throws cException
278:      * @throws cInvalidArgumentException
279:      */
280:     public function deleteByGroupIdType($type) {
281:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s'", $this->_groupId, $type);
282:         $this->select($sql);
283:         return $this->_deleteSelected();
284:     }
285: 
286:     /**
287:      * Deletes all group properties by groupid.
288:      *
289:      * @return bool
290:      *
291:      * @throws cDbException
292:      * @throws cException
293:      * @throws cInvalidArgumentException
294:      */
295:     public function deleteByGroupId() {
296:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
297:         $this->select($sql);
298:         return $this->_deleteSelected();
299:     }
300: 
301:     /**
302:      * Deletes selected group properties.
303:      *
304:      * @return bool
305:      * @throws cDbException
306:      * @throws cException
307:      * @throws cInvalidArgumentException
308:      */
309:     protected function _deleteSelected() {
310:         $result = false;
311:         while (($prop = $this->next()) !== false) {
312:             $id = $prop->get('idgroupprop');
313:             if (self::$_enableCache) {
314:                 $this->_deleteFromCache($id);
315:             }
316:             $result = $this->delete($id);
317:         }
318:         return $result;
319:     }
320: 
321:     /**
322:      * Loads/Caches all group properties.
323:      *
324:      * @throws cDbException
325:      * @throws cException
326:      */
327:     protected function _loadFromCache() {
328:         if (!isset(self::$_entries)) {
329:             self::$_entries = array();
330:         }
331: 
332:         if (isset(self::$_entries[$this->_groupId])) {
333:             // group is already cached, nothing to do
334:             return;
335:         }
336: 
337:         self::$_entries[$this->_groupId] = array();
338: 
339:         // remove entry from beginning, if we achieved the number of max
340:         // cachable groups
341:         if (count(self::$_entries) > self::$_maxGroups) {
342:             array_shift(self::$_entries);
343:         }
344: 
345:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
346:         $this->select($sql);
347:         while (($property = $this->next()) !== false) {
348:             $data = $property->toArray();
349:             self::$_entries[$this->_groupId][$data['idgroupprop']] = $data;
350:         }
351:     }
352: 
353:     /**
354:      * Adds a entry to the cache.
355:      *
356:      * @param cApiGroupProperty $item
357:      */
358:     protected function _addToCache($item) {
359:         $data = $item->toArray();
360:         self::$_entries[$this->_groupId][$data['idgroupprop']] = $data;
361:     }
362: 
363:     /**
364:      * Fetches group property by groupid, type and name from cache.
365:      *
366:      * @param string $type
367:      * @param string $name
368:      * @return cApiGroupProperty NULL
369:      */
370:     protected function _fetchByGroupIdTypeNameFromCache($type, $name) {
371:         $obj = new cApiGroupProperty();
372:         foreach (self::$_entries[$this->_groupId] as $entry) {
373:             if ($entry['type'] == $type && $entry['name'] == $name) {
374:                 $obj->loadByRecordSet($entry);
375:                 return $obj;
376:             }
377:         }
378:         return NULL;
379:     }
380: 
381:     /**
382:      * Fetches all group properties by groupid and type from cache.
383:      *
384:      * @param string $type
385:      * @return array
386:      */
387:     protected function _fetchByGroupIdTypeFromCache($type) {
388:         $props = array();
389:         $obj = new cApiGroupProperty();
390:         foreach (self::$_entries[$this->_groupId] as $entry) {
391:             if ($entry['type'] == $type) {
392:                 $obj->loadByRecordSet($entry);
393:                 $props[] = clone $obj;
394:             }
395:         }
396:         return $props;
397:     }
398: 
399:     /**
400:      * Fetches all group properties by groupid from cache.
401:      *
402:      * @return array
403:      */
404:     protected function _fetchByGroupIdFromCache() {
405:         $props = array();
406:         $obj = new cApiGroupProperty();
407:         foreach (self::$_entries[$this->_groupId] as $entry) {
408:             $obj->loadByRecordSet($entry);
409:             $props[] = clone $obj;
410:         }
411:         return $props;
412:     }
413: 
414:     /**
415:      * Removes a entry from cache.
416:      *
417:      * @param int $id
418:      */
419:     protected function _deleteFromCache($id) {
420:         if (isset(self::$_entries[$this->_groupId][$id])) {
421:             unset(self::$_entries[$this->_groupId][$id]);
422:         }
423:     }
424: 
425: }
426: 
427: /**
428:  * Group property item
429:  *
430:  * cApiGroupProperty instance contains following class properties:
431:  * - idgroupprop (int)
432:  * - group_id (string)
433:  * - type (string)
434:  * - name (string)
435:  * - value (string)
436:  * - idcatlang (int)
437:  *
438:  * If caching is enabled, see $cfg['properties']['group_prop']['enable_cache'],
439:  * all entries will be loaded at first time.
440:  * If enabled, each call of cApiGroupPropertyCollection functions to retrieve
441:  * properties
442:  * will return the cached entries without stressing the database.
443:  *
444:  * @package Core
445:  * @subpackage GenericDB_Model
446:  */
447: class cApiGroupProperty extends Item
448: {
449:     /**
450:      * Constructor to create an instance of this class.
451:      *
452:      * @param mixed $mId [optional]
453:      *                   Specifies the ID of item to load
454:      *
455:      * @throws cDbException
456:      * @throws cException
457:      * @throws cInvalidArgumentException
458:      */
459:     public function __construct($mId = false) {
460:         global $cfg;
461:         parent::__construct($cfg['tab']['group_prop'], 'idgroupprop');
462:         $this->setFilters(array(), array());
463:         if ($mId !== false) {
464:             $this->loadByPrimaryKey($mId);
465:         }
466:     }
467: 
468:     /**
469:      * Updates a group property value.
470:      *
471:      * @param string $value
472:      * @return bool
473:      * @throws cDbException
474:      * @throws cInvalidArgumentException
475:      */
476:     public function updateValue($value) {
477:         $this->set('value', $value);
478:         return $this->store();
479:     }
480: 
481:     /**
482:      * Userdefined setter for group property fields.
483:      *
484:      * @param string $name
485:      * @param mixed $value
486:      * @param bool $bSafe [optional]
487:      *         Flag to run defined inFilter on passed value
488:      * @return bool
489:      */
490:     public function setField($name, $value, $bSafe = true) {
491:         switch ($name) {
492:              case 'idcatlang':
493:                 $value = (int) $value;
494:                 break;
495:         }
496: 
497:         return parent::setField($name, $value, $bSafe);
498:     }
499: 
500: }
501: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0