| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- Lib::loadClass('Core_AclBase');
- Lib::loadClass('User');
- Lib::loadClass('UsersHelper');
- class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
- public function getSourceName() { return 'objects'; }
- public function init($force = false) {}
- public function isInitialized() { return true; }
- public function getName() { return 'AccessGroup'; }
- public function getRootTableName() { return 'CRM_LISTA_ZASOBOW'; }
- public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
- public function getVirtualFieldListByIdZasob() { return array(); }
- public function getRealFieldListByIdZasob($force = false) {
- $cols[100000] = 'id';// CRM_LISTA_ZASOBOW.ID
- $cols[100001] = 'name';// CRM_LISTA_ZASOBOW.DESC
- $cols[100002] = 'uid';// Ldap.uid -> value stored in fields: A_ADM_COMPANY, A_CLASSIFIED
- return $cols;
- }
- public function getFields() { return array_values($this->getRealFieldListByIdZasob()); }
- public function getFieldType($fieldName) { return null; }
- // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
- public function canCreateField($fieldName) { return false; }
- public function canReadField($fieldName) { return true; }
- public function canReadObjectField($fieldName, $record) {return true; }
- public function canWriteField($fieldName) { return false; }
- public function canWriteObjectField($fieldName, $record) { return false; }
- public function getItems($params = array()) {
- $DBG = V::get('DBG_DS', 0, $_GET, 'int');
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
- $items = array();
- // TODO: fetch groups connectes with current user
- {
- $userLdapGroups = UsersHelper::getLDAPGroupByUserName(User::getLogin());
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$userLdapGroups:";print_r($userLdapGroups);echo "\n";}
- if (empty($userLdapGroups)) throw new Exception("User groups not found", 404);
- foreach ($userLdapGroups as $vLdapGroup) {
- $allowGroup = false;
- if ('workgroup' == $vLdapGroup->cn) {
- $items[1] = ['id'=>0, 'name'=>$vLdapGroup->cn, 'uid'=>$vLdapGroup->cn];
- } else {
- $cnTest = str_replace('-', '_', $vLdapGroup->cn);
- $cnTest = explode('_', $cnTest);
- $idZasob = $cnTest[0];
- if (!is_numeric($idZasob)) {
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems - skip cn - missing id zasob \$vLdapGroup->cn:";print_r($vLdapGroup->cn);echo "\n";}
- continue;
- }
- $items[$idZasob] = ['id'=>$idZasob, 'name'=>$vLdapGroup->cn, 'uid'=>$vLdapGroup->cn];
- }
- }
- }
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
- return $items;
- }
- public function addItem($itemTodo) { throw new Exception("Insert not allowed"); }
- public function updateItem($itemPatch) { throw new Exception("Update not allowed"); }
- public function getGeomFieldType($fieldName) { return null; }
- public function getPrimaryKeyField() { return 'id'; }
- public function getID() { return 0; }
- public function getAttributesFromZasoby() { return array(); }
- public function isEnumerationField($fieldName) { return false; }
- public function getEnumerations($fieldName) { return null; }
- public function getXsdFieldType($fieldName) {
- if ('id' == $fieldName) return 'xsd:string';
- if ('name' == $fieldName) return 'xsd:string';
- if ('uid' == $fieldName) return 'xsd:string';
- }
- public function isGeomField($fldName) { return false; }
- }
|