public function toObject(array $import, $type = 'both') { $fields = array('pf_id' => 0, 'pf_name' => '', 'pf_content' => '', 'pf_date_created' => '', 'pf_date_updated' => '', 'pf_mailoption' => false, 'pf_mailto' => '', 'pf_captcha' => ''); $tslfields = array('pf_tsl_id' => 0, 'pageform_id' => 0, 'language' => '', 'name' => '', 'content' => '', 'active' => 1, 'confirm' => false, 'confirmto' => '', 'confirmsubject' => '', 'confirmcontent' => '', 'pf_tsl_date_created' => '', 'pf_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(); $item->setId((int) $fields['pf_id'])->setName($fields['pf_name'])->setContent($fields['pf_content'])->setDateCreated($fields['pf_date_created'])->setDateUpdated($fields['pf_date_updated'])->setMailoption($fields['pf_mailoption'])->setMailto($fields['pf_mailto'])->setCaptcha($fields['pf_captcha']); } if ($type == 'both' || $type == 'tsl') { $tsl = new SxModule_Pageform_Tsl(); $tsl->setId($tslfields['pf_tsl_id'])->setPageformId($tslfields['pageform_id'])->setLanguage($tslfields['language'])->setName($tslfields['name'])->setContent($tslfields['content'])->setActive($tslfields['active'])->setConfirm($tslfields['confirm'])->setConfirmto($tslfields['confirmto'])->setConfirmsubject($tslfields['confirmsubject'])->setConfirmcontent($tslfields['confirmcontent'])->setDateCreated($tslfields['pf_tsl_date_created'])->setDateUpdated($tslfields['pf_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; }