protected function checkOwnAction($action) { $biz = $this->user->getUserObject(); if ($action->getBiz()->getId() != $biz->getId()) { throw new \Exception('Акция вам не принадлежит'); } }
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); }
/** * upload image * @param Request $request * @param string $user_type * @param string $action * @return array info: * <ul> * <li>id</li> * <li>uri</li> * </ul> * @throws \Exception */ public function upload(Request $request, $user_type, $action) { $this->check_dir(); $this->auth->setType($user_type); $this->auth->requireAuth(); $uploaded_file = $request->files->get('_file'); if (is_null($uploaded_file)) { throw new \Exception('Картинка не загружена'); } if (!$uploaded_file->isValid()) { throw new \Exception('Не удалось загрузить файл'); } $file = $uploaded_file->move($this->pic_real_dir, $this->getPictureName(null, 'tmp')); unset($uploaded_file); $ext = $this->checkCorrectImageAndGetExt($file->getRealPath()); $new_name = $this->getPictureName($ext); $file->move($this->pic_real_dir, $new_name); unset($file); $id = $this->saveFile($new_name, $action); $uri = $this->pic_dir . $new_name; return ['id' => $id, 'uri' => $uri]; }
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; }