public function getDepartmentsAction()
 {
     $results = [];
     $departmentId = $this->params('id', false);
     try {
         $UserContainer = new Container('User');
         $em = $this->getEntityManager();
         if ($departmentId === false) {
             $restrictedBy['parent'] = null;
             if (empty($UserContainer->id)) {
                 $restrictedBy['isActive'] = true;
             }
             $departments = $em->getRepository('AdministrativeStructure\\Entity\\Department')->findBy($restrictedBy);
         } else {
             if (empty($UserContainer->id)) {
                 $departments = $em->getReference('AdministrativeStructure\\Entity\\Department', $departmentId)->getActiveChildren()->toArray();
             } else {
                 $departments = $em->getReference('AdministrativeStructure\\Entity\\Department', $departmentId)->getChildren()->toArray();
             }
         }
         if (count($departments) > 0) {
             $hydrator = new DoctrineHydrator($em);
             foreach ($departments as $dep) {
                 $extractedArray = $hydrator->extract($dep);
                 $extractedArray['numberOfChildren'] = $dep->getNumberOfChildren();
                 $results[] = $extractedArray;
             }
         }
         return new JsonModel(['message' => null, 'results' => $results]);
     } catch (Exception $ex) {
         return new JsonModel(['message' => $ex->getMessage(), 'results' => []]);
     }
 }
 public function execute()
 {
     $hydrator = new DoctrineHydrator($this->getEntityManager());
     $dataPrepared = [];
     foreach ($this->getData() as $row) {
         $dataExtracted = $hydrator->extract($row);
         $rowExtracted = [];
         foreach ($this->getColumns() as $column) {
             /* @var $column \ZfcDatagrid\Column\AbstractColumn */
             $part1 = $column->getSelectPart1();
             $part2 = $column->getSelectPart2();
             if (null === $part2) {
                 if (isset($dataExtracted[$part1])) {
                     $rowExtracted[$column->getUniqueId()] = $dataExtracted[$part1];
                 }
             } else {
                 // NESTED
                 if (isset($dataExtracted[$part1])) {
                     $dataExtractedNested = $hydrator->extract($dataExtracted[$part1]);
                     if (isset($dataExtractedNested[$part2])) {
                         $rowExtracted[$column->getUniqueId()] = $dataExtractedNested[$part2];
                     }
                 }
             }
         }
         $dataPrepared[] = $rowExtracted;
     }
     $source = new SourceArray($dataPrepared);
     $source->setColumns($this->getColumns());
     $source->setSortConditions($this->getSortConditions());
     $source->setFilters($this->getFilters());
     $source->execute();
     $this->setPaginatorAdapter($source->getPaginatorAdapter());
 }
Beispiel #3
0
 /**
  * Edit action
  *
  * @return \Zend\Http\Response|ViewModel
  * @throws \Doctrine\ORM\EntityNotFoundException
  */
 public function editAction()
 {
     $form = $this->getEditForm();
     $entity = $form->getObject();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost()->toArray();
         $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $hydrator = new DoctrineHydrator($entityManager);
         $hydrator->hydrate($data, $entity);
         if ($form->isValid()) {
             $entityManager->persist($entity);
             $entityManager->flush();
             $authService = new Service\Auth($this->getServiceLocator());
             if ($form->get('password')->getValue()) {
                 $authService->generateEquals($entity, $form->get('password')->getValue());
             }
             if (!$this->getRequest()->isXmlHttpRequest()) {
                 return $this->redirect()->toRoute(null, ['controller' => 'management']);
             } else {
                 return;
             }
         }
     }
     $viewModel = new ViewModel(['form' => $form]);
     $viewModel->setTerminal($this->getRequest()->isXmlHttpRequest());
     return $viewModel;
 }
 public function loadAction()
 {
     $userId = $this->params()->fromRoute('user_id');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $userRepository = $em->getRepository(User::class);
     $user = $userRepository->find($userId);
     $hydrator = new DoctrineObject($em, User::class);
     return new JsonModel($hydrator->extract($user));
 }
 /**
  * @param array $affiliateData
  * @return Affiliate
  */
 public function registerNewAffiliate(array $affiliateData)
 {
     $hydrator = new DoctrineHydrator($this->getEntityManager());
     $affiliate = $hydrator->hydrate($affiliateData, new Affiliate());
     $entityManager = $this->getEntityManager();
     $entityManager->persist($affiliate);
     $entityManager->flush();
     return $affiliate;
 }
 /**
  * @param object $entity
  * @param array $dadosArray
  * @return null|object
  */
 public function update($entity = null, $dadosArray = null)
 {
     if (!is_null($dadosArray)) {
         $hydrator = new DoctrineHydrator($this->em);
         $entity = $hydrator->hydrate($dadosArray, $entity);
     }
     $this->em->flush();
     return $entity;
 }
Beispiel #7
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Contact\\Entity\\OptIn');
     $this->optIn = $hydrator->hydrate($this->optInData, new OptIn());
     $this->entityManager->persist($this->optIn);
     $this->entityManager->flush();
     $this->assertInstanceOf('Contact\\Entity\\OptIn', $this->optIn);
     $this->assertNotNull($this->optIn->getId());
     $this->assertEquals($this->optIn->getOptIn(), $this->optInData['optIn']);
 }
 public function save($data)
 {
     $entityManager = $this->getEntityManager();
     /** @var DoctrineHydrator $hydrator */
     $hydrator = new DoctrineHydrator($entityManager, 'Authorization\\Entity\\Provider');
     $provider = $hydrator->hydrate($data, new Provider());
     $entityManager->persist($provider);
     $entityManager->flush();
     return $provider;
 }
 public function revisionEntityValueAction()
 {
     $revisionEntity = $this->getObjectManager()->getRepository('ZF\\Doctrine\\Audit\\Entity\\RevisionEntity')->find($this->params()->fromRoute('revision_entity_id'));
     $auditEntity = $this->getObjectManager()->getRepository($revisionEntity->getTargetEntity()->getAuditEntity()->getName())->findOneBy(['revisionEntity' => $revisionEntity]);
     $hydrator = new DoctrineHydrator($this->getObjectManager(), false);
     $data = $hydrator->extract($auditEntity);
     unset($data['revisionEntity']);
     ksort($data);
     return new ViewModel(['payload' => $data]);
 }
Beispiel #10
0
 public function indexAction()
 {
     $user = $this->identity();
     $em = $this->getServiceLocator()->get('Doctrine\\ORm\\EntityManager');
     $hydrator = new DoctrineObject($em, get_class($user));
     $data = $hydrator->extract($user);
     $form = new RegisterForm();
     $form->bind(new ArrayObject($data));
     return new ViewModel(['form' => $form]);
 }
Beispiel #11
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Contact\\Entity\\AddressType');
     $this->addressType = $hydrator->hydrate($this->addressTypeData, new AddressType());
     $this->entityManager->persist($this->addressType);
     $this->entityManager->flush();
     $this->assertInstanceOf('Contact\\Entity\\AddressType', $this->addressType);
     $this->assertNotNull($this->addressType->getId());
     $this->assertEquals($this->addressType->getType(), $this->addressTypeData['type']);
 }
 public function init()
 {
     $hydrator = new DoctrineHydrator($this->getObjectManager(), 'Agent\\Entity\\Agent');
     $hydrator->addStrategy('updated', new DateTimeStrategy());
     $this->setAttribute('method', 'post')->setHydrator($hydrator)->setObject(new Agent());
     $dateTime = date('Y-m-d H:i:s');
     $this->add(array('type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'id', 'required' => false));
     $this->add(array('type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'updated', 'required' => true, 'attributes' => array('value' => $dateTime)));
     $this->add(array('name' => 'filter', 'type' => 'Agent\\Form\\Fieldset\\FilterFieldset', 'options' => array('label' => "Filters", 'use_as_base_fieldset' => false), 'attributes' => array('id' => 'filter', 'class' => 'collection-fieldset')));
     $this->add(array('type' => 'Application\\Form\\Element\\Collection', 'name' => 'criteria', 'required' => false, 'options' => array('column-size' => 'md-12', 'label' => '3. Add Criteria', 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__index__', 'allow_add' => true, 'allow_remove' => true, 'target_element' => array('type' => 'Agent\\Form\\Fieldset\\AgentCriterionFieldset')), 'attributes' => array('id' => 'criteria', 'class' => 'collection-fieldset criteria-fieldset')));
 }
 public function getList()
 {
     $hydrator = new DoctrineObject($this->getEntityManager(), 'Application\\Entity\\Position');
     $positionEntities = $this->getEntityManager()->getRepository('Application\\Entity\\Position')->getLastPosition(['timeToExpire' => self::TIME_TO_EXPIRE]);
     $position = [];
     foreach ($positionEntities as $entity) {
         $img = $this->getImageDir() . '' . $entity->getImage();
         $entity->setImage($img);
         $position[] = $hydrator->extract($entity);
     }
     return new JsonModel($position);
 }
Beispiel #14
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Program\\Entity\\Roadmap');
     $this->roadmap = $hydrator->hydrate($this->roadmapData, new Roadmap());
     $this->entityManager->persist($this->roadmap);
     $this->entityManager->flush();
     $this->assertInstanceOf('Program\\Entity\\Roadmap', $this->roadmap);
     $this->assertNotNull($this->roadmap->getId());
     $this->assertSame($this->roadmapData['roadmap'], $this->roadmap->getRoadmap());
     $this->assertSame($this->roadmapData['description'], $this->roadmap->getDescription());
     $this->assertSame($this->roadmapData['dateReleased'], $this->roadmap->getDateReleased());
 }
Beispiel #15
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Contact\\Entity\\Web');
     $this->web = $hydrator->hydrate($this->webData, new Web());
     $this->entityManager->persist($this->web);
     $this->entityManager->flush();
     $this->assertInstanceOf('Contact\\Entity\\Web', $this->web);
     $this->assertNotNull($this->web->getId());
     $this->assertNotNull($this->web->getResourceId());
     $this->assertEquals($this->web->getContact()->getId(), $this->webData['contact']->getId());
     $this->assertEquals($this->web->getWeb(), $this->webData['web']);
 }
 /**
  * Update an existing resource
  *
  * @param mixed $id
  * @param mixed $data
  * @throws \Exception
  * @return mixed
  */
 public function update($id, $data)
 {
     $indicateurRepository = $this->getIndicsUsersRepository();
     $indicUser = $indicateurRepository->find($id);
     if (empty($indicUser)) {
         throw new \Exception('Aucun enregistrement trouvé pour cet id : ' . $id);
     }
     $hydrator = new DoctrineHydrator($this->entityManager);
     $indicUser = $hydrator->hydrate($data, $indicUser);
     $this->entityManager->flush();
     return new JsonModel(array("data" => $data));
 }
Beispiel #17
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'General\\Entity\\Eu');
     $this->eu = $hydrator->hydrate($this->euData, new Eu());
     $this->entityManager->persist($this->eu);
     $this->entityManager->flush();
     //Since we don't save, we give the $eu a virtual id
     $this->eu->setId(1);
     $this->assertInstanceOf('General\\Entity\\Eu', $this->eu);
     $this->assertNotNull($this->eu->getId());
     $this->assertEquals($this->eu->getSince(), $this->euData['since']);
     $this->assertEquals($this->eu->getCountry()->getCountry(), $this->euData['country']->getCountry());
 }
Beispiel #18
0
 public function create($data)
 {
     var_dump($data);
     $hydrator = new DoctrineObject($this->objectManager, 'Application\\Entity\\Credentials');
     $person = new Person();
     $credentials = new Credentials();
     $credentials->setOwner($person);
     $hydrator->hydrate($data, $credentials);
     $person->addCredential($credentials);
     $this->objectManager->persist($person);
     $this->objectManager->flush();
     return $person;
 }
Beispiel #19
0
 /**
  * display form to let user update some of profile data
  *
  * @return ViewModel
  */
 public function indexAction()
 {
     $form = new RegisterForm();
     $profileLayout = new ViewModel();
     $profileLayout->setTemplate('layout/profile');
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $user = $this->identity();
     $hydrate = new DoctrineObject($em, '\\Application\\Entity\\User');
     $userData = $hydrate->extract($user);
     $form->bind(new ArrayObject($userData));
     $this->actionView->setVariables(['form' => $form]);
     return $this->actionView;
 }
Beispiel #20
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Program\\Entity\\Domain');
     $this->domain = $hydrator->hydrate($this->domainData, new Domain());
     $this->entityManager->persist($this->domain);
     $this->entityManager->flush();
     $this->assertInstanceOf('Program\\Entity\\Domain', $this->domain);
     $this->assertNotNull($this->domain->getId());
     $this->assertSame($this->domainData['domain'], $this->domain->getDomain());
     $this->assertSame($this->domainData['roadmap']->getId(), $this->domain->getRoadmap()->getId());
     $this->assertSame($this->domainData['description'], $this->domain->getDescription());
     $this->assertSame($this->domainData['color'], $this->domain->getColor());
     $this->assertSame($this->domainData['mainId'], $this->domain->getMainId());
 }
Beispiel #21
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // Grab the entity manager.
     $em = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     // Set up a hydrator
     $hydrator = new DoctrineHydrator($em);
     $nullStrategy = new NullStrategy();
     $hydrator->addStrategy('estimatedHours', $nullStrategy);
     $hydrator->addStrategy('actualHours', $nullStrategy);
     // Create the form.
     $form = new TaskForm($em);
     $form->setHydrator($hydrator);
     return $form;
 }
Beispiel #22
0
 /**
  * @return ViewModel
  */
 public function createAction()
 {
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $repository = $entityManager->getRepository('Categories\\Entity\\Categories');
     /** @var \Categories\Service\Categories $categoriesService */
     $categoriesService = $this->getServiceLocator()->get('Categories\\Service\\Categories');
     $form = $this->getCreateForm();
     $parentId = !$this->params()->fromRoute('parentId') ? null : $this->params()->fromRoute('parentId');
     $urlHelper = $this->getServiceLocator()->get('viewhelpermanager')->get('url');
     $form->setAttribute('action', $urlHelper('categories/create', ['parentId' => $parentId]));
     if ($this->getRequest()->isPost()) {
         $form->setInputFilter(new Filter\CreateInputFilter($this->getServiceLocator()));
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             $aliasValid = new Validator\NoObjectExists(['object_repository' => $repository, 'fields' => ['alias', 'parentId']]);
             if ($aliasValid->isValid(['alias' => $form->get('alias')->getValue(), 'parentId' => $parentId])) {
                 $category = $this->getEntity();
                 $category->setParentId(!$parentId ? null : $repository->find($parentId));
                 $category->setOrder($this->getMaxOrder($parentId));
                 $hydrator = new DoctrineHydrator($entityManager);
                 $hydrator->hydrate($form->getData(), $category);
                 $entityManager->persist($category);
                 $entityManager->flush();
                 //Add image from session
                 if ($categoriesService->ifImagesExist()) {
                     $imageService = $this->getServiceLocator()->get('Media\\Service\\File');
                     foreach ($categoriesService->getSession()->ids as $imageId) {
                         $imageService->associateFileWithObject($this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager')->getRepository('Media\\Entity\\File')->find($imageId), $category);
                     }
                     $categoriesService->clearImages();
                 }
                 $this->flashMessenger()->addSuccessMessage('Category has been successfully created!');
                 if (!$this->getRequest()->isXmlHttpRequest()) {
                     return $this->redirect()->toRoute('categories/default', array('controller' => 'management', 'action' => 'index'));
                 } else {
                     return;
                 }
             } else {
                 $form->get('alias')->setMessages(array('errorMessageKey' => 'Alias must be unique in it\'s category!'));
             }
         }
     } else {
         $categoriesService->clearImages();
     }
     $imageService = new File($this->getServiceLocator());
     $viewModel = new ViewModel();
     $viewModel->setVariables(['form' => $form, 'fileUpload' => ['imageService' => $imageService, 'module' => 'image-categories', 'type' => \Media\Entity\File::IMAGE_FILETYPE, 'id' => null]]);
     $viewModel->setTerminal($this->getRequest()->isXmlHttpRequest());
     return $viewModel;
 }
Beispiel #23
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Contact\\Entity\\Email');
     $this->email = $hydrator->hydrate($this->emailData, new Email());
     $this->entityManager->persist($this->email);
     $this->entityManager->flush();
     $this->assertInstanceOf('Contact\\Entity\\Email', $this->email);
     $this->assertNotNull($this->email->getId());
     $this->assertNotNull($this->email->getDateCreated());
     $this->assertNotNull($this->email->getDateUpdated());
     $this->assertEquals($this->email->getContact()->getId(), $this->emailData['contact']->getId());
     $this->assertEquals($this->email->getEmail(), $this->emailData['email']);
     $this->assertNotNull($this->email->getResourceId());
 }
 /**
  * Load users.
  *
  * @param  ObjectManager $manager Object manager instance.
  *
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     $users = $this->getUsersToPopulate();
     $hydrator = new DoctrineHydrator($manager);
     echo 'Creating users..', PHP_EOL;
     $i = 0;
     foreach ($users as $item) {
         $user = $hydrator->hydrate($item, new UserEntity());
         $manager->persist($user);
         echo '.';
         $i++;
     }
     $manager->flush();
     echo PHP_EOL, 'Total of ', $i, ' users created.', PHP_EOL;
 }
Beispiel #25
0
 public function testCanSaveEntityInDatabase()
 {
     $hydrator = new DoctrineObject($this->entityManager, 'Contact\\Entity\\Address');
     $this->address = $hydrator->hydrate($this->addressData, new Address());
     $this->entityManager->persist($this->address);
     $this->entityManager->flush();
     $this->assertInstanceOf('Contact\\Entity\\Address', $this->address);
     $this->assertNotNull($this->address->getId());
     $this->assertEquals($this->address->getContact()->getId(), $this->addressData['contact']->getId());
     $this->assertEquals($this->address->getAddress(), $this->addressData['address']);
     $this->assertEquals($this->address->getZipcode(), $this->addressData['zipcode']);
     $this->assertEquals($this->address->getCity(), $this->addressData['city']);
     $this->assertEquals($this->address->getCountry()->getId(), $this->addressData['country']->getId());
     $this->assertNotNull($this->address->getResourceId());
 }
Beispiel #26
0
 protected function handleTypeConversions($value, $typeOfField)
 {
     if ($typeOfField == 'datetime') {
         return \DateTime::createFromFormat('d/m/Y', $value);
     }
     return parent::handleTypeConversions($value, $typeOfField);
 }
Beispiel #27
0
 /**
  * @param array $memberData
  * @return Member
  */
 public function registerNewMember(array $memberData)
 {
     $hydrator = new DoctrineHydrator($this->getEntityManager());
     $member = new Member();
     $member->setServiceLocator($this->getServiceLocator());
     $member = $hydrator->hydrate($memberData, $member);
     $entityManager = $this->getEntityManager();
     $entityManager->persist($member);
     $entityManager->flush();
     $mailService = $this->getMailService();
     $message = $mailService->prepareMessage('signup', array('member' => $member));
     $message->addTo($member->getEmail(), $member->getName());
     $message->setSubject('USCSS New Member Confirmation');
     $mailService->send($message);
     return $member;
 }
 public function addAction()
 {
     $request = $this->getRequest();
     if ($this->_isXmlHttpRequestViaPost()) {
         $em = $this->getEntityManager();
         $entity = new CalendarWorkItem();
         $start = new \DateTime();
         $start->setTimestamp(strtotime($this->params()->fromPost('start')));
         // Hydration
         $hydrator = new DoctrineHydrator($em);
         $hydrator->hydrate(array('name' => $this->params()->fromPost('title'), 'startAt' => $start, 'user' => $this->getCurrentUser(), 'calendar' => $this->getCurrentUser()->getCalendar()), $entity);
         $em->persist($entity);
         $em->flush();
         return new JsonModel(array('id' => $entity->getId()));
     }
 }
 /**
  * Extract entity into a flat array where references become getId()
  * then hydrate the auditEntity with those values.
  * Return the array of values for identifier processing.
  *
  * The auditing entity may have fields the target does not.  To handle changes
  * to the data model without losing data fields are revisioned.  All fields
  * remain in the audit database but only those fields which are active will be
  * audited here.
  */
 private function hydrateAuditEntityFromTargetEntity($auditEntity, $entity) : array
 {
     // Get list of active fields
     $queryBuilder = $this->getAuditObjectManager()->createQueryBuilder();
     $queryBuilder2 = $this->getAuditObjectManager()->createQueryBuilder();
     $queryBuilder->select('field.name')->from('ZF\\Doctrine\\Audit\\Entity\\Field', 'field')->innerJoin('field.fieldRevision', 'fieldRevision')->innerJoin('fieldRevision.fieldStatus', 'fieldStatus')->andWhere('fieldStatus.name = :fieldStatusName')->andWhere($queryBuilder->expr()->in('fieldRevision.id', $queryBuilder2->select('MAX(fieldRevision2.id)')->from('ZF\\Doctrine\\Audit\\Entity\\FieldRevision', 'fieldRevision2')->innerJoin('fieldRevision2.field', 'field2')->innerJoin('field2.targetEntity', 'targetEntity')->andWhere('targetEntity.name = :targetEntity')->groupBy('field2.id')->getQuery()->getDql()))->setParameter('fieldStatusName', 'active')->setParameter('targetEntity', get_class($entity));
     $auditFields = array_column($queryBuilder->getQuery()->getArrayResult(), 'name');
     $properties = array();
     $hydrator = new DoctrineHydrator($this->getObjectManager(), true);
     $auditHydrator = new DoctrineHydrator($this->getAuditObjectManager(), false);
     foreach ($hydrator->extract($entity) as $key => $value) {
         if (gettype($value) == 'object' and method_exists($value, 'getId')) {
             // Set values to getId for classes
             $value = $value->getId();
         } elseif ($value instanceof \Doctrine\ORM\PersistentCollection) {
             // If a property is an object we probably are not mapping that to
             // a field.  Do no special handing...
             continue;
         } elseif ($value instanceof \DateTime) {
             // DateTime is special and ok as-is
         } elseif (gettype($value) == 'object' and !method_exists($value, 'getId')) {
             throw new Exception(get_class($value) . " does not have a getId function");
         }
         if (in_array($key, $auditFields)) {
             $properties[$key] = $value;
         }
     }
     $auditHydrator->hydrate($properties, $auditEntity);
     return $properties;
 }
 public function testHydrateByValueUsesNamingStrategy()
 {
     $this->configureObjectManagerForNamingStrategyEntity();
     $name = 'Qux';
     $this->hydratorByValue->setNamingStrategy(new UnderscoreNamingStrategy());
     $entity = $this->hydratorByValue->hydrate(array('camel_case' => $name), new NamingStrategyEntity());
     $this->assertEquals($name, $entity->getCamelCase());
 }