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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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', $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 = $this->createNewItem();
150: 
151:         $item->set('group_id', $this->_groupId);
152:         $item->set('type', $type);
153:         $item->set('name', $name);
154:         $item->set('value', $value);
155:         $item->set('idcatlang', $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:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s' AND name = '%s'", $this->_groupId, $type, $name);
178:         $this->select($sql);
179:         if (($property = $this->next()) !== false) {
180:             return $property;
181:         }
182:         return NULL;
183:     }
184: 
185:     /**
186:      * Returns all group properties by groupid and type.
187:      *
188:      * @param string $type
189:      * @return cApiGroupProperty[]
190:      */
191:     public function fetchByGroupIdType($type) {
192:         if (self::$_enableCache) {
193:             return $this->_fetchByGroupIdTypeFromCache($type);
194:         }
195: 
196:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s'", $this->_groupId, $type);
197:         $this->select($sql);
198:         $props = array();
199:         while (($property = $this->next()) !== false) {
200:             $props[] = clone $property;
201:         }
202:         return $props;
203:     }
204: 
205:     /**
206:      * Returns all group properties by groupid.
207:      *
208:      * @return cApiGroupProperty[]
209:      */
210:     public function fetchByGroupId() {
211:         if (self::$_enableCache) {
212:             return $this->_fetchByGroupIdFromCache();
213:         }
214: 
215:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
216:         $this->select($sql);
217:         $props = array();
218:         while (($property = $this->next()) !== false) {
219:             $props[] = clone $property;
220:         }
221:         return $props;
222:     }
223: 
224:     /**
225:      * Deletes group property by groupid, type and name.
226:      *
227:      * @param string $type
228:      * @param string $name
229:      * @return bool
230:      */
231:     public function deleteByGroupIdTypeName($type, $name) {
232:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s' AND name = '%s'", $this->_groupId, $type, $name);
233:         $this->select($sql);
234:         return $this->_deleteSelected();
235:     }
236: 
237:     /**
238:      * Deletes group properties by groupid and type.
239:      *
240:      * @param string $type
241:      * @return bool
242:      */
243:     public function deleteByGroupIdType($type) {
244:         $sql = $this->db->prepare("group_id = '%s' AND type = '%s'", $this->_groupId, $type);
245:         $this->select($sql);
246:         return $this->_deleteSelected();
247:     }
248: 
249:     /**
250:      * Deletes all group properties by groupid.
251:      *
252:      * @return bool
253:      */
254:     public function deleteByGroupId() {
255:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
256:         $this->select($sql);
257:         return $this->_deleteSelected();
258:     }
259: 
260:     /**
261:      * Deletes selected group properties.
262:      *
263:      * @return bool
264:      */
265:     protected function _deleteSelected() {
266:         $result = false;
267:         while (($prop = $this->next()) !== false) {
268:             $id = $prop->get('idgroupprop');
269:             if (self::$_enableCache) {
270:                 $this->_deleteFromCache($id);
271:             }
272:             $result = $this->delete($id);
273:         }
274:         return $result;
275:     }
276: 
277:     /**
278:      * Loads/Caches all group properties.
279:      */
280:     protected function _loadFromCache() {
281:         if (!isset(self::$_entries)) {
282:             self::$_entries = array();
283:         }
284: 
285:         if (isset(self::$_entries[$this->_groupId])) {
286:             // group is already cached, nothing to do
287:             return;
288:         }
289: 
290:         self::$_entries[$this->_groupId] = array();
291: 
292:         // remove entry from beginning, if we achieved the number of max
293:         // cachable groups
294:         if (count(self::$_entries) > self::$_maxGroups) {
295:             array_shift(self::$_entries);
296:         }
297: 
298:         $sql = $this->db->prepare("group_id = '%s'", $this->_groupId);
299:         $this->select($sql);
300:         while (($property = $this->next()) !== false) {
301:             $data = $property->toArray();
302:             self::$_entries[$this->_groupId][$data['idgroupprop']] = $data;
303:         }
304:     }
305: 
306:     /**
307:      * Adds a entry to the cache.
308:      *
309:      * @param cApiGroupProperty $entry
310:      */
311:     protected function _addToCache($item) {
312:         $data = $item->toArray();
313:         self::$_entries[$this->_groupId][$data['idgroupprop']] = $data;
314:     }
315: 
316:     /**
317:      * Fetches group property by groupid, type and name from cache.
318:      *
319:      * @param string $type
320:      * @param string $name
321:      * @return cApiGroupProperty NULL
322:      */
323:     protected function _fetchByGroupIdTypeNameFromCache($type, $name) {
324:         $obj = new cApiGroupProperty();
325:         foreach (self::$_entries[$this->_groupId] as $entry) {
326:             if ($entry['type'] == $type && $entry['name'] == $name) {
327:                 $obj->loadByRecordSet($entry);
328:                 return $obj;
329:             }
330:         }
331:         return NULL;
332:     }
333: 
334:     /**
335:      * Fetches all group properties by groupid and type from cache.
336:      *
337:      * @param string $type
338:      * @return cApiGroupProperty[]
339:      */
340:     protected function _fetchByGroupIdTypeFromCache($type) {
341:         $props = array();
342:         $obj = new cApiGroupProperty();
343:         foreach (self::$_entries[$this->_groupId] as $entry) {
344:             if ($entry['type'] == $type) {
345:                 $obj->loadByRecordSet($entry);
346:                 $props[] = clone $obj;
347:             }
348:         }
349:         return $props;
350:     }
351: 
352:     /**
353:      * Fetches all group properties by groupid from cache.
354:      *
355:      * @return cApiGroupProperty[]
356:      */
357:     protected function _fetchByGroupIdFromCache() {
358:         $props = array();
359:         $obj = new cApiGroupProperty();
360:         foreach (self::$_entries[$this->_groupId] as $entry) {
361:             $obj->loadByRecordSet($entry);
362:             $props[] = clone $obj;
363:         }
364:         return $props;
365:     }
366: 
367:     /**
368:      * Removes a entry from cache.
369:      *
370:      * @param int $id
371:      */
372:     protected function _deleteFromCache($id) {
373:         if (isset(self::$_entries[$this->_groupId][$id])) {
374:             unset(self::$_entries[$this->_groupId][$id]);
375:         }
376:     }
377: 
378: }
379: 
380: /**
381:  * Group property item
382:  *
383:  * cApiGroupProperty instance contains following class properties:
384:  * - idgroupprop (int)
385:  * - group_id (string)
386:  * - type (string)
387:  * - name (string)
388:  * - value (string)
389:  * - idcatlang (int)
390:  *
391:  * If caching is enabled, see $cfg['properties']['group_prop']['enable_cache'],
392:  * all entries will be loaded at first time.
393:  * If enabled, each call of cApiGroupPropertyCollection functions to retrieve
394:  * properties
395:  * will return the cached entries without stressing the database.
396:  *
397:  * @package Core
398:  * @subpackage GenericDB_Model
399:  */
400: class cApiGroupProperty extends Item {
401: 
402:     /**
403:      * Constructor Function
404:      *
405:      * @param mixed $mId 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 Flag to run defined inFilter on passed value
433:      */
434:     public function setField($name, $value, $bSafe = true) {
435:         switch ($name) {
436:              case 'idcatlang':
437:                 $value = (int) $value;
438:                 break;
439:         }
440: 
441:         return parent::setField($name, $value, $bSafe);
442:     }
443: 
444: }
445: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen