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