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 client collection and item class.
  5:  *
  6:  * @package Core
  7:  * @subpackage GenericDB_Model
  8:  * @author Bjoern Behrens
  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:  * Client collection
 19:  *
 20:  * @package Core
 21:  * @subpackage GenericDB_Model
 22:  */
 23: class cApiClientCollection extends ItemCollection {
 24: 
 25:     /**
 26:      * Constructor to create an instance of this class.
 27:      */
 28:     public function __construct() {
 29:         global $cfg;
 30:         parent::__construct($cfg['tab']['clients'], 'idclient');
 31:         $this->_setItemClass('cApiClient');
 32:     }
 33: 
 34:     /**
 35:      * Creates a new client entry
 36:      *
 37:      * @global object $auth
 38:      * @param string $name
 39:      * @param int $errsite_cat [optional]
 40:      * @param int $errsite_art [optional]
 41:      * @param string $author [optional]
 42:      * @param string $created [optional]
 43:      * @param string $lastmodified [optional]
 44:      * @return cApiClient
 45:      */
 46:     public function create($name, $errsite_cat = 0, $errsite_art = 0, $author = '', $created = '', $lastmodified = '') {
 47:         global $auth;
 48: 
 49:         if (empty($author)) {
 50:             $author = $auth->auth['uname'];
 51:         }
 52:         if (empty($created)) {
 53:             $created = date('Y-m-d H:i:s');
 54:         }
 55:         if (empty($lastmodified)) {
 56:             $lastmodified = date('Y-m-d H:i:s');
 57:         }
 58: 
 59:         $item = $this->createNewItem();
 60:         $item->set('name', $name);
 61:         $item->set('errsite_cat', $errsite_cat);
 62:         $item->set('errsite_art', $errsite_art);
 63:         $item->set('author', $author);
 64:         $item->set('created', $created);
 65:         $item->set('lastmodified', $lastmodified);
 66:         $item->store();
 67: 
 68:         return $item;
 69:     }
 70: 
 71:     /**
 72:      * Returns all clients available in the system
 73:      *
 74:      * @return array
 75:      *         Array with id and name entries
 76:      */
 77:     public function getAvailableClients() {
 78:         $clients = array();
 79: 
 80:         $this->select();
 81: 
 82:         while (($item = $this->next()) !== false) {
 83:             $clients[$item->get('idclient')] = array(
 84:                 'name' => $item->get('name')
 85:             );
 86:         }
 87: 
 88:         return $clients;
 89:     }
 90: 
 91:     /**
 92:      * Returns all clients available in the system
 93:      *
 94:      * @return array
 95:      *         Array with id and name entries
 96:      */
 97:     public function getAccessibleClients() {
 98:         global $perm;
 99:         $clients = array();
100:         $this->select();
101:         while (($item = $this->next()) !== false) {
102:             if ($perm->have_perm_client("client[" . $item->get('idclient') . "]") || $perm->have_perm_client("admin[" . $item->get('idclient') . "]") || $perm->have_perm_client()) {
103:                 $clients[$item->get('idclient')] = array(
104:                     'name' => $item->get('name')
105:                 );
106:             }
107:         }
108:         return $clients;
109:     }
110: 
111:     /**
112:      * Returns first client available in the system
113:      *
114:      * @return cApiClient|NULL
115:      */
116:     public function getFirstAccessibleClient() {
117:         global $perm;
118:         $this->select();
119:         while (($item = $this->next()) !== false) {
120:             if ($perm->have_perm_client("client[" . $item->get('idclient') . "]") || $perm->have_perm_client("admin[" . $item->get('idclient') . "]")) {
121:                 return $item;
122:             }
123:         }
124:         return NULL;
125:     }
126: 
127:     /**
128:      * Returns the clientname of the given clientid
129:      *
130:      * @param int $idClient
131:      * @return string
132:      *         Clientname if found, or empty string if not.
133:      */
134:     public function getClientname($idClient) {
135:         $this->select("idclient='" . (int) $idClient . "'");
136:         if (($item = $this->next()) !== false) {
137:             return $item->get('name');
138:         } else {
139:             return i18n("No client");
140:         }
141:     }
142: 
143:     /**
144:      * Returns if the given client has a language
145:      *
146:      * @param int $idClient
147:      * @return bool
148:      *         true if the client has a language
149:      */
150:     public function hasLanguageAssigned($idClient) {
151:         $client = new cApiClient($idClient);
152: 
153:         return $client->hasLanguages();
154:     }
155: }
156: 
157: /**
158:  * Class cApiClient, client item
159:  *
160:  * @package Core
161:  * @subpackage GenericDB_Model
162:  * @author Marco Jahn
163:  */
164: class cApiClient extends Item {
165: 
166:     /**
167:      * Setting of client ID (deprecated)
168:      *
169:      * @deprecated [2014-12-03]
170:      *         Class variable idclient is deprecated
171:      * @var int
172:      */
173:      private $idclient;
174: 
175:     /**
176:      * Property collection instance
177:      *
178:      * @var cApiPropertyCollection
179:      */
180:     protected $_oPropertyCollection;
181: 
182:     /**
183:      * Constructor to create an instance of this class.
184:      *
185:      * @param mixed $id [optional]
186:      *         Specifies the ID of item to load
187:      */
188:     public function __construct($id = false) {
189:         global $cfg;
190:         parent::__construct($cfg['tab']['clients'], 'idclient');
191:         if ($id !== false) {
192:             $this->loadByPrimaryKey($id);
193:         }
194:     }
195: 
196:     /**
197:      * Magic getter method for deprecated idclient variable.
198:      *
199:      * @param string $name
200:      *         only works for "idclient"
201:      * @return mixed
202:      */
203:     public function __get($name) {
204:         if ($name === 'idclient') {
205:             return $this->get('idclient');
206:         } else {
207:             return parent::__get($name);
208:         }
209:     }
210: 
211:     /**
212:      * Magic setter method for deprecated idclient variable
213:      *
214:      * @param string $name
215:      *         only works for "idclient"
216:      * @param mixed $value
217:      *         Value to set
218:      */
219:     public function __set($name, $value) {
220:         if ($name === 'idclient') {
221:             $this->set('idclient', cSecurity::toInteger($value));
222:         } else {
223:             parent::__set($name, $value);
224:         }
225:     }
226: 
227:     /**
228:      * Static accessor to the singleton instance.
229:      *
230:      * @deprecated [2015-05-21]
231:      *         This method is no longer supported (no replacement)
232:      * @todo There is no need since caching is available at GenericDB level
233:      * @param int $client [optional]
234:      * @return cApiClient
235:      *         Reference to the singleton instance.
236:      */
237:     public static function getInstance($client = false) {
238:         static $currentInstance = array();
239: 
240:         cDeprecated('This method is deprecated and is not needed any longer');
241: 
242:         if (!$client) {
243:             // Use global $client
244:             $client = cRegistry::getClientId();
245:         }
246: 
247:         if (!isset($currentInstance[$client])) {
248:             $currentInstance[$client] = new cApiClient($client);
249:         }
250: 
251:         return $currentInstance[$client];
252:     }
253: 
254:     /**
255:      * Load dataset by primary key
256:      *
257:      * @param int $idKey
258:      * @return bool
259:      */
260:     public function loadByPrimaryKey($idKey) {
261:         if (parent::loadByPrimaryKey($idKey) == true) {
262:             $this->set('idclient', $idKey);
263:             return true;
264:         }
265:         return false;
266:     }
267: 
268:     /**
269:      * Set client property
270:      *
271:      * @todo should return return value as overwritten method
272:      * @param mixed $type
273:      *         Type of the data to store (arbitary data)
274:      * @param mixed $name
275:      *         Entry name
276:      * @param mixed $value
277:      *         Value
278:      * @param mixed $idproperty [optional]
279:      */
280:     public function setProperty($type, $name, $value, $idproperty = 0) {
281:         $oPropertyColl = $this->_getPropertiesCollectionInstance();
282:         $oPropertyColl->setValue('clientsetting', $this->get('idclient'), $type, $name, $value, $idproperty);
283:     }
284: 
285:     /**
286:      * Get client property
287:      *
288:      * @param mixed $type
289:      *         Type of the data to get
290:      * @param mixed $name
291:      *         Entry name
292:      * @param int $client [optional]
293:      *         Client id (not used, it's declared because of PHP strict warnings)
294:      * @return mixed
295:      *         Value
296:      */
297:     public function getProperty($type, $name, $client = 0) {
298:         $propertyColl = $this->_getPropertiesCollectionInstance();
299:         return $propertyColl->getValue('clientsetting', $this->get('idclient'), $type, $name);
300:     }
301: 
302:     /**
303:      * Delete client property
304:      *
305:      * @param int $idProp
306:      *         Id of property
307:      * @param string $p2 [optional]
308:      *         Not used, is here to prevent PHP Strict warnings
309:      * @param int $client [optional]
310:      *         Client id (not used, it's declared because of PHP strict warnings)
311:      */
312:     public function deleteProperty($idProp, $p2 = "", $client = 0) {
313:         $propertyColl = $this->_getPropertiesCollectionInstance();
314:         $propertyColl->delete($idProp);
315:     }
316: 
317:     /**
318:      * Get client properties by type
319:      *
320:      * @param mixed $type
321:      *         Type of the data to get
322:      * @return array
323:      *         Assoziative array
324:      */
325:     public function getPropertiesByType($type) {
326:         $propertyColl = $this->_getPropertiesCollectionInstance();
327:         return $propertyColl->getValuesByType('clientsetting', $this->get('idclient'), $type);
328:     }
329: 
330:     /**
331:      * Get all client properties
332:      *
333:      * @todo return value should be the same as getPropertiesByType(),
334:      *         e.g. an empty array instead of false
335:      * @return array|false
336:      *         array
337:      */
338:     public function getProperties() {
339:         $propertyColl = $this->_getPropertiesCollectionInstance();
340:         $whereString = "itemid='" . $this->get('idclient') . "' AND itemtype='clientsetting'";
341:         $propertyColl->select($whereString, "", "type, name, value ASC");
342: 
343:         if ($propertyColl->count() > 0) {
344:             $array = array();
345: 
346:             while (($item = $propertyColl->next()) !== false) {
347:                 $array[$item->get('idproperty')]['type'] = $item->get('type');
348:                 $array[$item->get('idproperty')]['name'] = $item->get('name');
349:                 $array[$item->get('idproperty')]['value'] = $item->get('value');
350:             }
351: 
352:             return $array;
353:         } else {
354:             return false;
355:         }
356:     }
357: 
358:     /**
359:      * Check if client has at least one language
360:      *
361:      * @return bool
362:      */
363:     public function hasLanguages() {
364:         $clientLanguageCollection = new cApiClientLanguageCollection();
365:         $clientLanguageCollection->setWhere("idclient", $this->get("idclient"));
366:         $clientLanguageCollection->query();
367: 
368:         if ($clientLanguageCollection->next()) {
369:             return true;
370:         } else {
371:             return false;
372:         }
373:     }
374: 
375:     /**
376:      * Userdefined setter for client fields.
377:      *
378:      * @param string $name
379:      * @param mixed $value
380:      * @param bool $bSafe [optional]
381:      *         Flag to run defined inFilter on passed value
382:      *                    
383:      * @return bool
384:      */
385:     public function setField($name, $value, $bSafe = true) {
386:         switch ($name) {
387:             case 'errsite_cat':
388:             case 'errsite_art':
389:                 $value = (int) $value;
390:                 break;
391:         }
392: 
393:         return parent::setField($name, $value, $bSafe);
394:     }
395: 
396:     /**
397:      * Lazy instantiation and return of properties object
398:      *
399:      * @param int $client [optional]
400:      *         Client id (not used, it's declared because of PHP strict warnings)
401:      * @return cApiPropertyCollection
402:      */
403:     protected function _getPropertiesCollectionInstance($client = 0) {
404:         // Runtime on-demand allocation of the properties object
405:         if (!is_object($this->_oPropertyCollection)) {
406:             $this->_oPropertyCollection = new cApiPropertyCollection();
407:             $this->_oPropertyCollection->changeClient($this->get('idclient'));
408:         }
409:         return $this->_oPropertyCollection;
410:     }
411: 
412: }
413: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0