Created
May 26, 2014 05:48
-
-
Save mockiemockiz/0ccbc5fe9ce36fd2b83a 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 | |
/** | |
* Created by PhpStorm. | |
* User: mockie | |
* Date: 5/19/14 | |
* Time: 7:54 PM | |
*/ | |
namespace Property\Model; | |
use Zend\InputFilter\InputFilterAwareInterface; | |
use Zend\InputFilter\InputFilter; | |
use Zend\InputFilter\InputFilterInterface; | |
class PropertyBaseInputFilter implements InputFilterAwareInterface | |
{ | |
protected $inputFilter; | |
public $id; | |
public $title; | |
public $price; | |
public $type; | |
public $purpose; | |
public $latitude; | |
public $longitude; | |
public $userId; | |
public $address; | |
public $country; | |
public $district; | |
public $city; | |
public $postalCode; | |
public $currencyCode; | |
public $insertDate; | |
public $tags; | |
public $description; | |
public $totalGasStation; | |
public $totalRestaurant; | |
public $totalSchool; | |
public $totalDepartmentStore; | |
public $totalUniversity; | |
public function __construct() | |
{ | |
$this->inputFilter = ''; | |
$this->inputFilter = new InputFilter(); | |
} | |
public function exchangeArray($data) | |
{ | |
$this->id = (!empty($data['id'])) ? $data['id'] : 0; | |
$this->title = (!empty($data['title'])) ? $data['title'] : null; | |
$this->price = (!empty($data['price'])) ? $data['price'] : 0; | |
$this->type = (!empty($data['type'])) ? $data['type'] : null; | |
$this->purpose = (!empty($data['purpose'])) ? $data['purpose'] : null; | |
$this->latitude = (!empty($data['latitude'])) ? $data['latitude'] : 0; | |
$this->longitude = (!empty($data['longitude'])) ? $data['longitude'] : 0; | |
$this->userId = (!empty($data['userId'])) ? $data['userId'] : 0; | |
$this->address = (!empty($data['address'])) ? $data['address'] : null; | |
$this->country = (!empty($data['country'])) ? $data['country'] : null; | |
$this->district = (!empty($data['district'])) ? $data['district'] : null; | |
$this->city = (!empty($data['city'])) ? $data['city'] : null; | |
$this->postalCode = (!empty($data['postalCode'])) ? $data['postalCode'] : null; | |
$this->currencyCode = (!empty($data['currencyCode'])) ? $data['currencyCode'] : null; | |
$this->insertDate = time(); | |
$this->tags = (!empty($data['tags'])) ? $data['tags'] : null; | |
$this->description = (!empty($data['description'])) ? $data['description'] : null; | |
$this->totalGasStation = (!empty($data['totalGasStation'])) ? $data['totalGasStation'] : null; | |
$this->totalRestaurant = (!empty($data['totalRestaurant'])) ? $data['totalRestaurant'] : null; | |
$this->totalSchool = (!empty($data['totalSchool'])) ? $data['totalSchool'] : null; | |
$this->totalDepartmentStore = (!empty($data['totalDepartmentStore'])) ? $data['totalDepartmentStore'] : null; | |
$this->totalUniversity = (!empty($data['totalUniversity'])) ? $data['totalUniversity'] : null; | |
} | |
public function getInputFilter() | |
{ | |
$this->inputFilter->add(array( | |
'name' => 'title', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
), | |
'options' => array( | |
'min' => 8, | |
), | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'price', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
), | |
'validators' => array( | |
array('name' => 'Int'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'type', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'Int'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'purpose', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'Int'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'latitude', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'longitude', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'address', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'country', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'district', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'city', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'postalCode', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags'), | |
) | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'description', | |
'required' => true, | |
'filters' => array() | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'totalGasStation', | |
'required' => false, | |
'filters' => array() | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'totalRestaurant', | |
'required' => false, | |
'filters' => array() | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'totalSchool', | |
'required' => false, | |
'filters' => array() | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'totalDepartmentStore', | |
'required' => false, | |
'filters' => array() | |
)); | |
$this->inputFilter->add(array( | |
'name' => 'period', | |
'required' => false, | |
'filters' => array() | |
)); | |
} | |
public function setInputFilter(InputFilterInterface $inputFilter) | |
{ | |
throw new \Exception("Not used"); | |
} | |
} |
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
if ($dataPost['type'] == 1) { | |
$inputFilter = new PropertyLandInputFilter(); | |
} elseif ($dataPost['type'] == 3) { | |
$inputFilter = new PropertyApartmentInputFilter(); | |
} | |
$inputFilter->userId = $this->identity()->userId; | |
$form->setInputFilter($inputFilter->getInputFilter()); | |
$form->setData($dataPost); | |
if ($form->isValid()) { |
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 | |
/** | |
* Created by PhpStorm. | |
* User: mockie | |
* Date: 5/14/14 | |
* Time: 5:43 PM | |
*/ | |
namespace Property\Form; | |
use Zend\Form\Form; | |
use Zend\Validator\Csrf; | |
class PropertyForm extends Form | |
{ | |
private $intlPlugin; | |
protected function loop($limit = 10) | |
{ | |
$return = array(); | |
for ($a=1; $a<$limit; $a++) { | |
$return[ $a ] = $a; | |
} | |
return $return; | |
} | |
public function __construct($config, $pluginManager) | |
{ | |
parent::__construct('PropertyForm'); | |
$this->intlPlugin = $pluginManager->get('intlPlugin'); | |
$this->add(array( | |
'name' => 'id', | |
'type' => 'Hidden', | |
'attributes' => array( | |
'class' => 'form-control', | |
) | |
)); | |
$this->add(array( | |
'name' => 'type', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'type', | |
'class' => ' js-type form-control', | |
), | |
'options' => array( | |
'label' => _('Property type'), | |
'value_options' => $config['type'] | |
) | |
)); | |
$this->add(array( | |
'name' => 'groupId' | |
)); | |
$this->add(array( | |
'name' => 'availableUnit', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'availableUnit', | |
'class' => ' availableUnit form-control', | |
), | |
'options' => array( | |
'label' => _('Available Unit '), | |
'value_options' => $this->loop(20), | |
) | |
)); | |
$this->add(array( | |
'name' => 'purpose', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'purpose', | |
'class' => ' js-purpose form-control', | |
), | |
'options' => array( | |
'label' => _('Purpose'), | |
'value_options' => $config['purpose'] | |
) | |
)); | |
$this->add(array( | |
'name' => 'period', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'period', | |
'class' => ' js-period form-control', | |
), | |
'options' => array( | |
'label' => _('Period'), | |
'value_options' => $config['period'] | |
) | |
)); | |
$this->add(array( | |
'name' => 'title', | |
'type' => 'Text', | |
'attributes' => array( | |
'data-field-name' => 'title', | |
'class' => ' js-title form-control', | |
), | |
'options' => array( | |
'label' => _('Property title'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'wideLand', | |
'type' => 'Text', | |
'attributes' => array( | |
'data-field-name' => 'wideLand', | |
'class' => ' js-wideLand form-control', | |
), | |
'options' => array( | |
'label' => _('Wide land'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'wideBuilding', | |
'type' => 'Text', | |
'attributes' => array( | |
'data-field-name' => 'wideBuilding', | |
'class' => ' js-wideBuilding form-control', | |
), | |
'options' => array( | |
'label' => _('wide building'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'bedroom', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'bedroom', | |
'class' => ' js-bedroom form-control', | |
), | |
'options' => array( | |
'label' => _('Bedroom'), | |
'empty_option' => _('How many bedroom ?'), | |
'value_options' => $this->loop(20), | |
) | |
)); | |
$this->add(array( | |
'name' => 'bathroom', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'bathroom', | |
'class' => ' js-bathroom form-control', | |
), | |
'options' => array( | |
'label' => _('Bathroom'), | |
'empty_option' => _('How many bathroom ?'), | |
'value_options' => $this->loop(20), | |
) | |
)); | |
$this->add(array( | |
'name' => 'floor', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'floor', | |
'class' => ' js-floor form-control', | |
), | |
'options' => array( | |
'label' => _('Floor'), | |
'empty_option' => _('How many floor ?'), | |
'value_options' => $this->loop(20), | |
) | |
)); | |
$this->add(array( | |
'name' => 'swimmingPool', | |
'type' => 'Checkbox', | |
'attributes' => array( | |
'data-field-name' => 'swimmingPool', | |
'class' => ' js-swimmingPool', | |
), | |
'options' => array( | |
'label' => _('Swimming pool'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'fittedFurniture', | |
'type' => 'Checkbox', | |
'attributes' => array( | |
'data-field-name' => 'fittedFurniture', | |
'class' => ' js-fittedFurniture', | |
), | |
'options' => array( | |
'label' => _('Fitted with furniture'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'country', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'country', | |
'id' => 'js-country', | |
'class' => ' js-country form-control', | |
'data-ajax' => $pluginManager->get('url')->fromRoute('intl/default', array( | |
'controller' => 'City', | |
'action' => 'ajaxDistrictByCountry' | |
), array('force_canonical' => true)), | |
), | |
'options' => array( | |
'label' => _('Country'), | |
'value' => array('IDN'), | |
'value_options' => $this->intlPlugin->getCountryList(), | |
) | |
)); | |
$this->add(array( | |
'name' => 'district', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'district', | |
'id' => 'js-district', | |
'class' => ' js-district form-control', | |
'data-ajax' => $pluginManager->get('url')->fromRoute('intl/default', array( | |
'controller' => 'City', | |
'action' => 'ajaxCityByDistrict' | |
), array('force_canonical' => true)), | |
), | |
'options' => array( | |
'label' => _('District'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'city', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'city', | |
'id' => 'js-city', | |
'class' => ' js-city form-control', | |
), | |
'options' => array( | |
'label' => _('City'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'postalCode', | |
'type' => 'Text', | |
'attributes' => array( | |
'data-field-name' => 'postalCode', | |
'id' => 'js-postalCode', | |
'class' => ' js-postalCode form-control', | |
), | |
'options' => array( | |
'label' => _('Postal Code'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'currencyCode', | |
'type' => 'Select', | |
'attributes' => array( | |
'data-field-name' => 'currencyCode', | |
'id' => 'js-currencyCode', | |
'class' => ' js-currencyCode form-control', | |
), | |
'options' => array( | |
'label' => _('Currency'), | |
'value_options' => $this->intlPlugin->getCurrencyCodeList(), | |
) | |
)); | |
$this->add(array( | |
'name' => 'price', | |
'type' => 'Text', | |
'attributes' => array( | |
'data-field-name' => 'price', | |
'class' => ' js-price form-control', | |
), | |
'options' => array( | |
'label' => _('Property price'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'address', | |
'type' => 'Text', | |
'attributes' => array( | |
'data-field-name' => 'address', | |
'class' => ' address form-control', | |
), | |
'options' => array( | |
'label' => _('Address'), | |
) | |
)); | |
$this->add(array( | |
'name' => 'latitude', | |
'type' => 'Hidden', | |
'attributes' => array( | |
'data-field-name' => 'latitude', | |
'class' => ' latitude form-control', | |
'id' => 'js-latitude' | |
), | |
)); | |
$this->add(array( | |
'name' => 'longitude', | |
'type' => 'Hidden', | |
'attributes' => array( | |
'data-field-name' => 'longitude', | |
'class' => 'longitude form-control', | |
'id' => 'js-longitude' | |
), | |
)); | |
$this->add(array( | |
'name' => 'description', | |
'type' => 'Textarea', | |
'attributes' => array( | |
'id' => 'js-description', | |
'data-field-name' => 'description', | |
'class' => ' js-description form-control', | |
), | |
'options' => array( | |
'label' => _('Description'), | |
) | |
)); | |
$csrfValidator = new Csrf(array('name' => 'csrf', | |
'salt' => 'asdsadasdsa' | |
)); | |
$csrf = new \Zend\Form\Element\Csrf('csrf'); | |
$csrf->setCsrfValidator($csrfValidator); | |
$this->add($csrf); | |
//assign! | |
$this->csrf = $csrf; | |
} | |
} |
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 | |
/** | |
* Created by PhpStorm. | |
* User: mockie | |
* Date: 5/19/14 | |
* Time: 8:13 PM | |
*/ | |
namespace Property\Model; | |
use Zend\InputFilter\InputFilterAwareInterface; | |
class PropertyLandInputFilter extends PropertyBaseInputFilter implements InputFilterAwareInterface | |
{ | |
public $wideLand; | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function exchangeArray($data) | |
{ | |
parent::exchangeArray($data); | |
$this->wideLand = (!empty($data['wideLand'])) ? $data['wideLand'] : null; | |
} | |
public function getInputFilter() | |
{ | |
parent::getInputFilter(); | |
$this->inputFilter->add(array( | |
'name' => 'wideLand', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'Int'), | |
) | |
)); | |
return $this->inputFilter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment