Beispiel #1
0
 public function search()
 {
     $offset_start = (int) $this->request->get('offset_start');
     $offset_start = $offset_start < 0 ? 0 : $offset_start;
     $results_quantity = (int) $this->request->get('per_page');
     $results_quantity = $results_quantity < 10 || $results_quantity > 50 ? 20 : $results_quantity;
     $this->query_parms = ['inactives' => $this->request->get('inactives'), 'like_field' => $this->request->get('like_field'), 'like_value' => $this->request->get('like_value'), 'sbas_id' => $this->request->get('sbas_id'), 'base_id' => $this->request->get('base_id'), 'last_model' => $this->request->get('last_model'), 'srt' => $this->request->get("srt", \User_Query::SORT_CREATIONDATE), 'ord' => $this->request->get("ord", \User_Query::ORD_DESC), 'per_page' => $results_quantity, 'offset_start' => $offset_start];
     $query = new \User_Query($this->app);
     if (is_array($this->query_parms['base_id'])) {
         $query->on_base_ids($this->query_parms['base_id']);
     } elseif (is_array($this->query_parms['sbas_id'])) {
         $query->on_sbas_ids($this->query_parms['sbas_id']);
     }
     $this->results = $query->sort_by($this->query_parms["srt"], $this->query_parms["ord"])->like($this->query_parms['like_field'], $this->query_parms['like_value'])->last_model_is($this->query_parms['last_model'])->get_inactives($this->query_parms['inactives'])->include_templates(true)->on_bases_where_i_am($this->app['acl']->get($this->app['authentication']->getUser()), ['canadmin'])->limit($offset_start, $results_quantity)->execute();
     if (null === ($invite = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST))) {
         $invite = $this->app['manipulator.user']->createUser(User::USER_GUEST, User::USER_GUEST);
     }
     if (null == ($autoregister = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER))) {
         $autoregister = $this->app['manipulator.user']->createUser(User::USER_AUTOREGISTER, User::USER_AUTOREGISTER);
     }
     foreach ($this->query_parms as $k => $v) {
         if (is_null($v)) {
             $this->query_parms[$k] = false;
         }
     }
     $query = new \User_Query($this->app);
     $templates = $query->only_templates(true)->execute()->get_results();
     return ['users' => $this->results, 'parm' => $this->query_parms, 'invite_user' => $invite, 'autoregister_user' => $autoregister, 'templates' => $templates];
 }
Beispiel #2
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => '', 'order_id' => []];
     $params = array_merge($default, $params);
     $order_id = $params['order_id'];
     $users = [];
     try {
         $repository = $this->app['EM']->getRepository('Phraseanet:OrderElement');
         $results = $repository->findBy(['orderId' => $order_id]);
         $base_ids = [];
         foreach ($results as $result) {
             $base_ids[] = $result->getBaseId();
         }
         $base_ids = array_unique($base_ids);
         $query = new User_Query($this->app);
         $users = $query->on_base_ids($base_ids)->who_have_right(['order_master'])->execute()->get_results();
     } catch (\Exception $e) {
     }
     if (count($users) == 0) {
         return;
     }
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $usr_id_dom = $dom_xml->createElement('usr_id');
     $order_id_dom = $dom_xml->createElement('order_id');
     $usr_id_dom->appendChild($dom_xml->createTextNode($params['usr_id']));
     $order_id_dom->appendChild($dom_xml->createTextNode($order_id));
     $root->appendChild($usr_id_dom);
     $root->appendChild($order_id_dom);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     if (null === ($orderInitiator = $this->app['manipulator.user']->getRepository()->find($params['usr_id']))) {
         return;
     }
     foreach ($users as $user) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($user->getId())) {
             $readyToSend = false;
             try {
                 $receiver = Receiver::fromUser($user);
                 $readyToSend = true;
             } catch (\Exception $e) {
                 continue;
             }
             if ($readyToSend) {
                 $mail = MailInfoNewOrder::create($this->app, $receiver);
                 $mail->setUser($orderInitiator);
                 $this->app['notification.deliverer']->deliver($mail);
                 $mailed = true;
             }
         }
         $this->broker->notify($user->getId(), __CLASS__, $datas, $mailed);
     }
     return;
 }
Beispiel #3
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$entry)
 {
     $params = ['entry_id' => $entry->getId(), 'notify_email' => $params['notify_email']];
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $entry_id = $dom_xml->createElement('entry_id');
     $entry_id->appendChild($dom_xml->createTextNode($params['entry_id']));
     $root->appendChild($entry_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $Query = new \User_Query($this->app);
     $Query->include_phantoms(true)->include_invite(false)->include_templates(false)->email_not_null(true);
     if ($entry->getFeed()->getCollection($this->app)) {
         $Query->on_base_ids([$entry->getFeed()->getCollection($this->app)->get_base_id()]);
     }
     $start = 0;
     $perLoop = 100;
     $from = ['email' => $entry->getAuthorEmail(), 'name' => $entry->getAuthorName()];
     do {
         $results = $Query->limit($start, $perLoop)->execute()->get_results();
         foreach ($results as $user_to_notif) {
             $mailed = false;
             if ($params['notify_email'] && $this->shouldSendNotificationFor($user_to_notif->getId())) {
                 $readyToSend = false;
                 try {
                     $token = $this->app['tokens']->getUrlToken(\random::TYPE_FEED_ENTRY, $user_to_notif->getId(), null, $entry->getId());
                     $url = $this->app->url('lightbox', ['LOG' => $token]);
                     $receiver = Receiver::fromUser($user_to_notif);
                     $readyToSend = true;
                 } catch (\Exception $e) {
                 }
                 if ($readyToSend) {
                     $mail = MailInfoNewPublication::create($this->app, $receiver);
                     $mail->setButtonUrl($url);
                     $mail->setAuthor($entry->getAuthorName());
                     $mail->setTitle($entry->getTitle());
                     $this->app['notification.deliverer']->deliver($mail);
                     $mailed = true;
                 }
             }
             $this->broker->notify($user_to_notif->getId(), __CLASS__, $datas, $mailed);
         }
         $start += $perLoop;
     } while (count($results) > 0);
     return true;
 }
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $databox = $this->container['phraseanet.appbox']->get_databox((int) $input->getArgument('databox_id'));
     $new_collection = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], $input->getArgument('collname'));
     if ($new_collection && $input->getOption('base_id_rights')) {
         $query = new \User_Query($this->container);
         $total = $query->on_base_ids([$input->getOption('base_id_rights')])->get_total();
         $n = 0;
         while ($n < $total) {
             $results = $query->limit($n, 40)->execute()->get_results();
             foreach ($results as $user) {
                 $this->container['acl']->get($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id());
             }
             $n += 40;
         }
     }
     $app = $this->container;
     $this->container['manipulator.acl']->resetAdminRights($this->container['manipulator.user']->getRepository()->findAdmins());
     $this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection));
 }
 /**
  *
  * @param string        $event
  * @param Array         $params
  * @param mixed content $object
  */
 public function fire($event, $params, &$object)
 {
     if (isset($params['lazaret_file']) && $params['lazaret_file'] instanceof LazaretFile) {
         /* @var $lazaretFile LazaretFile */
         $lazaretFile = $params['lazaret_file'];
         $domXML = new DOMDocument('1.0', 'UTF-8');
         $domXML->preserveWhiteSpace = false;
         $domXML->formatOutput = true;
         $root = $domXML->createElement('datas');
         //Filename
         $filename = $domXML->createElement('filename');
         $filename->appendChild($domXML->createTextNode($lazaretFile->getOriginalName()));
         $root->appendChild($filename);
         //Reasons for quarantine
         $reasons = $domXML->createElement('reasons');
         foreach ($lazaretFile->getChecks() as $check) {
             /* @var $check LazaretCheck */
             $reason = $domXML->createElement('checkClassName');
             $reason->appendChild($domXML->createTextNode($check->getCheckClassname()));
             $reasons->appendChild($reason);
         }
         $root->appendChild($reasons);
         $domXML->appendChild($root);
         $datas = $domXML->saveXml();
         //Sender
         if (null !== ($user = $lazaretFile->getSession()->getUser())) {
             $sender = $domXML->createElement('sender');
             $sender->appendChild($domXML->createTextNode($user->getDisplayName()));
             $root->appendChild($sender);
             $this->notifyUser($user, $datas);
         } else {
             //No lazaretSession user, fil is uploaded via automated tasks etc ..
             $query = new User_Query($this->app);
             $users = $query->on_base_ids([$lazaretFile->getBaseId()])->who_have_right(['canaddrecord'])->execute()->get_results();
             foreach ($users as $user) {
                 $this->notifyUser($user, $datas);
             }
         }
     }
     return;
 }
Beispiel #6
0
 /**
  * Create a new collection
  *
  * @param  Application $app        The silex application
  * @param  Request     $request    The current HTTP request
  * @param  integer     $databox_id The requested databox
  * @return Response
  */
 public function createCollection(Application $app, Request $request, $databox_id)
 {
     if (($name = trim($request->request->get('name', ''))) === '') {
         return $app->redirectPath('admin_database_display_new_collection_form', ['databox_id' => $databox_id, 'error' => 'name']);
     }
     try {
         $databox = $app['phraseanet.appbox']->get_databox($databox_id);
         $collection = \collection::create($app, $databox, $app['phraseanet.appbox'], $name, $app['authentication']->getUser());
         if ($request->request->get('ccusrothercoll') === "on" && null !== ($othcollsel = $request->request->get('othcollsel'))) {
             $query = new \User_Query($app);
             $total = $query->on_base_ids([$othcollsel])->get_total();
             $n = 0;
             while ($n < $total) {
                 $results = $query->limit($n, 20)->execute()->get_results();
                 foreach ($results as $user) {
                     $app['acl']->get($user)->duplicate_right_from_bas($othcollsel, $collection->get_base_id());
                 }
                 $n += 20;
             }
         }
         $app['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($collection));
         return $app->redirectPath('admin_display_collection', ['bas_id' => $collection->get_base_id(), 'success' => 1, 'reload-tree' => 1]);
     } catch (\Exception $e) {
         return $app->redirectPath('admin_database_submit_collection', ['databox_id' => $databox_id, 'error' => 'error']);
     }
 }
 public function unmount_collection(Application $app)
 {
     $params = [':base_id' => $this->get_base_id()];
     $query = new User_Query($app);
     $total = $query->on_base_ids([$this->get_base_id()])->include_phantoms(false)->include_special_users(true)->include_invite(true)->include_templates(true)->get_total();
     $n = 0;
     while ($n < $total) {
         $results = $query->limit($n, 50)->execute()->get_results();
         foreach ($results as $user) {
             $app['acl']->get($user)->delete_data_from_cache(ACL::CACHE_RIGHTS_SBAS);
             $app['acl']->get($user)->delete_data_from_cache(ACL::CACHE_RIGHTS_BAS);
         }
         $n += 50;
     }
     $sql = "DELETE FROM basusr WHERE base_id = :base_id";
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $sql = "DELETE FROM bas WHERE base_id = :base_id";
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
     phrasea::reset_baseDatas($app['phraseanet.appbox']);
     return $this;
 }
Beispiel #8
0
 /**
  * Create a new order
  *
  * @param Application $app
  * @param Request     $request
  *
  * @return RedirectResponse|JsonResponse
  */
 public function createOrder(Application $app, Request $request)
 {
     $success = false;
     $collectionHasOrderAdmins = new ArrayCollection();
     $toRemove = [];
     $records = RecordsRequest::fromRequest($app, $request, true, ['cancmd']);
     $hasOneAdmin = [];
     if (!$records->isEmpty()) {
         $order = new OrderEntity();
         $order->setUser($app['authentication']->getUser());
         $order->setDeadline(null !== ($deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine);
         $order->setOrderUsage($request->request->get('use', ''));
         foreach ($records as $key => $record) {
             if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) {
                 if (!$collectionHasOrderAdmins->get($record->get_base_id())) {
                     $records->remove($key);
                 }
             }
             if (!isset($hasOneAdmin[$record->get_base_id()])) {
                 $query = new \User_Query($app);
                 $hasOneAdmin[$record->get_base_id()] = (bool) count($query->on_base_ids([$record->get_base_id()])->who_have_right(['order_master'])->execute()->get_results());
             }
             $collectionHasOrderAdmins->set($record->get_base_id(), $hasOneAdmin[$record->get_base_id()]);
             if (!$hasOneAdmin[$record->get_base_id()]) {
                 $toRemove[] = $key;
             } else {
                 $orderElement = new OrderElement();
                 $order->addElement($orderElement);
                 $orderElement->setOrder($order);
                 $orderElement->setBaseId($record->get_base_id());
                 $orderElement->setRecordId($record->get_record_id());
                 $app['EM']->persist($orderElement);
             }
         }
         foreach ($toRemove as $key) {
             if ($records->containsKey($key)) {
                 $records->remove($key);
             }
         }
         $noAdmins = $collectionHasOrderAdmins->forAll(function ($key, $hasAdmin) {
             return false === $hasAdmin;
         });
         if ($noAdmins) {
             $msg = $app->trans('There is no one to validate orders, please contact an administrator');
         }
         $order->setTodo($order->getElements()->count());
         try {
             $app['events-manager']->trigger('__NEW_ORDER__', ['order_id' => $order->getId(), 'usr_id' => $order->getUser()->getId()]);
             $success = true;
             $app['EM']->persist($order);
             $app['EM']->flush();
         } catch (\Exception $e) {
         }
         if ($success) {
             $msg = $app->trans('The records have been properly ordered');
         } else {
             $msg = $app->trans('An error occured');
         }
     } else {
         $msg = $app->trans('There is no record eligible for an order');
     }
     if ('json' === $app['request']->getRequestFormat()) {
         return $app->json(['success' => $success, 'msg' => $msg]);
     }
     return $app->redirectPath('prod_orders', ['success' => (int) $success, 'action' => 'send']);
 }
 /**
  *
  * @return record_exportElement
  */
 protected function get_actions()
 {
     $this->downloadable = $downloadable = [];
     $this->orderable = $orderable = [];
     $sd = $this->get_subdefs();
     $sbas_id = phrasea::sbasFromBas($this->app, $this->base_id);
     $subdefgroups = $this->app['phraseanet.appbox']->get_databox($sbas_id)->get_subdef_structure();
     $subdefs = [];
     foreach ($subdefgroups as $subdef_type => $subdefs_obj) {
         if ($subdef_type == $this->get_type()) {
             $subdefs = $subdefs_obj;
             break;
         }
     }
     $go_dl = ['document' => false, 'preview' => false, 'thumbnail' => true];
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->get_base_id(), 'candwnldhd')) {
         $go_dl['document'] = true;
     }
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->get_base_id(), 'candwnldpreview')) {
         $go_dl['preview'] = true;
     }
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_hd_grant($this)) {
         $go_dl['document'] = true;
         $go_dl['preview'] = true;
     }
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_preview_grant($this)) {
         $go_dl['preview'] = true;
     }
     $query = new User_Query($this->app);
     $masters = $query->on_base_ids([$this->base_id])->who_have_right(['order_master'])->execute()->get_results();
     $go_cmd = count($masters) > 0 && $this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->base_id, 'cancmd');
     $orderable['document'] = false;
     $downloadable['document'] = false;
     if (isset($sd['document']) && is_file($sd['document']->get_pathfile())) {
         if ($go_dl['document'] === true) {
             if ($this->app['acl']->get($this->app['authentication']->getUser())->is_restricted_download($this->base_id)) {
                 $this->remain_hd--;
                 if ($this->remain_hd >= 0) {
                     $localizedLabel = $this->app->trans('document original');
                     $downloadable['document'] = ['class' => 'document', 'label' => $localizedLabel];
                 }
             } else {
                 $localizedLabel = $this->app->trans('document original');
                 $downloadable['document'] = ['class' => 'document', 'label' => $localizedLabel];
             }
         }
         if ($go_cmd === true) {
             $orderable['document'] = true;
         }
         $this->add_count('document', $sd['document']->get_size());
     }
     foreach ($subdefs as $subdef) {
         $name = $subdef->get_name();
         $class = $subdef->get_class();
         $subdef_label = $name;
         foreach ($subdef->get_labels() as $lang => $label) {
             if (trim($label) == '') {
                 continue;
             }
             if ($lang == $this->app['locale']) {
                 $subdef_label = $label;
                 break;
             }
             $subdef_label = $label;
         }
         $downloadable[$name] = false;
         $downloadable_settings = $subdef->is_downloadable();
         if (!$downloadable_settings || $go_dl[$class] === false) {
             continue;
         }
         if ($go_dl[$class]) {
             if (isset($sd[$name]) && $sd[$name]->is_physically_present()) {
                 if ($class == 'document') {
                     if ($this->app['acl']->get($this->app['authentication']->getUser())->is_restricted_download($this->base_id)) {
                         $this->remain_hd--;
                         if ($this->remain_hd >= 0) {
                             $downloadable[$name] = ['class' => $class, 'label' => $subdef_label];
                         }
                     } else {
                         $downloadable[$name] = ['class' => $class, 'label' => $subdef_label];
                     }
                 } else {
                     $downloadable[$name] = ['class' => $class, 'label' => $subdef_label];
                 }
                 $this->add_count($name, $sd[$name]->get_size());
             }
         }
     }
     $xml = $this->app['serializer.caption']->serialize($this->get_caption(), CaptionSerializer::SERIALIZE_XML);
     if ($xml) {
         $localizedLabel = $this->app->trans('caption XML');
         $downloadable['caption'] = ['class' => 'caption', 'label' => $localizedLabel];
         $this->add_count('caption', strlen($xml));
         $localizedLabel = $this->app->trans('caption YAML');
         $downloadable['caption-yaml'] = ['class' => 'caption', 'label' => $localizedLabel];
         $this->add_count('caption-yaml', strlen(strip_tags($xml)));
     }
     $this->downloadable = $downloadable;
     $this->orderable = $orderable;
     return $this;
 }
Beispiel #10
0
 /**
  * Set new admin to handle orders
  *
  * @param  Application      $app     The silex application
  * @param  Request          $request The current request
  * @param  integer          $bas_id  The collection base_id
  * @return RedirectResponse
  */
 public function setOrderAdmins(Application $app, Request $request, $bas_id)
 {
     $success = false;
     $admins = array_values($request->request->get('admins', []));
     if (count($admins) === 0) {
         $app->abort(400, 'No admins provided.');
     }
     if (!is_array($admins)) {
         $app->abort(400, 'Admins must be an array.');
     }
     $admins = array_map(function ($usrId) use($app) {
         if (null === ($user = $app['manipulator.user']->getRepository()->find($usrId))) {
             throw new RuntimeException(sprintf('Invalid usrId %s provided.', $usrId));
         }
         return $user;
     }, $admins);
     $conn = $app['phraseanet.appbox']->get_connection();
     $conn->beginTransaction();
     try {
         $userQuery = new \User_Query($app);
         $result = $userQuery->on_base_ids([$bas_id])->who_have_right(['order_master'])->execute()->get_results();
         foreach ($result as $user) {
             $app['acl']->get($user)->update_rights_to_base($bas_id, ['order_master' => false]);
         }
         foreach ($admins as $admin) {
             $app['acl']->get($admin)->update_rights_to_base($bas_id, ['order_master' => true]);
         }
         $conn->commit();
         $success = true;
     } catch (\Exception $e) {
         $conn->rollBack();
         throw $e;
     }
     return $app->redirectPath('admin_display_collection', ['bas_id' => $bas_id, 'success' => (int) $success]);
 }