summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-12-28 11:28:50 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-12-28 11:28:50 -0500
commit34d7450d3c13342715e90ec21bceaa13e1baa876 (patch)
treea2d8f2f22ad3fe9b56f01fe2db0357f9b963e660 /app/Model
parent88d84073aecbe8bdc5f10825b6d7ca6b81c5f7b1 (diff)
Template helpers refactoring
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php24
-rw-r--r--app/Model/Base.php2
-rw-r--r--app/Model/Config.php11
-rw-r--r--app/Model/Notification.php7
-rw-r--r--app/Model/ProjectActivity.php8
-rw-r--r--app/Model/ProjectPermission.php4
-rw-r--r--app/Model/User.php25
7 files changed, 56 insertions, 25 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index b8353b58..3f454885 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -42,6 +42,7 @@ class Acl extends Base
'category' => array('index', 'save', 'edit', 'update', 'confirm', 'remove'),
'action' => array('index', 'event', 'params', 'create', 'confirm', 'remove'),
'analytic' => array('tasks', 'users', 'cfd'),
+ 'swimlane' => array('index', 'save', 'change', 'edit', 'update', 'confirm', 'remove', 'disable', 'enable', 'moveup', 'movedown'),
);
/**
@@ -96,7 +97,7 @@ class Acl extends Base
*/
public function isAdminUser()
{
- return isset($_SESSION['user']['is_admin']) && $_SESSION['user']['is_admin'] === true;
+ return isset($this->session['user']['is_admin']) && $this->session['user']['is_admin'] === true;
}
/**
@@ -107,7 +108,7 @@ class Acl extends Base
*/
public function isRegularUser()
{
- return isset($_SESSION['user']['is_admin']) && $_SESSION['user']['is_admin'] === false;
+ return isset($this->session['user']['is_admin']) && $this->session['user']['is_admin'] === false;
}
/**
@@ -118,7 +119,18 @@ class Acl extends Base
*/
public function getUserId()
{
- return isset($_SESSION['user']['id']) ? (int) $_SESSION['user']['id'] : 0;
+ return isset($this->session['user']['id']) ? (int) $this->session['user']['id'] : 0;
+ }
+
+ /**
+ * Check if the given user_id is the connected user
+ *
+ * @param integer $user_id User id
+ * @return boolean
+ */
+ public function isCurrentUser($user_id)
+ {
+ return $this->acl->getUserId() == $user_id;
}
/**
@@ -129,7 +141,7 @@ class Acl extends Base
*/
public function isLogged()
{
- return ! empty($_SESSION['user']);
+ return ! empty($this->session['user']);
}
/**
@@ -142,10 +154,10 @@ class Acl extends Base
public function isRememberMe($value = null)
{
if ($value !== null) {
- $_SESSION['is_remember_me'] = $value;
+ $this->session['is_remember_me'] = $value;
}
- return empty($_SESSION['is_remember_me']) ? false : $_SESSION['is_remember_me'];
+ return empty($this->session['is_remember_me']) ? false : $this->session['is_remember_me'];
}
/**
diff --git a/app/Model/Base.php b/app/Model/Base.php
index ed96e5be..dfac12ae 100644
--- a/app/Model/Base.php
+++ b/app/Model/Base.php
@@ -10,6 +10,8 @@ use Pimple\Container;
* @package model
* @author Frederic Guillot
*
+ * @property \Core\Session $session
+ * @property \Core\Template $template
* @property \Model\Acl $acl
* @property \Model\Action $action
* @property \Model\Authentication $authentication
diff --git a/app/Model/Config.php b/app/Model/Config.php
index 16e9bf45..54d9d7cd 100644
--- a/app/Model/Config.php
+++ b/app/Model/Config.php
@@ -76,12 +76,13 @@ class Config extends Base
return $value ?: $default_value;
}
- if (! isset($_SESSION['config'][$name])) {
- $_SESSION['config'] = $this->getAll();
+ // Cache config in session
+ if (! isset($this->session['config'][$name])) {
+ $this->session['config'] = $this->getAll();
}
- if (! empty($_SESSION['config'][$name])) {
- return $_SESSION['config'][$name];
+ if (isset($this->session['config'][$name])) {
+ return $this->session['config'][$name];
}
return $default_value;
@@ -126,7 +127,7 @@ class Config extends Base
*/
public function reload()
{
- $_SESSION['config'] = $this->getAll();
+ $this->session['config'] = $this->getAll();
$this->setupTranslations();
}
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index 0fa4c9da..99db78ad 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -3,7 +3,6 @@
namespace Model;
use Core\Session;
-use Core\Template;
use Swift_Message;
use Swift_Mailer;
use Swift_TransportException;
@@ -184,8 +183,10 @@ class Notification extends Base
*/
public function getMailContent($template, array $data)
{
- $tpl = new Template;
- return $tpl->load('notification/'.$template, $data + array('application_url' => $this->config->get('application_url')));
+ return $this->template->render(
+ 'notification/'.$template,
+ $data + array('application_url' => $this->config->get('application_url'))
+ );
}
/**
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index bc2948f0..87c9bb56 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -2,8 +2,6 @@
namespace Model;
-use Core\Template;
-
/**
* Project activity model
*
@@ -134,8 +132,10 @@ class ProjectActivity extends Base
*/
public function getContent(array $params)
{
- $tpl = new Template;
- return $tpl->load('event/'.str_replace('.', '_', $params['event_name']), $params);
+ return $this->template->render(
+ 'event/'.str_replace('.', '_', $params['event_name']),
+ $params
+ );
}
/**
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php
index 3b42751a..bcb11eca 100644
--- a/app/Model/ProjectPermission.php
+++ b/app/Model/ProjectPermission.php
@@ -264,6 +264,10 @@ class ProjectPermission extends Base
*/
public function adminAllowed($project_id, $user_id)
{
+ if ($this->user->isAdmin($user_id)) {
+ return true;
+ }
+
if ($this->isUserAllowed($project_id, $user_id) && $this->project->isPrivate($project_id)) {
return true;
}
diff --git a/app/Model/User.php b/app/Model/User.php
index 8fdfa815..3754b918 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -29,6 +29,17 @@ class User extends Base
const EVERYBODY_ID = -1;
/**
+ * Return the full name
+ *
+ * @param array $user User properties
+ * @return string
+ */
+ public function getFullname(array $user)
+ {
+ return $user['name'] ?: $user['username'];
+ }
+
+ /**
* Return true is the given user id is administrator
*
* @access public
@@ -54,7 +65,7 @@ class User extends Base
*/
public function getFavoriteProjectId()
{
- return isset($_SESSION['user']['default_project_id']) ? $_SESSION['user']['default_project_id'] : 0;
+ return isset($this->session['user']['default_project_id']) ? $this->session['user']['default_project_id'] : 0;
}
/**
@@ -65,7 +76,7 @@ class User extends Base
*/
public function getLastSeenProjectId()
{
- return empty($_SESSION['user']['last_show_project_id']) ? 0 : $_SESSION['user']['last_show_project_id'];
+ return empty($this->session['last_show_project_id']) ? 0 : $this->session['last_show_project_id'];
}
/**
@@ -76,7 +87,7 @@ class User extends Base
*/
public function storeLastSeenProjectId($project_id)
{
- $_SESSION['user']['last_show_project_id'] = (int) $project_id;
+ $this->session['last_show_project_id'] = (int) $project_id;
}
/**
@@ -276,7 +287,7 @@ class User extends Base
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values);
// If the user is connected refresh his session
- if (Session::isOpen() && $_SESSION['user']['id'] == $values['id']) {
+ if (Session::isOpen() && $this->acl->getUserId() == $values['id']) {
$this->updateSession();
}
@@ -326,7 +337,7 @@ class User extends Base
public function updateSession(array $user = array())
{
if (empty($user)) {
- $user = $this->getById($_SESSION['user']['id']);
+ $user = $this->getById($this->acl->getUserId());
}
if (isset($user['password'])) {
@@ -338,7 +349,7 @@ class User extends Base
$user['is_admin'] = (bool) $user['is_admin'];
$user['is_ldap_user'] = (bool) $user['is_ldap_user'];
- $_SESSION['user'] = $user;
+ $this->session['user'] = $user;
}
/**
@@ -457,7 +468,7 @@ class User extends Base
if ($v->execute()) {
// Check password
- if ($this->authentication->authenticate($_SESSION['user']['username'], $values['current_password'])) {
+ if ($this->authentication->authenticate($this->session['user']['username'], $values['current_password'])) {
return array(true, array());
}
else {