public function updateAction()
 {
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-hydrating-result-set', 'action' => 'index'));
     }
     $form = new UserForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new UserFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             unset($data['submit']);
             if (empty($data['usr_registration_date'])) {
                 $data['usr_registration_date'] = '2013-07-19 12:00:00';
             }
             $this->getUsersTable()->update($data, array('usr_id' => $id));
             return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-hydrating-result-set', 'action' => 'index'));
         }
     } else {
         // $form->setData($this->getUsersTable()->select(array('usr_id' => $id))->current()); // this obviously doesn't work
         $user = $this->getUsersTable()->select(array('usr_id' => $id))->current();
         $hydrator = new ReflectionHydrator();
         $form->setData($hydrator->extract($user));
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
 public function updateAction()
 {
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-hydrating-result-set-bind', 'action' => 'index'));
     }
     $form = new UserForm();
     $form->setHydrator(new ReflectionHydrator());
     $user = $this->getUsersTable()->select(array('usr_id' => $id))->current();
     $form->bind($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new UserFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // ToDo raplace the code with something that uses user object
             $data = $form->getData();
             $hydrator = new ReflectionHydrator();
             $data = $hydrator->extract($data);
             // turn the object to array
             unset($data['submit']);
             if (empty($data['usr_registration_date'])) {
                 $data['usr_registration_date'] = '2013-07-19 12:00:00';
             }
             $this->getUsersTable()->update($data, array('usr_id' => $id));
             return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-hydrating-result-set-bind', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $appConfig = $serviceLocator->get('Config');
     $moduleOptions = new ModuleOptions();
     if (isset($appConfig['smarty']) && is_array($appConfig['smarty'])) {
         $hyd = new Reflection();
         $hyd->hydrate($appConfig['smarty'], $moduleOptions);
     }
     return $moduleOptions;
 }
示例#4
0
 public function testHydratorReflection()
 {
     $hydrator = new Reflection();
     $datas = $hydrator->extract($this->reflection);
     $this->assertTrue(isset($datas['foo']));
     $this->assertEquals($datas['foo'], '1');
     $this->assertTrue(isset($datas['fooBar']));
     $this->assertEquals($datas['fooBar'], '2');
     $this->assertTrue(isset($datas['fooBarBaz']));
     $this->assertEquals($datas['fooBarBaz'], '3');
     $test = $hydrator->hydrate(array('foo' => 'foo', 'fooBar' => 'bar', 'fooBarBaz' => 'baz'), $this->reflection);
     $this->assertEquals($test->foo, 'foo');
     $this->assertEquals($test->getFooBar(), 'bar');
     $this->assertEquals($test->getFooBarBaz(), 'baz');
 }
 /**
  * @param EntityManager     $entityManager
  * @param HydratorInterface $hydrator
  */
 public function __construct(EntityManager $entityManager = null)
 {
     if ($entityManager) {
         $this->setEntityManager($entityManager);
     }
     parent::__construct();
 }
示例#6
0
 /**
  * Creates a SettingsEntityHydrator
  */
 public function __construct()
 {
     parent::__construct();
     $this->addFilter('ignoreInternalProperties', function ($property) {
         return "_" != $property[0];
     });
 }
示例#7
0
 public function extract($object)
 {
     if (!$object instanceof LeadEntity) {
         throw new \InvalidArgumentException('Lead Entity could not be mapped.');
     }
     return parent::extract($object);
 }
 public function extract($object)
 {
     if (!$object instanceof AttributeEntity) {
         throw new \InvalidArgumentException('Attribute Entity could not be mapped.');
     }
     $data = parent::extract($object);
     return $data;
 }
 /**
  * Hydrate $object with the provided $data.
  *
  * @param array $data
  * @param Entity\ModuleInterface $object
  * @return Entity\ModuleInterface
  * @throws Exception\InvalidArgumentException
  */
 public function hydrate(array $data, $object)
 {
     if (!$object instanceof Entity\ModuleInterface) {
         throw new Exception\InvalidArgumentException('$object must be an instance of ZfModule\\Entity\\ModuleEntityInterface');
     }
     $this->changeKey('module_id', 'id', $data);
     $this->changeKey('created_at', 'createdAt', $data);
     $this->changeKey('updated_at', 'updatedAt', $data);
     $this->changeKey('photo_url', 'photoUrl', $data);
     return parent::hydrate($data, $object);
 }
示例#10
0
 public function __construct($repOrganization, $repOrganizationName, $repOrganizationImage)
 {
     parent::__construct();
     $this->repOrganization = $repOrganization;
     $this->repOrganizationName = $repOrganizationName;
     $this->repOrganizationImage = $repOrganizationImage;
     //$httpload = new HttploadStrategy($repOrganizationImage);
     //$organizationName = new OrganizationNameStrategy($repOrganizationName);
     //$this->addStrategy('image', $httpload);
     //$this->addStrategy('organizationName', $organizationName);
 }
示例#11
0
 public function extractFromSubmission($object)
 {
     if (!$object instanceof SubmissionEntity) {
         throw new \InvalidArgumentException('Submission Entity could not be mapped.');
     }
     $leadData = parent::extract($object->getLead());
     $formData = parent::extract($object->getForm());
     if (isset($leadData['referrer'])) {
         $formData['source'] = $this->getHost($leadData['referrer']);
     }
     return $formData;
 }
示例#12
0
 public function testCanHydrate()
 {
     $object = new stdClass();
     $this->assertSame($object, $this->hydrator->hydrate(array('foo' => 'bar'), $object));
 }
 /**
  * {@inheritDoc}
  * @throws PluginException
  */
 public function extract($object)
 {
     return array_merge(parent::extract($object), $this->extractFromPlugins($object));
 }