mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 11:03:17 +00:00

Conflicts: lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php lib/classes/API/OAuth2/Adapter.php lib/classes/API/V1/adapter.php lib/classes/Feed/Adapter.php lib/classes/Feed/Collection.php lib/classes/Feed/Entry/Adapter.php lib/classes/Feed/Entry/Item.php lib/classes/Feed/Publisher/Adapter.php lib/classes/User/Adapter.php lib/classes/base.php lib/classes/connection.php lib/classes/databox/cgu.php lib/classes/eventsmanager/notify/autoregister.php lib/classes/eventsmanager/notify/bridgeuploadfail.php lib/classes/eventsmanager/notify/order.php lib/classes/eventsmanager/notify/orderdeliver.php lib/classes/eventsmanager/notify/ordernotdelivered.php lib/classes/eventsmanager/notify/push.php lib/classes/eventsmanager/notify/register.php lib/classes/eventsmanager/notify/validate.php lib/classes/eventsmanager/notify/validationdone.php lib/classes/eventsmanager/notify/validationreminder.php lib/classes/module/console/taskState.php lib/classes/module/console/taskrun.php lib/classes/record/adapter.php lib/classes/registry.php lib/classes/set/order.php lib/classes/task/abstract.php lib/classes/task/appboxAbstract.php lib/classes/task/databoxAbstract.php lib/classes/task/manager.php lib/classes/task/period/RecordMover.php lib/classes/task/period/apibridge.php lib/classes/task/period/archive.php lib/classes/task/period/ftp.php lib/classes/task/period/ftpPull.php templates/web/prod/upload/lazaret.html.twig
193 lines
4.9 KiB
PHP
193 lines
4.9 KiB
PHP
<?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\Phrasea\Notification\Mail\MailInfoValidationDone;
|
|
use Alchemy\Phrasea\Notification\Emitter;
|
|
use Alchemy\Phrasea\Notification\Receiver;
|
|
|
|
class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
|
|
{
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
public $events = ['__VALIDATION_DONE__'];
|
|
|
|
/**
|
|
*
|
|
* @return notify_validationdone
|
|
*/
|
|
public function __construct(Application $app, eventsmanager_broker $broker)
|
|
{
|
|
parent::__construct($app, $broker);
|
|
$this->group = $this->app->trans('Validation');
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function icon_url()
|
|
{
|
|
return '/skins/icons/push16.png';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param Array $event
|
|
* @param Array $params
|
|
* @param mixed content $object
|
|
* @return boolean
|
|
*/
|
|
public function fire($event, $params, &$object)
|
|
{
|
|
$default = [
|
|
'from' => ''
|
|
, 'to' => ''
|
|
, 'ssel_id' => ''
|
|
];
|
|
|
|
$params = array_merge($default, $params);
|
|
|
|
$dom_xml = new DOMDocument('1.0', 'UTF-8');
|
|
|
|
$dom_xml->preserveWhiteSpace = false;
|
|
$dom_xml->formatOutput = true;
|
|
|
|
$root = $dom_xml->createElement('datas');
|
|
|
|
$from = $dom_xml->createElement('from');
|
|
$to = $dom_xml->createElement('to');
|
|
$ssel_id = $dom_xml->createElement('ssel_id');
|
|
|
|
$from->appendChild($dom_xml->createTextNode($params['from']));
|
|
$to->appendChild($dom_xml->createTextNode($params['to']));
|
|
$ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
|
|
|
|
$root->appendChild($from);
|
|
$root->appendChild($to);
|
|
$root->appendChild($ssel_id);
|
|
|
|
$dom_xml->appendChild($root);
|
|
|
|
$datas = $dom_xml->saveXml();
|
|
|
|
$mailed = false;
|
|
|
|
if ($this->shouldSendNotificationFor($params['to'])) {
|
|
$readyToSend = false;
|
|
try {
|
|
$user_from = User_Adapter::getInstance($params['from'], $this->app);
|
|
$user_to = User_Adapter::getInstance($params['to'], $this->app);
|
|
|
|
$basket = $this->app['EM']
|
|
->getRepository('Phraseanet:Basket')
|
|
->find($params['ssel_id']);
|
|
$title = $basket->getName();
|
|
|
|
$receiver = Receiver::fromUser($user_to);
|
|
$emitter = Emitter::fromUser($user_from);
|
|
|
|
$readyToSend = true;
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
|
|
if ($readyToSend) {
|
|
$mail = MailInfoValidationDone::create($this->app, $receiver, $emitter);
|
|
$mail->setButtonUrl($params['url']);
|
|
$mail->setTitle($title);
|
|
$mail->setUser($user_from);
|
|
|
|
$this->app['notification.deliverer']->deliver($mail);
|
|
$mailed = true;
|
|
}
|
|
}
|
|
|
|
return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $datas
|
|
* @param boolean $unread
|
|
* @return Array
|
|
*/
|
|
public function datas($datas, $unread)
|
|
{
|
|
$sx = simplexml_load_string($datas);
|
|
|
|
$from = (string) $sx->from;
|
|
$ssel_id = (string) $sx->ssel_id;
|
|
|
|
try {
|
|
$registered_user = User_Adapter::getInstance($from, $this->app);
|
|
} catch (\Exception $e) {
|
|
return [];
|
|
}
|
|
|
|
$sender = $registered_user->get_display_name();
|
|
|
|
try {
|
|
$basket = $this->app['converter.basket']->convert($ssel_id);
|
|
} catch (\Exception $e) {
|
|
return [];
|
|
}
|
|
|
|
$ret = [
|
|
'text' => $this->app->trans('%user% a envoye son rapport de validation de %title%', ['%user%' => $sender, '%title%' => '<a href="/lightbox/validate/'
|
|
. (string) $sx->ssel_id . '/" target="_blank">'
|
|
. $basket->getName() . '</a>'
|
|
])
|
|
, 'class' => ''
|
|
];
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_name()
|
|
{
|
|
return $this->app->trans('Rapport de Validation');
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_description()
|
|
{
|
|
return $this->app->trans('Reception d\'un rapport de validation');
|
|
}
|
|
|
|
/**
|
|
* @param integer $usr_id The id of the user to check
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_available($usr_id)
|
|
{
|
|
try {
|
|
$user = \User_Adapter::getInstance($usr_id, $this->app);
|
|
} catch (\Exception $e) {
|
|
return false;
|
|
}
|
|
|
|
return $this->app['acl']->get($user)->has_right('push');
|
|
}
|
|
}
|