%PDF- %PDF-
Direktori : /var/www/html/bbw/farmaci/kritik-portale/module/ReviewBase/src/ReviewBase/Form/ |
Current File : /var/www/html/bbw/farmaci/kritik-portale/module/ReviewBase/src/ReviewBase/Form/ContractForm.php |
<?php /** * Description of ContractForm * * @author Florian Koller ( conlabz GmbH ) <florian.koller at conlabz.de> */ namespace ReviewBase\Form; use ReviewBase\Model\Contract; use Zend\Form\Element\Hidden; use Zend\Form\Element\Submit; use Zend\Form\Element\Text; use Zend\Form\Form as ZForm; class ContractForm extends ZForm { protected $entityid; protected $userid; protected $objectid; protected $plan_name; protected $plan_version; protected $plan_start; protected $plan_end; protected $plan_early_end; protected $plan_price; protected $created_at; protected $modified; protected $plan_auto_extension; protected $billing_address; protected $customer_number; protected $billing_number; protected $contract_deleted; protected $submit; public function __construct($name = null, $options = array()) { parent::__construct($name, $options); } public function init() { parent::init(); $this->setName('contractform'); $this->setAttribute('class', 'smart-form'); $this->setAttribute('novalidate', 'novalidate'); $this->entityid = new Hidden("entityid"); $this->add($this->entityid); $this->objectid = new Hidden("objectid"); $this->add($this->objectid); $this->plan_price = new Text("plan_price"); $this->plan_price->setLabel("Monatlicher Paketpreis"); $this->plan_price->setAttribute("placeholder", "75,00"); $this->add($this->plan_price); $this->plan_start = new Text("plan_start"); $this->plan_start->setLabel("Startdatum"); $this->add($this->plan_start); $this->add(array( 'type' => 'PlanName', 'options' => array( 'label' => 'Tarif' ), 'attributes' => array( 'class' => 'form-control' ) )); $this->add(array( 'type' => 'PlanVersion', 'options' => array( 'label' => 'Version' ), 'attributes' => array( 'class' => 'form-control' ) )); $this->plan_end = new Hidden("plan_end"); $this->add($this->plan_end); $this->plan_early_end = new Hidden("plan_early_end"); $this->add($this->plan_early_end); $this->created_at = new Hidden("created_at"); $this->add($this->created_at); $this->modified = new Hidden("modified"); $this->add($this->modified); $this->plan_auto_extension = new Hidden("plan_auto_extension"); $this->add($this->plan_auto_extension); $this->billing_address = new Hidden("billing_address"); $this->add($this->billing_address); $this->contract_number = new Hidden("contract_number"); $this->add($this->contract_number); $this->customer_number = new Hidden("customer_number"); $this->add($this->customer_number); $this->billing_number = new Hidden("billing_number"); $this->add($this->billing_number); $this->contract_deleted = new Hidden("contract_deleted"); $this->add($this->contract_deleted); $this->submit = new Submit("submit"); //how can an ID be added to button? $this->submit->setValue("Speichern"); $this->submit->setAttribute("class", "btn btn-primary"); //make sure the submit button comes last in the form $this->add($this->submit, ['priority' => -10]); } public function setDefaultsBy(Contract $contract, $config) { $data = array( "entityid" => $contract->getId(), "objectid" => $contract->getObjectID(), "plan_name" => $contract->getPlanName(), "plan_version" => $contract->getPlanVersion(), "plan_start" => $contract->getPlanStart(), "plan_price" => $contract->getPlanPrice(), "userid" => $contract->getUserID(), "plan_end" => $contract->getPlanEnd(), "plan_early_end" => $contract->getPlanEarlyEnd(), "created_at" => $contract->getCreatedAt(), "modified" => $contract->getModified(), "plan_auto_extension" => $contract->getPlanAutoExtension(), "billing_address" => $contract->getBillingAddress(), "customer_number" => $contract->getCustomerNumber(), "contract_number" => $contract->getContractNumber(), "billing_number" => $contract->getBillingNumber(), "contract_deleted" => $contract->getContractDeleted() ); $this->changeVersionOptions($config, $contract->getPlanName(), $contract->getPlanVersion()); $this->setData($data); } public function setDefaultsByForm($formData, $config) { $data = array( "objectid" => isset($formData["objectid"]) ? $formData["objectid"] : null, "entityid" => isset($formData["entityid"]) ? $formData["entityid"] : null, "plan_name" => isset($formData["plan_name"]) ? $formData["plan_name"] : null, "plan_version" => isset($formData["plan_version"]) ? $formData["plan_version"] : null, "plan_start" => isset($formData["plan_start"]) ? $formData["plan_start"] : null, "plan_price" => isset($formData["plan_price"]) ? $formData["plan_price"] : null, "userid" => isset($formData["userid"]) ? $formData["userid"] : null, "plan_end" => isset($formData["plan_end"]) ? $formData["plan_end"] : null, "plan_early_end" => isset($formData["plan_early_end"]) ? $formData["plan_early_end"] : null, "created_at" => isset($formData["created_at"]) ? $formData["created_at"] : null, "modified" => isset($formData["modified"]) ? $formData["modified"] : null, "plan_auto_extension" => isset($formData["plan_auto_extension"]) ? $formData["plan_auto_extension"] : null, "billing_address" => isset($formData["billing_address"]) ? $formData["billing_address"] : null, "customer_number" => isset($formData["customer_number"]) ? $formData["customer_number"] : null, "contract_number" => isset($formData["contract_number"]) ? $formData["contract_number"] : null, "billing_number" => isset($formData["billing_number"]) ? $formData["billing_number"] : null, "contract_deleted" => isset($formData["contract_deleted"]) ? $formData["contract_deleted"] : null ); $this->changeVersionOptions($config, $data['plan_name'], $data['plan_version']); if(is_null($data['plan_price'])) { //set default price $data['plan_price'] = $config[$data['plan_name']][$data['plan_version']]['plan_price']; } //default value selection fix if (is_null($data['plan_version'])) { unset($data["plan_version"]); } $this->setData($data); } protected function changeVersionOptions($planConfig, $plan = "basis", $version) { //load version options depending on selected plan $plan = is_null($plan) ? "basis" : $plan; $valueOptions = array(); foreach ($planConfig[$plan] as $key => $plan) { $valueOptions[$key] = $key; } $this->get('plan_version')->setValueOptions($valueOptions); $this->setValue($version); } }