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

  • ArticleCommentView
  • ArticleView
  • DEnumView
  • PersonView
  • SequenceView
  • View
  • ViewState
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Alpha\View;
  4: 
  5: use Alpha\Controller\Front\FrontController;
  6: use Alpha\Util\Logging\Logger;
  7: use Alpha\Util\Config\ConfigProvider;
  8: use Alpha\Model\Type\String;
  9: use Alpha\View\Widget\Button;
 10: 
 11: /**
 12:  * The rendering class for the Sequence class.
 13:  *
 14:  * @since 1.0
 15:  *
 16:  * @author John Collins <dev@alphaframework.org>
 17:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 18:  * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
 19:  * All rights reserved.
 20:  *
 21:  * <pre>
 22:  * Redistribution and use in source and binary forms, with or
 23:  * without modification, are permitted provided that the
 24:  * following conditions are met:
 25:  *
 26:  * * Redistributions of source code must retain the above
 27:  *   copyright notice, this list of conditions and the
 28:  *   following disclaimer.
 29:  * * Redistributions in binary form must reproduce the above
 30:  *   copyright notice, this list of conditions and the
 31:  *   following disclaimer in the documentation and/or other
 32:  *   materials provided with the distribution.
 33:  * * Neither the name of the Alpha Framework nor the names
 34:  *   of its contributors may be used to endorse or promote
 35:  *   products derived from this software without specific
 36:  *   prior written permission.
 37:  *
 38:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 39:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 40:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 41:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 42:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 43:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 44:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 45:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 46:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 47:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 48:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 49:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 50:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 51:  * </pre>
 52:  */
 53: class SequenceView extends View
 54: {
 55:     /**
 56:      * Trace logger.
 57:      *
 58:      * @var Logger
 59:      *
 60:      * @since 1.0
 61:      */
 62:     private static $logger = null;
 63: 
 64:     /**
 65:      * Constructor.
 66:      *
 67:      * @param Alpha\Model\ActiveRecord $BO
 68:      *
 69:      * @throws Alpha\Exception\IllegalArguementException
 70:      *
 71:      * @since 1.0
 72:      */
 73:     protected function __construct($BO)
 74:     {
 75:         self::$logger = new Logger('SequenceView');
 76:         self::$logger->debug('>>__construct(BO=['.var_export($BO, true).'])');
 77: 
 78:         parent::__construct($BO);
 79: 
 80:         self::$logger->debug('<<__construct');
 81:     }
 82: 
 83:     /**
 84:      * Custom list view.
 85:      *
 86:      * @param array $fields Hash array of HTML fields to pass to the template.
 87:      *
 88:      * @since 1.0
 89:      */
 90:     public function listView($fields = array())
 91:     {
 92:         self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])');
 93: 
 94:         if (method_exists($this, 'before_listView_callback')) {
 95:             $this->before_listView_callback();
 96:         }
 97: 
 98:         $config = ConfigProvider::getInstance();
 99: 
100:         // the form action
101:         $fields['formAction'] = $fields['URI'];
102: 
103:         // work out how many columns will be in the table
104:         $reflection = new \ReflectionClass(get_class($this->BO));
105:         $properties = array_keys($reflection->getDefaultProperties());
106:         $fields['colCount'] = 1 + count(array_diff($properties, $this->BO->getDefaultAttributes(), $this->BO->getTransientAttributes()));
107: 
108:         // get the class attributes
109:         $properties = $reflection->getProperties();
110: 
111:         $html = '';
112: 
113:         $html .= '<tr>';
114:         foreach ($properties as $propObj) {
115:             $propName = $propObj->name;
116: 
117:             // skip over password fields
118:             $property = $this->BO->getPropObject($propName);
119:             if (!($property instanceof String && $property->checkIsPassword())) {
120:                 if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
121:                     $html .= '  <th>'.$this->BO->getDataLabel($propName).'</th>';
122:                 }
123:                 if ($propName == 'OID') {
124:                     $html .= '  <th>'.$this->BO->getDataLabel($propName).'</th>';
125:                 }
126:             } else {
127:                 $fields['colCount'] = $fields['colCount'] - 1;
128:             }
129:         }
130:         $html .= '</tr><tr>';
131: 
132:         $fields['formHeadings'] = $html;
133: 
134:         $html = '';
135: 
136:         // and now the values
137:         foreach ($properties as $propObj) {
138:             $propName = $propObj->name;
139: 
140:             $property = $this->BO->getPropObject($propName);
141:             if (!($property instanceof String && $property->checkIsPassword())) {
142:                 if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
143:                     $propClass = get_class($this->BO->getPropObject($propName));
144: 
145:                     if ($propClass == 'Alpha\Model\Type\Text') {
146:                         $text = htmlentities($this->BO->get($propName), ENT_COMPAT, 'utf-8');
147:                         if (mb_strlen($text) > 70) {
148:                             $html .= '  <td>&nbsp;'.mb_substr($text, 0, 70).'...</td>';
149:                         } else {
150:                             $html .= '  <td>&nbsp;'.$text.'</td>';
151:                         }
152:                     } elseif ($propClass == 'Alpha\Model\Type\DEnum') {
153:                         $html .= '  <td>&nbsp;'.$this->BO->getPropObject($propName)->getDisplayValue().'</td>';
154:                     } else {
155:                         $html .= '  <td>&nbsp;'.$this->BO->get($propName).'</td>';
156:                     }
157:                 }
158:                 if ($propName == 'OID') {
159:                     $html .= '  <td>&nbsp;'.$this->BO->getOID().'</td>';
160:                 }
161:             }
162:         }
163:         $html .= '</tr>';
164: 
165:         $fields['formFields'] = $html;
166: 
167:         $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'viewBut');
168:         $fields['viewButton'] = $button->render();
169: 
170:         // supressing the edit/delete buttons for Sequences
171:         $fields['adminButtons'] = '';
172: 
173:         // buffer security fields to $formSecurityFields variable
174:         $fields['formSecurityFields'] = $this->renderSecurityFields();
175: 
176:         $html = $this->loadTemplate($this->BO, 'list', $fields);
177: 
178:         if (method_exists($this, 'after_listView_callback')) {
179:             $this->after_listView_callback();
180:         }
181: 
182:         self::$logger->debug('<<listView');
183: 
184:         return $html;
185:     }
186: 
187:     /**
188:      * Custom display view.
189:      *
190:      * @param array $fields Hash array of HTML fields to pass to the template.
191:      *
192:      * @since 1.0
193:      */
194:     public function detailedView($fields = array())
195:     {
196:         self::$logger->debug('>>detailedView(fields=['.var_export($fields, true).'])');
197: 
198:         if (method_exists($this, 'before_detailedView_callback')) {
199:             $this->before_detailedView_callback();
200:         }
201: 
202:         $config = ConfigProvider::getInstance();
203: 
204:         // we may want to display the OID regardless of class
205:         $fields['OIDLabel'] = $this->BO->getDataLabel('OID');
206:         $fields['OID'] = $this->BO->getOID();
207: 
208:         // buffer form fields to $formFields
209:         $fields['formFields'] = $this->renderAllFields('view');
210: 
211:         // Back button
212:         $button = new Button('history.back()', 'Back', 'backBut');
213:         $fields['backButton'] = $button->render();
214: 
215:         $fields['adminButtons'] = '';
216: 
217:         $html = $this->loadTemplate($this->BO, 'detail', $fields);
218: 
219:         if (method_exists($this, 'after_detailedView_callback')) {
220:             $this->after_detailedView_callback();
221:         }
222: 
223:         self::$logger->debug('<<detailedView');
224: 
225:         return $html;
226:     }
227: }
228: 
Alpha Framework 2.0.4 API Documentation API documentation generated by ApiGen 2.8.0