Add table/pagination to the project list
This commit is contained in:
@@ -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.')'
|
||||
)));
|
||||
|
||||
@@ -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();
|
||||
return $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 $projects;
|
||||
/**
|
||||
* Get all project ids
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAllIds()
|
||||
{
|
||||
return $this->db->table(self::TABLE)->asc('name')->findAllByColumn('id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -8,15 +8,31 @@
|
||||
</ul>
|
||||
</div>
|
||||
<section>
|
||||
<?php if (empty($active_projects) && empty($inactive_projects)): ?>
|
||||
<p class="alert"><?= t('No project') ?></p>
|
||||
<?php else: ?>
|
||||
<?php if ($paginator->isEmpty()): ?>
|
||||
<p class="alert"><?= t('No project') ?></p>
|
||||
<?php else: ?>
|
||||
<table class="table-fixed">
|
||||
<tr>
|
||||
<th class="column-8"><?= $paginator->order(t('Id'), 'id') ?></th>
|
||||
<th class="column-8"><?= $paginator->order(t('Status'), 'is_active') ?></th>
|
||||
<th class="column-20"><?= $paginator->order(t('Project'), 'name') ?></th>
|
||||
<th><?= t('Columns') ?></th>
|
||||
</tr>
|
||||
<?php foreach ($paginator->getCollection() as $project): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?= $this->a('#'.$project['id'], 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link') ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($project['is_active']): ?>
|
||||
<?= t('Active') ?>
|
||||
<?php else: ?>
|
||||
<?= t('Inactive') ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $this->a('<i class="fa fa-table"></i>', 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?>
|
||||
|
||||
<?php if (! empty($active_projects)): ?>
|
||||
<h3><?= t('Active projects') ?></h3>
|
||||
<ul class="project-listing">
|
||||
<?php foreach ($active_projects as $project): ?>
|
||||
<li>
|
||||
<?php if ($project['is_public']): ?>
|
||||
<i class="fa fa-share-alt fa-fw"></i>
|
||||
<?php endif ?>
|
||||
@@ -24,25 +40,18 @@
|
||||
<i class="fa fa-lock fa-fw"></i>
|
||||
<?php endif ?>
|
||||
<?= $this->a($this->e($project['name']), 'project', 'show', array('project_id' => $project['id'])) ?>
|
||||
</li>
|
||||
</td>
|
||||
<td class="dashboard-project-stats">
|
||||
<?php foreach ($project['columns'] as $column): ?>
|
||||
<strong title="<?= t('Task count') ?>"><?= $column['nb_tasks'] ?></strong>
|
||||
<span><?= $this->e($column['title']) ?></span>
|
||||
<?php endforeach ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</table>
|
||||
|
||||
<?php if (! empty($inactive_projects)): ?>
|
||||
<h3><?= t('Inactive projects') ?></h3>
|
||||
<ul class="project-listing">
|
||||
<?php foreach ($inactive_projects as $project): ?>
|
||||
<li>
|
||||
<?php if ($project['is_private']): ?>
|
||||
<i class="fa fa-lock"></i>
|
||||
<?php endif ?>
|
||||
<?= $this->a($this->e($project['name']), 'project', 'show', array('project_id' => $project['id'])) ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?= $paginator ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php endif ?>
|
||||
</section>
|
||||
</section>
|
||||
Reference in New Issue
Block a user