Esempio n. 1
0
 /**
  * Creates an array of the form element specification for the given $field,
  * to be used by the factory.
  *
  * @param \Activity\Model\ActivityField $field
  * @param bool $setEnglish
  * @return array
  */
 protected function createFieldElementArray($field)
 {
     $result = ['name' => $field->getId()];
     switch ($field->getType()) {
         case 0:
             //'Text'
             $result['type'] = 'Text';
             break;
         case 1:
             //'Yes/No'
             $result['type'] = 'Zend\\Form\\Element\\Radio';
             $result['options'] = ['value_options' => ['1' => 'Yes', '0' => 'No']];
             break;
         case 2:
             //'Number'
             $result['type'] = 'Zend\\Form\\Element\\Number';
             $result['attributes'] = ['min' => $field->getMinimumValue(), 'max' => $field->getMaximumValue(), 'step' => '1'];
             break;
         case 3:
             //'Choice'
             $values = [];
             foreach ($field->getOptions() as $option) {
                 $values[$option->getId()] = $option->getValue();
             }
             $result['type'] = 'Zend\\Form\\Element\\Select';
             $result['options'] = ['value_options' => $values];
             break;
     }
     return $result;
 }
Esempio n. 2
0
 protected function createActivityFieldTranslation(ActivityFieldModel $field, $language)
 {
     $fieldTranslation = new FieldTranslationModel();
     //Populate the common-language parts
     $fieldTranslation->setId($field->getId());
     $fieldTranslation->setActivity($field->getActivity());
     $fieldTranslation->setMinimumValue($field->getMinimumValue());
     $fieldTranslation->setMaximumValue($field->getMaximumValue());
     $fieldTranslation->setType($field->getType());
     if ($language === 'en') {
         $fieldTranslation->setName($field->getNameEn());
     }
     if ($language === 'nl') {
         $fieldTranslation->setName($field->getName());
     }
     $optionTranslations = [];
     foreach ($field->getOptions() as $option) {
         $optionTranslations[] = $this->createActivityOptionTranslation($option, $language);
     }
     $fieldTranslation->setOptions($optionTranslations);
     return $fieldTranslation;
 }