blockoptions.json.php 1.73 KB
Newer Older
Robert Lyon's avatar
Robert Lyon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php
/**
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

define('INTERNAL', 1);
define('JSON', 1);

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'view.php');
safe_require('blocktype', 'placeholder');

$offset = param_integer('offset', 0);
$limit = param_integer('limit', 8);
$viewid = param_integer('viewid');
if (!can_view_view($viewid)) {
    json_reply('local', get_string('accessdenied', 'error'));
}
$view = new View($viewid);
$setlimit = false;
$orderby = param_alphanum('orderby', null);

list($count, $types) = PluginBlocktypePlaceholder::get_content_types($view, $offset, $limit);
$pagination = build_showmore_pagination(array(
    'count'  => $count,
    'limit'  => $limit,
    'offset' => $offset,
    'orderby' => 'popular',
    'databutton' => 'showmorebtn',
    'jscall' => 'wire_blockoptions',
    'jsonscript' => 'blocktype/placeholder/blockoptions.json.php',
    'extra' => array('viewid' => $viewid),
));

$smarty = smarty_core();
$smarty->assign('types', $types);
$typeslist = $smarty->fetch('blocktype:placeholder:contenttypeslist.tpl');
$typeslist .= $pagination['html'];

json_reply(false, array(
    'message' => null,
    'data' => array(
        'tablerows' => $typeslist,
        'pagination_js' => $pagination['javascript'],
        'count' => $count,
        'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')),
        'offset' => $offset,
        'setlimit' => $setlimit,
        'jscall' => 'wire_blockoptions',
    )
));