public function index()
{
$sort = (string) ($_GET['sort'] ?? 'name');
$dir = (string) ($_GET['dir'] ?? 'ASC');
$dir = \strtoupper($dir);
if ($dir !== 'ASC' && $dir !== 'DESC') {
$dir = 'ASC';
}
if ($this->isSuperUser()) {
$authors = $this->author->getAll($sort, $dir);
} else {
$authors = $this->author->getForUser($this->getActiveUserId(), $sort, $dir);
}
// We're just grabbing counts here:
foreach ($authors as $idx => $auth) {
$auth['authorid'] = (int) $auth['authorid'];
$authors[$idx]['num_users'] = $this->author->getNumUsersForAuthor($auth['authorid']);
$authors[$idx]['num_comments'] = $this->author->getNumCommentsForAuthor($auth['authorid']);
$authors[$idx]['num_files'] = $this->author->getNumFilesForAuthor($auth['authorid']);
$authors[$idx]['num_blog_posts'] = $this->author->getNumBlogPostsForAuthor($auth['authorid']);
}
switch ($sort) {
case 'blog_posts':
$this->sortArrayByIndex($authors, 'num_blog_posts', $dir === 'DESC');
break;
case 'comments':
$this->sortArrayByIndex($authors, 'num_comments', $dir === 'DESC');
break;
case 'files':
$this->sortArrayByIndex($authors, 'num_files', $dir === 'DESC');
break;
case 'users':
$this->sortArrayByIndex($authors, 'num_users', $dir === 'DESC');
break;
}
$this->lens('author/index', ['authors' => $authors, 'sort' => $sort, 'dir' => $dir]);
}