/** * Save subscription * * @param array $values * @param Newscoop\Entity\Subscription|null $subscription * @return Newscoop\Entity\Subscription */ public function save(array $values, Subscription $subscription = null) { if ($subscription === null) { $subscription = new Subscription(); $this->em->persist($subscription); } if (array_key_exists('user', $values)) { $subscription->setUser(is_numeric($values['user']) ? $this->em->getReference('Newscoop\\Entity\\User', $values['user']) : $values['user']); } if (array_key_exists('publication', $values)) { $subscription->setPublication(is_numeric($values['publication']) ? $this->em->getReference('Newscoop\\Entity\\Publication', $values['publication']) : $values['publication']); } if (array_key_exists('type', $values)) { $subscription->setType($values['type']); } if (array_key_exists('active', $values)) { $subscription->setActive($values['active']); } if (array_key_exists('currency', $values)) { $subscription->setCurrency($values['currency']); } if (array_key_exists('toPay', $values)) { $subscription->setToPay($values['toPay']); } if (array_key_exists('add_sections', $values) && $values['add_sections']) { if (!array_key_exists('publication', $values)) { throw new \InvalidArgumentException("No publication provided for adding sections"); } $publication = is_numeric($values['publication']) ? $this->em->getRepository('Newscoop\\Entity\\Publication')->find($values['publication']) : $values['publication']; $subscription->addSections($values, $publication); } $this->em->flush(); return $subscription; }
public function registraContacto(ContactoDTO $to) { $contacto = new Contacto($to->getId()); $contacto->setNombre($to->getNombre()); $contacto->setApellido($to->getApellido()); $contacto->setTelefono($to->getTelefono()); $contacto->setAsunto($to->getAsunto()); $contacto->setMensaje($to->getMensaje()); $contacto; try { $this->em->persist($contacto); $this->em->flush(); } catch (ORMInvalidArgumentException $exc) { echo '<pre>'; print_r($exc->getTraceAsString()); } catch (\Doctrine\ORM\ORMException $exc) { echo '<pre>'; print_r($exc->getTraceAsString()); echo '<pre>'; print_r($exc->getTrace()); } catch (Exception $e) { echo '<pre>'; print_r($e->getTraceAsString()); } //return $contacto->getIdContact(); }
/** * Save the Entity with the EntityManager. * * @param Core\Entity $object * * @return Core\Entity */ public function save($object) { $this->validate($object); $this->entityManager->persist($object); $this->entityManager->flush(); return $object; }
public function addCustomAction() { if ($this->_request->isPost()) { $addQuoteForm = new \App\Form\AddQuote(); if ($addQuoteForm->isValid($this->_request->getPost())) { $values = $addQuoteForm->getValues(); $newQuote = new \App\Entity\Quote(); $newQuote->setWording($values['quote']); $newQuote->setAuthor($values['name']); try { $this->_em->persist($newQuote); $this->_em->flush(); $this->indexQuote($newQuote); } catch (Exception $e) { $this->_redirect('/'); } } else { $addQuoteForm->buildBootstrapErrorDecorators(); } $data = $this->_em->getRepository("\\App\\Entity\\Quote")->findThemAll(); $this->view->data = $data; $this->_helper->viewRenderer('index'); } else { $this->_redirect('/'); } }
/** * * @param \calavera\customerBundle\DTO\CustomerDTO $customer */ public function registerNewsletter(\calavera\customerBundle\DTO\NewsletterDTO $newsletter) { $subscription = new NewsletterSubscription(); $gender = new CatGender(); $status = new CatNewsletterStatus(); $gender->setGender($newsletter->getGender()); $dql = "select s from \\calavera\\customerBundle\\Entity\\CatNewsletterStatus s where s.status = 'subscribed'"; try { $query = $this->em->createQuery($dql); $status = $query->getOneOrNullResult(); } catch (\Doctrine\ORM\ORMException $orme) { echo $orme->getTraceAsString(); } catch (\Doctrine\ORM\NoResultException $nre) { } catch (\Doctrine\ORM\ORMInvalidArgumentException $ormiae) { } $subscription->setIdNewsletterStatus($status); $subscription->setEmail($newsletter->getEmail()); $subscription->getGener(); $dql = ""; try { $this->em->persist($subscription); $this->em->flush(); $status = "Ha sido registrado en nuestro newsletter"; } catch (\Doctrine\ORM\ORMException $orme) { echo $orme->getTraceAsString(); $status = "No pudo ser registrado en nuestro newsletter."; } catch (\Doctrine\ORM\NoResultException $nre) { $status = "No pudo ser registrado en nuestro newsletter."; } catch (\Doctrine\ORM\ORMInvalidArgumentException $ormiae) { $status = "No pudo ser registrado en nuestro newsletter."; } catch (\Exception $e) { $status = "No pudo ser registrado en nuestro newsletter."; } return $status; }
public function insert(\Entity\Modalidade $modalidade) { try { $this->em->persist($modalidade); } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - modalidade_dao::insert '); } }
/** * Save ip * * @param array $values * @return Newscoop\Entity\User\Ip */ public function save(array $values) { $ip = new Ip($values['ip'], $values['number']); if (array_key_exists('user', $values)) { $ip->setUser(is_numeric($values['user']) ? $this->em->getReference('Newscoop\\Entity\\User', $values['user']) : $values['user']); } $this->em->persist($ip); $this->em->flush($ip); return $ip; }
public function insert(Entity\Categoria $categoria) { try { $this->em->persist($categoria); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - categoria_dao::insert '); } return false; }
public function testFind() { foreach (array('tic', 'tic tac', 'tac', 'tac toc', 'toc') as $description) { $image = new LocalImage($description); $image->setDescription($description); $this->orm->persist($image); } $this->orm->flush(); $this->assertEquals(2, count($this->service->find('tic'))); }
public function testCheckInvalidDate() { $token = new UserToken($this->user, 'test', 'qwerty'); $this->em->persist($token); $this->em->flush(); $property = new \ReflectionProperty($token, 'created'); $property->setAccessible(true); $property->setValue($token, new \DateTime('-3 days')); $this->assertFalse($this->service->checkToken($this->user, 'qwerty', 'test')); }
public function insert(\Entity\Voluntario $voluntario) { try { $this->em->persist($voluntario); $this->em->flush(); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - voluntario_dao::insert '); } return false; }
public function insert(\Entity\Curso $curso) { try { $this->em->persist($curso); $this->em->flush(); return $curso->getIdCurso(); } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - curso_dao::insert '); } return false; }
public function insert(\Entity\Avaliador $avaliador) { try { $this->em->persist($avaliador); $this->em->flush(); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - avaliador_dao::insert '); } return false; }
public function insert(\Entity\Ouvinte $ouvinte) { try { $this->em->persist($ouvinte); $this->em->flush(); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - ouvinte_dao::insert '); } return false; }
private function loadBaseInventory() { foreach (self::$inventoryArray as $inventoryArray) { $item = new Inventory(); $item->setItemDescription($inventoryArray['description']); $item->setItemName($inventoryArray['name']); $item->setPrice($inventoryArray['price']); $item->setQuantityInStock($inventoryArray['quantity']); $this->em->persist($item); } $this->em->flush(); }
public function register($name, $email, $login, $password) { if ($this->getUser($login) != null) { return "User with login '{$login}' already exists"; } $u = new \Model\User(); $u->setEmail($email); $u->setLogin($login); $u->setName($name); $u->setPassword($password); $this->entityManager->persist($u); $this->entityManager->flush(); return true; }
public function testTwoSameManagers() { $em1Article = new \Sluggable\Fixture\Article(); $em1Article->setCode('code'); $em1Article->setTitle('title'); $this->em1->persist($em1Article); $this->em1->flush(); $this->assertEquals('title-code', $em1Article->getSlug()); $user = new \Mapping\Fixture\Yaml\User(); $user->setUsername('user'); $user->setPassword('secret'); $this->em2->persist($user); $this->em2->flush(); $this->assertEquals(1, $user->getId()); }
/** * Get rendition * * @param int $width * @param int $height * @param string $specs * @param string $name * @return Newscoop\Image\Rendition */ private function getRendition($width, $height, $specs, $name) { $rendition = new Rendition($width, $height, $specs, $name); $this->orm->persist($rendition); $this->orm->flush($rendition); return $rendition; }
/** * @param Doctrine\ORM\EntityManager $em * @param string $entityName * @param integer $count * @return \Ojs\JournalBundle\Entity\Sums */ private function saveSum($em, $entityName, $count) { $check = $em->getRepository("OjsJournalBundle:Sums")->findOneBy(array('entity' => $entityName)); $sum = $check ? $check : new Sums(); $sum->setEntity($entityName); $sum->setSum($count); $em->persist($sum); $em->flush(); }
public function testFindBy() { $this->assertEquals(0, count($this->service->findBy(array()))); $this->assertEquals(0, $this->service->getCountBy(array())); $this->orm->persist(new LocalImage(self::PICTURE_LANDSCAPE)); $this->orm->persist(new LocalImage('file://' . realpath(APPLICATION_PATH . '/../' . self::PICTURE_LANDSCAPE))); $this->orm->flush(); $this->assertEquals(2, count($this->service->findBy(array()))); $this->assertEquals(2, $this->service->getCountBy(array())); }
/** * Atualiza a tabela de relação entre orientadores e seus respectivos campi * cadastrados * * @param Entity\OrientadorCampus $orientador_campus * @return int o número da sequência de inserções */ public function update(Entity\OrientadorCampus $orientador_campus) { try { $orientador_campus->setStatus(1); $this->em->persist($orientador_campus); } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - orientador_campus_dao::update '); } return $orientador_campus->getSeq(); }
/** * Atualiza a tabela de relação entre autores e seus respectivos cursos * cadastrados * * @param Entity\AutorCurso $autor_curso * @return int o número da sequência de inserções */ public function update(Entity\AutorCurso $autor_curso) { try { $autor_curso->setStatus(1); $this->em->persist($autor_curso); } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage()); } return $autor_curso->getSeq(); }
/** * Upload image and create entity * * @param UploadedFile $file * @param array $attributes * * @return Local */ public function upload(UploadedFile $file, array $attributes) { $filesystem = new Filesystem(); $imagine = new Imagine(); $errors = array(); $mimeType = $file->getClientMimeType(); if (!in_array($mimeType, $this->supportedTypes)) { $errors[] = $this->translator->trans('ads.error.unsupportedType', array('%type%' => $mimeType)); } if (!file_exists($this->config['image_path']) || !is_writable($this->config['image_path'])) { $errors[] = $this->translator->trans('ads.error.notwritable', array('%dir%' => $this->config['image_dir'])); } if (!file_exists($this->config['thumbnail_path']) || !is_writable($this->config['thumbnail_path'])) { $errors[] = $this->translator->trans('ads.error.notwritable', array('%dir%' => $this->config['thumbnail_dir'])); } if (!empty($errors)) { return $errors; } $attributes = array_merge(array('content_type' => $mimeType), $attributes); $image = new Image($file->getClientOriginalName()); $this->orm->persist($image); $this->fillImage($image, $attributes); $this->orm->flush(); $imagePath = $this->generateImagePath($image->getId(), $file->getClientOriginalExtension()); $thumbnailPath = $this->generateThumbnailPath($image->getId(), $file->getClientOriginalExtension()); $image->setBasename($this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true)); $image->setThumbnailPath($this->generateThumbnailPath($image->getId(), $file->getClientOriginalExtension(), true)); $this->orm->flush(); try { $file->move($this->config['image_path'], $this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true)); $filesystem->chmod($imagePath, 0644); $imagine->open($imagePath)->resize(new Box($this->config['thumbnail_max_size'], $this->config['thumbnail_max_size']))->save($thumbnailPath, array()); $filesystem->chmod($thumbnailPath, 0644); } catch (\Exceptiom $e) { $filesystem->remove($imagePath); $filesystem->remove($thumbnailPath); $this->orm->remove($image); $this->orm->flush(); return array($e->getMessage()); } return $image; }
/** * Add addtional Jobs so we can test record limits and pagers. * * @param Doctrine\ORM\EntityManager $manager * @param Job $job */ protected function duplicateLastJob($manager, $job) { for ($i = 100; $i <= 130; $i++) { $jobClone = clone $job; $jobClone->setCompany(sprintf($job->getCompany(), $i)); $jobClone->setHowToApply(sprintf($job->getHowToApply(), $i)); $jobClone->setToken(sprintf($job->getToken(), $i)); $manager->persist($jobClone); $manager->flush(); } }
public function testGetPublicUserCount() { $this->assertEquals(0, $this->service->getPublicUserCount()); $this->user->setActive(); $this->em->persist($this->user); $this->em->flush(); $this->assertEquals(0, $this->service->getPublicUserCount()); $this->user->setPublic(); $this->em->flush(); $this->assertEquals(1, $this->service->getPublicUserCount()); }
/** * Get rendition by given name * * @param string $name * @return Newscoop\Image\Rendition */ public function getRendition($name) { $renditions = $this->getRenditions(); $rendition = array_key_exists($name, $renditions) ? $renditions[$name] : null; if ($rendition !== null) { $rendition = $this->orm->getRepository('Newscoop\\Image\\Rendition')->find($rendition->getName()); $this->orm->persist($rendition); $this->orm->flush($rendition); } return $rendition; }
/** * Add article image * * @param int $articleNumber * @param Newscoop\Image\LocalImage $image * @param bool $defaultImage * @return Newscoop\Image\ArticleImage */ public function addArticleImage($articleNumber, LocalImage $image, $defaultImage = false) { if ($image->getId() === null) { $this->orm->persist($image); $this->orm->flush($image); } $articleImage = new ArticleImage($articleNumber, $image, $defaultImage || $this->getArticleImagesCount($articleNumber) === 0); $this->orm->persist($articleImage); $this->orm->flush($articleImage); return $articleImage; }
private function addUser() { $user = new User(); $user->username = '******'; $user->password = md5('apple'); $user->name = 'Steve <b>Jobs</b>'; $user->valid = 1; $user->role = 'admin'; $this->em->persist($user); $this->em->flush(); return $user; }
/** * Save section * * @param array $values * @param Newscoop\Subscription\Section|null $section * @return Newscoop\Subscription\Section */ public function save(array $values, Section $section = null) { if ($section === null) { if (!array_key_exists('subscription', $values)) { throw new \InvalidArgumentException("Subscription must be provided."); } if (!array_key_exists('section', $values)) { throw new \InvalidArgumentException("Section must be provided."); } $section = new Section($this->getSubscription($values), $this->getSectionNumber($values)); $this->em->persist($section); if (!empty($values['language'])) { $section->setLanguage($this->getLanguage($values)); } } $section->setStartDate(new \DateTime($values['startDate'])); $section->setDays($values['days']); $section->setPaidDays($values['paidDays']); $this->em->flush(); return $section; }
public function testLiftEmbargoOld() { $feed = new Feed('SDA'); $this->service->addFeed($feed); $entry = $this->getEntry(array('getTitle' => 'test', 'getContent' => 'test', 'getStatus' => 'Embargoed', 'getLiftEmbargo' => new \DateTime('-2 day'))); $this->em->persist($entry); $this->em->flush(); $this->em->clear(); $this->service->updateSDA(); $loaded = $this->em->find('Newscoop\\Entity\\Ingest\\Feed\\Entry', $entry->getId()); $this->assertEquals('Usable', $loaded->getStatus()); }