From 9a98013736f1acebbb62c5fce6a10c02e32b516f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 31 Jan 2015 11:21:43 -0500 Subject: Add table/pagination to the project list --- app/Controller/Project.php | 29 ++++++++++---------- app/Model/Project.php | 26 +++++++++--------- app/Model/ProjectPermission.php | 16 +++++++++++ app/Template/project/index.php | 59 ++++++++++++++++++++++++----------------- 4 files changed, 77 insertions(+), 53 deletions(-) (limited to 'app') diff --git a/app/Controller/Project.php b/app/Controller/Project.php index 4beb19ce..8178ab5f 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -17,24 +17,25 @@ class Project extends Base */ public function index() { - $projects = $this->project->getAll(! $this->userSession->isAdmin()); - $nb_projects = count($projects); - $active_projects = array(); - $inactive_projects = array(); - - foreach ($projects as $project) { - if ($project['is_active'] == 1) { - $active_projects[] = $project; - } - else { - $inactive_projects[] = $project; - } + if ($this->userSession->isAdmin()) { + $project_ids = $this->project->getAllIds(); + } + else { + $project_ids = $this->projectPermission->getMemberProjectIds($this->userSession->getId()); } + + $nb_projects = count($project_ids); + + $paginator = $this->paginator + ->setUrl('project', 'index') + ->setMax(20) + ->setOrder('name') + ->setQuery($this->project->getQueryColumnStats($project_ids)) + ->calculate(); $this->response->html($this->template->layout('project/index', array( 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()), - 'active_projects' => $active_projects, - 'inactive_projects' => $inactive_projects, + 'paginator' => $paginator, 'nb_projects' => $nb_projects, 'title' => t('Projects').' ('.$nb_projects.')' ))); diff --git a/app/Model/Project.php b/app/Model/Project.php index f802e4ed..dbb9db1b 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -98,24 +98,22 @@ class Project extends Base * Get all projects * * @access public - * @param bool $filter_permissions If true, remove projects not allowed for the current user * @return array */ - public function getAll($filter_permissions = false) + public function getAll() { - $projects = $this->db->table(self::TABLE)->asc('name')->findAll(); - - if ($filter_permissions) { - - foreach ($projects as $key => $project) { - - if (! $this->projectPermission->isUserAllowed($project['id'], $this->userSession->getId())) { - unset($projects[$key]); - } - } - } + return $this->db->table(self::TABLE)->asc('name')->findAll(); + } - return $projects; + /** + * Get all project ids + * + * @access public + * @return array + */ + public function getAllIds() + { + return $this->db->table(self::TABLE)->asc('name')->findAllByColumn('id'); } /** diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php index 352677d9..fb6316b6 100644 --- a/app/Model/ProjectPermission.php +++ b/app/Model/ProjectPermission.php @@ -321,6 +321,22 @@ class ProjectPermission extends Base ->getAll('projects.id', 'name'); } + /** + * Return a list of project ids where the user is member + * + * @access public + * @param integer $user_id User id + * @return []integer + */ + public function getMemberProjectIds($user_id) + { + return $this->db + ->table(Project::TABLE) + ->eq('user_id', $user_id) + ->join(self::TABLE, 'project_id', 'id') + ->findAllByColumn('projects.id'); + } + /** * Return a list of active projects where the user is member * diff --git a/app/Template/project/index.php b/app/Template/project/index.php index 58c520d1..a36a9ce1 100644 --- a/app/Template/project/index.php +++ b/app/Template/project/index.php @@ -8,15 +8,31 @@
- -

- + isEmpty()): ?> +

+ + + + + + + + + getCollection() as $project): ?> + + + + + + - - +
order(t('Id'), 'id') ?>order(t('Status'), 'is_active') ?>order(t('Project'), 'name') ?>
+ a('#'.$project['id'], 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link') ?> + + + + + + + + a('', 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?>  - -

-
    - -
  • @@ -24,25 +40,18 @@ a($this->e($project['name']), 'project', 'show', array('project_id' => $project['id'])) ?> -
  • +
+ + + e($column['title']) ?> + +
- -

- + - -
\ No newline at end of file -- cgit v1.2.3