Exemplo n.º 1
0
 /**
  * Is the default view partial correct?
  * Does setting and getting view partial work?
  */
 public function testSetAndGetViewPartial()
 {
     $target = new EmployeeFieldset();
     $this->assertEquals('organizations/form/employee-fieldset', $target->getViewPartial());
     $target->setViewPartial('test1234');
     $this->assertEquals('test1234', $target->getViewPartial());
 }
 /**
  * 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\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;
 }