public function __construct(array $data = null)
 {
     if (!empty($data)) {
         $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
         $hydrator->hydrate($data, $this);
     }
 }
 public function __construct($data)
 {
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods(false);
     $hydrator->hydrate($data, $this);
     // count the votes
     $this->countVotes();
 }
Beispiel #3
0
 public function __construct($data = null)
 {
     if (null !== $data) {
         $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
         $hydrator->hydrate($data, $this);
     }
 }
Beispiel #4
0
 public function toArray()
 {
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
     $array = $hydrator->extract($this);
     unset($array['iterator_class']);
     unset($array['iterator']);
     unset($array['flags']);
     unset($array['array_copy']);
     return $array;
 }
 public function update(array $data)
 {
     if (!isset($data['id'])) {
         throw new \InvalidArgumentException("A key ID é obrigatória dentro do array");
     }
     $entity = $this->getEm()->getReference('\\SON\\Entity\\Task', $data['id']);
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
     $hydrator->hydrate($data, $entity);
     $this->getEm()->persist($entity);
     $this->getEm()->flush();
     return $entity;
 }
Beispiel #6
0
 public function getExistingParent($option)
 {
     if (is_array($option)) {
         $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
         $option = $hydrator->hydrate($option, new \SpeckCatalog\Model\Option\Relational());
     }
     $parent = null;
     if ($option->getProductId()) {
         $data = array('product_id' => $option->getProductId());
         $parent = $this->getProductService()->find($data);
     } elseif ($option->getChoiceId()) {
         $data = array('choice_id' => $option->getChoiceId());
         $parent = $this->getChoiceService()->find($data);
     }
     return $parent;
 }
 /**
  * Create the fieldset.
  *
  * {@inheritDoc}
  *
  * @return EmployeeFieldset
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $serviceLocator \Zend\ServiceManager\AbstractPluginManager */
     $services = $serviceLocator->getServiceLocator();
     $fieldset = new EmployeeFieldset();
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods(false);
     //new EntityHydrator();
     $repositories = $services->get('repositories');
     $users = $repositories->get('Auth/User');
     /* @var $users \Auth\Repository\User */
     /* todo: WRITE own Hydrator strategy class */
     $strategy = new ClosureStrategy(function ($object) use($users) {
         if (is_string($object)) {
             return $users->find($object);
         }
         return $object;
     }, function ($data) use($users) {
         if (is_string($data)) {
             $data = $users->find($data);
         }
         return $data;
     });
     /* todo: write own strategy class */
     $permStrategy = new ClosureStrategy(function ($object) {
         /* @var $object \Organizations\Entity\EmployeePermissionsInterface */
         $values = array();
         foreach (array(Perms::JOBS_VIEW, Perms::JOBS_CHANGE, PERMS::JOBS_CREATE, Perms::APPLICATIONS_VIEW, Perms::APPLICATIONS_CHANGE) as $perm) {
             if ($object->isAllowed($perm)) {
                 $values[] = $perm;
             }
         }
         return $values;
     }, function ($data) {
         $permissions = array_reduce($data, function ($c, $i) {
             return $c | $i;
         }, 0);
         return new EmployeePermissions($permissions);
     });
     $hydrator->addStrategy('user', $strategy);
     $hydrator->addStrategy('permissions', $permStrategy);
     $fieldset->setHydrator($hydrator);
     $fieldset->setObject(new \Organizations\Entity\Employee());
     return $fieldset;
 }
Beispiel #8
0
 /**
  * Return the rowset as array:
  * The parameter is a column name that is used as the array index.
  * Without the parameter the function looks after a nId-column to use as array indizes.
  * If the column was not found a normal non assoziative array is returned.
  *
  * Column as Index    |
  * (standard: id):   |    No Column as Index:
  *                    |
  * array(             |    array(
  *   4 => ..,         |      0 => ...,
  *   23 => ...,       |      1 => ...,
  *   16 => ...        |      2 => ...
  * )                  |    )
  *
  *
  * ATTENTION: Think over when using the parameter! Otherwise rows can be lost!
  *
  * @param  string|null $columnAsIndex Name of the column that serves as array index.
  * @return array
  */
 public function getArrayCopy($columnAsIndex = null)
 {
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
     if (!empty($columnAsIndex)) {
         $result = array();
         if (is_array($columnAsIndex) && count($columnAsIndex) == 2) {
             // compound primary key
             foreach ($this as $row) {
                 $tmp = is_object($row) ? $hydrator->extract($row) : $row;
                 if (!isset($result[$tmp[$columnAsIndex[0]]])) {
                     $result[$tmp[$columnAsIndex[0]]] = array();
                 }
                 $result[$tmp[$columnAsIndex[0]]][$tmp[$columnAsIndex[1]]] = $tmp;
             }
         } elseif (is_string($columnAsIndex)) {
             // primary key is given
             foreach ($this as $row) {
                 $tmp = is_object($row) ? $hydrator->extract($row) : $row;
                 $result[$tmp[$columnAsIndex]] = $tmp;
             }
         } else {
             // primary key not given
             try {
                 // try to take 'id' as primary key
                 foreach ($this as $row) {
                     $tmp = is_object($row) ? $hydrator->extract($row) : $row;
                     $result[$tmp['id']] = $tmp;
                 }
             } catch (Exception $e) {
                 // 'id' doesn't work, so just convert to array
                 //$this->log(\Zend\Log\Loger::INFO, 'getArrayCopy(): could not determine primary key');
                 $result = $this->toArray();
             }
         }
     } else {
         $result = $this->toArray();
     }
     return $result;
 }
Beispiel #9
0
 public function __construct($data)
 {
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods(false);
     $hydrator->hydrate($data, $this);
 }
Beispiel #10
0
 /**
  * Utilise les donnée du tableau pour remplir le model.
  *
  * @param array
  */
 public function exchangeArray($aData)
 {
     $oHydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
     $oHydrator->hydrate($aData, $this);
 }
Beispiel #11
0
 public function __construct(array $data = null)
 {
     if (!empty($data)) {
         $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
         $hydrator->hydrate($data, $this);
     }
     $this->_candidate_neighborhoods = array();
 }
 public function toArray()
 {
     $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
     return $hydrator->extract($this);
 }