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\Util\Config\ConfigProvider;
  6: use Alpha\Util\Security\SecurityUtils;
  7: use Alpha\Util\Http\Session\SessionProviderFactory;
  8: use Alpha\Controller\Front\FrontController;
  9: use Alpha\View\Widget\StringBox;
 10: use Alpha\View\Widget\Button;
 11: use Alpha\Model\Type\DEnumItem;
 12: use Alpha\Model\Type\String;
 13: 
 14: /**
 15:  * The rendering class for the DEnum class.
 16:  *
 17:  * @since 1.0
 18:  *
 19:  * @author John Collins <dev@alphaframework.org>
 20:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 21:  * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
 22:  * All rights reserved.
 23:  *
 24:  * <pre>
 25:  * Redistribution and use in source and binary forms, with or
 26:  * without modification, are permitted provided that the
 27:  * following conditions are met:
 28:  *
 29:  * * Redistributions of source code must retain the above
 30:  *   copyright notice, this list of conditions and the
 31:  *   following disclaimer.
 32:  * * Redistributions in binary form must reproduce the above
 33:  *   copyright notice, this list of conditions and the
 34:  *   following disclaimer in the documentation and/or other
 35:  *   materials provided with the distribution.
 36:  * * Neither the name of the Alpha Framework nor the names
 37:  *   of its contributors may be used to endorse or promote
 38:  *   products derived from this software without specific
 39:  *   prior written permission.
 40:  *
 41:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 42:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 43:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 44:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 45:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 46:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 47:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 48:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 49:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 50:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 51:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 52:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 53:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 54:  * </pre>
 55:  */
 56: class DEnumView extends View
 57: {
 58:     /**
 59:      * Custom list view.
 60:      *
 61:      * @return string
 62:      *
 63:      * @since 1.0
 64:      */
 65:     public function listView($fields = array())
 66:     {
 67:         $config = ConfigProvider::getInstance();
 68:         $sessionProvider = $config->get('session.provider.name');
 69:         $session = SessionProviderFactory::getInstance($sessionProvider);
 70: 
 71:         $reflection = new \ReflectionClass(get_class($this->BO));
 72:         $properties = $reflection->getProperties();
 73:         $labels = $this->BO->getDataLabels();
 74:         $colCount = 1;
 75: 
 76:         $html = '<form action="'.$fields['URI'].'" method="POST">';
 77:         $html .= '<table class="table">';
 78:         // first render all of the table headers
 79:         $html .= '<tr>';
 80:         foreach ($properties as $propObj) {
 81:             $prop = $propObj->name;
 82:             if (!in_array($prop, $this->BO->getDefaultAttributes()) && !in_array($prop, $this->BO->getTransientAttributes())) {
 83:                 if (get_class($this->BO->getPropObject($prop)) != 'Alpha\Model\Type\Text') {
 84:                     ++$colCount;
 85:                     $html .= '  <th>'.$labels[$prop].'</th>';
 86:                 }
 87:             }
 88:             if ($prop == 'OID') {
 89:                 $html .= '  <th>'.$labels[$prop].'</th>';
 90:             }
 91:         }
 92:         // render the count
 93:         $html .= '  <th>Item count</th>';
 94: 
 95:         $html .= '</tr><tr>';
 96: 
 97:         // and now the values
 98:         foreach ($properties as $propObj) {
 99:             $prop = $propObj->name;
100:             if (!in_array($prop, $this->BO->getDefaultAttributes()) && !in_array($prop, $this->BO->getTransientAttributes())) {
101:                 if (get_class($this->BO->getPropObject($prop)) != 'Alpha\Model\Type\Text') {
102:                     $html .= '  <td>&nbsp;'.$this->BO->get($prop).'</td>';
103:                 }
104:             }
105:             if ($prop == 'OID') {
106:                 $html .= '  <td>&nbsp;'.$this->BO->getID().'</td>';
107:             }
108:         }
109:         // render the count
110:         $html .= '  <td>&nbsp;'.$this->BO->getItemCount().'</td>';
111: 
112:         $html .= '</tr>';
113: 
114:         $html .= '<tr><td colspan="'.($colCount + 1).'" style="text-align:center;">';
115:         // render edit buttons for admins only
116:         if ($session->get('currentUser') != null && $session->get('currentUser')->inGroup('Admin')) {
117:             $html .= '&nbsp;&nbsp;';
118:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\DEnumController&denumOID='.$this->BO->getOID())."'", 'Edit', 'edit'.$this->BO->getOID().'But');
119:             $html .= $button->render();
120:         }
121:         $html .= '</td></tr>';
122: 
123:         $html .= '</table>';
124: 
125:         $html .= '</form>';
126: 
127:         return $html;
128:     }
129: 
130:     /**
131:      * Custom edit view.
132:      *
133:      * @return string
134:      *
135:      * @since 1.0
136:      */
137:     public function editView($fields = array())
138:     {
139:         $config = ConfigProvider::getInstance();
140: 
141:         $labels = $this->BO->getDataLabels();
142:         $obj_type = '';
143: 
144:         $html = '<form action="'.$fields['URI'].'" method="POST" accept-charset="UTF-8">';
145: 
146:         $temp = new StringBox($this->BO->getPropObject('name'), $labels['name'], 'name', '', 0, true, true);
147:         $html .= $temp->render();
148: 
149:         $html .= '<h3>DEnum display values:</h3>';
150: 
151:         // now get all of the options for the enum and render
152:         $denum = $this->BO;
153:         $tmp = new DEnumItem();
154:         $denumItems = $tmp->loadItems($denum->getID());
155: 
156:         foreach ($denumItems as $item) {
157:             $labels = $item->getDataLabels();
158:             $temp = new StringBox($item->getPropObject('value'), $labels['value'], 'value_'.$item->getID(), '');
159:             $html .= $temp->render();
160:         }
161: 
162:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num');
163: 
164:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getVersion().'"/>';
165: 
166:         $html .= '<h3>Add a new value to the DEnum dropdown list:</h3>';
167: 
168:         $temp = new StringBox(new String(), 'Dropdown value', 'new_value', '');
169:         $html .= $temp->render();
170: 
171:         $temp = new Button('submit', 'Save', 'saveBut');
172:         $html .= $temp->render();
173:         $html .= '&nbsp;&nbsp;';
174:         $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\DEnumController')."'", 'Back to List', 'cancelBut');
175:         $html .= $temp->render();
176:         $html .= '';
177: 
178:         $html .= View::renderSecurityFields();
179: 
180:         $html .= '</form>';
181: 
182:         return $html;
183:     }
184: }
185: 
Alpha Framework 2.0.4 API Documentation API documentation generated by ApiGen 2.8.0