serve() public method

return/output the JSON
public serve ( $success = true )
Ejemplo n.º 1
0
// Calculate the offset
$start = $state['limit'] * $state['page'] - $state['limit'];
if ($start < 0) {
    $start = 0;
}
/**********************************
	RECORD RETREVIAL
*********************************/
// Normalize sort column to match DB column
if ($state['sort'] == 'registered' || $state['sort'] == 'touched') {
    $state['sort'] = 'time_' . $state['sort'];
} elseif (substr($state['sort'], 0, 1) == 'd') {
    $state['sort'] = substr($state['sort'], 1);
}
// fetch subscribers for this page
$subscribers = $group->members(array('sort' => $state['sort'], 'order' => $state['order'], 'limit' => $state['limit'], 'offset' => $start));
/**********************************
	OUTPUT FORMATTING
*********************************/
// format subscribers for JSON output to jqGrid
$subOut = array();
foreach ($subscribers as $s) {
    $sub = array('id' => $s['id'], 'email' => $s['email'], 'touched' => $s['touched'], 'registered' => $s['registered'], 'ip' => $s['ip']);
    foreach ($s['data'] as $key => $d) {
        $sub['d' . $key] = $d;
    }
    array_push($subOut, $sub);
}
$json->add(array('page' => $state['page'], 'total' => $state['pages'], 'records' => $group->_tally, 'rows' => $subOut));
$json->serve();
Ejemplo n.º 2
0
$logger = Pommo::$_logger;
$dbo = Pommo::$_dbo;
/**********************************
	SETUP TEMPLATE, PAGE
 *********************************/
require_once Pommo::$_baseDir . 'classes/Pommo_Template.php';
$view = new Pommo_Template();
/**********************************
	JSON OUTPUT INITIALIZATION
 *********************************/
require_once Pommo::$_baseDir . 'classes/Pommo_Json.php';
$json = new Pommo_Json();
$success = false;
if (isset($_POST['skip']) || isset($_POST['template']) && !is_numeric($_POST['template'])) {
    $success = true;
} elseif (isset($_POST['load'])) {
    $template = current(Pommo_Mailing_Template::get(array('id' => $_POST['template'])));
    Pommo::$_session['state']['mailing']['body'] = $template['body'];
    Pommo::$_session['state']['mailing']['altbody'] = $template['altbody'];
    $success = true;
} elseif (isset($_POST['delete'])) {
    $msg = Pommo_Mailing_Template::delete($_POST['template']) ? Pommo::_T('Template Deleted') : Pommo::_T('Error with deletion.');
    $json->add('callbackFunction', 'deleteTemplate');
    $json->add('callbackParams', array('id' => $_POST['template'], 'msg' => $msg));
} else {
    $view->assign('templates', Pommo_Mailing_Template::getNames());
    $view->display('admin/mailings/mailing/templates');
    Pommo::kill();
}
$json->serve($success);