/**
  * Add form elements when a responseDatabase is present
  * @param  \Gems_Form $form existing form type
  * @param  array data existing options set in the form
  * @return array of form elements
  */
 protected function addResponseDatabaseForm($form, &$data, &$elements)
 {
     if (isset($data['tid']) && !empty($data['tid'])) {
         // If we have a responsedatabase and a track id, try something cool ;-)
         $responseDb = $this->project->getResponseDatabase();
         if ($this->db === $responseDb) {
             // We are in the same database, now put that to use by allowing to filter respondents based on an answer in any survey
             $empty = $this->util->getTranslated()->getEmptyDropdownArray();
             $allSurveys = $empty + $this->util->getDbLookup()->getSurveysForExport();
             $element = new \Zend_Form_Element_Select('filter_sid');
             $element->setLabel($this->_('Survey'))->setMultiOptions($allSurveys);
             $groupElements = array($element);
             if (isset($data['filter_sid']) && !empty($data['filter_sid'])) {
                 $filterSurvey = $this->loader->getTracker()->getSurvey($data['filter_sid']);
                 $filterQuestions = $empty + $filterSurvey->getQuestionList($this->locale->getLanguage());
                 $element = new \Zend_Form_Element_Select('filter_answer');
                 $element->setLabel($this->_('Question'))->setMultiOptions($filterQuestions);
                 $groupElements[] = $element;
             }
             if (isset($filterSurvey) && isset($data['filter_answer']) && !empty($data['filter_answer'])) {
                 $questionInfo = $filterSurvey->getQuestionInformation($this->locale->getLanguage());
                 if (array_key_exists($data['filter_answer'], $questionInfo)) {
                     $questionInfo = $questionInfo[$data['filter_answer']];
                 } else {
                     $questionInfo = array();
                 }
                 if (array_key_exists('answers', $questionInfo) && is_array($questionInfo['answers']) && count($questionInfo['answers']) > 1) {
                     $element = new \Zend_Form_Element_Multiselect('filter_value');
                     $element->setMultiOptions($empty + $questionInfo['answers']);
                     $element->setAttrib('size', count($questionInfo['answers']) + 1);
                 } else {
                     $element = new \Zend_Form_Element_Text('filter_value');
                 }
                 $element->setLabel($this->_('Value'));
                 $groupElements[] = $element;
             }
             $form->addDisplayGroup($groupElements, 'filter', array('showLabels' => true, 'Description' => $this->_('Filter')));
             array_shift($elements);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Add a display group to the subform
  *
  * This allows to render multiple fields in one table cell. Provide a description to set the label for
  * the group. When the special option showLabels is set to true, inside the tabel cell all fields will
  * still show their own label.
  *
  * Example:
  * <code>
  * $this->addDisplayGroup(array('firstname', 'infix', 'lastname'), 'name_group', array('description'=>'Name', 'showLabels'=>true);
  * </code>
  * This would result in a two cell table row, with first cell the description of the group 'Name' and in the
  * second cell the three input boxes, with their label in front. If you leave the showLabels out, you will get
  * just three inputboxes for the name parts.
  *
  * @param array $elements   Array with names of the fields you want to add
  * @param string $name      The (unique) name for this new group
  * @param array $options    An array of key=>value options to set for the group
  * @return \Gems_Form_TabSubForm
  */
 public function addDisplayGroup(array $elements, $name, $options = null)
 {
     //Add the group as usual, but skip decorator loading as we don't need that
     return parent::addDisplayGroup($elements, $name, (array) $options + array('disableLoadDefaultDecorators' => true));
 }
Ejemplo n.º 3
0
 /**
  * Add an element to the form, when a tab (subform) had been added, it will return
  * the subform instead of the form, keep this in mind when chaining methods
  *
  * @param  array $elements
  * @param  string $name
  * @param  array|\Zend_Config $options
  * @return \Gems_TabForm|\Gems_Form_TabSubForm
  * @throws \Zend_Form_Exception if no valid elements provided
  */
 public function addDisplayGroup(array $elements, $name, $options = null)
 {
     if ($this->currentTab) {
         return $this->currentTab->addDisplayGroup($elements, $name, $options);
     } else {
         //Add the group as usual
         parent::addDisplayGroup($elements, $name, $options);
         //Retrieve it and set decorators
         $group = $this->getDisplayGroup($name);
         $group->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => $group->getName() . ' ' . $group->getAttrib('class')))));
         return $this;
     }
 }