Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $sql = 'DELETE FROM UserQueries';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app->getApplicationBox()->get_connection();
     $sql = 'SELECT * FROM dsel';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 0;
     $em = $app['orm.em'];
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['orm.em'], $row['usr_id']))) {
             continue;
         }
         $userQuery = new UserQuery();
         $userQuery->setQuery($row['query']);
         $userQuery->setUser($user);
         $em->persist($userQuery);
         $n++;
         if ($n % 1000 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $em->flush();
     $em->clear();
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function setUser(\Alchemy\Phrasea\Model\Entities\User $user)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUser', array($user));
     return parent::setUser($user);
 }
 /**
  * Logs a user query.
  *
  * @param User   $user
  * @param string $query
  */
 public function logQuery(User $user, $query)
 {
     $userQuery = new UserQuery();
     $userQuery->setUser($user);
     $userQuery->setQuery($query);
     $userQuery->setUser($user);
     $user->addQuery($userQuery);
     $this->manager->update($user);
 }
Beispiel #4
0
 private function prepare_search_request(Request $request)
 {
     $options = SearchEngineOptions::fromRequest($this->app, $request);
     $offsetStart = (int) ($request->get('offset_start') ?: 0);
     $perPage = (int) $request->get('per_page') ?: 10;
     $query = (string) $request->get('query');
     $this->app['phraseanet.SE']->resetCache();
     $search_result = $this->app['phraseanet.SE']->query($query, $offsetStart, $perPage, $options);
     $userQuery = new UserQuery();
     $userQuery->setUser($this->app['authentication']->getUser());
     $userQuery->setQuery($query);
     $this->app['EM']->persist($userQuery);
     $this->app['EM']->flush();
     foreach ($options->getDataboxes() as $databox) {
         $colls = array_map(function (\collection $collection) {
             return $collection->get_coll_id();
         }, array_filter($options->getCollections(), function (\collection $collection) use($databox) {
             return $collection->get_databox()->get_sbas_id() == $databox->get_sbas_id();
         }));
         $this->app['phraseanet.SE.logger']->log($databox, $search_result->getQuery(), $search_result->getTotal(), $colls);
     }
     $this->app['phraseanet.SE']->clearCache();
     $ret = ['offset_start' => $offsetStart, 'per_page' => $perPage, 'available_results' => $search_result->getAvailable(), 'total_results' => $search_result->getTotal(), 'error' => $search_result->getError(), 'warning' => $search_result->getWarning(), 'query_time' => $search_result->getDuration(), 'search_indexes' => $search_result->getIndexes(), 'suggestions' => array_map(function (SearchEngineSuggestion $suggestion) {
         return $suggestion->toArray();
     }, $search_result->getSuggestions()->toArray()), 'results' => [], 'query' => $search_result->getQuery()];
     return [$ret, $search_result];
 }
Beispiel #5
0
 /**
  * Queries database to fetch documents
  *
  * @param  Application $app
  * @param  Request     $request
  * @return Response
  */
 public function query(Application $app, Request $request)
 {
     $query = $this->buildQueryFromRequest($request);
     $displayMode = explode('X', $request->request->get('mod', '3X6'));
     if (count($displayMode) === 1) {
         $modRow = (int) $displayMode[0];
         $modCol = 1;
     } else {
         $modRow = (int) $displayMode[0];
         $modCol = (int) $displayMode[1];
     }
     $perPage = $modCol * $modRow;
     $options = SearchEngineOptions::fromRequest($app, $request);
     $currentPage = (int) $request->request->get('pag', 0);
     if ($currentPage < 1) {
         $app['phraseanet.SE']->resetCache();
         $currentPage = 1;
     }
     $result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage, $options);
     $userQuery = new UserQuery();
     $userQuery->setUser($app['authentication']->getUser());
     $userQuery->setQuery($query);
     $app['EM']->persist($userQuery);
     $app['EM']->flush();
     if ($app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page') === 'LAST_QUERY') {
         $app['manipulator.user']->setUserSetting($app['authentication']->getUser(), 'start_page_query', $query);
     }
     foreach ($options->getDataboxes() as $databox) {
         $colls = array_map(function (\collection $collection) {
             return $collection->get_coll_id();
         }, array_filter($options->getCollections(), function (\collection $collection) use($databox) {
             return $collection->get_databox()->get_sbas_id() == $databox->get_sbas_id();
         }));
         $app['phraseanet.SE.logger']->log($databox, $result->getQuery(), $result->getTotal(), $colls);
     }
     $searchData = $result->getResults();
     if (count($searchData) === 0) {
         return new Response($app['twig']->render("client/help.html.twig"));
     }
     $resultData = [];
     foreach ($searchData as $record) {
         try {
             $record->get_subdef('document');
             $lightInfo = $app['twig']->render('common/technical_datas.html.twig', ['record' => $record]);
         } catch (\Exception $e) {
             $lightInfo = '';
         }
         $caption = $app['twig']->render('common/caption.html.twig', ['view' => 'answer', 'record' => $record]);
         $docType = $record->get_type();
         $isVideo = $docType == 'video';
         $isAudio = $docType == 'audio';
         $isImage = $docType == 'image';
         $isDocument = $docType == 'document';
         if (!$isVideo && !$isAudio) {
             $isImage = true;
         }
         $canDownload = $app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'candwnldpreview') || $app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'candwnldhd') || $app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'cancmd');
         try {
             $previewExists = $record->get_preview()->is_physically_present();
         } catch (\Exception $e) {
             $previewExists = false;
         }
         $resultData[] = ['record' => $record, 'mini_logo' => \collection::getLogo($record->get_base_id(), $app), 'preview_exists' => $previewExists, 'light_info' => $lightInfo, 'caption' => $caption, 'is_video' => $isVideo, 'is_audio' => $isAudio, 'is_image' => $isImage, 'is_document' => $isDocument, 'can_download' => $canDownload, 'can_add_to_basket' => $app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'canputinalbum')];
     }
     return new Response($app['twig']->render("client/answers.html.twig", ['mod_col' => $modCol, 'mod_row' => $modRow, 'result_data' => $resultData, 'per_page' => $perPage, 'search_engine' => $app['phraseanet.SE'], 'search_engine_option' => $options->serialize(), 'history' => \queries::history($app, $app['authentication']->getUser()->getId()), 'result' => $result, 'proposals' => $currentPage === 1 ? $result->getProposals() : null, 'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '']));
 }