Ejemplo n.º 1
0
 protected function _makeDisplayGroup(Centurion_Form $form, $data, $class)
 {
     if (isset($data['noFieldset']) && $data['noFieldset'] === true) {
         $form->addInDisplayGroup($data['elements'], $class, array('class' => 'form-' . substr($class, 1)));
         foreach ($data['elements'] as $key => $element) {
             if (null !== ($element = $form->getElement($element))) {
                 $element->setLabel(null);
                 $element->removeDecorator('label');
             }
         }
         return true;
     }
     if (!isset($data['label'])) {
         $name = uniqid();
     } else {
         $name = Centurion_Inflector::slugify($data['label']);
     }
     $name = $name . '_group';
     $form->addDisplayGroup($data['elements'], $name, array('class' => 'form-group'));
     $displayGroup = $form->getDisplayGroup($name);
     if (isset($data['label']) && is_string($data['label'])) {
         $displayGroup->setLegend($data['label']);
         if (isset($data['description'])) {
             $displayGroup->setDescription($data['description']);
         }
     } else {
         $displayGroup->setDescription(' ');
     }
     $form->addInDisplayGroup(array($name), $class, array('class' => 'form-' . substr($class, 1)));
 }
Ejemplo n.º 2
0
 /**
  * Render form
  *
  * @param  Zend_View_Interface $view
  * @return string
  */
 public function render(Zend_View_Interface $view = null)
 {
     foreach ($this->getElements() as $key => $element) {
         if (!$element->hasErrors()) {
             continue;
         }
         $element->setDecorators($this->defaultErrorElementDecorators);
     }
     return parent::render($view);
 }
 public function indexAction()
 {
     $form = new Centurion_Form();
     $form->addElement('text', 'module_name', array('required' => true, 'label' => $this->view->translate('Module:')));
     $form->addElement('text', 'controller_name', array('required' => true, 'label' => $this->view->translate('Controller:')));
     $form->addElement('text', 'ressource_name', array('required' => true, 'label' => $this->view->translate('Ressource:')));
     $form->addElement('submit', 'submit', array('label' => $this->view->translate('Submit')));
     $post = $this->_request->getParams();
     if ($form->isValid($post)) {
         $this->view->message = 'Les permission ont bien été ajoutées. <br />';
         $permissionTable = Centurion_Db::getSingleton('auth/permission');
         $tab = array('index' => 'View %s %s index', 'list' => 'View %s %s list', 'get' => 'View an %s %s', 'post' => 'Create an %s %s', 'new' => 'Access to creation of an %s %s', 'delete' => 'Delete an %s %s', 'put' => 'Update an %s %s', 'batch' => 'Batch an %s %s', 'switch' => 'Switch an %s %s');
         foreach ($tab as $key => $description) {
             list($row, $created) = $permissionTable->getOrCreate(array('name' => $post['module_name'] . '_' . $post['controller_name'] . '_' . $key));
             if ($created) {
                 $row->description = sprintf($description, $post['module_name'], $post['ressource_name']);
                 $row->save();
             }
         }
         /*
             INSERT INTO \`auth_permission\` (\`name\`,\`description\`)
             VALUES
             ('${1:module}_${2:controller}_index', 'View ${1:module} ${3:resource} index'),
             ('${1:module}_${2:controller}_list', 'View ${1:module} ${3:resource} list'),
             ('${1:module}_${2:controller}_get', 'View an ${1:module} ${3:resource}'),
             ('${1:module}_${2:controller}_post', 'Create an ${1:module} ${3:resource}'),
             ('${1:module}_${2:controller}_new', 'Access to creation of an ${1:module} ${3:resource}'),
             ('${1:module}_${2:controller}_delete', 'Delete an ${1:module} ${3:resource}'),
             ('${1:module}_${2:controller}_put', 'Update an ${1:module} ${3:resource}');
         */
     }
     $this->view->form = $form;
 }
Ejemplo n.º 4
0
 /**
  * Validate the form
  *
  * @param  array $data
  * @return boolean
  */
 public function isValid($data)
 {
     $valid = parent::isValid($data);
     if ($valid) {
         $session = new Zend_Session_Namespace('Zend_Auth');
         if ((bool) $this->getValue('remember_me')) {
             Zend_Session::rememberMe();
         } else {
             $session->setExpirationSeconds($this->_loginLifetime);
         }
     }
     return $valid;
 }
Ejemplo n.º 5
0
 /**
  * Constructor.
  *
  * @param string $value Value for the checked element
  * @return void
  */
 public function __construct($value = null)
 {
     parent::__construct();
     $this->addElements(array(array('hidden', 'permission_id'), array('hidden', 'group_id'), array('checkbox', 'switch'), array('submit', 'submit')));
     if (!is_null($value)) {
         $this->getElement('switch')->setChecked($value);
     }
     foreach ($this->getElements() as $element) {
         $element->removeDecorator('Label');
         $element->removeDecorator('Description');
         $element->removeDecorator('HtmlTag');
     }
     $this->getElement('submit')->removeDecorator('DtDdWrapper');
     $this->addDecorator('HtmlTag', array('tag' => 'div'));
 }
Ejemplo n.º 6
0
 public function Cui_MakeSaveButton(Centurion_Form $form)
 {
     $label = 'Save';
     if (null !== $form->getTranslator()) {
         $label = $form->getTranslator()->_($label);
     }
     $form->addElement('button', '_saveBig', array('type' => 'submit', 'label' => $label));
     if (null === $form->getDisplayGroup('_header')) {
         $this->view->getHelper('GridForm')->makeHeader($form, array('_saveBig'));
     } else {
         $form->addInDisplayGroup('_saveBig', '_header');
     }
     $save = $form->getElement('_saveBig');
     $save->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'ui-button-big'));
     $save->setAttrib('class', 'ui-button ui-button-bg-white-gradient ui-button-text-red ui-button-text-only');
     $save->setAttrib('class1', null);
     $save->setAttrib('class2', 'ui-button-text');
     $save->setAttrib('role', 'submit');
     return $form;
 }
Ejemplo n.º 7
0
 /**
  * @param Centurion_Form $form
  * @return $this
  */
 public function cleanSubForm(Centurion_Form $form)
 {
     $form->setAttrib('class', 'subform')->setIsArray(true)->cleanForm()->setDecorators($this->defaultSubFormDecorators)->postCleanAsSubform();
     $form->removeElement('_XSRF');
     return $this;
 }
Ejemplo n.º 8
0
 public function init()
 {
     parent::init();
     $this->setAttrib('id', 'grid-filter-form');
 }
Ejemplo n.º 9
0
 public function makeOnOff(Centurion_Form $form)
 {
     if (null !== ($displayGroups = $form->getDisplayGroup('_aside'))) {
         foreach ($form->getDisplayGroup('_aside') as $displayGroup) {
             foreach ($displayGroup->getElements() as $name => $element) {
                 if (!strncmp($element->getName(), 'is_', 3) || !strncmp($element->getName(), 'can_be_', 7)) {
                     $onLabel = $this->view->translate('On');
                     $offLabel = $this->view->translate('Off');
                     $value = $element->getValue();
                     $element = new Zend_Form_Element_Select(array('disableTranslator' => true, 'name' => $name, 'class' => 'field-switcher', 'label' => $element->getLabel(), 'decorators' => $form->defaultElementDecorators));
                     $element->addMultiOption('1', $onLabel);
                     $element->addMultiOption('0', $offLabel);
                     $element->setValue($value);
                     $displayGroup->addElement($element);
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     $subForm = new Centurion_Form();
     $this->addSubForm($subForm, 'language');
 }
Ejemplo n.º 11
0
 public function removeSubForm($name)
 {
     $removed = parent::removeSubForm($name);
     if ($removed) {
         foreach (self::$_specialSubForms as $specialSubFormType) {
             $keys = array_keys($this->{$specialSubFormType}, $name);
             if (count($keys)) {
                 foreach ($keys as $key) {
                     unset($this->{$specialSubFormType}[$key]);
                 }
                 break;
             }
         }
     }
     return $removed;
 }