Created
October 12, 2014 19:50
-
-
Save alihammad-gist/7c40c811ec1cf007a4a9 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* @package Staff | |
* @subpackage Form | |
* @author Ali Hammad | |
* @version 0.0.1 | |
* | |
*/ | |
namespace Staff\Form; | |
use Staff\Entity\Member as MemberEntity; | |
use Staff\Repository\Rank as RankRepo; | |
use Zend\Form\Form; | |
use Zend\InputFilter\InputFilterProviderInterface; | |
class Member extends Form implements InputFilterProviderInterface | |
{ | |
protected $rankRepository; | |
public function init() | |
{ | |
$this->add(array( | |
'type' => 'text', | |
'name' => 'name', | |
'options' => array( | |
'label' => 'Name', | |
), | |
'attributes' => array( | |
'class' => 'fifty-percent', | |
) | |
)); | |
$this->add(array( | |
'type' => 'select', | |
'name' => 'rank', | |
'options' => array( | |
'label' => 'Select a rank for this member', | |
'value_options' => $this->getRankRepository()->getRanksList(), | |
), | |
)); | |
$this->add(array( | |
'type' => 'file', | |
'name' => 'imagePath', | |
'options' => array( | |
'label' => 'Choose a Display Image', | |
) | |
)); | |
$this->add(array( | |
'type' => 'textarea', | |
'name' => 'description', | |
'options' => array( | |
'label' => 'Description', | |
), | |
'attributes' => array( | |
'class' => 'html-accepted', | |
), | |
)); | |
$this->add(array( | |
'type' => 'submit', | |
'name' => 'submit', | |
'attributes' => array( | |
'value' => 'Save', | |
'class' => 'btn btn-primary pull-right', | |
), | |
)); | |
} | |
public function getInputFilterSpecification() | |
{ | |
return array( | |
'name' => array( | |
'required' => true, | |
'validators' => array( | |
array( | |
'name' => 'stringlength', | |
'options' => array( | |
'max' => 150, | |
) | |
) | |
), | |
'filters' => array( | |
array( | |
'name' => 'htmlentities', | |
) | |
) | |
), | |
'description' => array( | |
'required' => false | |
), | |
'imagePath' => array( | |
'required' => false, | |
'filters' => array( | |
array( | |
'name' => 'filerenameupload', | |
'options' => array( | |
'target' => './public' . MemberEntity::IMAGE_BASE_PATH, | |
'randomize' => true, | |
'use_upload_extension' => true, | |
) | |
), | |
array( | |
'name' => 'callback', | |
'options' => array( | |
'callback' => function ($value) { | |
// the buddy up there returns something like below | |
// array(5) { ["name"]=> string(10) "blocks.jpg" ["type"]=> string(10) "image/jpeg" ["tmp_name"]=> string(46) "./public/img/staff/phpvsS4Sw_543ad29598df1.jpg" ["error"]=> int(0) ["size"]=> int(219072) } | |
// lets get the file name from tmp_name | |
return basename($value['tmp_name']); | |
} | |
) | |
) | |
) | |
) | |
); | |
} | |
public function getRankRepository() | |
{ | |
return $this->rankRepository; | |
} | |
public function setRankRepository(RankRepo $repo) | |
{ | |
$this->rankRepository = $repo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment