Beispiel #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;
 }
 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;
 }
Beispiel #3
0
 /**
  * Create a new field
  *
  * @pre $params is valid data of Activity\Form\ActivityFieldFieldset
  *
  * @param array $params Parameters for the new field.
  * @param ActivityModel $activity The activity the field belongs to.
  * @param bool $dutch
  * @param bool $english
  * @return \Activity\Model\ActivityField The new field.
  */
 public function createActivityField(array $params, ActivityModel $activity, $dutch, $english)
 {
     assert($dutch || $english, "Activities should have either be in dutch or english");
     $field = new ActivityFieldModel();
     $field->setActivity($activity);
     if ($dutch) {
         $field->setName($params['name']);
     }
     if ($english) {
         $field->setNameEn($params['nameEn']);
     }
     $field->setType($params['type']);
     if ($params['type'] === '2') {
         $field->setMinimumValue($params['min. value']);
         $field->setMaximumValue($params['max. value']);
     }
     if ($params['type'] === '3') {
         $this->createActivityOptions($field, $params, $params['optionsEn'] !== '' && $english, $params['options'] !== '' && $dutch);
     }
     return $field;
 }