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