Last active
December 17, 2015 08:18
-
-
Save rufinus/5579117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Form; | |
use DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity as DoctrineHydrator; | |
use Zend\Form\Form; | |
use Zend\ServiceManager\ServiceManager; | |
class Event extends Form | |
{ | |
public function __construct($fields, $calendar, ServiceManager $sm) | |
{ | |
parent::__construct('create_event'); | |
$this->setAttribute('method', 'post'); | |
$fieldset = new \Application\Form\Fieldset\Event($fields, $calendar, $sm); | |
$fieldset->setOptions(array('use_as_base_fieldset' => true)); | |
$this->add($fieldset); | |
$this->add(array( | |
'name' => 'submit', | |
'attributes' => array( | |
'type' => 'submit', | |
'value' => 'Send' | |
) | |
)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Form\Fieldset; | |
use Zend\Form\Element\Radio; | |
use Zend\Form\Element\Select; | |
use Zend\Form\Fieldset; | |
use Zend\InputFilter\InputFilterProviderInterface; | |
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator; | |
use Zend\ServiceManager\ServiceManager; | |
class Event extends Fieldset implements InputFilterProviderInterface | |
{ | |
public function __construct($fields, \Application\Entity\Calendar $calendar, ServiceManager $sm) | |
{ | |
parent::__construct('event'); | |
$this->setHydrator(new DoctrineHydrator($sm->get('Doctrine\ORM\EntityManager'))); | |
$this->setObject(new \Application\Entity\Event()); | |
$this->add( | |
array( | |
'type' => 'hidden', | |
'name' => 'event_id' | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'hidden', | |
'name' => 'calendar_id' | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'name', | |
'options' => array( | |
'label' => 'Eventname' | |
), | |
'attributes' => array( | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'shortname', | |
'options' => array( | |
'label' => 'Shortname' | |
), | |
'attributes' => array( | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'date_start', | |
'options' => array( | |
'label' => 'Date' | |
), | |
'attributes' => array( | |
'id' => 'date-from-raw' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'date_start_display', | |
'options' => array( | |
'label' => 'Date Display' | |
), | |
'attributes' => array( | |
'id' => 'date-from', | |
'class' => 'datepicker' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'date_end', | |
'options' => array( | |
'label' => 'Date' | |
), | |
'attributes' => array( | |
'id' => 'date-to-raw' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'date_end_display', | |
'options' => array( | |
'label' => 'Date Display' | |
), | |
'attributes' => array( | |
'id' => 'date-to', | |
'class' => 'datepicker' | |
) | |
) | |
); | |
$radio = new Radio('state'); | |
$radio->setAttribute('id', 'radio'); | |
if($calendar->getLicence() == 1) { | |
$radio->setValueOptions(array( | |
'0' => 'Info', | |
'1' => 'Geplant' | |
)); | |
}else{ | |
$layout = $calendar->getCalendarLayout(); | |
$radio->setValueOptions(array( | |
'1' => $layout->getRow1Name(), | |
'2' => $layout->getRow2Name(), | |
'3' => $layout->getRow3Name(), | |
'4' => $layout->getRow4Name(), | |
'5' => $layout->getRow5Name() | |
)); | |
} | |
$this->add($radio); | |
$milestoneFs = new \Application\Form\Fieldset\Milestone($sm); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Collection', | |
'name' => 'milestones', | |
'options' => array( | |
'label' => 'Milestones', | |
'allow_add' => true, | |
'should_create_template' => true, | |
'count' => 1, | |
'target_element' => array( | |
'type' => $milestoneFs | |
) | |
) | |
) | |
); | |
$select = new Select('field_id'); | |
$select->setValueOptions($this->getFields($fields)); | |
$select->setAttributes( | |
array( | |
'id' => 'position', | |
'class'=> 'fake-select' | |
) | |
); | |
$this->add($select); | |
$this->add( | |
array( | |
'name' => 'department', | |
'options' => array( | |
'label' => 'Department' | |
), | |
'attributes' => array( | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'responsible', | |
'options' => array( | |
'label' => 'Responsible' | |
), | |
'attributes' => array( | |
) | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Textarea', | |
'name' => 'comment', | |
'options' => array( | |
'label' => 'Comment' | |
), | |
'attributes' => array( | |
) | |
) | |
); | |
} | |
protected function getFields($fields) { | |
$data = array(); | |
foreach($fields as $field) { | |
$data[$field->getFieldId()] = $field->getName(); | |
} | |
return $data; | |
} | |
public function getInputFilterSpecification() | |
{ | |
return array( | |
array( | |
'name' => 'name', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 150 | |
) | |
) | |
) | |
), | |
array( | |
'name' => 'shortname', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 0, | |
'max' => 50 | |
) | |
) | |
) | |
), | |
array( | |
'name' => 'date_start', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
) | |
), | |
array( | |
'name' => 'department', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 0, | |
'max' => 150 | |
) | |
) | |
) | |
), | |
array( | |
'name' => 'responsible', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 0, | |
'max' => 100 | |
) | |
) | |
) | |
), | |
array( | |
'name' => 'comment', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
), | |
), | |
array( | |
'name' => 'state', | |
'required' => true | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Form\Fieldset; | |
use Zend\Form\Fieldset; | |
use Zend\InputFilter\InputFilterProviderInterface; | |
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator; | |
use Zend\ServiceManager\ServiceManager; | |
class Milestone extends Fieldset implements InputFilterProviderInterface | |
{ | |
public function __construct(ServiceManager $sm) | |
{ | |
parent::__construct('milestone'); | |
$this->setHydrator(new DoctrineHydrator($sm->get('Doctrine\ORM\EntityManager'))); | |
$this->setObject(new \Application\Entity\Milestone()); | |
$this->add( | |
array( | |
'type' => 'hidden', | |
'name' => 'date_start', | |
'options' => array( | |
//'label' => 'Date start' | |
), | |
'attributes' => array( | |
'id' => 'milestones-from-__ID__-raw' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'hidden', | |
'name' => 'event_id' | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'hidden', | |
'name' => 'milestone_id' | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'milestones_display_from', | |
'options' => array( | |
'label' => 'from' | |
), | |
'attributes' => array( | |
'id' => 'milestones-from-__ID__', | |
'class' => 'datepicker' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'hidden', | |
'name' => 'date_end', | |
'options' => array( | |
//'label' => 'Date end' | |
), | |
'attributes' => array( | |
'id' => 'milestones-to-__ID__-raw' | |
) | |
) | |
); | |
$this->add( | |
array( | |
'name' => 'milestones_display_to', | |
'options' => array( | |
'label' => 'to' | |
), | |
'attributes' => array( | |
'id' => 'milestones-to-__ID__', | |
'class' => 'datepicker' | |
) | |
) | |
); | |
} | |
public function getInputFilterSpecification() | |
{ | |
return array( | |
array( | |
'name' => 'date_start', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
) | |
), | |
array( | |
'name' => 'date_to', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim') | |
) | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function editAction() | |
{ | |
// Removed some unnessary lines... | |
$form = new Event($fields, $calendar, $this->getServiceLocator()); | |
$form->bind($event); | |
if($this->getRequest()->isPost()) { | |
$form->setData($this->getRequest()->getPost()); | |
if($form->isValid()) { | |
echo '<pre>'.print_r($form->getData(),1).'</pre>'; | |
$this->getEntityManager()->flush(); | |
} | |
} | |
$view->setVariable('form', $form); | |
return $view; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PHP Warning: Illegal offset type in isset or empty in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 669 | |
PHP Warning: Illegal offset type in isset or empty in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 822 | |
PHP Warning: strtr() expects parameter 1 to be string, object given in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 827 | |
PHP Warning: Illegal offset type in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 827 | |
PHP Warning: class_exists() expects parameter 1 to be string, object | |
given in [PATH]/Zend/ServiceManager/AbstractPluginManager.php on line 98 | |
PHP Warning: Illegal offset type in isset or empty in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 443 | |
PHP Warning: Illegal offset type in isset or empty in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 822 | |
PHP Warning: strtr() expects parameter 1 to be string, object given in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 827 | |
PHP Warning: Illegal offset type in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 827 | |
PHP Warning: Illegal offset type in isset or empty in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 822 | |
PHP Warning: strtr() expects parameter 1 to be string, object given in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 827 | |
PHP Warning: Illegal offset type in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 827 | |
PHP Catchable fatal error: Object of class | |
Application\Form\Fieldset\Milestone could not be converted to string in | |
[PATH]/Zend/ServiceManager/ServiceManager.php on line 500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment