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