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 user 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:  * User property collection
 19:  *
 20:  * @package Core
 21:  * @subpackage GenericDB_Model
 22:  */
 23: class cApiUserPropertyCollection extends ItemCollection {
 24: 
 25:     /**
 26:      * User id (usually the current logged in user)
 27:      *
 28:      * @var string
 29:      */
 30:     protected $_userId = '';
 31: 
 32:     /**
 33:      * List of cached entries
 34:      *
 35:      * @var array
 36:      */
 37:     protected static $_entries;
 38: 
 39:     /**
 40:      * Flag to enable caching.
 41:      *
 42:      * @var bool
 43:      */
 44:     protected static $_enableCache;
 45: 
 46:     /**
 47:      * Constructor to create an instance of this class.
 48:      *
 49:      * @param string $userId
 50:      *
 51:      * @throws cDbException
 52:      * @throws cException
 53:      * @throws cInvalidArgumentException
 54:      */
 55:     public function __construct($userId) {
 56:         $cfg = cRegistry::getConfig();
 57:         parent::__construct($cfg['tab']['user_prop'], 'iduserprop');
 58:         $this->_setItemClass('cApiUserProperty');
 59: 
 60:         // set the join partners so that joins can be used via link() method
 61:         $this->_setJoinPartner('cApiUserCollection');
 62: 
 63:         if (!isset(self::$_enableCache)) {
 64:             if (isset($cfg['properties']) && isset($cfg['properties']['user_prop']) && isset($cfg['properties']['user_prop']['enable_cache'])) {
 65:                 self::$_enableCache = (bool) $cfg['properties']['user_prop']['enable_cache'];
 66:             } else {
 67:                 self::$_enableCache = false;
 68:             }
 69:         }
 70: 
 71:         $this->setUserId($userId);
 72:     }
 73: 
 74:     /**
 75:      * Resets the states of static properties.
 76:      */
 77:     public static function reset() {
 78:         self::$_enableCache = null;
 79:         self::$_entries = null;
 80:     }
 81: 
 82:     /**
 83:      * User id setter
 84:      *
 85:      * @param string $userId
 86:      *
 87:      * @throws cDbException
 88:      * @throws cException
 89:      * @throws cInvalidArgumentException If passed user id is empty
 90:      */
 91:     public function setUserId($userId) {
 92:         if (empty($userId)) {
 93:             throw new cInvalidArgumentException("Empty user id");
 94:         }
 95:         $this->_userId = $userId;
 96:         if (self::$_enableCache) {
 97:             $this->_loadFromCache();
 98:         }
 99:     }
100: 
101:     /**
102:      * Updates an existing user property entry or creates it.
103:      *
104:      * @param string $type
105:      * @param string $name
106:      * @param string $value
107:      * @param int    $idcatlang [optional]
108:      *
109:      * @return cApiUserProperty
110:      * 
111:      * @throws cDbException
112:      * @throws cException
113:      * @throws cInvalidArgumentException
114:      */
115:     public function setValueByTypeName($type, $name, $value, $idcatlang = 0) {
116:         $item = $this->fetchByUserIdTypeName($type, $name);
117:         if ($item) {
118:             $item->set('value', $value);
119:             $item->store();
120:         } else {
121:             $item = $this->create($type, $name, $value, $idcatlang);
122:         }
123: 
124:         if (self::$_enableCache) {
125:             $this->_addToCache($item);
126:         }
127: 
128:         return $item;
129:     }
130: 
131:     /**
132:      * Creates a user property entry.
133:      *
134:      * @param string $type
135:      * @param string $name
136:      * @param string $value
137:      * @param int    $idcatlang [optional]
138:      * @return cApiUserProperty
139:      * @throws cDbException
140:      * @throws cException
141:      * @throws cInvalidArgumentException
142:      */
143:     public function create($type, $name, $value, $idcatlang = 0) {
144:         $item = $this->createNewItem();
145: 
146:         $item->set('user_id', $this->_userId);
147:         $item->set('type', $type);
148:         $item->set('name', $name);
149:         $item->set('value', $value);
150:         $item->set('idcatlang', $idcatlang);
151:         $item->store();
152: 
153:         if (self::$_enableCache) {
154:             $this->_addToCache($item);
155:         }
156: 
157:         return $item;
158:     }
159: 
160:     /**
161:      * Returns all user properties by userid.
162:      *
163:      * @return array
164:      *
165:      * @throws cDbException
166:      * @throws cException
167:      */
168:     public function fetchByUserId() {
169:         if (self::$_enableCache) {
170:             return $this->_fetchByUserIdFromCache();
171:         }
172: 
173:         $sql = $this->db->prepare("user_id = '%s'", $this->_userId);
174:         $this->select($sql);
175:         $props = array();
176:         while (($property = $this->next()) !== false) {
177:             $props[] = clone $property;
178:         }
179:         return $props;
180:     }
181: 
182:     /**
183:      * Returns all user properties of all users by type and name.
184:      * NOTE: Enabled caching will be skipped in this case, since it will return
185:      * settings for all usery!
186:      *
187:      * @param string $type
188:      * @param string $name
189:      *
190:      * @return array
191:      * 
192:      * @throws cDbException
193:      * @throws cException
194:      */
195:     public function fetchByTypeName($type, $name) {
196:         $sql = $this->db->prepare("type = '%s' AND name = '%s'", $type, $name);
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 user properties by userid, type and name.
207:      *
208:      * @param string $type
209:      * @param string $name
210:      *
211:      * @return cApiUserProperty|NULL
212:      * 
213:      * @throws cDbException
214:      * @throws cException
215:      */
216:     public function fetchByUserIdTypeName($type, $name) {
217:         if (self::$_enableCache) {
218:             return $this->_fetchByUserIdTypeNameFromCache($type, $name);
219:         }
220: 
221:         $sql = $this->db->prepare("user_id = '%s' AND type = '%s' AND name = '%s'", $this->_userId, $type, $name);
222:         $this->select($sql);
223:         if (($property = $this->next()) !== false) {
224:             return $property;
225:         }
226:         return NULL;
227:     }
228: 
229:     /**
230:      * Returns all user properties by userid and type.
231:      *
232:      * @param string $type
233:      *
234:      * @return array
235:      * 
236:      * @throws cDbException
237:      * @throws cException
238:      */
239:     public function fetchByUserIdType($type) {
240:         if (self::$_enableCache) {
241:             return $this->_fetchByUserIdTypeFromCache($type);
242:         }
243: 
244:         $sql = $this->db->prepare("user_id = '%s' AND type = '%s'", $this->_userId, $type);
245:         $this->select($sql);
246:         $props = array();
247:         while (($property = $this->next()) !== false) {
248:             $props[] = clone $property;
249:         }
250:         return $props;
251:     }
252: 
253:     /**
254:      * Deletes user property by userid, type and name.
255:      *
256:      * @param string $type
257:      * @param string $name
258:      *
259:      * @return bool
260:      * 
261:      * @throws cDbException
262:      * @throws cException
263:      * @throws cInvalidArgumentException
264:      */
265:     public function deleteByUserIdTypeName($type, $name) {
266:         $sql = $this->db->prepare("user_id = '%s' AND type = '%s' AND name = '%s'", $this->_userId, $type, $name);
267:         $this->select($sql);
268:         return $this->_deleteSelected();
269:     }
270: 
271:     /**
272:      * Deletes user properties by userid and type.
273:      *
274:      * @param string $type
275:      *
276:      * @return bool
277:      * 
278:      * @throws cDbException
279:      * @throws cException
280:      * @throws cInvalidArgumentException
281:      */
282:     public function deleteByUserIdType($type) {
283:         $sql = $this->db->prepare("user_id = '%s' AND type = '%s'", $this->_userId, $type);
284:         $this->select($sql);
285:         return $this->_deleteSelected();
286:     }
287: 
288:     /**
289:      * Deletes all user properties by userid.
290:      *
291:      * @return bool
292:      * 
293:      * @throws cDbException
294:      * @throws cException
295:      * @throws cInvalidArgumentException
296:      */
297:     public function deleteByUserId() {
298:         $sql = $this->db->prepare("user_id = '%s'", $this->_userId);
299:         $this->select($sql);
300:         return $this->_deleteSelected();
301:     }
302: 
303:     /**
304:      * Deletes selected user properties.
305:      *
306:      * @return bool
307:      * 
308:      * @throws cDbException
309:      * @throws cException
310:      * @throws cInvalidArgumentException
311:      */
312:     protected function _deleteSelected() {
313:         $result = false;
314:         while (($prop = $this->next()) !== false) {
315:             $id = $prop->get('iduserprop');
316:             if (self::$_enableCache) {
317:                 $this->_deleteFromCache($id);
318:             }
319:             $result = $this->delete($id);
320:         }
321:         return $result;
322:     }
323: 
324:     /**
325:      * Loads/Caches all user properties.
326:      *
327:      * @throws cDbException
328:      * @throws cException
329:      */
330:     protected function _loadFromCache() {
331:         self::$_entries = array();
332:         $sql = $this->db->prepare("user_id = '%s'", $this->_userId);
333:         $this->select($sql);
334:         while (($property = $this->next()) !== false) {
335:             $data = $property->toArray();
336:             self::$_entries[$data['iduserprop']] = $data;
337:         }
338:     }
339: 
340:     /**
341:      * Adds a entry to the cache.
342:      *
343:      * @param cApiUserProperty $entry
344:      */
345:     protected function _addToCache($entry) {
346:         $data = $entry->toArray();
347:         self::$_entries[$data['iduserprop']] = $data;
348:     }
349: 
350:     /**
351:      * Fetches all user properties by userid from cache.
352:      *
353:      * @return array
354:      */
355:     protected function _fetchByUserIdFromCache() {
356:         $props = array();
357:         $obj = new cApiUserProperty();
358:         foreach (self::$_entries as $entry) {
359:             $obj->loadByRecordSet($entry);
360:             $props[] = clone $obj;
361:         }
362:         return $props;
363:     }
364: 
365:     /**
366:      * Fetches user properties by userid, type and name from cache.
367:      *
368:      * @param string $type
369:      * @param string $name
370:      * @return cApiUserProperty|NULL
371:      */
372:     public function _fetchByUserIdTypeNameFromCache($type, $name) {
373:         $props = array();
374:         $obj = new cApiUserProperty();
375:         foreach (self::$_entries as $entry) {
376:             if ($entry['type'] == $type && $entry['name'] == $name) {
377:                 $obj->loadByRecordSet($entry);
378:                 return $obj;
379:             }
380:         }
381:         return NULL;
382:     }
383: 
384:     /**
385:      * Fetches user properties by userid and type from cache.
386:      *
387:      * @param string $type
388:      * @return array
389:      */
390:     public function _fetchByUserIdTypeFromCache($type) {
391:         $props = array();
392:         $obj = new cApiUserProperty();
393:         foreach (self::$_entries as $entry) {
394:             if ($entry['type'] == $type) {
395:                 $obj->loadByRecordSet($entry);
396:                 $props[] = clone $obj;
397:             }
398:         }
399:         return $props;
400:     }
401: 
402:     /**
403:      * Removes a entry from cache.
404:      *
405:      * @param int $id
406:      */
407:     protected function _deleteFromCache($id) {
408:         if (isset(self::$_entries[$id])) {
409:             unset(self::$_entries[$id]);
410:         }
411:     }
412: 
413: }
414: 
415: /**
416:  * User property item
417:  *
418:  * @package Core
419:  * @subpackage GenericDB_Model
420:  */
421: class cApiUserProperty extends Item
422: {
423:     /**
424:      * Constructor to create an instance of this class.
425:      *
426:      * @param mixed $mId [optional]
427:      *                   Specifies the ID of item to load
428:      *
429:      * @throws cDbException
430:      * @throws cException
431:      */
432:     public function __construct($mId = false) {
433:         $cfg = cRegistry::getConfig();
434:         parent::__construct($cfg['tab']['user_prop'], 'iduserprop');
435:         $this->setFilters(array(), array());
436:         if ($mId !== false) {
437:             $this->loadByPrimaryKey($mId);
438:         }
439:     }
440: 
441:     /**
442:      * Updates a user property value.
443:      *
444:      * @param string $value
445:      * @return bool
446:      * @throws cDbException
447:      * @throws cInvalidArgumentException
448:      */
449:     public function updateValue($value) {
450:         $this->set('value', $value);
451:         return $this->store();
452:     }
453: 
454:     /**
455:      * Userdefined setter for user property fields.
456:      *
457:      * @param string $name
458:      * @param mixed $value
459:      * @param bool $bSafe [optional]
460:      *         Flag to run defined inFilter on passed value
461:      * @return bool
462:      */
463:     public function setField($name, $value, $bSafe = true) {
464:         switch ($name) {
465:             case 'idcatlang':
466:                 $value = (int) $value;
467:                 break;
468:         }
469: 
470:         return parent::setField($name, $value, $bSafe);
471:     }
472: 
473: }
474: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0