Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Model for a Client
- *
- * This class holds generic information about a client of a project, providing
- * first steps for multi-client-support of the application.
- *
- * @author Manuel Stosic
- */
- class Application_Model_Client
- {
- //region Properties
- /**
- * Filters
- *
- * All filters for this model data
- *
- * @var array
- * @access protected
- */
- protected $_filters;
- /**
- * Validators
- *
- * All validators for this model data
- *
- * @var array
- * @access protected
- */
- protected $_validators;
- /**
- * Client ID
- *
- * @var int
- * @access protected
- */
- protected $_id = 0;
- /**
- * Client Name
- *
- * @var string
- * @access protected
- */
- protected $_name;
- /**
- * Client Description
- *
- * @var string
- * @access protected
- */
- protected $_description;
- /**
- * Client Flag Active
- *
- * @var bool
- * @access protected
- */
- protected $_flag_active;
- /**
- * Client Flag Deleted
- *
- * @var bool
- * @access protected
- */
- protected $_flag_deleted;
- //endregion
- //region Magic functions
- /**
- * __construct()
- *
- * Constructor which sets the filters and validators
- *
- * @access public
- * @param mixed[] $props Array || StdClass of Properties
- */
- public function __construct($props = null)
- {
- // Set Filters
- $this->_filters = array(
- 'id' => array(),
- 'name' => array('StringTrim', 'StripTags'),
- 'description' => array('StringTrim', 'StripTags'),
- 'flag_active' => array(),
- 'flag_deleted' => array()
- );
- // Set Validators
- $this->_validators = array(
- 'id' => array('Int'),
- 'name' => array(new Zend_Validate_StringLength(array('min'=>4, 'max'=>50)), new Zend_Validate_Alnum(true)),
- 'description' => array(new Zend_Validate_StringLength(array('max'=>5000))),
- 'flag_active' => array(),
- 'flag_deleted' => array()
- );
- // Set Properties
- if (!is_null($props)) {
- $this->populate($props);
- }
- }
- //endregion
- //region Setters and getters
- /**
- * setId()
- *
- * Sets the ID of the Client Model
- *
- * @param int $id ID of the Client
- * @access public
- * @return Application_Model_Client
- */
- public function setId($arg)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array('id'=>$arg));
- if (!$input->isValid('id') || $input->id < 0) {
- throw new Zend_Exception('Invalid ID provided');
- }
- $this->_id = (int) $input->id;
- return $this;
- }
- /**
- * getId()
- *
- * Gets the ID of the Client Model
- *
- * @access public
- * @return integer
- */
- public function getId()
- {
- return $this->_id;
- }
- /**
- * setName()
- *
- * Sets the name of the model
- *
- * @access public
- * @return Application_Model_Client
- */
- public function setName($arg)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array('name'=>$arg));
- if (!$input->isValid('name') || is_numeric($input->name)) {
- throw new Zend_Exception('Invalid NAME provided');
- }
- $this->_name = (string) $input->getUnescaped('name');
- return $this;
- }
- /**
- * getName()
- *
- * Returns the name of the client
- *
- * @access public
- * @return string || null
- */
- public function getName()
- {
- return $this->_name;
- }
- /**
- * setDescription()
- *
- * Sets the description of the client
- *
- * @access public
- * @return Application_Model_Client
- */
- public function setDescription($arg)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array('description'=>$arg));
- if (!$input->isValid('description')) {
- throw new Zend_Exception('Invalid DESCRIPTION provided');
- }
- $this->_description = (string) $input->getUnescaped('description');
- return $this;
- }
- /**
- * getDescription()
- *
- * Returns the description of the client
- *
- * @access public
- * @return string || null
- */
- public function getDescription()
- {
- return $this->_description;
- }
- /**
- * setFlagActive()
- *
- * Sets the active flag of the client
- *
- * @access public
- * @return Application_Model_Client
- */
- public function setFlagActive($arg)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array('flag_active'=>$arg));
- if (!$input->isValid('flag_active')) {
- throw new Zend_Exception("Invalid FLAG_ACTIVE provided\n".Zend_Debug::dump($input->getMessages()));
- }
- $this->_description = (string) $input->getUnescaped('flag_active');
- return $this;
- }
- /**
- * getFlagActive()
- *
- * Returns the active flag of the client
- *
- * @access public
- * @return bool || null
- */
- public function getFlagActive()
- {
- return $this->_flag_active;
- }
- /**
- * setFlagDeleted()
- *
- * Sets the deleted flag of the client
- *
- * @access public
- * @return Application_Model_Client
- */
- public function setFlagDeleted($arg)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array('flag_deleted'=>$arg));
- if (!$input->isValid('flag_deleted')) {
- throw new Zend_Exception("Invalid FLAG_DELETED provided\n".Zend_Debug::dump($input->getMessages()));
- }
- $this->_description = (string) $input->getUnescaped('flag_deleted');
- return $this;
- }
- /**
- * getFlagDeleted()
- *
- * Returns the deleted flag of the client
- *
- * @access public
- * @return bool || null
- */
- public function getFlagDeleted()
- {
- return $this->_flag_deleted;
- }
- /**
- * populate()
- *
- * Populates the model with specified attributes
- *
- * @access public
- * @param ArrayObject || array $data Data to be populated
- * @return Application_Model_Client
- */
- public function populate($data)
- {
- if (is_array($data)) {
- $data = new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS);
- }
- if (isset($data->id)) $this->setId($data->id);
- if (isset($data->name)) $this->setName($data->name);
- if (isset($data->description)) $this->setDescription($data->description);
- if (isset($data->flag_active)) $this->setFlagActive($data->flag_active);
- if (isset($data->flag_deleted)) $this->setFlagDeleted($data->flag_deleted);
- }
- /**
- * toArray()
- *
- * Returns the objects data as an array
- *
- * @access public
- * @return array
- */
- public function toArray()
- {
- return array(
- 'id' => $this->getId(),
- 'name' => $this->getName(),
- 'description' => $this->getDescription(),
- 'flag_active' => $this->getFlagActive(),
- 'flag_deleted' => $this->getFlagDeleted()
- );
- }
- //endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment