public function extract($object) { if (!$object instanceof LeadEntity) { throw new \InvalidArgumentException('Lead Entity could not be mapped.'); } return parent::extract($object); }
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 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 extract($object) { if (!$object instanceof AttributeEntity) { throw new \InvalidArgumentException('Attribute Entity could not be mapped.'); } $data = parent::extract($object); return $data; }
/** * Extract values from an object * * @param object $object * @return array * @throws Exception\InvalidArgumentException */ public function extract($object) { if (!$object instanceof Entity\ModuleInterface) { throw new Exception\InvalidArgumentException('$object must be an instance of ZfModule\\Entity\\ModuleEntityInterface'); } $data = parent::extract($object); $this->changeKey('id', 'module_id', $data); $this->changeKey('createdAt', 'created_at', $data); $this->changeKey('updatedAt', 'updated_at', $data); $this->changeKey('photoUrl', 'photo_url', $data); return $data; }
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; }
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'); }
public function testCanExtract() { $this->assertSame(array(), $this->hydrator->extract(new stdClass())); }
/** * {@inheritDoc} * @throws PluginException */ public function extract($object) { return array_merge(parent::extract($object), $this->extractFromPlugins($object)); }