Pluf Framework

Pluf Framework Commit Details


Date:2008-11-21 14:56:24 (16 years 1 month ago)
Author:Loic d'Anterroches
Branch:develop, master
Commit:98d7f915624ebcd701ca98b4177052cc268c2b3c
Parents: 37c40e5278f00a019e6538c2b620a6615e9fb8ad
Message:Added JSON specific class and method.

Changes:

File differences

src/Pluf/HTTP/Response/Json.php
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
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
class Pluf_HTTP_Response_Json extends Pluf_HTTP_Response
{
/**
* @param mixed Values, will be encoded using json_encode
*/
function __construct($data, $mimetype=null)
{
if (null == $mimetype) {
$mimetype = Pluf::f('mimetype_json', 'application/json').'; charset=utf-8';
}
parent::__construct(json_encode($data), $mimetype);
}
}
src/Pluf/Paginator.php
299299
300300
301301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
302352
303353
304354
}
/**
* Render as array.
*
* An array rendering do not honor the limits, that is, all the
* items are returned. Also, the output is not formatted values
* from the db are directly returned. This is perfect to then use
* the values in a JSON response.
*
* @return Array.
*/
function render_array()
{
if (count($this->sort_order) != 2) {
$order = null;
} else {
$s = $this->sort_order[1];
if (in_array($this->sort_order[0], $this->sort_reverse_order)) {
$s = ($s == 'ASC') ? 'DESC' : 'ASC';
}
$order = $this->sort_order[0].' '.$s;
}
if (!is_null($this->model)) {
$items = $this->model->getList(array('view' => $this->model_view,
'filter' => $this->filter(),
'order' => $order,
));
} else {
$items = $this->items;
}
$out = array();
foreach ($items as $item) {
$idata = array();
if (!empty($this->list_display)) {
$i = 0;
foreach ($this->list_display as $key=>$col) {
if (!is_array($col)) {
$idata[$key] = $item->$key;
} else {
$_col = $col[0];
$idata[$col[0]] = $item->$_col;
}
}
} else {
$idata = $item->id;
}
$out[] = $idata;
}
return $out;
}
/**
* Generate the footer of the table.
*/
function footer()

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.05893s using 13 queries.