Ejemplo n.º 1
0
 /**
  * Определяем массив записей, тип элемента и дергаем родительский конструктор
  *
  * @param mixed $spec
  * @param array $options
  */
 public function __construct($spec, $options = null)
 {
     $translate = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('Translate');
     $pairs = array();
     /**
      * Определяем тип элемента
      * select, radio - одиночный выбор
      * multiselect, checkbox - множественный выбор
      */
     $type = isset($options['type']) && in_array(strtolower($options['type']), array('select', 'multiselect', 'checkbox', 'radio')) ? strtolower($options['type']) : 'select';
     switch ($type) {
         case 'multiselect':
             $this->helper = 'formSelect';
             $this->_isArray = true;
             $this->multiple = 'multiple';
             break;
         case 'checkbox':
             $this->helper = 'formMultiCheckbox';
             $this->_isArray = true;
             $this->multiple = 'multiple';
             break;
         case 'radio':
             $this->helper = 'formRadio';
             break;
         default:
             $pairs = array(null => $translate->_('---Выберите---'));
             break;
     }
     /**
      * Добавляем записи из справочника на элемент
      */
     if (isset($options['dictionaryid'])) {
         require_once 'Phorm/Dictionaries.php';
         $Dictionaries = new Phorm_Dictionaries();
         if (isset($options['multioptions']) && is_array($options['multioptions'])) {
             $pairs += $options['multioptions'];
         }
         $options['multioptions'] = $pairs + $Dictionaries->getEntriesListAsPairs($options['dictionaryid']);
         unset($options['dictionaryid']);
     }
     parent::__construct($spec, $options);
 }
Ejemplo n.º 2
0
 /**
  * Удаление записи в справочнике
  * 
  * @return void
  */
 public function deleteentryAction()
 {
     if (isset($this->_params['entryid']) && ($EntryInfo = $this->Dictionaries->getEntryInfo($this->_params['entryid']))) {
         $redirect = '/control/dictionaries/entries/dictionaryid/' . $EntryInfo['dictionaryid'] . '/';
         if ($this->Dictionaries->deleteEntry($EntryInfo['entryid'])) {
             return $this->composeSuccessMessage('Выбранная запись удалена', $redirect);
         } else {
             return $this->composeDeleteErrorMessage($this->Dictionaries->_errors, $redirect);
         }
     } else {
         return $this->composeErrorMessage('Запись с указанным Id не найдена', '/control/dictionaries/');
     }
 }
Ejemplo n.º 3
0
 /**
  * Возвращает форму создания/редактирования свойства
  *
  * @param string $section
  * @return Phorm_Form
  */
 public function getPropertyForm($section = 'addproperty')
 {
     $form = new Phorm_Form('forms/control/structures.xml', $section);
     if ($element = $form->getElement('structureid')) {
         $element->setMultiOptions($this->getStructuresListAsPairs());
     }
     if ($element = $form->getElement('dictionaryid')) {
         $Dictionaries = new Phorm_Dictionaries();
         $element->setMultiOptions($Dictionaries->getDictionariesListAsPairs());
     }
     return $form;
 }
Ejemplo n.º 4
0
 /**
  * Определяем массив опций и дергаем родительский конструктор
  *
  * @param mixed $spec
  * @param array $options
  */
 public function __construct($spec, $options = null)
 {
     $this->translate = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('Translate');
     /**
      * Получаем информацию о структуре или структурах
      */
     if (isset($options['structures'])) {
         $options['structures'] = explode(',', $options['structures']);
         require_once 'Phorm/Structures.php';
         $StructuresModel = new Phorm_Structures();
         $structures = array();
         $multioptions = array();
         foreach ($options['structures'] as $key => $structureid) {
             if ($StructureInfo = $StructuresModel->getStructureFullInfo($structureid)) {
                 $structures[$StructureInfo['structureid']] = $StructureInfo;
             } else {
                 unset($options['structures'][$key]);
             }
             $multioptions[$StructureInfo['structureid']] = $StructureInfo['structurename'];
             $options['multioptions'] = $multioptions;
         }
         /**
          * Определяем шаблон формы для элементов структур
          */
         $form_tpl = new Phorm_Form(null, null, array('elements' => $options['elements']));
         /**
          * Создаем форму для каждой из структур
          */
         require_once 'Phorm/Form.php';
         foreach ($structures as $structure) {
             $form = new Phorm_Form();
             $form->removeDecorator('Form');
             $form->removeDecorator('DtDdWrapper');
             foreach ($structure['groups'] as $group) {
                 $form->setElementsBelongTo($spec . '[' . $structure['structureid'] . ']' . '[' . $group['groupid'] . ']');
                 /**
                  * Добавляем элементы на форму
                  * @todo Добавить обязательность заполнения
                  */
                 $elements = array();
                 // массив элементов для добавления в DisplayGroup
                 foreach ($group['properties'] as $property) {
                     /**
                      * Определяем тип используемого элемента
                      */
                     $type = $property['propertytype'];
                     $realtype = in_array($type, array('select', 'structure', 'dictionary')) && $property['ismultiple'] == 'yes' ? 'multiselect' : $type;
                     if ($element = clone $form_tpl->getElement($realtype)) {
                         // Устанавливаем имя и заголовок элемента
                         $element->setLabel($property['propertyname'])->setName($property['propertyid']);
                         // Допиливаем обычный селект
                         if ($type == 'select' && !empty($property['propertyoptions'])) {
                             $propertyoptions = array();
                             // ставим ключи массива опций в их значение
                             foreach ($property['propertyoptions'] as $prop) {
                                 $propertyoptions[$prop] = $prop;
                             }
                             if ($property['ismultiple'] == 'no') {
                                 $propertyoptions = array(null => $this->translate->_('---Выберите---')) + $propertyoptions;
                             }
                             $element->setMultiOptions($propertyoptions);
                         }
                         // Допиливаем селект из другой структуры
                         if ($type == 'structure' && $property['structureid'] > 0) {
                             $propertyoptions = $StructuresModel->getStructureResourcesAsPairs($property['structureid']);
                             if ($property['ismultiple'] == 'no') {
                                 $propertyoptions = array(null => $this->translate->_('---Выберите---')) + $propertyoptions;
                             }
                             $element->setMultiOptions($propertyoptions);
                         }
                         // Допиливаем селект из справочника
                         if ($type == 'dictionary' && $property['dictionaryid'] > 0) {
                             $DictionariesModel = new Phorm_Dictionaries();
                             $propertyoptions = $DictionariesModel->getEntriesListAsPairs($property['dictionaryid']);
                             if ($property['ismultiple'] == 'no') {
                                 $propertyoptions = array(null => $this->translate->_('---Выберите---')) + $propertyoptions;
                             }
                             $element->setMultiOptions($propertyoptions);
                         }
                         $form->addElement($element);
                         $elements[] = $property['propertyid'];
                     }
                 }
                 /**
                  * Если групп несколько, то добавляем DisplayGroup
                  * @todo Добавить в опции возможность задавать css-классы
                  */
                 if (count($structure['groups']) > 1) {
                     $DisplayGroup = $form->addDisplayGroup($elements, 'group-' . $group['groupid'], array('legend' => $group['groupname']));
                 }
             }
             $this->forms[$structure['structureid']] = $form;
             $this->renderforms[$structure['structureid']] = $form->render();
         }
         unset($options['elements']);
     }
     /**
      * Инициализируем родительский конструктор
      */
     parent::__construct($spec, $options);
 }