| 1 | <?php |
||
| 2 | //------------------------------------------------------------------------- |
||
| 3 | // OVIDENTIA http://www.ovidentia.org |
||
| 4 | // Ovidentia is free software; you can redistribute it and/or modify |
||
| 5 | // it under the terms of the GNU General Public License as published by |
||
| 6 | // the Free Software Foundation; either version 2, or (at your option) |
||
| 7 | // any later version. |
||
| 8 | // |
||
| 9 | // This program is distributed in the hope that it will be useful, but |
||
| 10 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 12 | // See the GNU General Public License for more details. |
||
| 13 | // |
||
| 14 | // You should have received a copy of the GNU General Public License |
||
| 15 | // along with this program; if not, write to the Free Software |
||
| 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
||
| 17 | // USA. |
||
| 18 | //------------------------------------------------------------------------- |
||
| 19 | /** |
||
| 20 | * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
||
| 21 | * @copyright Copyright (c) 2022 by SI4YOU ({@link https://www.siforyou.com}) |
||
| 22 | */ |
||
| 23 | |||
| 24 | namespace Capwelton\LibApp\Ui; |
||
| 25 | |||
| 26 | use Capwelton\Widgets\Widgets\Abstracts\WidgetItem; |
||
|
0 ignored issues
–
show
|
|||
| 27 | use Capwelton\Widgets\Widgets\Interfaces\WidgetDisplayableInterface; |
||
|
0 ignored issues
–
show
The type
Capwelton\Widgets\Widget...getDisplayableInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 28 | use Capwelton\Widgets\Widgets\Item\WidgetSection; |
||
|
0 ignored issues
–
show
The type
Capwelton\Widgets\Widgets\Item\WidgetSection was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 29 | use Capwelton\Widgets\Widgets\Layout\WidgetLayout; |
||
|
0 ignored issues
–
show
The type
Capwelton\Widgets\Widgets\Layout\WidgetLayout was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 30 | use Capwelton\LibApp\AppUiObject; |
||
| 31 | use Capwelton\LibApp\Func_App; |
||
| 32 | use Capwelton\LibApp\Set\AppRecord; |
||
| 33 | use Capwelton\LibOrm\Field\ORMField; |
||
|
0 ignored issues
–
show
The type
Capwelton\LibOrm\Field\ORMField was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 34 | use Capwelton\LibOrm\Field\ORMTextField; |
||
|
0 ignored issues
–
show
The type
Capwelton\LibOrm\Field\ORMTextField was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 35 | use Capwelton\LibOrm\Field\ORMUrlField; |
||
|
0 ignored issues
–
show
The type
Capwelton\LibOrm\Field\ORMUrlField was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 36 | use Capwelton\LibOrm\Field\ORMEmailField; |
||
|
0 ignored issues
–
show
The type
Capwelton\LibOrm\Field\ORMEmailField was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 37 | use Capwelton\LibOrm\Field\ORMFkField; |
||
|
0 ignored issues
–
show
The type
Capwelton\LibOrm\Field\ORMFkField was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 38 | |||
| 39 | /** |
||
| 40 | * A card frame is a frame with contact informations |
||
| 41 | */ |
||
| 42 | class AppCardFrame extends AppUiObject |
||
| 43 | { |
||
| 44 | |||
| 45 | const IMAGE_WIDTH = 28; |
||
| 46 | const IMAGE_HEIGHT = 28; |
||
| 47 | |||
| 48 | |||
| 49 | const MAPS_URL = '//maps.google.com/?q=%s'; |
||
| 50 | |||
| 51 | const MAPS_ROUTE_URL = '//maps.google.com/maps?saddr=%s&daddr=%s'; |
||
| 52 | |||
| 53 | const STATIC_MAPS_URL = '//maps.google.com/maps/api/staticmap?'; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var WidgetSection[] $sections |
||
| 57 | */ |
||
| 58 | protected $sections = array(); |
||
| 59 | |||
| 60 | |||
| 61 | protected $menu = null; |
||
| 62 | |||
| 63 | public function __construct(Func_App $App, $id = null, WidgetLayout $layout = null) |
||
| 64 | { |
||
| 65 | parent::__construct($App); |
||
| 66 | |||
| 67 | $W = bab_Widgets(); |
||
| 68 | |||
| 69 | $this->setInheritedItem($W->Frame($id, $layout)); |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * render a labeled string |
||
| 75 | * |
||
| 76 | * @param string | WidgetItem $label |
||
| 77 | * @param string | WidgetItem $value |
||
| 78 | * |
||
| 79 | * @return WidgetItem |
||
| 80 | */ |
||
| 81 | protected function labelStr($label, $value) |
||
| 82 | { |
||
| 83 | $W = bab_Widgets(); |
||
| 84 | |||
| 85 | if (!($label instanceOf WidgetItem)) { |
||
| 86 | $label = $W->Label($label); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (!($value instanceOf WidgetDisplayableInterface)) { |
||
| 90 | $value = $W->Label($value); |
||
| 91 | } |
||
| 92 | |||
| 93 | |||
| 94 | return $W->VBoxItems( |
||
|
0 ignored issues
–
show
|
|||
| 95 | $label->colon(false)->addClass('crm-display-label'), |
||
| 96 | $value->addClass('crm-display-value') |
||
| 97 | )->setVerticalAlign('middle')->setVerticalSpacing(3, 'px'); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * render a labeled string only if value set |
||
| 102 | * |
||
| 103 | * @param string | WidgetItem $label |
||
| 104 | * @param string | WidgetItem $value |
||
| 105 | * |
||
| 106 | * @return WidgetItem | null |
||
| 107 | */ |
||
| 108 | protected function labelStrSet($label, $value) |
||
| 109 | { |
||
| 110 | if (!isset($value) || '' === $value) { |
||
| 111 | return null; |
||
| 112 | } |
||
| 113 | |||
| 114 | return $this->labelStr($label, $value); |
||
| 115 | } |
||
| 116 | |||
| 117 | |||
| 118 | /** |
||
| 119 | * render a labeled string with a field value, if the value is not set, return null |
||
| 120 | * |
||
| 121 | * |
||
| 122 | * @param string $label |
||
| 123 | * @param AppRecord $record |
||
| 124 | * @param ORMField $field |
||
| 125 | */ |
||
| 126 | protected function labeledField($label, AppRecord $record, ORMField $field) |
||
| 127 | { |
||
| 128 | $W = bab_Widgets(); |
||
| 129 | |||
| 130 | $fieldName = $field->getName(); |
||
| 131 | $value = $record->$fieldName; |
||
| 132 | |||
| 133 | if (!$field->isValueSet($value)) { |
||
| 134 | return null; |
||
| 135 | } |
||
| 136 | |||
| 137 | $displayable = $field->output($value); |
||
| 138 | |||
| 139 | switch(true) { |
||
| 140 | case ($field instanceof ORMTextField): |
||
| 141 | $displayable = $W->RichText($displayable)->setRenderingOptions(BAB_HTML_ALL ^ BAB_HTML_P); |
||
| 142 | break; |
||
| 143 | |||
| 144 | case ($field instanceof ORMUrlField): |
||
| 145 | $displayable = $W->Link($displayable, $displayable); |
||
| 146 | break; |
||
| 147 | |||
| 148 | case ($field instanceof ORMEmailField): |
||
| 149 | $displayable = $W->Link($displayable, 'mailto:'.$displayable); |
||
| 150 | break; |
||
| 151 | |||
| 152 | case ($field instanceof ORMFkField): |
||
| 153 | $record = $record->$fieldName(); |
||
| 154 | if (!isset($record)) { |
||
| 155 | return null; |
||
| 156 | } |
||
| 157 | $displayable = $record->getRecordTitle(); |
||
| 158 | break; |
||
| 159 | } |
||
| 160 | |||
| 161 | return $this->labelStr($label, $displayable); |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | /** |
||
| 169 | * Creates section in the editor. |
||
| 170 | * If a section with the same header text (title) was already |
||
| 171 | * created it is replaced by an empty section. |
||
| 172 | * |
||
| 173 | * @param string $headerText |
||
| 174 | * @return WidgetSection |
||
| 175 | */ |
||
| 176 | protected function addSection($id, $headerText, $layout = null) |
||
| 177 | { |
||
| 178 | $W = bab_Widgets(); |
||
| 179 | if (!isset($layout)) { |
||
| 180 | $layout = $W->VBoxLayout()->setVerticalSpacing(1, 'em'); |
||
| 181 | } |
||
| 182 | $this->sections[$id] = $W->Section( |
||
| 183 | $headerText, |
||
| 184 | $layout |
||
| 185 | )->setFoldable(true); |
||
| 186 | |||
| 187 | return $this->sections[$id]; |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Creates section in the editor. |
||
| 192 | * If a section with the same header text (title) was already |
||
| 193 | * created it is replaced by an empty section. |
||
| 194 | * |
||
| 195 | * @param string $headerText |
||
| 196 | * @return WidgetSection |
||
| 197 | */ |
||
| 198 | protected function createSection($headerText, $layout = null) |
||
| 199 | { |
||
| 200 | return $this->addSection($headerText, $headerText, $layout); |
||
| 201 | } |
||
| 202 | |||
| 203 | |||
| 204 | /** |
||
| 205 | * Retrieves a section in the editor. |
||
| 206 | * |
||
| 207 | * @param string $headerText |
||
| 208 | * @return WidgetSection |
||
| 209 | */ |
||
| 210 | protected function getSection($id) |
||
| 211 | { |
||
| 212 | if (!isset($this->sections[$id])) { |
||
| 213 | return null; |
||
| 214 | } |
||
| 215 | return $this->sections[$id]; |
||
| 216 | } |
||
| 217 | |||
| 218 | |||
| 219 | /** |
||
| 220 | * Returns the list of sections created via createSection(). |
||
| 221 | * |
||
| 222 | * @return WidgetSection[] |
||
| 223 | */ |
||
| 224 | public function getSections() |
||
| 225 | { |
||
| 226 | return $this->sections; |
||
| 227 | } |
||
| 228 | |||
| 229 | |||
| 230 | /** |
||
| 231 | * @param WidgetDisplayableInterface $item |
||
| 232 | * @return self |
||
| 233 | */ |
||
| 234 | public function addAction(WidgetDisplayableInterface $item) |
||
| 235 | { |
||
| 236 | if (!isset($this->menu)) { |
||
| 237 | $W = bab_Widgets(); |
||
| 238 | $this->menu = $W->Menu() |
||
| 239 | ->setLayout($W->FlowLayout()) |
||
| 240 | ->addClass(\Func_Icons::ICON_LEFT_SYMBOLIC); |
||
| 241 | |||
| 242 | } |
||
| 243 | $this->menu->addItem($item); |
||
| 244 | return $this; |
||
| 245 | } |
||
| 246 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths