mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 04:53:26 +00:00
Add UserQuery entity
This commit is contained in:
@@ -220,7 +220,7 @@ class Root implements ControllerProviderInterface
|
||||
'per_page' => $perPage,
|
||||
'search_engine' => $app['phraseanet.SE'],
|
||||
'search_engine_option' => $options->serialize(),
|
||||
'history' => \queries::history($app['phraseanet.appbox'], $app['authentication']->getUser()->get_id()),
|
||||
'history' => \queries::history($app, $app['authentication']->getUser()->get_id()),
|
||||
'result' => $result,
|
||||
'proposals' => $currentPage === 1 ? $result->getProposals() : null,
|
||||
'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '',
|
||||
|
@@ -119,7 +119,7 @@ class Root implements ControllerProviderInterface
|
||||
'GV_google_api' => $app['phraseanet.registry']->get('GV_google_api'),
|
||||
'queries_topics' => $queries_topics,
|
||||
'search_status' => \databox_status::getSearchStatus($app),
|
||||
'queries_history' => \queries::history($app['phraseanet.appbox'], $app['authentication']->getUser()->get_id()),
|
||||
'queries_history' => \queries::history($app, $app['authentication']->getUser()->get_id()),
|
||||
'thesau_js_list' => $thjslist,
|
||||
'thesau_json_sbas' => json_encode($sbas),
|
||||
'thesau_json_bas2sbas' => json_encode($bas2sbas),
|
||||
|
@@ -18,7 +18,7 @@ namespace Alchemy\Phrasea\Core;
|
||||
*/
|
||||
class Version
|
||||
{
|
||||
protected static $number = '3.9.0.a2';
|
||||
protected static $number = '3.9.0.a3';
|
||||
protected static $name = 'Diplodocus';
|
||||
|
||||
public static function getNumber()
|
||||
|
@@ -18,6 +18,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Entities\UserQuery;
|
||||
|
||||
class PhraseaEngine implements SearchEngineInterface
|
||||
{
|
||||
@@ -575,8 +576,17 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($this->app['authentication']->getUser()) {
|
||||
\User_Adapter::saveQuery($this->app, $query);
|
||||
if (null !== $user = $this->app['authentication']->getUser()) {
|
||||
$userQuery = new UserQuery();
|
||||
$userQuery->setUsrId($user->get_id());
|
||||
$userQuery->setQuery($query);
|
||||
|
||||
$this->app['EM']->persist($userQuery);
|
||||
$this->app['EM']->flush();
|
||||
|
||||
if ($user->getPrefs('start_page') === 'LAST_QUERY') {
|
||||
$user->setPrefs('start_page_query', $query);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
104
lib/Doctrine/Entities/UserQuery.php
Normal file
104
lib/Doctrine/Entities/UserQuery.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Entities;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="UserQueries")
|
||||
* @ORM\Entity(repositoryClass="Repositories\UserQueryRepository")
|
||||
*/
|
||||
class UserQuery
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", name="usr_id")
|
||||
*/
|
||||
private $usrId;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=256)
|
||||
*/
|
||||
private $query;
|
||||
|
||||
/**
|
||||
* @Gedmo\Timestampable(on="create")
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
private $created;
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getUsrId()
|
||||
{
|
||||
return $this->usrId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $usrId
|
||||
*/
|
||||
public function setUsrId($usrId)
|
||||
{
|
||||
$this->usrId = $usrId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
*
|
||||
* @return \User_Adapter
|
||||
*/
|
||||
public function getUser(Application $app)
|
||||
{
|
||||
return \User_Adapter::getInstance($this->usrId, $app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreated()
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
}
|
24
lib/Doctrine/Repositories/UserQueryRepository.php
Normal file
24
lib/Doctrine/Repositories/UserQueryRepository.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Repositories;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* UserQuery
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class UserQueryRepository extends EntityRepository
|
||||
{
|
||||
}
|
@@ -414,36 +414,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
return $this->ACL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query in the cache
|
||||
*
|
||||
* @param Application $app
|
||||
* @param string $query
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function saveQuery(Application $app, $query)
|
||||
{
|
||||
try {
|
||||
$sql = "INSERT INTO dsel (id, name, usr_id, query)
|
||||
VALUES (null, :name, :usr_id, :query)";
|
||||
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(
|
||||
':name' => $query,
|
||||
':usr_id' => $app['authentication']->getUser()->get_id(),
|
||||
':query' => $query
|
||||
));
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($app['authentication']->getUser()->getPrefs('start_page') == 'LAST_QUERY')
|
||||
$app['authentication']->getUser()->setPrefs('start_page_query', $query);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
|
@@ -128,8 +128,6 @@ interface User_Interface
|
||||
|
||||
public static function getInstance($id, Application $app);
|
||||
|
||||
public static function saveQuery(Application $app, $query);
|
||||
|
||||
public static function get_usr_id_from_login(Application $app, $login);
|
||||
|
||||
public static function get_usr_id_from_email(Application $app, $email);
|
||||
|
80
lib/classes/patch/3903.php
Normal file
80
lib/classes/patch/3903.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Entities\UserQuery;
|
||||
|
||||
class patch_3903 implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0.a3';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::APPLICATION_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$conn = $app['phraseanet.appbox']->get_connection();
|
||||
$sql = 'SELECT * FROM dsel';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$n = 0;
|
||||
$em = $app['EM'];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$userQuery = new UserQuery();
|
||||
$userQuery->setQuery($row['query']);
|
||||
$userQuery->setUsrId($row['usr_id']);
|
||||
|
||||
$em->persist($userQuery);
|
||||
|
||||
$n++;
|
||||
|
||||
if ($n % 1000 === 0) {
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
@@ -9,15 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
class queries
|
||||
{
|
||||
|
||||
public static function tree_topics($I18N)
|
||||
{
|
||||
$out = '';
|
||||
@@ -188,22 +183,16 @@ class queries
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function history(appbox $appbox, $usr_id)
|
||||
public static function history(Application $app, $usrId)
|
||||
{
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
$sql = "SELECT query from dsel where usr_id = :usr_id
|
||||
ORDER BY id DESC LIMIT 0,25";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':usr_id' => $usr_id));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$history = '<ul>';
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$history .= '<li onclick="doSpecialSearch(\'' . str_replace(array("'", '"'), array("\'", '"'), $row["query"]) . '\')">' . $row["query"] . '</li>';
|
||||
$queries = $app['EM']
|
||||
->getRepository('Entities\UserQuery')
|
||||
->findBy(array('usrId' => $usrId), array('created' => 'ASC'), 25, 0);
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$history .= '<li onclick="doSpecialSearch(\'' . str_replace(array("'", '"'), array("\'", '"'), $query->getQuery()) . '\')">' . $query->getQuery() . '</li>';
|
||||
}
|
||||
|
||||
$history .= '<ul>';
|
||||
|
Reference in New Issue
Block a user