Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.4 Cookbook

Listing Users

You can list users inside every page. Inside list_users list you have access to $user object under $gimme->list_user variable.

Simple example:

{{ list_users length=5 }}
  {{ $gimme->list_user->first_name }}
{{ /list_users }}

list_users have several really useful parameters, for example:

search:

{{ list_users length=5 search="username" }}
  {{ $gimme->list_user->first_name }}
{{ /list_users }}

filter by most active users:

{{ list_users length=5 filter="active" }}
  {{ $gimme->list_user->first_name }}
{{ /list_users }}

filter by editors (editor_groups are id for your installation editors groups):

{{ list_users length=5 filter="editors" editor_groups="1,2,3,4" }}
  {{ $gimme->list_user->first_name }}
{{ /list_users }}

filter by alphabet range:

{{ list_users length=5 filter="a-c" }}
  {{ $gimme->list_user->first_name }}
{{ /list_users }}

Default Newscoop users list page

Newscoop has user listing page by default. You can find it under mypage.com/user. You can edit this default page by creating user_index.tpl template in root directory of Your theme. Inside this file you can access $users object and loop through it like this.

{{ foreach $users as $user }}
    {{ $user->image(<width>, <height>) }} <!-- user profile image -->
    {{ $user->first_name }} 
    {{ $user->last_name }} 
    {{ $user->uname }} <!-- user name -->
    {{ $user['bio'] }} <!-- user biography text -->
    {{ $user->isAuthor() }} <!-- returns true if user is connected to author -->
{{ /foreach }}

Check user object reference to find out more.

Link to user profile

{{ foreach $users as $user }}
    ...
     <a href="{{ $view->url(['username' => $user->uname], 'user') }}" title="">
         {{ $user->uname }}
    </a>
    ...
{{ /foreach }}

Pagination

{{ foreach $users as $user }}
   ...
{{ /foreach }}

{{ if isset($paginator->previous) }}
      <a href="{{ $view->url(['page' => $paginator->previous]) }}">previous</a>

{{ /if }}
 
<!-- page numbers -->
{{foreach $paginator->pagesInRange as $page}}
   {{if $paginator->current eq $page}}
        <a class="current" href="{{ $view->url(['page' => $page]) }}">{{ $page }}</a>
   {{else}}
        <a href="{{ $view->url(['page' => $page]) }}">{{ $page }}</a>
   {{/if}} 
 {{/foreach}}
 
{{ if isset($paginator->next) }}
    <a href="{{ $view->url(['page' => $paginator->next]) }}">next</a>
{{ /if }}

Search and list filtering

Creating a search form for user_index.tpl template is pretty easy and straight forward. Simply use code below.

<form method="GET" action="{{ $view->url(['controller' => 'user', 'action' => 'search'], 'default', true) }}">
         <input type="text" name="q"></input>
         <input type="submit" value="Search"></input>
 </form>

To filter user list by surname use this simple code. 

<ul>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'index'], 'default', true) }}">Active Users</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'filter', 'f' => 'a-z'], 'default', true) }}">All Users</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'filter', 'f' => 'a-d'], 'default', true) }}">A-D</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'filter', 'f' => 'e-k'], 'default', true) }}">E-K</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'filter', 'f' => 'l-p'], 'default', true) }}">L-P</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'filter', 'f' => 'q-t'], 'default', true) }}">Q-T</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'filter', 'f' => 'u-z'], 'default', true) }}">U-Z</a></li>
    <li><a href="{{ $view->url(['controller' => 'user', 'action' => 'editors'], 'default', true) }}">Editors</a></li>
</ul>

Community feed

Community functionality in Newscoop was initially developed for some clients, but has since then become the part of our offical themes. 

Here we present Community Feed widget that lists two specific activities of the community memebrs - newly registered users notification and recommended comment by registered users.

Template that generates this output in New Custodian is _tpl/sidebar-community-feed.tpl. 

{{ list_community_feeds length="10" }}
{{ if $gimme->current_list->at_beginning }}
<div class="community_ticker" class="clearfix">
<h3>Community feed</h3>
<ul>
{{ /if }}
{{ assign var="created" value=$gimme->community_feed->created }}
{{ assign var="user" value=$gimme->community_feed->user }}
 {{ if $gimme->community_feed->type == 'user-register' && $user->uname }}
 <li class="registered">{{ include file="_tpl/relative_date.tpl" date=$created }}
    <a {{ if $user->is_active }} href="{{ $view->url(['username' => $user->uname], 'user') }}"{{ /if }}>{{ $user->first_name }} {{ $user->last_name }}</a> registered
 </li>
  {{ elseif $gimme->community_feed->type == 'comment-recommended' && $gimme->community_feed->comment->article }}
   <li class="commented">
      {{ include file="_tpl/relative_date.tpl" date=$created }} New comment on <a href="{{ $gimme->community_feed->comment->article->url }}">{{ $gimme->community_feed->comment->article->title }}</a>
    </li>
{{ /if }}
  {{ if $gimme->current_list->at_end }}
</ul>
</div>
{{ /if }}
{{ /list_community_feeds }}

Template for showing relative time since the action was performed is needed to nicely format time since the action was performed, and that template is here

{{ $diff=date_diff(date_create('now'), date_create($date)) }}
<small class="date relative">
{{ if $diff->y }} {{ $diff->y }} {{ if $diff->y > 1 }}years{{ else }}year{{ /if }}{{ /if }}
{{ if $diff->m }} {{ $diff->m }} {{ if $diff->m > 1 }}months{{ else }}month{{ /if }}{{ /if }}
{{ if $diff->d }} {{ $diff->d }} {{ if $diff->d > 1 }}days{{ else }}day{{ /if }}{{ /if }}
{{ if $diff->h && (!$diff->d || empty($short)) }} {{ $diff->h }} h{{ /if }}
{{ if !$diff->d && $diff->i && (empty($short) || !$diff->h) }} {{ $diff->i }} min{{ /if }}
{{ if !$diff->d && !$diff->h && !$diff->i && $diff->s }} {{ $diff->s }} sec{ /if }} ago
</small>

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.