Skip to content

Instantly share code, notes, and snippets.

@aforwark
Created April 10, 2012 22:26
Show Gist options
  • Save aforwark/2355110 to your computer and use it in GitHub Desktop.
Save aforwark/2355110 to your computer and use it in GitHub Desktop.
aritcle list new stuff
<?php
class ArticleListModule extends AppModule
{
public
$template = 'article_list',
$uses = array('ArticlesChannel', 'Article'),
$channel = 'entertainment',
$limit = 10,
$styleclass = '',
/**
* @Param(type="string")
*/
$dateformat = '',
/**
* @Param(type="string")
*/
$seemore = false,
/**
* @Param(type="string")
*/
$title = '';
public function getPaginationLinks()
{
unset($this->view->params['models'], $this->view->params['isAjax'], $this->view->params['form']);
$baseUrl = $this->view->params;
unset($baseUrl['named']);
unset($baseUrl['url']);
unset($baseUrl['pass']);
$currentPage = max($this->view->params['named']['page'], 1);
$baseUrl['page'] = $currentPage > 2 ? $currentPage - 1 : false;
$nextPage = Router::url($baseUrl);
$baseUrl['page'] = $currentPage + 1;
$prevPage = Router::url($baseUrl);
return compact('prevPage','nextPage','currentPage');
}
public function render($params = array())
{
/*$this->Article->unbindModel(array
(
'hasMany' => array('RelatedArticle'),
'belongsTo' => array('ArticleType','Partner','Channel'),
'hasAndBelongsToMany' => array('Author')
),
true
);*/
$currentPage = max($this->view->params['named']['page'], 1);
$articles = $this->ArticlesChannel->find('all',array
(
//'model' => 'Channel',
//'scope' => array(
// 'Channel.url_name' => $params['current_channel']
//),
'fields' => array
(
'Article.id', 'Article.title', 'Article.date_active',
'Article.body', 'Article.blurb'
),
'conditions' => array
(
'Article.flag_active' => true,
'Article.date_active < now()',
'Channel.url_name' => $this->channel
),
'order' => array('Article.date_active' => 'DESC'),
'limit' => $this->limit,
'page' => $currentPage,
)
);
$text = helper('Text');
foreach ($articles AS $i => $item)
{
$article = $item['Article'];
$article['intro'] = $text->truncate($article['body'], 600, array('ending'=>'...', 'exact'=>true, 'html'=>true));
$article['channels'] = $item['Channel'];
$article['authors'] = $item['Author'];
$articles[$i] = $article;
}
$posts = $this->getPaginationLinks();
$styleclass = $this->styleclass;
$dateformat = $this->dateformat;
$title = $this->title;
if ($this->seemore) {
if ($this->Channels->isMainChannel($this->channel)) {
$seemore_link = Router::url(array(
'plugin' => null,
'controller' => 'articles',
'action' => 'index',
'url_name' => $this->channel
));
} else {
$main_channel = $this->Channels->getMainChannelSlug($this->channel);
$seemore_link = Router::url(array(
'plugin' => null,
'controller' => 'articles',
'action' => 'index',
'channel' => $main_channel,
'url_name' => $this->channel
));
}
$this->set(compact('seemore_link'));
}
return $this->view->module($this->template,compact('articles','posts','styleclass','dateformat','title'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment