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: /**
  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:     public function __construct($groupId) {
 63:         global $cfg;
 64:         parent::__construct($cfg['tab']['group_prop'], 'idgroupprop');
 65:         $this->_setItemClass('cApiGroupProperty');
 66: 
 67:         // set the join partners so that joins can be used via link() method
 68:         $this->_setJoinPartner('cApiGroupCollection');
 69: 
 70:         if (!isset(self::$_enableCache)) {
 71:             if (isset($cfg['properties']) && isset($cfg['properties']['group_prop']) && isset($cfg['properties']['group_prop']['enable_cache'])) {
 72:                 self::$_enableCache = (bool) $cfg['properties']['group_prop']['enable_cache'];
 73: 
 74:                 if (isset($cfg['properties']['group_prop']['max_groups'])) {
 75:                     self::$_maxGroups = (int) $cfg['properties']['group_prop']['max_groups'];
 76:                     // if caching is enabled, there is no need to set max cache
 77:                     // value to lower than 1
 78:                     if (self::$_maxGroups < 1) {
 79:                         self::$_maxGroups = 1;
 80:                     }
 81:                 }
 82:             } else {
 83:                 self::$_enableCache = false;
 84:             }
 85:         }
 86: 
 87:         $this->setGroupId($groupId);
 88:     }
 89: 
 90:     /**
 91:      * Resets the states of static properties.
 92:      */
 93:     public static function reset() {
 94:         unset(self::$_enableCache, self::$_entries, self::$_maxGroups);
 95:     }
 96: 
 97:     /**
 98:      * Group id setter
 99:      *
100:      * @param string $groupId
101:      * @throws cInvalidArgumentException If passed group id is empty
102:      */
103:     public function setGroupId($groupId) {
104:         if (empty($groupId)) {
105:             throw new cInvalidArgumentException("Empty group id");
106:         }
107:         $this->_groupId = $groupId;
108:         if (self::$_enableCache) {
109:             $this->_loadFromCache();
110:         }
111:     }
112: 
113:     /**
114:      * Updatess a existing group property entry or creates it.
115:      *
116:      * @param string $type
117:      * @param string $name
118:      * @param string $value
119:      * @param int $idcatlang [optional]
120:      * @return cApiGroupProperty
121:      */
122:     public function setValueByTypeName($type, $name, $value, $idcatlang = 0) {
123:         $item = $this->fetchByGroupIdTypeName($type, $name);
124:         if ($item) {
125:             $item->set('value', $value);
126:             $item->store();
127:         } else {
128:             $item = $this->create($type, $name, $value, $idcatlang);
129:         }
130: 
131:         if (self::$_enableCache) {
132:             $this->_addToCache($item);
133:         }
134: 
135:         return $item;
136:     }
137: 
138:     /**
139:      * Creates a group property entry.
140:      *
141:      * @param string $type
142:      * @param string $name
143:      * @param string $value
144:      * @param int $idcatlang [optional]
145:      * @return cApiGroupProperty
146:      */
147:     public function create($type, $name, $value, $idcatlang = 0) {
148:         $item = $this->createNewItem();
149: 
150:         $item->set('group_id', $this->_groupId);
151:         $item->set('type', $type);
152:         $item->set('name', $name);
153:         $item->set('value', $value);
154:         $item->set('idcatlang', $idcatlang);
155:         $item->store();
156: 
157:         if (self::$_enableCache) {
158:             $this->_addToCache($item);
159:         }
160: 
161:         return $item;
162:     }
163: 
164:     /**
165:      * Returns group property by groupid, type and name.
166:      *
167:      * @param string $type
168:      * @param string $name
169:      * @return cApiGroupProperty|NULL
170:      */
171:     public function fetchByGroupIdTypeName($type, $name) {
172:         if (self::$_enableCache) {
173:             return $this->_fetchByGroupIdTypeNameFromCache($type, $name);
174:         }
175: 
176:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s' AND name = '%s'", $this->_groupId, $type, $name);
177:         $this->select($sql);
178:         if (($property = $this->next()) !== false) {
179:             return $property;
180:         }
181:         return NULL;
182:     }
183: 
184:     /**
185:      * Returns all group properties by groupid and type.
186:      *
187:      * @param string $type
188:      * @return array
189:      */
190:     public function fetchByGroupIdType($type) {
191:         if (self::$_enableCache) {
192:             return $this->_fetchByGroupIdTypeFromCache($type);
193:         }
194: 
195:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s'", $this->_groupId, $type);
196:         $this->select($sql);
197:         $props = array();
198:         while (($property = $this->next()) !== false) {
199:             $props[] = clone $property;
200:         }
201:         return $props;
202:     }
203: 
204:     /**
205:      * Returns all group properties by groupid.
206:      *
207:      * @return array
208:      */
209:     public function fetchByGroupId() {
210:         if (self::$_enableCache) {
211:             return $this->_fetchByGroupIdFromCache();
212:         }
213: 
214:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
215:         $this->select($sql);
216:         $props = array();
217:         while (($property = $this->next()) !== false) {
218:             $props[] = clone $property;
219:         }
220:         return $props;
221:     }
222: 
223:     /**
224:      * Deletes group property by groupid, type and name.
225:      *
226:      * @param string $type
227:      * @param string $name
228:      * @return bool
229:      */
230:     public function deleteByGroupIdTypeName($type, $name) {
231:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s' AND name = '%s'", $this->_groupId, $type, $name);
232:         $this->select($sql);
233:         return $this->_deleteSelected();
234:     }
235: 
236:     /**
237:      * Deletes group properties by groupid and type.
238:      *
239:      * @param string $type
240:      * @return bool
241:      */
242:     public function deleteByGroupIdType($type) {
243:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s'", $this->_groupId, $type);
244:         $this->select($sql);
245:         return $this->_deleteSelected();
246:     }
247: 
248:     /**
249:      * Deletes all group properties by groupid.
250:      *
251:      * @return bool
252:      */
253:     public function deleteByGroupId() {
254:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
255:         $this->select($sql);
256:         return $this->_deleteSelected();
257:     }
258: 
259:     /**
260:      * Deletes selected group properties.
261:      *
262:      * @return bool
263:      */
264:     protected function _deleteSelected() {
265:         $result = false;
266:         while (($prop = $this->next()) !== false) {
267:             $id = $prop->get('idgroupprop');
268:             if (self::$_enableCache) {
269:                 $this->_deleteFromCache($id);
270:             }
271:             $result = $this->delete($id);
272:         }
273:         return $result;
274:     }
275: 
276:     /**
277:      * Loads/Caches all group properties.
278:      */
279:     protected function _loadFromCache() {
280:         if (!isset(self::$_entries)) {
281:             self::$_entries = array();
282:         }
283: 
284:         if (isset(self::$_entries[$this->_groupId])) {
285:             // group is already cached, nothing to do
286:             return;
287:         }
288: 
289:         self::$_entries[$this->_groupId] = array();
290: 
291:         // remove entry from beginning, if we achieved the number of max
292:         // cachable groups
293:         if (count(self::$_entries) > self::$_maxGroups) {
294:             array_shift(self::$_entries);
295:         }
296: 
297:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
298:         $this->select($sql);
299:         while (($property = $this->next()) !== false) {
300:             $data = $property->toArray();
301:             self::$_entries[$this->_groupId][$data['idgroupprop']] = $data;
302:         }
303:     }
304: 
305:     /**
306:      * Adds a entry to the cache.
307:      *
308:      * @param cApiGroupProperty $entry
309:      */
310:     protected function _addToCache($item) {
311:         $data = $item->toArray();
312:         self::$_entries[$this->_groupId][$data['idgroupprop']] = $data;
313:     }
314: 
315:     /**
316:      * Fetches group property by groupid, type and name from cache.
317:      *
318:      * @param string $type
319:      * @param string $name
320:      * @return cApiGroupProperty NULL
321:      */
322:     protected function _fetchByGroupIdTypeNameFromCache($type, $name) {
323:         $obj = new cApiGroupProperty();
324:         foreach (self::$_entries[$this->_groupId] as $entry) {
325:             if ($entry['type'] == $type && $entry['name'] == $name) {
326:                 $obj->loadByRecordSet($entry);
327:                 return $obj;
328:             }
329:         }
330:         return NULL;
331:     }
332: 
333:     /**
334:      * Fetches all group properties by groupid and type from cache.
335:      *
336:      * @param string $type
337:      * @return array
338:      */
339:     protected function _fetchByGroupIdTypeFromCache($type) {
340:         $props = array();
341:         $obj = new cApiGroupProperty();
342:         foreach (self::$_entries[$this->_groupId] as $entry) {
343:             if ($entry['type'] == $type) {
344:                 $obj->loadByRecordSet($entry);
345:                 $props[] = clone $obj;
346:             }
347:         }
348:         return $props;
349:     }
350: 
351:     /**
352:      * Fetches all group properties by groupid from cache.
353:      *
354:      * @return array
355:      */
356:     protected function _fetchByGroupIdFromCache() {
357:         $props = array();
358:         $obj = new cApiGroupProperty();
359:         foreach (self::$_entries[$this->_groupId] as $entry) {
360:             $obj->loadByRecordSet($entry);
361:             $props[] = clone $obj;
362:         }
363:         return $props;
364:     }
365: 
366:     /**
367:      * Removes a entry from cache.
368:      *
369:      * @param int $id
370:      */
371:     protected function _deleteFromCache($id) {
372:         if (isset(self::$_entries[$this->_groupId][$id])) {
373:             unset(self::$_entries[$this->_groupId][$id]);
374:         }
375:     }
376: 
377: }
378: 
379: /**
380:  * Group property item
381:  *
382:  * cApiGroupProperty instance contains following class properties:
383:  * - idgroupprop (int)
384:  * - group_id (string)
385:  * - type (string)
386:  * - name (string)
387:  * - value (string)
388:  * - idcatlang (int)
389:  *
390:  * If caching is enabled, see $cfg['properties']['group_prop']['enable_cache'],
391:  * all entries will be loaded at first time.
392:  * If enabled, each call of cApiGroupPropertyCollection functions to retrieve
393:  * properties
394:  * will return the cached entries without stressing the database.
395:  *
396:  * @package Core
397:  * @subpackage GenericDB_Model
398:  */
399: class cApiGroupProperty extends Item {
400: 
401:     /**
402:      * Constructor to create an instance of this class.
403:      *
404:      * @param mixed $mId [optional]
405:      *         Specifies the ID of item to load
406:      */
407:     public function __construct($mId = false) {
408:         global $cfg;
409:         parent::__construct($cfg['tab']['group_prop'], 'idgroupprop');
410:         $this->setFilters(array(), array());
411:         if ($mId !== false) {
412:             $this->loadByPrimaryKey($mId);
413:         }
414:     }
415: 
416:     /**
417:      * Updates a group property value.
418:      *
419:      * @param string $value
420:      * @return bool
421:      */
422:     public function updateValue($value) {
423:         $this->set('value', $value);
424:         return $this->store();
425:     }
426: 
427:     /**
428:      * Userdefined setter for group property fields.
429:      *
430:      * @param string $name
431:      * @param mixed $value
432:      * @param bool $bSafe [optional]
433:      *         Flag to run defined inFilter on passed value
434:      * @return bool
435:      */
436:     public function setField($name, $value, $bSafe = true) {
437:         switch ($name) {
438:              case 'idcatlang':
439:                 $value = (int) $value;
440:                 break;
441:         }
442: 
443:         return parent::setField($name, $value, $bSafe);
444:     }
445: 
446: }
447: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0