Overview

Namespaces

  • Alpha
    • Controller
      • Front
    • Exception
    • Model
      • Type
    • Task
    • Util
      • Backup
      • Cache
      • Code
        • Highlight
        • Metric
      • Config
      • Convertor
      • Email
      • Extension
      • Feed
      • File
      • Graph
      • Helper
      • Http
        • Filter
        • Session
      • Image
      • Logging
      • Search
      • Security
    • View
      • Renderer
        • Html
        • Json
      • Widget

Classes

  • RendererProviderJSON
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Alpha\View\Renderer\Json;
  4: 
  5: use Alpha\View\Renderer\RendererProviderInterface;
  6: use Alpha\Util\Logging\Logger;
  7: 
  8: /**
  9:  * JSON renderer.
 10:  *
 11:  * @since 2.0
 12:  *
 13:  * @author John Collins <dev@alphaframework.org>
 14:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 15:  * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
 16:  * All rights reserved.
 17:  *
 18:  * <pre>
 19:  * Redistribution and use in source and binary forms, with or
 20:  * without modification, are permitted provided that the
 21:  * following conditions are met:
 22:  *
 23:  * * Redistributions of source code must retain the above
 24:  *   copyright notice, this list of conditions and the
 25:  *   following disclaimer.
 26:  * * Redistributions in binary form must reproduce the above
 27:  *   copyright notice, this list of conditions and the
 28:  *   following disclaimer in the documentation and/or other
 29:  *   materials provided with the distribution.
 30:  * * Neither the name of the Alpha Framework nor the names
 31:  *   of its contributors may be used to endorse or promote
 32:  *   products derived from this software without specific
 33:  *   prior written permission.
 34:  *
 35:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 36:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 37:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 38:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 39:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 40:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 41:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 42:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 43:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 44:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 45:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 46:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 47:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 48:  * </pre>
 49:  */
 50: class RendererProviderJSON implements RendererProviderInterface
 51: {
 52:     /**
 53:      * Trace logger.
 54:      *
 55:      * @var Alpha\Util\Logging\Logger;
 56:      *
 57:      * @since 2.0
 58:      */
 59:     private static $logger = null;
 60: 
 61:     /**
 62:      * The active record that we are renderering.
 63:      *
 64:      * @var Alpha\Model\ActiveRecord
 65:      *
 66:      * @since 2.0
 67:      */
 68:     private $BO;
 69: 
 70:     /**
 71:      * The constructor.
 72:      *
 73:      * @since 2.0
 74:      */
 75:     public function __construct()
 76:     {
 77:         self::$logger = new Logger('RendererProviderJSON');
 78:         self::$logger->debug('>>__construct()');
 79: 
 80:         self::$logger->debug('<<__construct');
 81:     }
 82: 
 83:     /**
 84:      * {@inheritdoc}
 85:      */
 86:     public function setBO($BO)
 87:     {
 88:         $this->BO = $BO;
 89:     }
 90: 
 91:     /**
 92:      * {@inheritdoc}
 93:      */
 94:     public function createView($fields = array())
 95:     {
 96:         return '';
 97:     }
 98: 
 99:     /**
100:      * {@inheritdoc}
101:      */
102:     public function editView($fields = array())
103:     {
104:         return '';
105:     }
106: 
107:     /**
108:      * {@inheritdoc}
109:      */
110:     public function listView($fields = array())
111:     {
112:         self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])');
113: 
114:         $json = json_encode($this->BO->toArray()).',';
115: 
116:         self::$logger->debug('<<listView [JSON]');
117: 
118:         return $json;
119:     }
120: 
121:     /**
122:      * {@inheritdoc}
123:      */
124:     public function detailedView($fields = array())
125:     {
126:         self::$logger->debug('>>detailedView(fields=['.var_export($fields, true).'])');
127: 
128:         $json = json_encode($this->BO->toArray());
129: 
130:         self::$logger->debug('<<detailedView [JSON]');
131: 
132:         return $json;
133:     }
134: 
135:     /**
136:      * {@inheritdoc}
137:      */
138:     public function adminView($fields = array())
139:     {
140:         return '';
141:     }
142: 
143:     /**
144:      * {@inheritdoc}
145:      */
146:     public static function displayPageHead($controller)
147:     {
148:         return '';
149:     }
150: 
151:     /**
152:      * {@inheritdoc}
153:      */
154:     public static function displayPageFoot($controller)
155:     {
156:         return '';
157:     }
158: 
159:     /**
160:      * {@inheritdoc}
161:      */
162:     public static function displayUpdateMessage($message)
163:     {
164:         self::$logger->debug('>>displayUpdateMessage(fields=['.var_export($message, true).'])');
165: 
166:         $json = json_encode(array('message' => $message));
167: 
168:         self::$logger->debug('<<displayUpdateMessage [JSON]');
169: 
170:         return $json;
171:     }
172: 
173:     /**
174:      * {@inheritdoc}
175:      */
176:     public static function displayErrorMessage($message)
177:     {
178:         self::$logger->debug('>>displayErrorMessage(fields=['.var_export($message, true).'])');
179: 
180:         $json = json_encode(array('message' => $message));
181: 
182:         self::$logger->debug('<<displayErrorMessage [JSON]');
183: 
184:         return $json;
185:     }
186: 
187:     /**
188:      * {@inheritdoc}
189:      */
190:     public static function renderErrorPage($code, $message)
191:     {
192:         return '';
193:     }
194: 
195:     /**
196:      * {@inheritdoc}
197:      */
198:     public static function renderDeleteForm($URI)
199:     {
200:         return '';
201:     }
202: 
203:     /**
204:      * {@inheritdoc}
205:      */
206:     public static function renderSecurityFields()
207:     {
208:         return '';
209:     }
210: 
211:     /**
212:      * {@inheritdoc}
213:      */
214:     public function renderIntegerField($name, $label, $mode, $value = '')
215:     {
216:         return '';
217:     }
218: 
219:     /**
220:      * {@inheritdoc}
221:      */
222:     public function renderDoubleField($name, $label, $mode, $value = '')
223:     {
224:         return '';
225:     }
226: 
227:     /**
228:      * {@inheritdoc}
229:      */
230:     public function renderBooleanField($name, $label, $mode, $value = '')
231:     {
232:     }
233: 
234:     /**
235:      * {@inheritdoc}
236:      */
237:     public function renderEnumField($name, $label, $mode, $options, $value = '')
238:     {
239:         return '';
240:     }
241: 
242:     /**
243:      * {@inheritdoc}
244:      */
245:     public function renderDEnumField($name, $label, $mode, $options, $value = '')
246:     {
247:         return '';
248:     }
249: 
250:     /**
251:      * {@inheritdoc}
252:      */
253:     public function renderDefaultField($name, $label, $mode, $value = '')
254:     {
255:         return '';
256:     }
257: 
258:     /**
259:      * {@inheritdoc}
260:      */
261:     public function renderTextField($name, $label, $mode, $value = '')
262:     {
263:         return '';
264:     }
265: 
266:     /**
267:      * {@inheritdoc}
268:      */
269:     public function renderStringField($name, $label, $mode, $value = '')
270:     {
271:         return '';
272:     }
273: 
274:     /**
275:      * {@inheritdoc}
276:      */
277:     public function renderRelationField($name, $label, $mode, $value = '', $expanded = false, $buttons = true)
278:     {
279:         return '';
280:     }
281: 
282:     /**
283:      * {@inheritdoc}
284:      */
285:     public function renderAllFields($mode, $filterFields = array(), $readOnlyFields = array())
286:     {
287:         self::$logger->debug('>>renderAllFields(fields=['.var_export($fields, true).'])');
288: 
289:         $json = json_encode(array_diff($this->BO->toArray(), $filterFields));
290: 
291:         self::$logger->debug('<<renderAllFields [JSON]');
292: 
293:         return $json;
294:     }
295: }
296: 
Alpha Framework 2.0.4 API Documentation API documentation generated by ApiGen 2.8.0