Example #1
0
 public function toObject(array $import, $type = 'both')
 {
     $fields = array('pffm_id' => 0, 'pffm_field_id' => 0, 'pffm_place' => 0);
     $tslFields = array('pffm_tsl_id' => 0, 'pffm_tsl_meta_id' => 0, 'pffm_tsl_language' => '', 'pffm_tsl_name' => '', 'pffm_tsl_value' => '', 'pffm_tsl_date_created' => '', 'pffm_tsl_date_updated' => '');
     foreach ($import as $key => $value) {
         if (array_key_exists($key, $fields)) {
             $fields[$key] = $value;
         }
     }
     foreach ($import as $key => $value) {
         if (array_key_exists($key, $tslFields)) {
             $tslFields[$key] = $value;
         }
     }
     if ($type == 'both' || $type == 'item') {
         $item = new SxModule_Pageform_Field_Meta();
         $item->setId((int) $fields['pffm_id'])->setFieldId((int) $fields['pffm_field_id'])->setPlace((int) $fields['pffm_place']);
     }
     if ($type == 'both' || $type == 'tsl') {
         $tsl = new SxModule_Pageform_Field_Meta_Tsl();
         $tsl->setId($tslFields['pffm_tsl_id'])->setMetaId($tslFields['pffm_tsl_meta_id'])->setLanguage($tslFields['pffm_tsl_language'])->setName($tslFields['pffm_tsl_name'])->setValue($tslFields['pffm_tsl_value'])->setDateCreated($tslFields['pffm_tsl_date_created'])->setDateUpdated($tslFields['pffm_tsl_date_updated']);
         if ($type == 'both') {
             $item->setTsl($tsl);
         } else {
             $item = $tsl;
         }
     }
     return $item;
 }
 public function mapFieldsToObjects($fields, $id = 0)
 {
     $objects = array();
     $system = new Zend_Session_Namespace('System');
     $user = Zend_Auth::getInstance()->getIdentity();
     $pageform = new SxModule_Pageform();
     $pageform->setId((int) $id)->setName($this->_getParam('pf_name'))->setContent($this->_getParam('pf_content'))->setMailoption($this->_getParam('pf_mailoption'))->setMailto($this->_getParam('pf_mailto'))->setPages($this->_getParam('pages'))->setCaptcha($this->_getParam('pf_captcha') ? 1 : 0);
     $pageform_tsl = new SxModule_Pageform_Tsl();
     $pageform_tsl->setId($this->_getParam('pf_tsl_id'))->setLanguage($system->lng)->setPageformId((int) $id)->setName($this->_getParam('pf_name'))->setContent($this->_getParam('pf_content'))->setConfirm($this->_getParam('pf_confirm'))->setConfirmto($this->_getParam('pf_confirmto'))->setConfirmsubject($this->_getParam('pf_confirmsubject'))->setConfirmcontent($this->_getParam('pf_confirmcontent'))->setActive($this->_getParam('pf_active'));
     $pageform->setTsl($pageform_tsl);
     foreach ($fields as $field) {
         $object = new SxModule_Pageform_Field();
         $object->setId($field['id'])->setKey($this->toKey($field['name']))->setFieldType($field['type'])->setValidation($field['validation']);
         if (isset($field['option'])) {
             foreach ($field['option'] as $values) {
                 $meta = new SxModule_Pageform_Field_Meta();
                 $meta->setId($values['id']);
                 $meta_tsl = new SxModule_Pageform_Field_Meta_Tsl();
                 $meta_tsl->setLanguage($system->lng)->setId($values['tsl-id'])->setName($values['name'])->setValue($values['key']);
                 $meta->setTsl($meta_tsl);
                 $object->addMeta($meta);
             }
         }
         $object_tsl = new SxModule_Pageform_Field_Tsl();
         $object_tsl->setId($field['tsl-id'])->setName($field['name'])->setLanguage($system->lng);
         $object->setTsl($object_tsl);
         $pageform->addField($object);
     }
     return $pageform;
 }