public function getForm($entityClass = null) { $form = parent::getForm($entityClass); if ($form) { $entityClass = $entityClass ?: $this->getEntityClass(); $hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass); $hydrator->addStrategy('timecreated', new DateTimeStrategy()); $hydrator->addStrategy('lastsubmitted', new DateTimeStrategy()); $form->setHydrator($hydrator); if ($form->has('submit')) { $form->get('submit')->setLabel('Save'); } if ($form->has('cancelar')) { $form->get('cancelar')->setLabel('Cancel')->setName('cancel'); } } return $form; }
public function init() { $hydrator = new DoctrineHydrator($this->getObjectManager(), 'Agent\\Entity\\AgentCriterionValue'); $hydrator->addStrategy('value', new AgentCriterionValueStrategy()); $this->setHydrator($hydrator)->setObject(new AgentCriterionValue()); $this->add(array('type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'id', 'required' => false)); $this->add(array('type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'type', 'required' => true, 'attributes' => array('class' => 'type'))); $this->add(array('type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'value', 'required' => false, 'attributes' => array('class' => 'value'))); $this->add(array('options' => array('label' => 'Enter Value:', 'label_attributes' => array('class' => '')), 'attributes' => array('class' => 'criterion string', 'placeholder' => 'Enter Value'), 'type' => 'text', 'name' => 'string')); $this->add(array('options' => array('label' => 'Choose Value(s): ', 'label_attributes' => array('class' => 'sr-only'), 'empty_option' => 'Select Value(s)', 'value_options' => array()), 'attributes' => array('class' => 'criterion multiple', 'multiple' => 'multiple'), 'type' => 'select', 'name' => 'multiple')); $this->add(array('options' => array('label' => 'Select a Boolean Value: ', 'label_attributes' => array('class' => 'horizontal'), 'value_options' => array(0 => 'No', 1 => 'Yes')), 'attributes' => array('class' => 'criterion boolean horizontal', 'style' => 'width: 100px'), 'type' => 'select', 'name' => 'boolean')); $this->add(array('name' => 'daterange', 'allow_empty' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'type' => 'Application\\Form\\Element\\DateRange', 'options' => array('column-size' => 'xs-12 col-sm-6 col-md-4', 'label' => 'Select Date Range: ', 'label_attributes' => array('class' => '')), 'attributes' => array('class' => 'criterion daterange', 'id' => 'daterange_' . uniqid()))); $this->add(array('name' => 'location', 'type' => 'Agent\\Form\\Fieldset\\LocationFieldset', 'use_as_base_fieldset' => false, 'attributes' => array('class' => 'criterion location group-fieldset', 'id' => 'location_' . uniqid()))); $this->add(array('type' => 'Application\\Form\\Element\\Slider', 'name' => 'range', 'options' => array('label' => 'Select Range: ', 'label_attributes' => array('class' => 'horizontal')), 'attributes' => array('data-slider-min' => 0, 'data-slider-max' => 100, 'data-slider-step' => 1, 'data-slider-range' => true, 'data-slider-tick' => '[0, 25, 50, 75, 100]', 'data-slider-ticks_labels' => '["0", "25", "50", "75", "100"]', 'data-slider-handle' => 'square', 'class' => 'criterion range slider horizontal', 'id' => 'slider_' . uniqid()))); }
public function init() { $this->serviceLocator = $this->getFormFactory()->getFormElementManager()->getServiceLocator(); $hydrator = new DoctrineHydrator($this->getObjectManager(), 'Lead\\Entity\\Lead'); $hydrator->addStrategy('timecreated', new DateTimeStrategy()); $this->setAttribute('method', 'post')->setHydrator($hydrator); $dateTime = date('Y-m-d H:i:s'); $this->add(array('options' => array('label' => 'IP Address'), 'required' => false, 'type' => 'text', 'name' => 'ipaddress')); $this->add(array('options' => array('label' => 'Referrer'), 'required' => false, 'type' => 'Zend\\Form\\Element\\Url', 'name' => 'referrer')); $this->add(array('name' => 'account', 'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'required' => false, 'allow_empty' => true, 'continue_if_empty' => true, 'options' => array('label' => 'Account', 'empty_option' => 'None', 'object_manager' => $this->getObjectManager(), 'target_class' => 'Account\\Entity\\Account', 'property' => 'name', 'find_method' => array('name' => 'findBy', 'params' => array('criteria' => array('active' => 1)))), 'attributes' => array('id' => 'account'))); $this->add(array('type' => 'Application\\Form\\Element\\Collection', 'name' => 'attributes', 'required' => true, 'options' => array('label' => 'Add Lead Details', 'count' => 8, 'should_create_template' => true, 'template_placeholder' => '__index__', 'allow_add' => true, 'allow_remove' => true, 'target_element' => array('type' => 'Lead\\Form\\Fieldset\\LeadAttributeValueFieldset')), 'attributes' => array('id' => 'leadAttributes'))); $this->add(array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf')); $this->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('type' => 'submit', 'value' => 'Add Lead', 'id' => 'submit', 'class' => 'btn btn-primary'))); $this->add(array('name' => 'cancel', 'type' => 'button', 'class' => 'btn btn-default', 'options' => array('label' => 'Cancel', 'label_attributes' => array('sr-only')), 'attributes' => array('value' => 'Cancel', 'class' => 'btn btn-default'))); }
public function init() { $this->serviceLocator = $this->getFormFactory()->getFormElementManager()->getServiceLocator(); $hydrator = new DoctrineHydrator($this->getObjectManager(), 'Report\\Entity\\Report'); $hydrator->addStrategy('updated', new DateTimeStrategy()); $this->setAttribute('method', 'post')->setHydrator($hydrator)->setInputFilter(new AddFormInputFilter($this->getServiceLocator())); $dateTime = date('Y-m-d H:i:s'); $this->add(array('required' => false, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'id')); $this->add(array('required' => false, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'active')); $this->add(array('required' => true, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'updated', 'attributes' => array('value' => $dateTime))); $this->add(array('required' => true, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'name', 'attributes' => array('value' => "Search ({$dateTime})"))); $this->add(array('required' => true, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'account', 'attributes' => array('id' => 'account'))); $this->add(array('name' => 'agent', 'type' => 'Agent\\Form\\Fieldset\\AgentFieldset', 'options' => array('label' => "Advanced Search", 'use_as_base_fieldset' => false), 'attributes' => array('id' => 'agent', 'class' => 'collection-fieldset'))); $this->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('type' => 'submit', 'value' => 'Search', 'id' => 'submit', 'class' => 'btn btn-primary'))); $this->add(array('name' => 'cancel', 'type' => 'button', 'class' => 'btn btn-default', 'options' => array('label' => 'Cancel', 'label_attributes' => array('sr-only')), 'attributes' => array('value' => 'Cancel', 'class' => 'btn btn-default'))); }
public function init() { $this->serviceLocator = $this->getFormFactory()->getFormElementManager()->getServiceLocator(); $hydrator = new DoctrineHydrator($this->getObjectManager(), 'Report\\Entity\\Report'); $hydrator->addStrategy('updated', new DateTimeStrategy()); $this->setAttribute('method', 'post')->setHydrator($hydrator)->setInputFilter(new AddFormInputFilter($this->getServiceLocator())); $dateTime = date('Y-m-d H:i:s'); $this->add(array('required' => false, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'id')); $this->add(array('required' => true, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'updated')); $this->add(array('required' => true, 'type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'active')); $this->add(array('options' => array('label' => 'Name'), 'attributes' => array('value' => "Report ({$dateTime})"), 'required' => true, 'type' => 'text', 'name' => 'name')); $this->add(array('name' => 'account', 'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'required' => false, 'allow_empty' => true, 'continue_if_empty' => true, 'options' => array('label' => 'Client Account', 'empty_option' => 'None', 'object_manager' => $this->getObjectManager(), 'target_class' => 'Account\\Entity\\Account', 'property' => 'name', 'find_method' => array('name' => 'findBy', 'params' => array('criteria' => array('active' => 1)))), 'attributes' => array('id' => 'account'))); $this->add(array('name' => 'agent', 'type' => 'Agent\\Form\\Fieldset\\AgentFieldset', 'options' => array('label' => "Setup Search Agent", 'use_as_base_fieldset' => false), 'attributes' => array('id' => 'agent', 'class' => 'collection-fieldset'))); $this->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('type' => 'submit', 'value' => 'Create Report', 'id' => 'submit', 'class' => 'btn btn-primary'))); $this->add(array('name' => 'cancel', 'type' => 'button', 'class' => 'btn btn-default', 'options' => array('label' => 'Cancel', 'label_attributes' => array('sr-only')), 'attributes' => array('value' => 'Cancel', 'class' => 'btn btn-default'))); }
protected function extract(Lead $lead) { $entityClass = get_class($lead); $hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass); $hydrator->addStrategy('timecreated', new DateTimeStrategy()); $hydrator->addStrategy('lastsubmitted', new DateTimeStrategy()); return $hydrator->extract($lead); }
protected function dispatch($entity, $event, $data = [], $updateEntity = false) { $valid = false; $base = $this->getEvent($data['action'], $data['message']); $eventName = basename(str_replace('\\', '/', get_class($event))); $entityName = is_object($entity) ? basename(str_replace('\\', '/', get_class($entity))) : false; if ($base && $event) { $event->setEvent($base); switch ($entityName) { case 'Account': switch ($eventName) { case 'AccountEvent': $event->setAccount($entity); $valid = true; break; case 'ErrorEvent': $valid = true; break; } break; case 'Api': switch ($eventName) { case 'ApiEvent': $event->setApi($entity); $valid = true; break; case 'ErrorEvent': $valid = true; break; } break; case 'Report': switch ($eventName) { case 'ReportEvent': $event->setReport($entity); $valid = true; break; case 'AccountEvent': $account = $entity->getAccount(); if ($account) { $event->setAccount($account); $valid = true; } break; } break; case 'Agent': switch ($eventName) { case 'AgentEvent': $event->setAgent($entity); $valid = true; break; } break; case 'Lead': default: switch ($eventName) { case 'TenStreetApiEvent': case 'WebWorksApiEvent': case 'EmailApiEvent': if ($updateEntity && $entity instanceof Lead) { $entity->setLastsubmitted($base->getOccurred()); } $account = $entity->getAccount(); if ($account) { switch ($eventName) { case 'EmailApiEvent': $name = 'Email'; break; case 'WebWorksApiEvent': $name = 'WebWorks'; break; case 'TenStreetApiEvent': $name = 'Tenstreet'; break; } $api = $account->findApi($name); if ($api) { $accountApiEvent = new AccountApiEvent(); $accountApiEvent->setEvent($base)->setApi($api)->setAccount($account); $this->dispatch($entity, $accountApiEvent, $data); // $apiEvent = new ApiEvent(); // $apiEvent->setEvent($base)->setApi($api); // $this->dispatch($entity, $apiEvent, // $data); $valid = true; } $event->setAccount($account); } break; case 'ErrorEvent': $valid = true; break; case 'LeadEvent': $event->setLead($entity); $account = $entity->getAccount(); if ($account) { $accountEvent = new AccountEvent(); $accountEvent->setEvent($base)->setAccount($account); $this->dispatch($entity, $accountEvent, $data); $valid = true; } $valid = true; break; case 'AccountEvent': $account = $entity->getAccount(); if ($account) { $event->setAccount($account); $valid = true; } break; } break; } if ($valid) { try { $hydrator = new DoctrineHydrator($this->getEntityManager(), get_class($event)); foreach (['response', 'trace'] as $serializable) { if (method_exists($event, 'get' . ucwords($serializable))) { $hydrator->addStrategy($serializable, new MaybeSerializableStrategy()); } } $event = $hydrator->hydrate($data, $event); $em = $this->getEntityManager(); $em->persist($event); $em->flush(); if ($updateEntity) { $em->persist($entity); } $em->flush(); } catch (\Exception $e) { // fail silently return false; } return true; } } return false; }