Fix tests

This commit is contained in:
Nicolas Le Goff
2013-12-05 14:21:50 +01:00
parent 49744c5e2f
commit b341495c88
122 changed files with 963 additions and 3454 deletions

View File

@@ -114,11 +114,6 @@ class ACL implements cache_cacheableInterface
return $this;
}
public function set_app(Application $app)
{
$this->app = $app;
}
/**
* Check if a hd grant has been received for a record
*
@@ -195,7 +190,6 @@ class ACL implements cache_cacheableInterface
*/
public function has_preview_grant(record_Interface $record)
{
$this->load_hd_grant();
$key = $record->get_serialize_key();
@@ -757,7 +751,11 @@ class ACL implements cache_cacheableInterface
public function set_admin($boolean)
{
$this->app['manipulator.user']->promote($this->user);
if ($boolean) {
$this->app['manipulator.user']->promote($this->user);
} else {
$this->app['manipulator.user']->demote($this->user);
}
return $this;
}

View File

@@ -1374,7 +1374,7 @@ class API_V1_adapter extends API_V1_Abstract
$choices[] = [
'validation_user' => [
'usr_id' => $user->getId(),
'usr_name' => $user->getDisplayName(),
'usr_name' => $user->getDisplayName($this->app['translator']),
'confirmed' => $participant->getIsConfirmed(),
'can_agree' => $participant->getCanAgree(),
'can_see_others' => $participant->getCanSeeOthers(),
@@ -1818,7 +1818,7 @@ class API_V1_adapter extends API_V1_Abstract
$users[] = [
'usr_id' => $user->getId(),
'usr_name' => $user->getDisplayName(),
'usr_name' => $user->getDisplayName($this->app['translator']),
'confirmed' => $participant->getIsConfirmed(),
'can_agree' => $participant->getCanAgree(),
'can_see_others' => $participant->getCanSeeOthers(),

View File

@@ -1,917 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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 Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
use Alchemy\Phrasea\Model\Entities\FtpCredential;
class User_Adapter implements User_Interface, cache_cacheableInterface
{
/**
*
* @var ACL
*/
protected $ACL;
/**
*
* @var Array
*/
public static $locales = [
'ar' => 'العربية'
, 'de' => 'Deutsch'
, 'nl' => 'Dutch'
, 'en' => 'English'
, 'es' => 'Español'
, 'fr' => 'Français'
];
/**
*
* @var array
*/
protected static $_instance = [];
/**
*
* @var array
*/
protected $_prefs = [];
/**
*
* @var array
*/
protected $_updated_prefs = [];
/**
*
* @var array
*/
public static $def_values = array(
'view' => 'thumbs',
'images_per_page' => 20,
'images_size' => 120,
'editing_images_size' => 134,
'editing_top_box' => '180px',
'editing_right_box' => '400px',
'editing_left_box' => '710px',
'basket_sort_field' => 'name',
'basket_sort_order' => 'ASC',
'warning_on_delete_story' => 'true',
'client_basket_status' => '1',
'css' => '000000',
'advanced_search_reload' => '1',
'start_page_query' => 'last',
'start_page' => 'QUERY',
'rollover_thumbnail' => 'caption',
'technical_display' => '1',
'doctype_display' => '1',
'bask_val_order' => 'nat',
'basket_caption_display' => '0',
'basket_status_display' => '0',
'basket_title_display' => '0'
];
/**
*
* @var array
*/
protected static $available_values = [
'view' => ['thumbs', 'list'],
'basket_sort_field' => ['name', 'date'],
'basket_sort_order' => ['ASC', 'DESC'],
'start_page' => ['PUBLI', 'QUERY', 'LAST_QUERY', 'HELP'],
'technical_display' => ['0', '1', 'group'],
'rollover_thumbnail' => ['caption', 'preview'],
'bask_val_order' => ['nat', 'asc', 'desc']
];
/**
*
* @var Application
*/
protected $app;
/**
*
* @var int
*/
protected $id;
/**
*
* @var string
*/
protected $email;
/**
*
* @var string
*/
protected $login;
/**
*
* @var string
*/
protected $locale;
/**
*
* @var string
*/
protected $firstname;
/**
*
* @var string
*/
protected $lastname;
/**
*
* @var string
*/
protected $address;
/**
*
* @var string
*/
protected $city;
/**
*
* @var int
*/
protected $geonameid;
/**
*
* @var string
*/
protected $zip;
/**
*
* @var int
*/
protected $gender;
/**
*
* @var string
*/
protected $tel;
/**
*
* @var int
*/
protected $lastModel;
/**
*
* @var DateTime
*/
protected $creationdate;
/**
*
* @var DateTime
*/
protected $modificationdate;
/**
*
* @var string
*/
protected $fax;
/**
*
* @var string
*/
protected $job;
/**
*
* @var string
*/
protected $position;
/**
*
* @var string
*/
protected $company;
/**
*
* @var boolean
*/
protected $ldap_created;
/**
*
* @var boolean
*/
protected $is_guest;
/**
*
* @var boolean
*/
protected $mail_locked;
/**
*
* @var FtpCredential
*/
protected $ftpCredential;
/**
*
* @var string
*/
protected $mail_notifications;
/**
*
* @var string
*/
protected $country;
/**
*
* @var boolean
*/
protected $is_template;
/**
*
* @var User_Adapter
*/
protected $template_owner;
protected $password;
protected $preferences_loaded = false;
protected $notifications_preferences_loaded = false;
/**
*
* @param Integer $id
* @param Application $app
*
* @return User_Adapter
*/
public function __construct($id, Application $app)
{
$this->app = $app;
$this->load($id);
return $this;
}
public static function unsetInstances()
{
foreach (self::$_instance as $id => $user) {
self::unsetInstance($id);
}
}
public static function unsetInstance($id)
{
if (isset(self::$_instance[$id])) {
self::$_instance[$id] = null;
unset(self::$_instance[$id]);
}
}
/**
*
* @param type $id
* @param Application $app
* @return User_Adapter
*/
public static function getInstance($id, Application $app)
{
if (is_int((int) $id) && (int) $id > 0) {
$id = (int) $id;
} else
throw new Exception('Invalid usr_id');
if (!isset(self::$_instance[$id])) {
try {
self::$_instance[$id] = $app['phraseanet.appbox']->get_data_from_cache('_user_' . $id);
self::$_instance[$id]->set_app($app);
} catch (Exception $e) {
self::$_instance[$id] = new self($id, $app);
$app['phraseanet.appbox']->set_data_to_cache(self::$_instance[$id], '_user_' . $id);
}
} else {
self::$_instance[$id]->set_app($app);
}
return array_key_exists($id, self::$_instance) ? self::$_instance[$id] : false;
}
/**
*
* @param type $pasword
* @return User_Adapter
*/
public function set_password($pasword)
{
$sql = 'UPDATE usr SET usr_password = :password, salted_password = "1"
WHERE usr_id = :usr_id';
$password = $this->app['auth.password-encoder']->encodePassword($pasword, $this->get_nonce());
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':password' => $password, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->password = $password;
return $this;
}
/**
*
* @param string $email
* @return User_Adapter
*/
public function set_email($email)
{
if (trim($email) == '') {
$email = null;
}
$test_user = User_Adapter::get_usr_id_from_email($this->app, $email);
if ($test_user && $test_user != $this->get_id()) {
throw new Exception_InvalidArgument($this->app->trans('A user already exists with email addres %email%', ['%email%' => $email]));
}
$sql = 'UPDATE usr SET usr_mail = :new_email WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':new_email' => $email, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->email = $email;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param bollean $boolean
* @return User_Adapter
*/
public function set_mail_notifications($boolean)
{
$value = $boolean ? '1' : '0';
$sql = 'UPDATE usr SET mail_notifications = :mail_notifications WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':mail_notifications' => $value, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->mail_notifications = !!$boolean;
$this->delete_data_from_cache();
return $this;
}
/**
*
* @param boolean $boolean
* @return User_Adapter
*/
public function set_ldap_created($boolean)
{
$value = $boolean ? '1' : '0';
$sql = 'UPDATE usr SET ldap_created = :ldap_created WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':ldap_created' => $value, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->ldap_created = $boolean;
return $this;
}
public function set_firstname($firstname)
{
$sql = 'UPDATE usr SET usr_prenom = :usr_prenom WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_prenom' => $firstname, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->firstname = $firstname;
$this->delete_data_from_cache();
return $this;
}
public function set_lastname($lastname)
{
$sql = 'UPDATE usr SET usr_nom = :usr_nom WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_nom' => $lastname, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->lastname = $lastname;
$this->delete_data_from_cache();
return $this;
}
public function set_address($address)
{
$sql = 'UPDATE usr SET adresse = :adresse WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':adresse' => $address, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->address = $address;
$this->delete_data_from_cache();
return $this;
}
public function set_city($city)
{
$sql = 'UPDATE usr SET ville = :city WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':city' => $city, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->city = $city;
$this->delete_data_from_cache();
return $this;
}
public function set_geonameid($geonameid)
{
$country_code = null;
try {
$country = $this->app['geonames.connector']
->geoname($this->geonameid)
->get('country');
if (isset($country['code'])) {
$country_code = $country['code'];
}
} catch (GeonamesExceptionInterface $e) {
}
$sql = 'UPDATE usr SET geonameid = :geonameid, pays=:country_code WHERE usr_id = :usr_id';
$datas = [
':geonameid' => $geonameid,
':usr_id' => $this->get_id(),
':country_code' => $country_code
];
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($datas);
$stmt->closeCursor();
$this->geonameid = $geonameid;
$this->country = $country_code;
$this->delete_data_from_cache();
return $this;
}
public function set_zip($zip)
{
$sql = 'UPDATE usr SET cpostal = :cpostal WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':cpostal' => $zip, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->zip = $zip;
$this->delete_data_from_cache();
return $this;
}
public function set_gender($gender)
{
$sql = 'UPDATE usr SET usr_sexe = :usr_sexe WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_sexe' => $gender, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->gender = $gender;
$this->delete_data_from_cache();
return $this;
}
public function set_tel($tel)
{
$sql = 'UPDATE usr SET tel = :tel WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':tel' => $tel, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->tel = $tel;
$this->delete_data_from_cache();
return $this;
}
public function set_fax($fax)
{
$sql = 'UPDATE usr SET fax = :fax WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':fax' => $fax, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->fax = $fax;
$this->delete_data_from_cache();
return $this;
}
public function set_job($job)
{
$sql = 'UPDATE usr SET fonction = :fonction WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':fonction' => $job, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->job = $job;
$this->delete_data_from_cache();
return $this;
}
public function set_position($position)
{
$sql = 'UPDATE usr SET activite = :activite WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':activite' => $position, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->position = $position;
$this->delete_data_from_cache();
return $this;
}
public function set_company($company)
{
$sql = 'UPDATE usr SET societe = :company WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':company' => $company, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->company = $company;
$this->delete_data_from_cache();
return $this;
}
public function set_template(User_Adapter $owner)
{
$this->is_template = true;
$this->template_owner = $owner;
if ($owner->get_id() == $this->get_id())
throw new Exception_InvalidArgument ();
$sql = 'UPDATE usr SET model_of = :owner_id WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':owner_id' => $owner->get_id(), ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this
->set_city('')
->set_company('')
->set_email(null)
->set_fax('')
->set_firstname('')
->set_gender('')
->set_geonameid('')
->set_job('')
->set_lastname('')
->set_mail_locked(false)
->set_mail_notifications(true)
->set_position('')
->set_zip('')
->set_tel('');
$this->ftpCredential = new FtpCredential();
$this->ftpCredential->setUsrId($this->get_id());
$this->app['EM']->persist($this->ftpCredential);
$this->app['EM']->flush();
$this->delete_data_from_cache();
return $this;
}
/**
* @todo close all open session
* @return type
*/
public function delete()
{
$repo = $this->app['EM']->getRepository('Phraseanet:UsrAuthProvider');
foreach ($repo->findByUser($this) as $provider) {
$this->app['EM']->remove($provider);
}
$repo = $this->app['EM']->getRepository('Phraseanet:FtpExport');
foreach ($repo->findByUser($this) as $export) {
$this->app['EM']->remove($export);
}
$repo = $this->app['EM']->getRepository('Phraseanet:Order');
foreach ($repo->findByUser($this) as $order) {
$this->app['EM']->remove($order);
}
$repo = $this->app['EM']->getRepository('Phraseanet:Session');
foreach ($repo->findByUser($this) as $session) {
$this->app['EM']->remove($session);
}
$this->app['EM']->flush();
$sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null
WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_login' => '(#deleted_' . $this->get_login() . '_' . $this->get_id(), ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$sql = 'DELETE FROM basusr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$sql = 'DELETE FROM sbasusr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$sql = 'DELETE FROM dsel WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$sql = 'DELETE FROM edit_presets WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$sql = 'DELETE FROM tokens WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$sql = 'DELETE FROM usr_settings WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$stmt->closeCursor();
unset(self::$_instance[$this->get_id()]);
return;
}
public function get_mail_notifications()
{
return $this->mail_notifications;
}
/**
*
* @param <type> $id
* @return user
*/
public function load($id)
{
$sql = 'SELECT usr_id, ldap_created, create_db, usr_login, usr_password, usr_nom, activite,
usr_prenom, usr_sexe as gender, usr_mail, adresse, usr_creationdate, usr_modificationdate,
ville, cpostal, tel, fax, fonction, societe, geonameid, lastModel, invite,
mail_notifications, mail_locked, model_of, locale
FROM usr WHERE usr_id= :id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':id' => $id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row) {
throw new \Exception('User unknown');
}
$this->id = (int) $row['usr_id'];
$this->email = $row['usr_mail'];
$this->login = $row['usr_login'];
$this->password = $row['usr_password'];
$this->ldap_created = $row['ldap_created'];
$this->mail_notifications = $row['mail_notifications'];
$this->mail_locked = !!$row['mail_locked'];
$this->firstname = $row['usr_prenom'];
$this->lastname = $row['usr_nom'];
$this->address = $row['adresse'];
$this->city = $row['ville'];
$this->geonameid = $row['geonameid'];
$this->zip = $row['cpostal'];
$this->gender = $row['gender'];
$this->tel = $row['tel'];
$this->locale = $row['locale'];
$this->fax = $row['fax'];
$this->job = $row['fonction'];
$this->position = $row['activite'];
$this->company = $row['societe'];
$this->creationdate = new DateTime($row['usr_creationdate']);
$this->modificationdate = new DateTime($row['usr_modificationdate']);
$this->applied_template = $row['lastModel'];
$this->country = $this->get_country();
$this->is_guest = ($row['invite'] == '1');
if ($row['model_of'] > 0) {
$this->is_template = true;
$this->template_owner = self::getInstance($row['model_of'], $this->app);
}
return $this;
}
public function set_last_template(User_Interface $template)
{
$sql = 'UPDATE usr SET lastModel = :template_id WHERE usr_id = :usr_id';
$params = [
':usr_id' => $this->get_id()
, ':template_id' => $template->get_login()
];
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->delete_data_from_cache();
return $this;
}
public function set_mail_locked($boolean)
{
$sql = 'UPDATE usr SET mail_locked = :mail_locked WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id(), ':mail_locked' => ($boolean ? '1' : '0')]);
$stmt->closeCursor();
$this->mail_locked = !!$boolean;
return $this;
}
public function get_notifications_preference(Application $app, $notification_id)
{
if (!$this->notifications_preferences_loaded)
$this->load_notifications_preferences($app);
return isset($this->_prefs['notification_' . $notification_id]) ? $this->_prefs['notification_' . $notification_id] : '0';
}
public function set_notification_preference(Application $app, $notification_id, $value)
{
if (!$this->notifications_preferences_loaded)
$this->load_notifications_preferences($app);
$prop = 'notification_' . $notification_id;
$value = $value ? '1' : '0';
$this->setPrefs($prop, $value);
return ;
}
public function get_cache_key($option = null)
{
return '_user_' . $this->get_id() . ($option ? '_' . $option : '');
}
public function delete_data_from_cache($option = null)
{
$this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option));
return $this;
}
public function get_data_from_cache($option = null)
{
$this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option));
return $this;
}
public function set_data_to_cache($value, $option = null, $duration = 0)
{
$this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration);
return $this;
}
public function setPrefs($prop, $value)
{
$this->load_preferences();
if (isset($this->_prefs[$prop]) && $this->_prefs[$prop] === $value) {
return $this->_prefs[$prop];
}
$ok = true;
if (isset(self::$available_values[$prop])) {
$ok = false;
if (in_array($value, self::$available_values[$prop]))
$ok = true;
}
if ($ok) {
$this->_prefs[$prop] = $value;
$this->update_pref($prop, $value);
}
return $this->_prefs[$prop];
}
public function getPrefs($prop, $default = null)
{
$this->load_preferences();
return array_key_exists($prop, $this->_prefs) ? $this->_prefs[$prop] : $default;
}
public static function set_sys_admins(Application $app, $admins)
{
try {
$sql = "UPDATE usr SET create_db='0' WHERE create_db='1' AND usr_id != :usr_id";
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $app['authentication']->getUser()->getId()]);
$stmt->closeCursor();
$sql = "UPDATE usr SET create_db='1' WHERE usr_id IN (" . implode(',', $admins) . ")";
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
return true;
} catch (Exception $e) {
}
return false;
}
public function get_locale()
{
return $this->locale ?: $this->app['conf']->get(['languages', 'default'], 'en');
}
public function set_locale($locale)
{
if (!array_key_exists($locale, $this->app['locales.available'])) {
throw new \InvalidArgumentException(sprintf('Locale %s is not recognized', $locale));
}
$sql = 'UPDATE usr SET locale = :locale WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':locale' => $locale, ':usr_id' => $this->get_id()]);
$stmt->closeCursor();
$this->delete_data_from_cache();
$this->locale = $locale;
return $this->locale;
}
public function __sleep()
{
$vars = [];
foreach ($this as $key => $value) {
if (in_array($key, ['ACL', 'app']))
continue;
$vars[] = $key;
}
return $vars;
}
public static function purge()
{
self::$_instance = [];
}
}

View File

@@ -144,19 +144,6 @@ abstract class base implements cache_cacheableInterface
return $this->connection;
}
/**
* Replaces the connection
*
* @param \connection_pdo $connection
* @return \base
*/
public function set_connection(\connection_pdo $connection)
{
$this->connection = $connection;
return $this;
}
public function get_cache()
{
return $this->app['cache'];

View File

@@ -12,7 +12,6 @@
use Alchemy\Phrasea\Notification\Receiver;
use Alchemy\Phrasea\Notification\Mail\MailInfoSomebodyAutoregistered;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract
{
@@ -50,23 +49,8 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract
$mailColl = [];
$rsm = new ResultSetMappingBuilder($this->app['EM']);
$rsm->addRootEntityFromClassMetadata('Alchemy\Phrasea\Model\Entities\User', 'u');
$rsm->addScalarResult('base_id', 'base_id');
$selectClause = $rsm->generateSelectClause();
$query = $this->app['EM']->createNativeQuery('
SELECT b.base_id, '.$selectClause.' FROM Users u, basusr b
WHERE u.id = b.usr_id
AND b.base_id IN (' . implode(', ', array_keys($base_ids)) . ')
AND u.model_of IS NULL
AND b.actif="1"
AND b.canadmin="1"
AND u.deleted="0"', $rsm
);
try {
$rs = $query->getResult();
$rs = $this->app['phraseanet.native-query']->getAdminsOfBases(array_keys($base_ids));
foreach ($rs as $row) {
$user = $row[0];
@@ -145,7 +129,7 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract
}
$ret = [
'text' => $this->app->trans('%user% s\'est enregistre sur une ou plusieurs %before_link% scollections %after_link%', ['%user%' => $user->getDisplayName(), '%before_link%' => '<a href="/admin/?section=users" target="_blank">', '%after_link%' => '</a>'])
'text' => $this->app->trans('%user% s\'est enregistre sur une ou plusieurs %before_link% scollections %after_link%', ['%user%' => $user->getDisplayName($this->app['translator']), '%before_link%' => '<a href="/admin/?section=users" target="_blank">', '%after_link%' => '</a>'])
, 'class' => ''
];
@@ -179,15 +163,16 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract
*/
public function mail(User $to, User $registeredUser)
{
$body .= sprintf("Login : %s\n", $registeredUser->get_login());
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur nom'), $registeredUser->get_firstname());
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur prenom'), $registeredUser->get_lastname());
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur email'), $registeredUser->get_email());
$body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->get_company());
$body = '';
$body .= sprintf("Login : %s\n", $registeredUser->getLogin());
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur nom'), $registeredUser->getFirstName());
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur prenom'), $registeredUser->getLastName());
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur email'), $registeredUser->getEmail());
$body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->getCompany());
$readyToSend = false;
try {
$receiver = Receiver::fromUser($to);
$receiver = Receiver::fromUser($to, $this->app['translator']);
$readyToSend = true;
} catch (Exception $e) {

View File

@@ -81,7 +81,7 @@ class eventsmanager_notify_bridgeuploadfail extends eventsmanager_notifyAbstract
try {
$user = $this->app['manipulator.user']->getRepository()->find($params['usr_id']);
$account = Bridge_Account::load_account($this->app, $params['account_id']);
$receiver = Receiver::fromUser($user);
$receiver = Receiver::fromUser($user, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {

View File

@@ -97,7 +97,7 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
$url = $this->app->url('lightbox', ['LOG' => $token]);
$receiver = Receiver::fromUser($user_to_notif);
$receiver = Receiver::fromUser($user_to_notif, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {

View File

@@ -102,7 +102,7 @@ class eventsmanager_notify_order extends eventsmanager_notifyAbstract
if ($this->shouldSendNotificationFor($user->getId())) {
$readyToSend = false;
try {
$receiver = Receiver::fromUser($user);
$receiver = Receiver::fromUser($user, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {
continue;
@@ -140,7 +140,7 @@ class eventsmanager_notify_order extends eventsmanager_notifyAbstract
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
$ret = [
'text' => $this->app->trans('%user% a passe une %opening_link% commande %end_link%', [

View File

@@ -95,8 +95,8 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
$user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
$user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$receiver = Receiver::fromUser($user_to, $this->app['translator']);
$emitter = Emitter::fromUser($user_from, $this->app['translator']);
$repository = $this->app['EM']->getRepository('Phraseanet:Basket');
$basket = $repository->find($params['ssel_id']);
@@ -148,7 +148,7 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
try {
$repository = $this->app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Basket');

View File

@@ -78,8 +78,8 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac
$user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
$user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$receiver = Receiver::fromUser($user_to, $this->app['translator']);
$emitter = Emitter::fromUser($user_from, $this->app['translator']);
$readyToSend = true;
} catch (Exception $e) {
@@ -111,7 +111,7 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
$ret = [
'text' => $this->app->trans('%user% a refuse la livraison de %quantity% document(s) pour votre commande', ['%user%' => $sender, '%quantity%' => $n])

View File

@@ -86,8 +86,8 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
$user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
$user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$receiver = Receiver::fromUser($user_to, $this->app['translator']);
$emitter = Emitter::fromUser($user_from, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {
@@ -123,7 +123,7 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
$ret = [
'text' => $this->app->trans('%user% vous a envoye un %before_link% panier %after_link%', ['%user%' => $sender, '%before_link%' => '<a href="#" onclick="openPreview(\'BASK\',1,\''

View File

@@ -10,7 +10,6 @@
*/
use Alchemy\Phrasea\Notification\Receiver;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Alchemy\Phrasea\Notification\Mail\MailInfoUserRegistered;
class eventsmanager_notify_register extends eventsmanager_notifyAbstract
@@ -53,23 +52,10 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
$mailColl = [];
$rsm = new ResultSetMappingBuilder($this->app['EM']);
$rsm->addRootEntityFromClassMetadata('Alchemy\Phrasea\Model\Entities\User', 'u');
$rsm->addScalarResult('base_id', 'base_id');
$selectClause = $rsm->generateSelectClause();
$query = $this->app['EM']->createNativeQuery('
SELECT b.base_id, '.$selectClause.' FROM Users u, basusr b
WHERE u.id = b.usr_id
AND b.base_id IN (' . implode(', ', array_keys($base_ids)) . ')
AND u.model_of IS NULL
AND b.actif="1"
AND b.canadmin="1"
AND u.deleted="0"',
$rsm);
try {
foreach ($query->getResult() as $row) {
$rs = $this->app['phraseanet.native-query']->getAdminsOfBases(array_keys($base_ids));
foreach ($rs as $row) {
$user = $row[0];
if (!isset($mailColl[$user->getId()])) {
@@ -117,7 +103,7 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
$readyToSend = false;
try {
$admin_user = $this->app['manipulator.user']->getRepository()->find($usr_id);
$receiver = Receiver::fromUser($admin_user);
$receiver = Receiver::fromUser($admin_user, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {
continue;
@@ -155,7 +141,7 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
$ret = [
'text' => $this->app->trans('%user% demande votre approbation sur une ou plusieurs %before_link% collections %after_link%', ['%user%' => $sender, '%before_link%' => '<a href="' . $this->app->url('admin', ['section' => 'registrations']) . '" target="_blank">', '%after_link%' => '</a>'])

View File

@@ -74,7 +74,7 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract
//Sender
if (null !== $user = $lazaretFile->getSession()->getUser()) {
$sender = $domXML->createElement('sender');
$sender->appendChild($domXML->createTextNode($user->getDisplayName()));
$sender->appendChild($domXML->createTextNode($user->getDisplayName($this->app['translator'])));
$root->appendChild($sender);
$this->notifyUser($user, $datas);
@@ -109,7 +109,7 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract
if ($this->shouldSendNotificationFor($user->getId())) {
$readyToSend = false;
try {
$receiver = Receiver::fromUser($user);
$receiver = Receiver::fromUser($user, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {

View File

@@ -101,8 +101,8 @@ class eventsmanager_notify_validate extends eventsmanager_notifyAbstract
->find($params['ssel_id']);
$title = $basket->getName();
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$receiver = Receiver::fromUser($user_to, $this->app['translator']);
$emitter = Emitter::fromUser($user_from, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {
@@ -141,7 +141,7 @@ class eventsmanager_notify_validate extends eventsmanager_notifyAbstract
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
try {
$basket = $this->app['converter.basket']->convert($ssel_id);

View File

@@ -96,8 +96,8 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
->find($params['ssel_id']);
$title = $basket->getName();
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$receiver = Receiver::fromUser($user_to, $this->app['translator']);
$emitter = Emitter::fromUser($user_from, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {
@@ -135,7 +135,7 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
return [];
}
$sender = $registered_user->getDisplayName();
$sender = $registered_user->getDisplayName($this->app['translator']);
try {
$repository = $this->app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Basket');

View File

@@ -102,8 +102,8 @@ class eventsmanager_notify_validationreminder extends eventsmanager_notifyAbstra
->find($params['ssel_id']);
$title = $basket->getName();
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$receiver = Receiver::fromUser($user_to, $this->app['translator']);
$emitter = Emitter::fromUser($user_from, $this->app['translator']);
$readyToSend = true;
} catch (\Exception $e) {
@@ -140,7 +140,7 @@ class eventsmanager_notify_validationreminder extends eventsmanager_notifyAbstra
return [];
}
$sender = $user->getDisplayName();
$sender = $user->getDisplayName($this->app['translator']);
try {
$basket = $this->app['converter.basket']->convert($ssel_id);

View File

@@ -50,7 +50,7 @@ class module_console_checkExtension extends Command
$output->writeln(
sprintf(
"\nWill do the check with user <info>%s</info> (%s)\n"
, $TestUser->getDisplayName()
, $TestUser->getDisplayName($this->container['translator'])
, $TestUser->getEmail()
)
);

View File

@@ -295,7 +295,7 @@ class module_report_activity extends module_report
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$login = $this->app['manipulator.user']->getRepository()->find($usr)->getDisplayName();
$login = $this->app['manipulator.user']->getRepository()->find($usr)->getDisplayName($this->app['translator']);
$this->setChamp($rs);

View File

@@ -78,7 +78,7 @@ class module_report_add extends module_report
$caption = $value;
if ($field == "getter") {
if (null !== $user = $this->app['manipulator.user']->getRepository()->find($value)) {
$caption = $user->getDisplayName();
$caption = $user->getDisplayName($this->app['translator']);
}
} elseif ($field == 'date')
$caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));

View File

@@ -78,7 +78,7 @@ class module_report_edit extends module_report
$caption = $value;
if ($field == "getter") {
if (null !== $user = $this->app['manipulator.user']->getRepository()->find($value)) {
$caption = $user->getDisplayName();
$caption = $user->getDisplayName($this->app['translator']);
}
} elseif ($field == 'date') {
$caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));

View File

@@ -79,7 +79,7 @@ class module_report_push extends module_report
$caption = $value;
if ($field == "getter") {
if (null !== $user = $this->app['manipulator.user']->getRepository()->find($value)) {
$caption = $user->getDisplayName();
$caption = $user->getDisplayName($this->app['translator']);
}
} elseif ($field == 'date') {
$caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));

View File

@@ -79,7 +79,7 @@ class module_report_sent extends module_report
$caption = $value;
if ($field == "getter") {
if (null !== $user = $this->app['manipulator.user']->getRepository()->find($value)) {
$caption = $user->getDisplayName();
$caption = $user->getDisplayName($this->app['translator']);
}
} elseif ($field == 'date') {
$caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));

View File

@@ -79,7 +79,7 @@ class module_report_validate extends module_report
$caption = $value;
if ($field == "getter") {
if (null !== $user = $this->app['manipulator.user']->getRepository()->find($value)) {
$caption = $user->getDisplayName();
$caption = $user->getDisplayName($this->app['translator']);
}
} elseif ($field == 'date') {
$caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));

View File

@@ -100,7 +100,7 @@ class patch_320alpha4b implements patchInterface
$entry = new FeedEntry();
$entry->setAuthorEmail($user->getEmail());
$entry->setAuthorName($user->getDisplayName());
$entry->setAuthorName($user->getDisplayName($app['translator']));
$entry->setFeed($feed);
$entry->setPublisher($publishers->first());
$entry->setTitle($row['name']);
@@ -188,11 +188,11 @@ class patch_320alpha4b implements patchInterface
if ( ! array_key_exists($user_key, self::$feeds) || ! isset(self::$feeds[$user_key][$feed_key])) {
if ($homelink == '1')
$title = $user->getDisplayName() . ' - ' . 'homelink Feed';
$title = $user->getDisplayName($app['translator']) . ' - ' . 'homelink Feed';
elseif ($pub_restrict == '1')
$title = $user->getDisplayName() . ' - ' . 'private Feed';
$title = $user->getDisplayName($app['translator']) . ' - ' . 'private Feed';
else
$title = $user->getDisplayName() . ' - ' . 'public Feed';
$title = $user->getDisplayName($app['translator']) . ' - ' . 'public Feed';
$feed = new Feed();
$publisher = new FeedPublisher();

View File

@@ -1728,14 +1728,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
ON (g.rid_parent = r.record_id)
WHERE rid_child = :record_id';
$params = array(
':GV_site' => $this->app['conf']->get(['main', 'key'])
, ':usr_id' => $this->app['authentication']->getUser()->get_id()
, ':record_id' => $this->get_record_id()
];
$stmt = $this->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->execute([
':site' => $this->app['conf']->get(['main', 'key']),
':usr_id' => $this->app['authentication']->getUser()->getId(),
':record_id' => $this->get_record_id(),
]);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();

View File

@@ -54,7 +54,7 @@ class record_orderElement extends record_adapter
if ($this->order_master_id) {
$user = $this->app['manipulator.user']->getRepository()->find($this->order_master_id);
return $user->getDisplayName();
return $user->getDisplayName($this->app['translator']);
}
return '';

View File

@@ -39,7 +39,7 @@ class set_exportftp extends set_export
$text_mail_receiver = "Bonjour,\n"
. "L'utilisateur "
. $this->app['authentication']->getUser()->getDisplayName() . " (login : " . $this->app['authentication']->getUser()->getLogin() . ") "
. $this->app['authentication']->getUser()->getDisplayName($this->app['translator']) . " (login : " . $this->app['authentication']->getUser()->getLogin() . ") "
. "a fait un transfert FTP sur le serveur ayant comme adresse \""
. $host . "\" avec le login \"" . $login . "\" "
. "et pour repertoire de destination \""