public function paginateByUser($user_id = null, int $perPage = 20, string $group = 'default', int $page = 0)
{
// Get the necessary parts.
$page = $page >= 1 ? $page : (ctype_digit($_GET['page'] ?? '') && $_GET['page'] > 1 ? $_GET['page'] : 1);
$total = $this->countAllResultsByUser($user_id, false);
// Store it in the Pager library so it can be
// paginated in the views.
$pager = \Config\Services::pager();
$this->pager = $pager->store($group, $page, $perPage, $total);
$offset = ($page - 1) * $perPage;
return $this->findAllByUser($user_id, $perPage, $offset);
}
public function findAllByUser($user_id = null, int $limit = 0, int $offset = 0)
{
if (is_null($user_id))
$user_id = \Config\Services::auth()->getUserID();
$this->select($this->table.'.*');
$this->join('users_projects up', 'up.project_id = '.$this->table.'.project_id AND up.deleted_at IS NULL AND up.user_id = '.intval($user_id));
return parent::findAll($limit, $offset);
}
public function countAllResultsByUser($user_id = null, bool $reset = true, bool $test = false)
{
if (is_null($user_id))
$user_id = \Config\Services::auth()->getUserID();
$this->join('users_projects up', 'up.project_id = '.$this->table.'.project_id AND up.deleted_at IS NULL AND up.user_id = '.intval($user_id));
return parent::countAllResults($reset, $test);
}