Created
November 25, 2013 17:54
-
-
Save gpfiel/7645531 to your computer and use it in GitHub Desktop.
Bug while check isValid() on runtime isValid() the system redirect to 'home'... The problem is related to DATE while im using the firefox, i needed to use the modernizr with datepicker for (safari, internet explorer and firefox), on chorme it works ok! But when i set the datepicker to format pt_BR somethign happens and the system does not valid …
This file contains hidden or 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 Admin\Entity; | |
use Doctrine\ORM\Mapping as ORM, | |
Doctrine\Common\Collections\ArrayCollection; | |
use Zend\InputFilter\Factory as InputFactory; | |
use Zend\InputFilter\InputFilter; | |
use Zend\InputFilter\InputFilterAwareInterface; | |
use Zend\InputFilter\InputFilterInterface; | |
/** | |
* Album | |
* | |
* @ORM\Table(name="bnc_album") | |
* @ORM\Entity | |
* @ORM\HasLifecycleCallbacks | |
*/ | |
class Album implements InputFilterAwareInterface | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="IDENTITY") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="title", type="string", nullable=false) | |
*/ | |
private $title; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="description", type="text", nullable=true) | |
*/ | |
private $description; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="mainPhoto", type="string", nullable=true) | |
*/ | |
private $mainPhoto; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="date", type="date", nullable=true) | |
*/ | |
private $date; | |
/** | |
* @param integer | |
* | |
* @ORM\Column(name="status", type="integer") | |
*/ | |
private $status; | |
/** | |
* @ORM\OneToMany(targetEntity="Photo", mappedBy="album", cascade={"persist", "remove"}) | |
* @ORM\OrderBy({"orderImage" = "ASC"}) | |
* @var Photo[] | |
*/ | |
protected $assignedPhotos = null; | |
protected $inputFilter; | |
public function __construct() | |
{ | |
$this->assignedPhotos = new ArrayCollection(); | |
} | |
################### | |
# GET AND SETTERS # | |
################### | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
public function setTitle($title) | |
{ | |
$this->title = $title; | |
return $this; | |
} | |
public function getDescription() | |
{ | |
return $this->description; | |
} | |
public function setDescription($description) | |
{ | |
$this->description = $description; | |
return $this; | |
} | |
public function getMainPhoto() | |
{ | |
return $this->mainPhoto; | |
} | |
public function setMainPhoto($mainPhoto) | |
{ | |
$this->mainPhoto = $mainPhoto; | |
return $this; | |
} | |
public function getDate() | |
{ | |
return $this->date; | |
} | |
public function setDate($date) | |
{ | |
$this->date = $date; | |
return $this; | |
} | |
public function getStatus() | |
{ | |
return $this->status; | |
} | |
public function setStatus($status) | |
{ | |
$this->status = $status; | |
return $this; | |
} | |
public function assignedToPhoto($photo) | |
{ | |
$this->assignedPhotos[] = $photo; | |
} | |
public function getAssignedPhotos() | |
{ | |
return $this->assignedPhotos; | |
} | |
/** | |
* Set input method | |
* | |
* @param InputFilterInterface $inputFilter | |
*/ | |
public function setInputFilter(InputFilterInterface $inputFilter) | |
{ | |
throw new \Exception("Not used"); | |
} | |
/** | |
* Get input filter | |
* | |
* @return InputFilterInterface | |
*/ | |
public function getInputFilter() | |
{ | |
if (!$this->inputFilter) { | |
$inputFilter = new InputFilter(); | |
$factory = new InputFactory(); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'id', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'Int'), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'status', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'Int'), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'description', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
), | |
), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'title', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 255, | |
), | |
), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'date', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 255, | |
), | |
), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'mainPhoto', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 255, | |
), | |
), | |
), | |
))); | |
$this->inputFilter = $inputFilter; | |
} | |
return $this->inputFilter; | |
} | |
} |
This file contains hidden or 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 | |
public function editAction() | |
{ | |
$album = new Album; | |
if ((int)$this->params() -> fromRoute('id') > 0) | |
$album = $this->getEntityManager()->getRepository('Admin\Entity\Album')->find($this->params('id')); | |
if(!$album) | |
return $this -> redirect() ->toRoute("album"); | |
$form = new AlbumForm($this->getEntityManager()); | |
$form->setHydrator(new DoctrineEntity($this->getEntityManager(),'Admin\Entity\Album')); | |
$form->bind($album); | |
$request = $this->getRequest(); | |
if ($request->isPost()) { | |
$form->setInputFilter($album->getInputFilter()); | |
$form->setData($request->getPost()); | |
if ($form->isValid()) { | |
$em = $this->getEntityManager(); | |
$em->persist($album); | |
$em->flush(); | |
$this->pluginMensagem()->adicionarMensagem($this->params('action'),'ok', "O álbum <strong>{$album->getTitle()}</strong> foi editado."); | |
return $this->redirect()->toRoute('album'); | |
} | |
} | |
$form->get('date')->setValue(self::formatDate($form->get('date')->getValue())); | |
return new ViewModel(array( | |
'album' => $album, | |
'form' => $form | |
)); | |
} |
This file contains hidden or 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 Admin\Form; | |
use Doctrine\ORM\EntityManager; | |
use Zend\Form\Form; | |
class AlbumForm extends Form | |
{ | |
public function __construct(EntityManager $em) | |
{ | |
parent::__construct('albumForm'); | |
$this->setAttribute('method', 'post'); | |
$this->add(array( | |
'name' => 'id', | |
'type' => 'Zend\Form\Element\Hidden', | |
'attributes' => array( | |
'id' => 'id', | |
) | |
)); | |
$this->add(array( | |
'name' => 'title', | |
'type' => 'Zend\Form\Element\Text', | |
'attributes' => array( | |
'id' => 'title', | |
'placeholder' => 'Título do álbum', | |
'required' => 'required', | |
'class' => 'span6' | |
), | |
'options' => array( | |
'label' => 'Título', | |
), | |
)); | |
$this->add(array( | |
'name' => 'mainPhoto', | |
'attributes' => array( | |
'type' => 'file', | |
'id' => 'file_upload' | |
), | |
'options' => array( | |
), | |
)); | |
$this->add(array( | |
'name' => 'description', | |
'type' => 'Zend\Form\Element\Textarea', | |
'attributes' => array( | |
'id' => 'description', | |
'class' => 'wysiwyg' | |
), | |
'options' => array( | |
'label' => 'Descrição', | |
), | |
)); | |
$this->add(array( | |
'name' => 'status', | |
'type' => 'Zend\Form\Element\Select', | |
'attributes' => array( | |
'required' => 'required', | |
'value' => '1', | |
), | |
'options' => array( | |
'label' => 'Situação', | |
'value_options' => array( | |
'1' => 'Ativo', | |
'2' => 'Inativo', | |
), | |
), | |
)); | |
$this->add(array( | |
'name' => 'date', | |
'type' => 'Zend\Form\Element\Date', | |
'attributes' => array( | |
'placeholder' => 'Selecione a data', | |
'required' => 'required', | |
// 'data-format' => 'd/m/y', | |
'id' => 'thedate', | |
), | |
'options' => array( | |
'format' => 'd/m/Y', | |
'label' => 'Data do álbum', | |
), | |
)); | |
$this->add(array( | |
'name' => 'submit', | |
'attributes' => array( | |
'type' => 'submit', | |
'value' => 'Salvar', | |
'id' => 'submitbutton', | |
'class' => 'btn btn-primary' | |
) | |
)); | |
$this->add(array( | |
'type' => 'Zend\Form\Element\Csrf', | |
'name' => 'csrf', | |
'options' => array( | |
'csrf_options' => array( | |
'timeout' => 600 | |
) | |
) | |
)); | |
} | |
} |
This file contains hidden or 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
$.datepicker.regional['pt-BR'] = { | |
closeText: 'Fechar', | |
prevText: '<Anterior', | |
nextText: 'Próximo>', | |
currentText: 'Hoje', | |
monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho', | |
'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'], | |
monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun', | |
'Jul','Ago','Set','Out','Nov','Dez'], | |
dayNames: ['Domingo','Segunda-feira','Terça-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'], | |
dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'], | |
dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'], | |
weekHeader: 'Sm', | |
// dateFormat: 'dd/mm/yy', | |
firstDay: 0, | |
isRTL: false, | |
showMonthAfterYear: false, | |
yearSuffix: ''}; | |
$.datepicker.setDefaults($.datepicker.regional['pt-BR']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment