Skip to content

Commit

Permalink
add list block
Browse files Browse the repository at this point in the history
  • Loading branch information
craigh committed Apr 14, 2012
1 parent 0c72a20 commit 468a34f
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/modules/Downloads/lib/Downloads/Block/List.php
@@ -0,0 +1,107 @@
<?php

/**
* Downloads
*
* @license GNU/LGPLv3 (or at your option, any later version).
*/
class Downloads_Block_List extends Zikula_Controller_AbstractBlock
{

/**
* initialise block
*/
public function init()
{
SecurityUtil::registerPermissionSchema('Downloads:listblock:', 'Block title::');
}

/**
* get block information
*/
public function info()
{
return array(
'text_type' => 'Downloads',
'module' => 'Downloads',
'text_type_long' => $this->__('Downloads list Block'),
'allow_multiple' => true,
'form_content' => false,
'form_refresh' => false,
'show_preview' => true);
}

/**
* display block
*/
public function display($blockinfo)
{
if (!SecurityUtil::checkPermission('Downloads:listblock:', "$blockinfo[title]::", ACCESS_OVERVIEW)) {
return;
}
if (!ModUtil::available('Downloads')) {
return;
}
// Get variables from content block
$vars = BlockUtil::varsFromContent($blockinfo['content']);

// return if no category
if (empty($vars['category'])) {
return;
}

$downloads = ModUtil::apiFunc('Downloads', 'user', 'getall', array(
'category' => $vars['category'],
'limit' => $vars['limit'],
'orderby' => 'date',
'orderdir' => 'DESC',
));

// create the output object
$this->view->setCacheId('listblock' . '|' . $blockinfo['bid'] . "|" . $vars['category']);

// assign the item
$this->view->assign('downloads', $downloads);

// Populate block info and pass to theme
$blockinfo['content'] = $this->view->fetch('blocks/list.tpl');
return BlockUtil::themeBlock($blockinfo);
}

/**
* modify block settings
*/
public function modify($blockinfo)
{
$vars = BlockUtil::varsFromContent($blockinfo['content']);
// Defaults
$vars['category'] = (!empty($vars['category'])) ? $vars['category'] : 1; // default to first available category
$vars['limit'] = (!empty($vars['limit'])) ? $vars['limit'] : 10;

$this->view->assign('catselectoptions', Downloads_Util::getCatSelectList(array(
'sel' => $vars['category'])));

$this->view->assign('vars', $vars);

return $this->view->fetch('blocks/list_modify.tpl');
}

/**
* update block settings
*/
public function update($blockinfo)
{
// Get current content
$vars = BlockUtil::varsFromContent($blockinfo['content']);

// overwrite with new values
$vars['category'] = $this->request->request->get('category', 1); // default to first available category
$vars['limit'] = $this->request->request->get('limit', 10);

$this->view->clear_cache('blocks/list.tpl');
$blockinfo['content'] = BlockUtil::varsToContent($vars);

return $blockinfo;
}

}
17 changes: 17 additions & 0 deletions src/modules/Downloads/templates/blocks/list.tpl
@@ -0,0 +1,17 @@
<ul>
{foreach from=$downloads item='d'}
<li>
<a href="{modurl modname="Downloads" type="user" func="prepHandOut" lid=$d.lid}">{$d.title|safetext} (v{$d.version|safetext})[{$d.filesize|safetext}Kb]</a>
<a href="{modurl modname="Downloads" type="user" func="display" lid=$d.lid}">{img modname='core' set='icons/extrasmall' src='info.png' __title='View' __alt='View'}</a>
</li>
{* other array values available in a template override *}
{*$d.hits*}
{*$d.description*}
{*$d.submitter*}
{*$d.category.title*}
{*$d.url is available but don't use it! - use prepHandOut method above*}

{foreachelse}
<li>{gt text='No downloads available'}</li>
{/foreach}
</ul>
10 changes: 10 additions & 0 deletions src/modules/Downloads/templates/blocks/list_modify.tpl
@@ -0,0 +1,10 @@
<div class="z-formrow">
<label for='category'>{gt text='Select a category'}</label>
<select id='category' name='category'>
{$catselectoptions}
</select>
</div>
<div class="z-formrow">
<label for="limit">{gt text="Maximum items to display"}</label>
<input id="limit" type="text" name="lmit" value="{$vars.limit}" size="5" />
</div>

0 comments on commit 468a34f

Please sign in to comment.