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
    • NavigationMain
    • 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 collection and item class.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       GenericDB_Model
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Dominik Ziegler
 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 collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiGroupCollection extends ItemCollection {
 25: 
 26:     public function __construct() {
 27:         global $cfg;
 28:         parent::__construct($cfg['tab']['groups'], 'group_id');
 29:         $this->_setItemClass('cApiGroup');
 30:     }
 31: 
 32:     /**
 33:      * Creates a group entry.
 34:      *
 35:      * @param string $groupname
 36:      * @param string $perms
 37:      * @param string $description
 38:      * @return cApiGroup null
 39:      */
 40:     public function create($groupname, $perms, $description) {
 41:         $primaryKeyValue = md5($groupname);
 42: 
 43:         $item = parent::createNewItem($primaryKeyValue);
 44:         if (!is_object($item)) {
 45:             return null;
 46:         }
 47: 
 48:         $groupname = cApiGroup::prefixedGroupName($groupname);
 49: 
 50:         $item->set('groupname', $this->escape($groupname));
 51:         $item->set('perms', $this->escape($perms));
 52:         $item->set('description', $this->escape($description));
 53:         $item->store();
 54: 
 55:         return $item;
 56:     }
 57: 
 58:     /**
 59:      * Returns the groups a user is in
 60:      *
 61:      * @param string $userid
 62:      * @return cApiGroup[] List of groups
 63:      */
 64:     public function fetchByUserID($userid) {
 65:         global $cfg;
 66: 
 67:         $aIds = array();
 68:         $aGroups = array();
 69: 
 70:         $sql = "SELECT a.group_id FROM `%s` AS a, `%s` AS b " . "WHERE (a.group_id  = b.group_id) AND (b.user_id = '%s')";
 71: 
 72:         $this->db->query($sql, $this->table, $cfg['tab']['groupmembers'], $userid);
 73:         $this->_lastSQL = $sql;
 74: 
 75:         while ($this->db->nextRecord()) {
 76:             $aIds[] = $this->db->f('group_id');
 77:         }
 78: 
 79:         if (0 === count($aIds)) {
 80:             return $aGroups;
 81:         }
 82: 
 83:         $where = "group_id IN ('" . implode("', '", $aIds) . "')";
 84:         $this->select($where);
 85:         while (($oItem = $this->next()) !== false) {
 86:             $aGroups[] = clone $oItem;
 87:         }
 88: 
 89:         return $aGroups;
 90:     }
 91: 
 92:     /**
 93:      * Removes the specified group from the database.
 94:      *
 95:      * @param string $groupname Specifies the groupname
 96:      * @return bool True if the delete was successful
 97:      */
 98:     public function deleteGroupByGroupname($groupname) {
 99:         $groupname = cApiGroup::prefixedGroupName($groupname);
100:         $result = $this->deleteBy('groupname', $groupname);
101:         return ($result > 0)? true : false;
102:     }
103: 
104:     /**
105:      * Returns all groups which are accessible by the current group.
106:      *
107:      * @param array $perms
108:      * @return cApiGroup Array of group objects
109:      */
110:     public function fetchAccessibleGroups($perms) {
111:         $groups = array();
112:         $limit = array();
113:         $where = '';
114: 
115:         if (!in_array('sysadmin', $perms)) {
116:             // not sysadmin, compose where rules
117:             $oClientColl = new cApiClientCollection();
118:             $allClients = $oClientColl->getAvailableClients();
119:             foreach ($allClients as $key => $value) {
120:                 if (in_array('client[' . $key . ']', $perms) || in_array('admin[' . $key . ']', $perms)) {
121:                     $limit[] = 'perms LIKE "%client[' . $this->escape($key) . ']%"';
122:                 }
123:                 if (in_array('admin[' . $key . ']', $perms)) {
124:                     $limit[] = 'perms LIKE "%admin[' . $this->escape($key) . ']%"';
125:                 }
126:             }
127: 
128:             if (count($limit) > 0) {
129:                 $where = '1 AND ' . implode(' OR ', $limit);
130:             }
131:         }
132: 
133:         $this->select($where);
134:         while (($oItem = $this->next()) !== false) {
135:             $groups[] = clone $oItem;
136:         }
137: 
138:         return $groups;
139:     }
140: 
141:     /**
142:      * Returns all groups which are accessible by the current group.
143:      * Is a wrapper of fetchAccessibleGroups() and returns contrary to that
144:      * function
145:      * a multidimensional array instead of a list of objects.
146:      *
147:      * @param array $perms
148:      * @return array Array of user like $arr[user_id][groupname],
149:      *         $arr[user_id][description]
150:      *         Note: Value of $arr[user_id][groupname] is cleaned from prefix
151:      *         "grp_"
152:      */
153:     public function getAccessibleGroups($perms) {
154:         $groups = array();
155:         $oGroups = $this->fetchAccessibleGroups($perms);
156:         foreach ($oGroups as $oItem) {
157:             $groups[$oItem->get('group_id')] = array(
158:                 'groupname' => $oItem->getGroupName(true),
159:                 'description' => $oItem->get('description')
160:             );
161:         }
162:         return $groups;
163:     }
164: 
165: }
166: 
167: /**
168:  * Group item
169:  *
170:  * @package Core
171:  * @subpackage GenericDB_Model
172:  */
173: class cApiGroup extends Item {
174: 
175:     const PREFIX = 'grp_';
176: 
177:     /**
178:      * Constructor Function
179:      *
180:      * @param mixed $mId Specifies the ID of item to load
181:      */
182:     public function __construct($mId = false) {
183:         global $cfg;
184:         parent::__construct($cfg['tab']['groups'], 'group_id');
185:         $this->setFilters(array(), array());
186:         if ($mId !== false) {
187:             $this->loadByPrimaryKey($mId);
188:         }
189:     }
190: 
191:     /**
192:      * Loads a group from the database by its groupId.
193:      *
194:      * @param string $groupId Specifies the groupId
195:      * @return bool True if the load was successful
196:      */
197:     public function loadGroupByGroupID($groupId) {
198:         return $this->loadByPrimaryKey($groupId);
199:     }
200: 
201:     /**
202:      * Loads a group entry by its groupname.
203:      *
204:      * @param string $groupname Specifies the groupname
205:      * @return bool True if the load was successful
206:      */
207:     public function loadGroupByGroupname($groupname) {
208:         $groupname = cApiGroup::prefixedGroupName($groupname);
209:         return $this->loadBy('groupname', $groupname);
210:     }
211: 
212:     /**
213:      * User defined field value setter.
214:      *
215:      * @param string $sField Field name
216:      * @param string $mValue Value to set
217:      * @param bool $bSafe Flag to run defined inFilter on passed value
218:      */
219:     public function setField($sField, $mValue, $bSafe = true) {
220:         if ('perms' === $sField) {
221:             if (is_array($mValue)) {
222:                 $mValue = implode(',', $mValue);
223:             }
224:         }
225: 
226:         return parent::setField($sField, $mValue, $bSafe);
227:     }
228: 
229:     /**
230:      * Returns list of group permissions.
231:      *
232:      * @return array
233:      */
234:     public function getPermsArray() {
235:         return explode(',', $this->get('perms'));
236:     }
237: 
238:     /**
239:      * Returns name of group.
240:      *
241:      * @return bool $removePrefix Flag to remove "grp_" prefix from group name
242:      */
243:     public function getGroupName($removePrefix = false) {
244:         $groupname = $this->get('groupname');
245:         return (false === $removePrefix)? $groupname : self::getUnprefixedGroupName($groupname);
246:     }
247: 
248:     /**
249:      * Returns name of a group cleaned from prefix "grp_".
250:      *
251:      * @param string $groupname
252:      * @return string
253:      */
254:     public static function getUnprefixedGroupName($groupname) {
255:         return substr($groupname, strlen(self::PREFIX));
256:     }
257: 
258:     /**
259:      * Returns the passed groupname prefixed with "grp_", if not exists.
260:      *
261:      * @param string $groupname
262:      * @return string
263:      */
264:     public static function prefixedGroupName($groupname) {
265:         if (substr($groupname, 0, strlen(cApiGroup::PREFIX)) != cApiGroup::PREFIX) {
266:             return cApiGroup::PREFIX . $groupname;
267:         }
268:         return $groupname;
269:     }
270: 
271:     /**
272:      * Returns group property by its type and name
273:      *
274:      * @param string $type
275:      * @param string $name
276:      * @return string bool value or false
277:      */
278:     public function getGroupProperty($type, $name) {
279:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
280:         $groupProp = $groupPropColl->fetchByGroupIdTypeName($type, $name);
281:         return ($groupProp)? $groupProp->get('value') : false;
282:     }
283: 
284:     /**
285:      * Retrieves all available properties of the group.
286:      *
287:      * @return array Returns assoziative properties array as follows:
288:      *         - $arr[idgroupprop][name]
289:      *         - $arr[idgroupprop][type]
290:      *         - $arr[idgroupprop][value]
291:      */
292:     public function getGroupProperties() {
293:         $props = array();
294: 
295:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
296:         $groupProps = $groupPropColl->fetchByGroupId();
297:         foreach ($groupProps as $groupProp) {
298:             $props[$groupProp->get('idgroupprop')] = array(
299:                 'name' => $groupProp->get('name'),
300:                 'type' => $groupProp->get('type'),
301:                 'value' => $groupProp->get('value')
302:             );
303:         }
304: 
305:         return $props;
306:     }
307: 
308:     /**
309:      * Stores a property to the database.
310:      *
311:      * @param string $type Type (class, category etc) for the property to
312:      *        retrieve
313:      * @param string $name Name of the property to retrieve
314:      * @param string $value Value to insert
315:      * @return cApiGroupProperty
316:      */
317:     public function setGroupProperty($type, $name, $value) {
318:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
319:         return $groupPropColl->setValueByTypeName($type, $name, $value);
320:     }
321: 
322:     /**
323:      * Deletes a group property from the table.
324:      *
325:      * @param string $type Type (class, category etc) for the property to delete
326:      * @param string $name Name of the property to delete
327:      */
328:     public function deleteGroupProperty($type, $name) {
329:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
330:         return $groupPropColl->deleteByGroupIdTypeName($type, $name);
331:     }
332: 
333: }
334: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0