/**
  * Create field description to the comment.
  *
  * @param string $fieldName Field name.
  * @return FieldDescription
  */
 protected function createFieldDescription($fieldName = '')
 {
     if ($fieldName) {
         $this->commentsFieldName = $fieldName;
     }
     $fd = new FieldDescription($this->commentsFieldName);
     $fd->setSystemType(FieldDescription::FIELD_TYPE_CUSTOM);
     return $fd;
 }
Exemple #2
0
 protected function createDataDescription()
 {
     $result = parent::createDataDescription();
     if (in_array($this->getState(), array('add', 'edit'))) {
         foreach ($result as $fieldDescription) {
             $fieldDescription->setProperty('tabName', E()->Utils->translate('TXT_USER_EDITOR'));
         }
         $result->getFieldDescriptionByName('u_name')->setType(FieldDescription::FIELD_TYPE_EMAIL);
         if ($fd = $result->getFieldDescriptionByName('u_is_active')) {
             $result->removeFieldDescription($fd);
         }
         $fd = new FieldDescription('group_id');
         $fd->setSystemType(FieldDescription::FIELD_TYPE_INT);
         $fd->setType(FieldDescription::FIELD_TYPE_MULTI);
         $fd->setProperty('tabName', E()->Utils->translate('TXT_USER_GROUPS'));
         $fd->setProperty('customField', true);
         $data = $this->dbh->select('user_groups', array('group_id', 'group_name'), 'group_id IN(select group_id from user_groups where group_default=0)');
         $fd->loadAvailableValues($data, 'group_id', 'group_name');
         $result->addFieldDescription($fd);
     }
     if ($this->getType() == self::COMPONENT_TYPE_FORM_ALTER && ($f = $result->getFieldDescriptionByName('u_password'))) {
         $f->removeProperty('pattern');
         $f->removeProperty('message');
         $f->setProperty('nullable', true);
     }
     return $result;
 }
 /**
  * Build tab of rights.
  *
  * @param int $id Division ID.
  *
  * @note By creation of new division use parent ID.
  */
 private function buildRightsTab($id)
 {
     $builder = new Builder($this->getTitle());
     //получаем информацию о всех группах имеющихся в системе
     $groups = $this->dbh->select('user_groups', ['group_id', 'group_name']);
     $groups = convertDBResult($groups, 'group_id');
     //создаем матриц
     //название группы/перечень прав
     foreach (array_keys($groups) as $groupID) {
         $res[] = ['right_id' => 0, 'group_id' => $groupID];
     }
     $resultData = new Data();
     $resultData->load($res);
     $builder->setData($resultData);
     $rightsField = $resultData->getFieldByName('right_id');
     $groupsField = $resultData->getFieldByName('group_id');
     //создаем переменную содержащую идентификторы групп в которые входит пользователь
     $data = $this->dbh->select('share_access_level', ['group_id', 'right_id'], ['smap_id' => $id]);
     if ($data) {
         $data = convertDBResult($data, 'group_id', true);
         for ($i = 0; $i < $resultData->getRowCount(); $i++) {
             //если установлены права для группы  - изменяем в объекте данных
             if (isset($data[$groupsField->getRowData($i)])) {
                 $rightsField->setRowData($i, $data[$groupsField->getRowData($i)]['right_id']);
             }
             $groupsField->setRowProperty($i, 'group_id', $groupsField->getRowData($i));
         }
     }
     for ($i = 0; $i < $resultData->getRowCount(); $i++) {
         $groupsField->setRowProperty($i, 'group_id', $groupsField->getRowData($i));
         $groupsField->setRowData($i, $groups[$groupsField->getRowData($i)]['group_name']);
     }
     $resultDD = new DataDescription();
     $fd = new FieldDescription('group_id');
     $fd->setSystemType(FieldDescription::FIELD_TYPE_STRING);
     $fd->setMode(FieldDescription::FIELD_MODE_READ);
     $fd->setLength(30);
     $resultDD->addFieldDescription($fd);
     $fd = new FieldDescription('right_id');
     $fd->setSystemType(FieldDescription::FIELD_TYPE_SELECT);
     $data = $this->dbh->select('user_group_rights', ['right_id', 'right_const as right_name']);
     $data = array_map(function ($a) {
         $a["right_name"] = translate("TXT_" . $a["right_name"]);
         return $a;
     }, $data);
     $data[] = ['right_id' => 0, 'right_name' => $this->translate('TXT_NO_RIGHTS')];
     $fd->loadAvailableValues($data, 'right_id', 'right_name');
     $resultDD->addFieldDescription($fd);
     $builder->setDataDescription($resultDD);
     $builder->build();
     $field = new Field('page_rights');
     for ($i = 0; $i < count(E()->getLanguage()->getLanguages()); $i++) {
         $field->addRowData($builder->getResult());
     }
     $this->getData()->addField($field);
 }