Skip to content
Snippets Groups Projects
Commit 3aeb5e07 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #58111 refacto

parent d6f22dc0
Branches
Tags
2 merge requests!2517Dev#58111 ouvrir automatiquement la note de version a la premiere connection d un administrateur,!2515Dev#58111 ouvrir automatiquement la note de version a la premiere connection d un administrateur
Pipeline #3517 passed with stage
in 27 minutes and 40 seconds
......@@ -32,12 +32,6 @@ class Class_Feature {
$_cookie_jar;
/** @category testing */
public static function setCookieJar($cookie_jar) {
static::$_cookie_jar = $cookie_jar;
}
public function hasNew() {
return 0 < $this->countNew();
}
......@@ -127,78 +121,80 @@ class Class_Feature {
}
/** @category testing */
public static function setCookieJar($cookie_jar) {
static::$_cookie_jar = $cookie_jar;
}
public function trackFeatures() {
if (!Class_AdminVar::get('FEATURES_TRACKING_ENABLE'))
if(!$this->_isTrackingFeaturesReady())
return;
if(!$user = Class_Users::getIdentity())
if(!$features = $this->findNewFor(Class_Users::getIdentity()))
return;
if(!$user->isAdmin())
if (isset($_COOKIE[$this->_getCookieJar()->getKey()]))
return;
if(!$features = $this->findNewFor($user))
$session = new Zend_Session_Namespace($this->_getCookieJar()->getKey());
if ($session->seen)
return;
$this->_session = new Zend_Session_Namespace($this->_getCookieJar()->getKey());
$session->seen = true;
if (isset($_COOKIE[$this->_getCookieJar()->getKey()]))
return;
Class_ScriptLoader::getInstance()
->notify($this->_renderContent($features), false, 10, 'new_features');
}
if ($this->_session->seen)
return;
$this->_session->seen = true;
protected function _isTrackingFeaturesReady() {
if (!Class_AdminVar::get('FEATURES_TRACKING_ENABLE'))
return false;
$features_url = Class_Url::absolute(['module' => 'admin',
'controller' => 'feature',
'action' => 'index'], null, true);
if(!$user = Class_Users::getIdentity())
return false;
$stop_tracking_url = Class_Url::absolute(['module' => 'admin',
'controller' => 'feature',
'action' => 'stop-tracking'], null, true);
if(!$user->isAdmin())
return false;
$content = [];
foreach($features as $feature)
$content[] = sprintf('<li>%s</li>', $feature->getLabel());
return true;
}
$content = sprintf('<ul>%s</ul>', implode($content));
$content = sprintf('<h2>%s</h2>',
$this->_('Nouvelles fonctionnalités depuis votre dernière connexion : '))
. $content;
$buttons = sprintf('<button class="admin-button" onclick="window.open(\'%s\', \'_top\');">%s</button>',
$features_url,
$this->_('En savoir plus'))
protected function _renderContent($features) {
$buttons = [sprintf('<button class="admin-button" onclick="window.open(\'%s\');">%s</button>',
Class_Url::absolute(['module' => 'admin',
'controller' => 'feature',
'action' => 'index'], null, true),
$this->_('En savoir plus')),
. sprintf('<button class="admin-button" onclick="window.open(\'%s\', \'_top\')">%s</button>',
$stop_tracking_url,
$this->_('Ne plus m\'avertir'));
$buttons = sprintf('<div class="button_wrapper">%s</div>', $buttons);
sprintf('<button class="admin-button" onclick="window.open(\'%s\', \'_top\')">%s</button>',
Class_Url::absolute(['module' => 'admin',
'controller' => 'feature',
'action' => 'stop-tracking'], null, true),
$this->_('Ne plus m\'avertir'))];
$content .= $buttons;
$content = sprintf('<div class="features">%s</div>', $content);
$html_features = [];
foreach($features as $feature)
$html_features[] = sprintf('<li>%s</li>', $feature->getLabel());
Class_ScriptLoader::getInstance()
->notify($content,
false,
10,
'new_features');
$html = [sprintf('<h2>%s</h2>',
$this->_('Nouvelles fonctionnalités depuis votre dernière connexion : ')),
sprintf('<ul>%s</ul>',
implode($html_features)),
sprintf('<div class="button_wrapper">%s</div>',
implode($buttons))];
return sprintf('<div class="features">%s</div>', implode($html));
}
public function stopTracking() {
if (!Class_AdminVar::get('FEATURES_TRACKING_ENABLE'))
return;
if(!$user = Class_Users::getIdentity())
return;
if(!$user->isAdmin())
if(!$this->_isTrackingFeaturesReady())
return;
$this->_getCookieJar()->getKey();
$this->_session = new Zend_Session_Namespace($this->_getCookieJar()->getKey());
return $this->_getCookieJar()
->setcookie($this->_getCookieJar()->getKey(),
'1',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment