protected function checkOwnAction($action) { $biz = $this->user->getUserObject(); if ($action->getBiz()->getId() != $biz->getId()) { throw new \Exception('Акция вам не принадлежит'); } }
/** * save file to db * @param string $file_name * @param string $action * @param bool $is_cached * @return integer file id */ protected function saveFile($file_name, $action) { $f = new Image(); $f->setUidType(User::typeToInt($this->auth->getType())); $f->setUri($this->pic_dir . $file_name); $f->setUid($this->auth->getUserObject()->getId()); $f->setType(static::actionToType($action)); $this->em->persist($f); $this->em->flush(); $id = $f->getId(); $this->em->clear(); unset($f); return $id; }
protected function processReport($biz_id = null, Request $request = null) { $object = new FundReport(); $object->biz_id = $biz_id; return $this->formbuilder->processForm(['object' => $object, 'caption' => 'Отправить', 'action' => $this->action], function ($form) { $data = $form->getData(); $this->user->checkImageAccess($data->photo, 'report_image'); $fund = $this->user->getUserObject(); $biz = $this->em->getRepository('AppBundle:UserBiz')->getExistsById($data->biz_id); $c = $this->em->createQuery('SELECT count(u) ' . 'FROM AppBundle:Cert u ' . 'WHERE u.brand=:biz and u.fund=:fund')->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)->execute(['biz' => $biz, 'fund' => $fund]); if (!$c) { throw new \Exception('Отправка отчета недоступна т.к. нет сертификатов для данного бизнеса'); } $data->setFund($fund); $data->setBiz($biz); $this->em->persist($data); $this->em->flush(); }, $request); }
public function getReports() { $user = $this->user->getUserObject(); $r = $this->em->createQuery('SELECT r ' . 'FROM AppBundle:FundReport r ' . 'JOIN r.biz b ' . 'JOIN r.fund f ' . 'LEFT JOIN r.photo p ' . 'JOIN AppBundle:BizAction a WITH a.biz=b ' . 'LEFT JOIN AppBundle:UserClientActionsClicks cl WITH cl.action=a and cl.clickPriceActual=false and cl.user=:user ' . 'LEFT JOIN AppBundle:UserClientActivatedAction cla WITH cla.action=a and cla.status=2 and cla.user=:user ' . 'WHERE (cl.id is not null) or (cla.id is not null) ')->execute(['user' => $user]); return $r; }