/** * get today timeline json * * @return array|null timeline or null */ public function getTodayTimeline() { $get_query = ['user_id' => $this->user->getTwitterId()]; $today = (new \DateTime())->format('Y-m-d'); $since_id_at = $this->user->getSinceIdAt(); // 今日の始点ツイートのsince_idが無ければsince_idを計算後、timlineを返す if ($since_id_at === null || $since_id_at->format('Y-m-d') !== $today) { $result = $this->findIdRangeByDate(new \DateTime(), $get_query); // エラーメッセージの場合 if (isset($result['error'])) { return $result; } // since_idのDB登録 $user = $this->user; $user->setTodaySinceId($result['since_id']); $user->setSinceIdAt(new \DateTime()); $user->setUpdateAt(new \DateTime()); $em = $this->doctrine->getEntityManager(); $user = $em->merge($user); $em->persist($user); $em->flush(); return $result['timeline_json']; } // since_idがあればget_queryに指定して今日のつぶやき一覧をapiから取得 $today_since_id = $this->user->getTodaySinceId(); if ($today_since_id !== '') { $get_query['since_id'] = $today_since_id; // since_idが無ければ200件まで取得 今日以前のつぶやきが存在しないアカウントなど } else { $get_query['count'] = '200'; } $timeline = $this->callStatusesUserTimeline($get_query); return $timeline; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->mediaService = $this->getContainer()->get('services.doctor.media'); $this->doctrine = $this->getContainer()->get('doctrine'); $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $qb->select('d, m')->from('DoctorBundle:Doctor', 'd')->innerJoin('d.media', 'm'); $doctors = $qb->getQuery()->getResult(); $doctorDirectory = $this->getWebRootDirectory(); $logoSizes = $this->mediaService->getSizesByType(DoctorMediaService::LOGO_TYPE_IMAGE); foreach ($doctors as $doctor) { $this->output->writeln("Migrate images of Doctor #{$doctor->getId()}"); $this->output->write(" "); if ($media = $doctor->getMedia()) { $doctorFile = $doctorDirectory . '/' . $media->getName(); if (\file_exists($doctorFile)) { // resize the image $this->mediaService->resize($media, $logoSizes); $this->output->writeln('Ok'); } else { $this->output->writeln('Not found'); } } else { $this->output->writeln('No media'); } } $this->output->writeln('All done'); }
/** * Find an instance of LogClass by class name. If class exists and there is no record yet, a new LogClass will be saved * * @param string $className * @return \HealthCareAbroad\LogBundle\Entity\LogClass */ public function getLogClassByName($className) { if (!\class_exists($className)) { throw ListenerException::logClassDoesNotExist($className); } // if (\array_key_exists($className, self::$logClassMap)) { // $logClass = self::$logClassMap[$className]; // } // else { // $logClass = $this->doctrine->getRepository('LogBundle:LogClass')->findOneBy(array('name' => $className)); // if (!$logClass) { // $logClass = new LogClass(); // $logClass->setName($className); // $this->saveLogClass($logClass); // } // else { // self::$logClassMap[$className] = $logClass; // } // } $logClass = $this->doctrine->getEntityManager('logger')->getRepository('LogBundle:LogClass')->findOneBy(array('name' => $className)); if (!$logClass) { $logClass = new LogClass(); $logClass->setName($className); $this->saveLogClass($logClass); } return $logClass; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->doctrine = $this->getContainer()->get('doctrine'); $entity = $input->getArgument('entity'); $property = $input->getArgument('property'); $width = $input->getArgument('width'); $height = $input->getArgument('height'); $size = array($width . 'x' . $height); $cropImage = $input->getOption('crop-image'); $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $qb->select('a')->from($entity, 'a')->where("a.{$property} IS NOT NULL"); if ($entityId = $input->getOption('entity-id')) { $qb->andWhere('a.id = :id')->setParameter('id', $entityId); } $objects = $qb->getQuery()->getResult(); $entityArr = explode(':', $entity); if ($entityArr[1] == 'InstitutionMedicalCenter') { $entityArr[1] = 'institution'; } $mediaServiceName = 'services.' . lcfirst($entityArr[1]) . '.media'; $mediaService = $this->getContainer()->get($mediaServiceName); $propertyGetMethod = 'get' . ucfirst($property); foreach ($objects as $each) { $media = $each->{$propertyGetMethod}(); if ($media && $mediaService->getFilesystem()->has($media->getName())) { $this->output->write('Resizing image: ' . $media->getName() . ' (id: ' . $media->getId() . ') ... '); $mediaService->resize($media, $size, $cropImage); $this->output->writeln('DONE'); } } $this->output->writeln('END OF SCRIPT'); }
/** * Listener for event.institution_user.add event. Will delete used invitation * * @param CreateInstitutionUserEvent $event */ public function onAdd(CreateInstitutionUserEvent $event) { if ($invitation = $event->getUsedInvitation()) { $em = $this->doctrine->getEntityManager(); $em->remove($invitation); $em->flush(); } }
/** * @see StoreImplementationInterface::storeLog() */ public function storeLog($time, $name, $tag, $version) { $em = $this->doctrine->getEntityManager(); $log = new Log(); $log->setTime(number_format($time, 4)); $log->setName($name); $log->setTag($tag); $log->setVersion($version); $log->setExecutions(1); $em->persist($log); $em->flush(); }
/** * @param Request $request * @param $user * @return bool|Form|FormInterface */ public function UserEditProfile(Request $request, $user) { $form = $this->FormFactory->create('profile_edit', $user); if ($request->getMethod() === 'POST') { $form->handleRequest(); if ($form->isValid()) { $user = $form->getData(); $em = $this->doctrine->getEntityManager(); $em->persist($user); $em->flush(); return true; } } return $form; }
private function cleanUpUserContactDetails() { $em = $this->doctrine->getEntityManager(); $qb = $em->createQueryBuilder(); $qb->select('a, b')->from('UserBundle:InstitutionUser', 'a')->innerJoin('a.contactDetails', 'b'); $users = $qb->getQuery()->getResult(); foreach ($users as $user) { $this->output->write('Cleaning up for user #' . $user->getId() . ' ['); foreach ($user->getContactDetails() as $contactDetail) { $number = $contactDetail->getNumber(); if (!\is_numeric($number)) { $number = \preg_replace('/\\D/', '', $number); } $contactDetail->setNumber((int) $number); if (!$number || strlen($number) < 5) { $contactDetail->setIsInvalid(true); } $contactDetail->setFromNewWidget(true); $em->persist($contactDetail); $this->output->write('.'); } $this->output->writeln('] Done.'); } $em->flush(); }
public function testGetUnknownEntityManager() { $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $registry = new Registry($container, array(), array(), 'default', 'default'); $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Manager named "default" does not exist.'); $registry->getEntityManager('default'); }
public function removeTreatment(Treatment $treatment) { $em = $this->doctrine->getEntityManager(); $em->remove($treatment); $em->flush(); return true; }
/** * @param Request $request * @return Form|FormInterface */ public function IssueRegistration(Request $request) { $form = $this->FormFactory->create('form_issue_registration', null); if ($request->getMethod() === 'POST') { $form->handleRequest($request); if ($form->isValid()) { $issue = $form->getData(); $em = $this->doctrine->getEntityManager(); $em->persist($issue); $update = $issue->getCreated(); $issue->setUpdated($update); $em->flush(); return true; } } return $form; }
/** * TODO: copied this to ErrorLogService; use that instead * * @param \Exception $exception */ public function logException(\Exception $exception) { $errorLog = new ErrorLog(); $errorLog->setErrorType(ErrorType::EXCEPTION); $errorLog->setMessage($exception->getMessage()); $errorLog->setStacktrace($exception->getTraceAsString()); $errorLog->setHttpUserAgent(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); $errorLog->setRemoteAddress(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); $errorLog->setServerJSON(\json_encode($_SERVER)); $em = $this->doctrine->getEntityManager('logger'); if (!$em->isOpen()) { $this->doctrine->resetEntityManager('logger'); $em = $this->doctrine->getEntityManager('logger'); } $em->persist($errorLog); $em->flush(); // save log }
/** * * @param array $ids * @return void|multitype: */ public function deleteMailsByIds(array $ids = array()) { if (!count($ids)) { return; } $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $result = $qb->select('a')->delete('MailerBundle:MailQueue', 'a')->where($qb->expr()->in('a.id', $ids))->getQuery()->getResult(); return $result; }
/** TODO: DEPRECATED ?? * Remove draft institution specialization and associated procedure types * * @param Institution $institution * @param int $institutionSpecializationId * @throws Exception * @return InstitutionSpecialization $institutionSpecialization */ public function deleteDraftInstitutionSpecialization(Institution $institution, $institutionSpecializationId) { $em = $this->doctrine->getEntityManager(); //TODO: check that the institution owns the center. $center = $em->getRepository('InstitutionBundle:InstitutionSpecialization')->find($institutionSpecializationId); if (InstitutionMedicalCenterStatus::DRAFT != $center->getStatus()) { throw new Exception('Delete operation not allowed.'); } //NOTE: Supposedly a DRAFT institution specialization will have no procedure types // so the loop below will never run. But this specification can change. //TODO: Use DQL DELETE statement to delete multiple entities of a type with a single command and without hydrating these entities foreach ($center->getInstitutionTreatments() as $entity) { $em->remove($entity); } $em->remove($center); $em->flush(); return $center; }
/** * Save institution * * @param Institution $institution */ public function save(Institution $institution) { $em = $this->doctrine->getEntityManager(); $em->persist($institution); $em->flush(); // get the memcache key for this institution // $memcacheKey = $this->memcacheKeyFactory->generate('institution_entity', array('id' => $institution->getId()), array('institutionId' => $institution->getId())); // // delete this from memcache // $this->memcache->delete($memcacheKey); }
public function __construct(Registry $doctrine, FormFactoryInterface $formFactory, RouterInterface $router, EngineInterface $templating, UserManager $userManager, SecurityContext $security, BasketFactory $basketFactory) { $this->doctrine = $doctrine; $this->router = $router; $this->formFactory = $formFactory; $this->em = $doctrine->getEntityManager(); $this->templating = $templating; $this->userManager = $userManager; $this->security = $security; $this->basket = $basketFactory->getBasket(); }
public function onUpload(PostPersistEvent $event) { $file = $event->getFile(); /* @var $file \Symfony\Component\HttpFoundation\File\File */ $request = $event->getRequest(); $response = $event->getResponse(); $r = array(); $em = $this->doctrine->getEntityManager(); if ($request->get('attachment')) { $contratto = $em->getRepository('CasaFront2Bundle:Contratto')->find($request->get('attachment')); $documento = new Documento(); $documento->setFile('upload/' . $contratto->getId() . '/documenti/' . $file->move('upload/' . $contratto->getId() . '/documenti/', $file->getFileName())->getFileName()); $documento->setContratto($contratto); $r = array('name' => $file->getFilename(), 'url' => str_replace('app_dev.php/', '', $this->router->generate('home', array(), true)) . 'uploads/attachment/' . $file->getFilename()); $documento->setJson($r); $em->persist($documento); $em->flush(); } elseif ($request->get('contratto_id')) { $contratto = $em->getRepository('CasaFront2Bundle:Contratto')->find($request->get('contratto_id')); /* @var $contratto \Casa\Front2Bundle\Entity\Contratto */ $foto = new Foto(); $foto->setContratto($contratto); $foto->setFile($file->getFilename()); $foto->setPrincipale(count($contratto->getFoto()) == 0); $em->persist($foto); $em->flush(); $r = array('name' => $file->getFilename(), 'size' => $file->getSize(), 'type' => $file->getMimeType(), 'url' => str_replace('app_dev.php/', '', $this->router->generate('home', array(), true)) . 'uploads/gallery/' . $foto->getFile()); // Image sizes (x >= y): $size = array('bigImage' => array('x' => 1024, 'y' => 768), 'mediumImage' => array('x' => 600, 'y' => 400), 'thumbnail' => array('x' => 300, 'y' => 227), 'icon' => array('x' => 64, 'y' => 64)); $this->gdResize($size, $file, $r); $foto->setJson($r); $em->persist($foto); $em->flush(); } else { unlink($file->getRealPath()); $response['error'] = "File format don't supported"; } $response['files'] = array($r); }
public function addMedicalCenterSpecializationsWithTreatments(InstitutionMedicalCenter $institutionMedicalCenter, array $specializationsWithTreatments) { $specializationRepo = $this->doctrine->getRepository('TreatmentBundle:Specialization'); //TODO: optimize this is very db intensive $institutionTreatmentIds = array(); $specializationIds = array(); $subQuery = ''; foreach ($specializationsWithTreatments as $specializationId => $treatmentIds) { if (!isset($treatmentIds['treatments']) || empty($treatmentIds['treatments'])) { continue; } $specialization = $specializationRepo->find($specializationId); $subQuery .= "('" . $specialization->getDescription() . "', 1, " . $specialization->getId() . ", " . $institutionMedicalCenter->getId() . "),"; $institutionTreatmentIds[$specializationId] = $treatmentIds['treatments']; $specializationIds[] = $specializationId; } $conn = $this->doctrine->getEntityManager()->getConnection(); $subQuery = substr($subQuery, 0, -1) . " ON DUPLICATE KEY UPDATE status = 1"; $sqlQuery = "INSERT INTO institution_specializations (description, status, specialization_id, institution_medical_center_id) VALUES {$subQuery}"; $conn->executeQuery($sqlQuery); $sqlQuery = "SELECT id, specialization_id from institution_specializations where institution_medical_center_id = " . $institutionMedicalCenter->getId() . " and specialization_id in ( " . implode(',', $specializationIds) . ")"; $result = $conn->executeQuery($sqlQuery); $subQuery = ''; $resultIds = array(); foreach ($result as $each) { $treatmentIds = $institutionTreatmentIds[$each['specialization_id']]; foreach ($treatmentIds as $treatmentId) { $subQuery .= "(" . $each['id'] . ", " . $treatmentId . "),"; } $resultIds[] = $each['id']; } $subQuery = substr($subQuery, 0, -1) . " ON DUPLICATE KEY UPDATE treatment_id = treatment_id"; $sqlQuery = "INSERT INTO institution_treatments (institution_specialization_id, treatment_id) VALUES {$subQuery}"; $conn->executeQuery($sqlQuery); $conn->close(); return $resultIds; }
public function __construct(SecurityContext $context, Doctrine $doctrine) { $this->context = $context; $this->em = $doctrine->getEntityManager(); }
/** * * @return \Doctrine\ORM\QueryBuilder */ private function getQueryBuilderForInstitutionPublicProfileData() { $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $qb->select('inst, imc, ct, co, st, icd, fm, lg')->from('InstitutionBundle:Institution', 'inst')->innerJoin('inst.institutionMedicalCenters', 'imc', Join::WITH, 'imc.status = :imcActiveStatus')->setParameter('imcActiveStatus', InstitutionMedicalCenterStatus::APPROVED)->leftJoin('inst.city', 'ct')->leftJoin('inst.country', 'co')->leftJoin('inst.state', 'st')->leftJoin('inst.contactDetails', 'icd')->leftJoin('inst.featuredMedia', 'fm')->leftJoin('inst.logo', 'lg')->where('1=1')->andWhere('inst.status = :activeStatus')->setParameter('activeStatus', InstitutionStatus::getBitValueForApprovedStatus()); return $qb; }
public final function save(StatisticsDaily $data) { $em = $this->doctrine->getEntityManager('statistics'); $em->persist($data); $em->flush(); }
public function getInquiriesByInstitutionAndStatus(Institution $institution, $status) { $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $qb->select('a.id, a.inquirerName, a.inquirerEmail, a.message, a.dateCreated, a.status')->from('InstitutionBundle:InstitutionInquiry', 'a')->where('a.status = :status')->andWhere('a.institution = :institution')->setParameter('status', $status)->setParameter('institution', $institution)->orderBy('a.dateCreated', 'DESC'); return $qb->getQuery()->getResult(Query::HYDRATE_ARRAY); }
public function __construct(Registry $doctrine, Session $session) { $this->em = $doctrine->getEntityManager(); $this->session = $session; }
public function findTreatmentsByIds(array $ids) { $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $query = $qb->select('a')->from('TreatmentBundle:Treatment', 'a')->where($qb->expr()->in('a.id', ':ids'))->setParameter('ids', $ids)->getQuery(); return $query->getResult(); }
/** * Constructor * * @param Doctrine $doctrine */ public function __construct(\Swift_Mailer $mailer, Doctrine $doctrine) { $this->mailer = $mailer; $this->em = $doctrine->getEntityManager(); }
/** * Get query builder for a fully eagerloaded medical center * * @return \Doctrine\ORM\QueryBuilder */ private function getQueryBuilderForFullInstitutionMedicalCenterProfile() { $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); $qb->select('imc, inst, co, st, ct, inst_lg, imc_lg, inst_fm, imc_m, imc_cd, imc_bh, inst_sp, sp, sp_lg, tr, sub_sp')->from('InstitutionBundle:InstitutionMedicalCenter', 'imc')->innerJoin('imc.institution', 'inst')->leftJoin('inst.country', 'co')->leftJoin('inst.state', 'st')->leftJoin('inst.city', 'ct')->leftJoin('inst.logo', 'inst_lg')->leftJoin('inst.featuredMedia', 'inst_fm')->leftJoin('imc.logo', 'imc_lg')->leftJoin('imc.media', 'imc_m')->leftJoin('imc.contactDetails', 'imc_cd')->leftJoin('imc.businessHours', 'imc_bh')->leftJoin('imc.institutionSpecializations', 'inst_sp')->leftJoin('inst_sp.specialization', 'sp')->leftJoin('sp.media', 'sp_lg')->leftJoin('sp.treatments', 'tr')->leftJoin('tr.subSpecializations', 'sub_sp')->where('1=1')->andWhere('imc.status = :imcActiveStatus')->setParameter('imcActiveStatus', InstitutionMedicalCenterStatus::APPROVED)->andWhere('inst.status = :instActiveStatus')->setParameter('instActiveStatus', InstitutionStatus::getBitValueForApprovedStatus()); return $qb; }
public function __construct(Registry $doctrine) { $this->doctrine = $doctrine; $this->em = $doctrine->getEntityManager(); $this->repository = $this->em->getRepository('AdvertisementBundle:Advertisement'); }
public function __construct(Registry $doctrine) { $this->doctrine = $doctrine; $queryBuilder = $doctrine->getEntityManager()->createQueryBuilder(); $this->pagerAdapter = new DoctrineOrmAdapter(); }
/** * Persist to database * * @param PageMetaConfiguration $pageMetaConfiguration */ public function save(PageMetaConfiguration $pageMetaConfiguration) { $em = $this->doctrine->getEntityManager(); $em->persist($pageMetaConfiguration); $em->flush(); }
public function __construct(\Doctrine\Bundle\DoctrineBundle\Registry $doctrine) { $this->doctrine = $doctrine; $this->queryBuilder = $doctrine->getEntityManager()->createQueryBuilder(); }