@@ -142,7 +142,9 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | public function addMenu() |
| 144 | 144 | { |
| 145 | - if ($this->isLocked()) return; |
|
| 145 | + if ($this->isLocked()) { |
|
| 146 | + return; |
|
| 147 | + } |
|
| 146 | 148 | |
| 147 | 149 | $dashboardId = $this->dashboard()->id; |
| 148 | 150 | |
@@ -165,14 +167,18 @@ discard block |
||
| 165 | 167 | $dashboardMenu->addItem([__('Rename dashboard'), 'icon' => 'i cursor'])->on('click', $modal->show()); |
| 166 | 168 | |
| 167 | 169 | // there is only one admin default dashboard |
| 168 | - if ($this->admin) return; |
|
| 170 | + if ($this->admin) { |
|
| 171 | + return; |
|
| 172 | + } |
|
| 169 | 173 | |
| 170 | 174 | // ***** add ***** // |
| 171 | 175 | $modal = $this->add(['Modal', 'title' => __('Add Dashboard')])->set(\Closure::fromCallable([$this, 'addDashboard'])); |
| 172 | 176 | |
| 173 | 177 | $dashboardMenu->addItem([__('Add dashboard'), 'icon' => 'add'])->on('click', $modal->show()); |
| 174 | 178 | |
| 175 | - if ($this->isSingleDashboard()) return; |
|
| 179 | + if ($this->isSingleDashboard()) { |
|
| 180 | + return; |
|
| 181 | + } |
|
| 176 | 182 | |
| 177 | 183 | // ***** reorder ***** // |
| 178 | 184 | $modal = $this->add(['Modal', 'title' => __('Reorder Dashboards')])->set(\Closure::fromCallable([$this, 'reorderDashboards'])); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $columns = $this->add(['Columns', 'id' => 'dashboard', 'ui' => 'three stackable grid' . ($this->isLocked()? ' locked': '')]); |
| 49 | 49 | |
| 50 | 50 | foreach ([1, 2, 3] as $columnId) { |
| 51 | - $columnApplets = clone $applets; |
|
| 51 | + $columnApplets = clone $applets; |
|
| 52 | 52 | |
| 53 | 53 | /** @scrutinizer ignore-call */ |
| 54 | 54 | $col = $columns->addColumn([ |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | $existingList = collect($existing->export())->pluck('name', 'id'); |
| 206 | 206 | |
| 207 | 207 | $form->addFields([ |
| 208 | - ['name', __('Name')], |
|
| 209 | - ['base', ['DropDown', 'caption' => __('Copy applets from'), 'values' => $existingList]] |
|
| 210 | - ]); |
|
| 208 | + ['name', __('Name')], |
|
| 209 | + ['base', ['DropDown', 'caption' => __('Copy applets from'), 'values' => $existingList]] |
|
| 210 | + ]); |
|
| 211 | 211 | |
| 212 | 212 | $form->layout->addButton(['Button', __('Cancel')])->on('click', $view->owner->hide()); |
| 213 | 213 | |
@@ -219,19 +219,19 @@ discard block |
||
| 219 | 219 | $dashboardId = (int) $dashboard->insert([ |
| 220 | 220 | 'name' => $values['name'], |
| 221 | 221 | 'user_id' => $this->userId(), |
| 222 | - 'position' => count($existingList) |
|
| 222 | + 'position' => count($existingList) |
|
| 223 | 223 | ]); |
| 224 | 224 | |
| 225 | 225 | if ($values['base']) { |
| 226 | - foreach ($dashboard->withID($values['base'])->ref('applets') as $baseApplet) { |
|
| 227 | - // only save on below does not work for some reason. fails when reloading |
|
| 228 | - $baseApplet->duplicate()->saveAndUnload(['dashboard_id' => $dashboardId]); |
|
| 226 | + foreach ($dashboard->withID($values['base'])->ref('applets') as $baseApplet) { |
|
| 227 | + // only save on below does not work for some reason. fails when reloading |
|
| 228 | + $baseApplet->duplicate()->saveAndUnload(['dashboard_id' => $dashboardId]); |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return [ |
| 233 | 233 | $form->notify(__('Dashboard created, redirecting ...')), |
| 234 | - new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $dashboardId])]) |
|
| 234 | + new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $dashboardId])]) |
|
| 235 | 235 | ]; |
| 236 | 236 | }); |
| 237 | 237 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | return [ |
| 251 | 251 | $form->notifySuccess(__('Dashboard renamed, reloading ...')), |
| 252 | - new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $this->dashboard()->id])]) |
|
| 252 | + new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink('body', ['dashboard' => $this->dashboard()->id])]) |
|
| 253 | 253 | ]; |
| 254 | 254 | }); |
| 255 | 255 | } |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | $name = $dashboard['name']; |
| 262 | 262 | |
| 263 | 263 | return $dashboard->delete()? [ |
| 264 | - $this->notifySuccess(__('Dashboard ":name" deleted, redirecting ...', compact('name'))), |
|
| 265 | - new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink()]) |
|
| 264 | + $this->notifySuccess(__('Dashboard ":name" deleted, redirecting ...', compact('name'))), |
|
| 265 | + new jsExpression('window.setTimeout(function() {window.location.replace([])}, 1200)', [$this->selfLink()]) |
|
| 266 | 266 | ]: $this->notifyError(__('Error deleting dashboard')); |
| 267 | 267 | } |
| 268 | 268 | |
@@ -271,14 +271,14 @@ discard block |
||
| 271 | 271 | $grid = $view->add(['Grid', 'paginator' => false, 'menu' => false, 'model' => $this->userDashboards()->setOrder('position')]); |
| 272 | 272 | |
| 273 | 273 | $grid->addDragHandler()->onReorder(function ($order) use ($grid) { |
| 274 | - foreach ($this->userDashboards() as $dashboard) { |
|
| 274 | + foreach ($this->userDashboards() as $dashboard) { |
|
| 275 | 275 | $dashboard->save(['position' => array_search($dashboard->id, $order)]); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - return [ |
|
| 279 | - new jsReload($grid), |
|
| 280 | - $this->notifySuccess(__('Dashboards reordered!')) |
|
| 281 | - ]; |
|
| 278 | + return [ |
|
| 279 | + new jsReload($grid), |
|
| 280 | + $this->notifySuccess(__('Dashboards reordered!')) |
|
| 281 | + ]; |
|
| 282 | 282 | }); |
| 283 | 283 | |
| 284 | 284 | $view->add(['View', 'ui' => 'buttons'])->add(['Button', __('Done'), 'primary'])->on('click', new jsExpression('location.reload()')); |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $form->model->set($applet['options']); |
| 334 | 334 | |
| 335 | 335 | $form->validate(function(Form $form) use ($applet) { |
| 336 | - $applet->save(['options' => $form->model->get()]); |
|
| 336 | + $applet->save(['options' => $form->model->get()]); |
|
| 337 | 337 | |
| 338 | 338 | return $form->notifySuccess(__('Settings saved!')); |
| 339 | 339 | }); |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | protected function defaultSystemDashboard() |
| 392 | 392 | { |
| 393 | - return $this->userDashboards(0)->setOrder('position')->tryLoadAny(); |
|
| 393 | + return $this->userDashboards(0)->setOrder('position')->tryLoadAny(); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | protected function userDashboards($userId = null) |
@@ -26,8 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | if ($this->admin) { |
| 28 | 28 | $this->set($joint->info())->setAttr('searchkey', strtolower($joint->caption() . ';' . $joint->info())); |
| 29 | - } |
|
| 30 | - else { |
|
| 29 | + } else { |
|
| 31 | 30 | if (! $this->locked) { |
| 32 | 31 | $this->addControl('close', 'applet-close')->setAttr('title', __('Close applet')); |
| 33 | 32 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class CommonDataSettings extends ModuleView |
| 12 | 12 | { |
| 13 | - use SessionTrait; |
|
| 13 | + use SessionTrait; |
|
| 14 | 14 | |
| 15 | 15 | protected $label = 'Common Data'; |
| 16 | 16 | |
@@ -36,23 +36,23 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function setAncestors() |
| 38 | 38 | { |
| 39 | - $parent = $this->stickyGet('parent'); |
|
| 39 | + $parent = $this->stickyGet('parent'); |
|
| 40 | 40 | |
| 41 | - if (isset($parent)) { |
|
| 42 | - $this->memorize('parent', $parent?: null); |
|
| 43 | - } |
|
| 41 | + if (isset($parent)) { |
|
| 42 | + $this->memorize('parent', $parent?: null); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $this->ancestors = Models\CommonData::ancestorsAndSelf($this->recall('parent')); |
|
| 45 | + $this->ancestors = Models\CommonData::ancestorsAndSelf($this->recall('parent')); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function setLocation() |
| 49 | 49 | { |
| 50 | - $location = [['label' => $this->label, 'link' => '?parent=0']]; |
|
| 50 | + $location = [['label' => $this->label, 'link' => '?parent=0']]; |
|
| 51 | 51 | foreach (Models\CommonData::create()->withID($this->ancestors) as $node) { |
| 52 | - $location[] = [ |
|
| 53 | - 'label' => $node['value'] ?: $node['key'], |
|
| 54 | - 'link' => '?parent=' . $node['id'] |
|
| 55 | - ]; |
|
| 52 | + $location[] = [ |
|
| 53 | + 'label' => $node['value'] ?: $node['key'], |
|
| 54 | + 'link' => '?parent=' . $node['id'] |
|
| 55 | + ]; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $this->label = null; |
@@ -69,17 +69,17 @@ discard block |
||
| 69 | 69 | 'editFields' => ['key', 'value'], |
| 70 | 70 | 'addFields' => ['key', 'value'], |
| 71 | 71 | 'displayFields' => ['key', 'value', 'readonly'], |
| 72 | - 'notifyDefault' => ['jsToast', 'settings' => ['message' => __('Data is saved!'), 'class' => 'success']], |
|
| 72 | + 'notifyDefault' => ['jsToast', 'settings' => ['message' => __('Data is saved!'), 'class' => 'success']], |
|
| 73 | 73 | 'paginator' => false, |
| 74 | - 'menu' => ActionBar::instance(), |
|
| 75 | - 'quickSearch' => ['key', 'value'] |
|
| 74 | + 'menu' => ActionBar::instance(), |
|
| 75 | + 'quickSearch' => ['key', 'value'] |
|
| 76 | 76 | ]); |
| 77 | 77 | |
| 78 | 78 | $this->grid->setModel($this->nodes()->setOrder('position')); |
| 79 | 79 | |
| 80 | 80 | $this->grid->addActionButton(['icon' => 'level down', 'attr' => ['title' => __('Drilldown')]], new jsExpression( |
| 81 | - 'document.location=\'?parent=\'+[]', |
|
| 82 | - [$this->grid->jsRow()->data('id')] |
|
| 81 | + 'document.location=\'?parent=\'+[]', |
|
| 82 | + [$this->grid->jsRow()->data('id')] |
|
| 83 | 83 | )); |
| 84 | 84 | |
| 85 | 85 | $this->grid->addDragHandler()->onReorder(function ($order) { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | }); |
| 95 | 95 | |
| 96 | 96 | if ($this->ancestors && $this->grid->menu) { |
| 97 | - $this->grid->menu->addItem([__('Level Up'), 'icon' => 'level up'], '?parent=' . $this->parent(1)); |
|
| 97 | + $this->grid->menu->addItem([__('Level Up'), 'icon' => 'level up'], '?parent=' . $this->parent(1)); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $this; |
@@ -102,29 +102,29 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | public function parent($level = 0) |
| 104 | 104 | { |
| 105 | - return $this->ancestors[$level] ?? 0; |
|
| 105 | + return $this->ancestors[$level] ?? 0; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | public function nodes() |
| 109 | 109 | { |
| 110 | - $nodes = Models\CommonData::create(); |
|
| 110 | + $nodes = Models\CommonData::create(); |
|
| 111 | 111 | |
| 112 | - //@TODO: remove below when adding null condition fixed |
|
| 113 | - if ($parent = $this->parent()) { |
|
| 114 | - $nodes->addCondition('parent', $parent); |
|
| 115 | - } |
|
| 116 | - else { |
|
| 117 | - $nodes->addCondition($nodes->expr('parent is NULL')); |
|
| 118 | - } |
|
| 112 | + //@TODO: remove below when adding null condition fixed |
|
| 113 | + if ($parent = $this->parent()) { |
|
| 114 | + $nodes->addCondition('parent', $parent); |
|
| 115 | + } |
|
| 116 | + else { |
|
| 117 | + $nodes->addCondition($nodes->expr('parent is NULL')); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - $nodes->addHook('beforeInsert', function($node, & $data) { |
|
| 121 | - $data['parent'] = $this->recall('parent'); |
|
| 122 | - }); |
|
| 120 | + $nodes->addHook('beforeInsert', function($node, & $data) { |
|
| 121 | + $data['parent'] = $this->recall('parent'); |
|
| 122 | + }); |
|
| 123 | 123 | |
| 124 | - $nodes->getAction('edit')->enabled = function($row = null) { |
|
| 125 | - return $row ? !$row['readonly'] : true; |
|
| 126 | - }; |
|
| 124 | + $nodes->getAction('edit')->enabled = function($row = null) { |
|
| 125 | + return $row ? !$row['readonly'] : true; |
|
| 126 | + }; |
|
| 127 | 127 | |
| 128 | - return $nodes; |
|
| 128 | + return $nodes; |
|
| 129 | 129 | } |
| 130 | 130 | } |
@@ -112,8 +112,7 @@ |
||
| 112 | 112 | //@TODO: remove below when adding null condition fixed |
| 113 | 113 | if ($parent = $this->parent()) { |
| 114 | 114 | $nodes->addCondition('parent', $parent); |
| 115 | - } |
|
| 116 | - else { |
|
| 115 | + } else { |
|
| 117 | 116 | $nodes->addCondition($nodes->expr('parent is NULL')); |
| 118 | 117 | } |
| 119 | 118 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | public function install() |
| 28 | 28 | { |
| 29 | - Models\CommonData::migrate(); |
|
| 29 | + Models\CommonData::migrate(); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function uninstall() |
@@ -9,259 +9,259 @@ |
||
| 9 | 9 | class CommonDataNotFound extends \Exception {} |
| 10 | 10 | |
| 11 | 11 | class CommonData extends Model { |
| 12 | - use HasEpesiConnection; |
|
| 12 | + use HasEpesiConnection; |
|
| 13 | 13 | |
| 14 | - public $table = 'commondata'; |
|
| 14 | + public $table = 'commondata'; |
|
| 15 | 15 | |
| 16 | - public $caption = 'Common Data'; |
|
| 16 | + public $caption = 'Common Data'; |
|
| 17 | 17 | |
| 18 | - public $title_field = 'value'; |
|
| 18 | + public $title_field = 'value'; |
|
| 19 | 19 | |
| 20 | - protected static $cache = [ |
|
| 21 | - 'id' => [], |
|
| 22 | - 'value' => [], |
|
| 23 | - 'array' => [] |
|
| 24 | - ]; |
|
| 20 | + protected static $cache = [ |
|
| 21 | + 'id' => [], |
|
| 22 | + 'value' => [], |
|
| 23 | + 'array' => [] |
|
| 24 | + ]; |
|
| 25 | 25 | |
| 26 | - function init() { |
|
| 27 | - parent::init(); |
|
| 26 | + function init() { |
|
| 27 | + parent::init(); |
|
| 28 | 28 | |
| 29 | - $this->addFields([ |
|
| 30 | - 'key' => ['caption' => __('Key')], |
|
| 31 | - 'value' => ['caption' => __('Value')], |
|
| 32 | - 'position' => ['type' => 'integer', 'caption' => __('Position')], |
|
| 33 | - 'readonly' => ['type' => 'boolean'] |
|
| 34 | - ]); |
|
| 29 | + $this->addFields([ |
|
| 30 | + 'key' => ['caption' => __('Key')], |
|
| 31 | + 'value' => ['caption' => __('Value')], |
|
| 32 | + 'position' => ['type' => 'integer', 'caption' => __('Position')], |
|
| 33 | + 'readonly' => ['type' => 'boolean'] |
|
| 34 | + ]); |
|
| 35 | 35 | |
| 36 | - $this->hasOne('parent', [self::class, 'our_field' => 'parent']); |
|
| 36 | + $this->hasOne('parent', [self::class, 'our_field' => 'parent']); |
|
| 37 | 37 | |
| 38 | - $this->getAction('edit')->ui['execButton'] = ['Button', __('Save'), 'class' => ['primary']]; |
|
| 38 | + $this->getAction('edit')->ui['execButton'] = ['Button', __('Save'), 'class' => ['primary']]; |
|
| 39 | 39 | |
| 40 | - $this->addHook('beforeInsert', function($node, & $data) { |
|
| 41 | - $data['position'] = $node->action('fx', ['max', 'position'])->getOne() + 1; |
|
| 40 | + $this->addHook('beforeInsert', function($node, & $data) { |
|
| 41 | + $data['position'] = $node->action('fx', ['max', 'position'])->getOne() + 1; |
|
| 42 | 42 | |
| 43 | - $data['readonly'] = $data['readonly'] ?? 0; |
|
| 44 | - }); |
|
| 45 | - } |
|
| 43 | + $data['readonly'] = $data['readonly'] ?? 0; |
|
| 44 | + }); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public static function getId($path, $clearCache = false) |
|
| 48 | - { |
|
| 49 | - $id = null; |
|
| 50 | - foreach(explode('/', trim($path,'/')) as $nodeKey) { |
|
| 51 | - $parentId = $id; |
|
| 47 | + public static function getId($path, $clearCache = false) |
|
| 48 | + { |
|
| 49 | + $id = null; |
|
| 50 | + foreach(explode('/', trim($path,'/')) as $nodeKey) { |
|
| 51 | + $parentId = $id; |
|
| 52 | 52 | |
| 53 | - if ($nodeKey === '') continue; //ignore empty paths |
|
| 53 | + if ($nodeKey === '') continue; //ignore empty paths |
|
| 54 | 54 | |
| 55 | - if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
|
| 56 | - $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny(); |
|
| 55 | + if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
|
| 56 | + $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny(); |
|
| 57 | 57 | |
| 58 | - if (! $node->loaded()) return false; |
|
| 58 | + if (! $node->loaded()) return false; |
|
| 59 | 59 | |
| 60 | - self::$cache['id'][$parentId][$nodeKey] = $node->id; |
|
| 61 | - } |
|
| 60 | + self::$cache['id'][$parentId][$nodeKey] = $node->id; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $id = self::$cache['id'][$parentId][$nodeKey]; |
|
| 64 | - } |
|
| 63 | + $id = self::$cache['id'][$parentId][$nodeKey]; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return $id; |
|
| 67 | - } |
|
| 66 | + return $id; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public static function newId($path, $readonly = false) |
|
| 70 | - { |
|
| 71 | - if (! $path = trim($path,'/')) return false; |
|
| 69 | + public static function newId($path, $readonly = false) |
|
| 70 | + { |
|
| 71 | + if (! $path = trim($path,'/')) return false; |
|
| 72 | 72 | |
| 73 | - $id = null; |
|
| 74 | - foreach(explode('/', $path) as $nodeKey) { |
|
| 75 | - if ($nodeKey === '') continue; |
|
| 73 | + $id = null; |
|
| 74 | + foreach(explode('/', $path) as $nodeKey) { |
|
| 75 | + if ($nodeKey === '') continue; |
|
| 76 | 76 | |
| 77 | - $parentId = $id; |
|
| 77 | + $parentId = $id; |
|
| 78 | 78 | |
| 79 | - $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny(); |
|
| 79 | + $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny(); |
|
| 80 | 80 | |
| 81 | - if ($node->loaded()) { |
|
| 82 | - $id = $node->id; |
|
| 83 | - } |
|
| 84 | - else { |
|
| 85 | - $id = $node->insert([ |
|
| 86 | - 'parent' => $parentId, |
|
| 87 | - 'key' => $nodeKey, |
|
| 88 | - 'readonly' => $readonly |
|
| 89 | - ]); |
|
| 90 | - } |
|
| 91 | - } |
|
| 81 | + if ($node->loaded()) { |
|
| 82 | + $id = $node->id; |
|
| 83 | + } |
|
| 84 | + else { |
|
| 85 | + $id = $node->insert([ |
|
| 86 | + 'parent' => $parentId, |
|
| 87 | + 'key' => $nodeKey, |
|
| 88 | + 'readonly' => $readonly |
|
| 89 | + ]); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return $id; |
|
| 94 | - } |
|
| 93 | + return $id; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public static function setValue($path, $value, $overwrite = true, $readonly = false) |
|
| 97 | - { |
|
| 98 | - if (! $id = self::getId($path)) { |
|
| 99 | - if (! $id = self::newId($path, $readonly)) return false; |
|
| 100 | - } else { |
|
| 101 | - if (! $overwrite) return false; |
|
| 102 | - } |
|
| 96 | + public static function setValue($path, $value, $overwrite = true, $readonly = false) |
|
| 97 | + { |
|
| 98 | + if (! $id = self::getId($path)) { |
|
| 99 | + if (! $id = self::newId($path, $readonly)) return false; |
|
| 100 | + } else { |
|
| 101 | + if (! $overwrite) return false; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - self::create()->tryLoad($id)->save(compact('value', 'readonly')); |
|
| 104 | + self::create()->tryLoad($id)->save(compact('value', 'readonly')); |
|
| 105 | 105 | |
| 106 | - self::clearCache(); |
|
| 106 | + self::clearCache(); |
|
| 107 | 107 | |
| 108 | - return true; |
|
| 109 | - } |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public static function clearCache() |
|
| 112 | - { |
|
| 113 | - self::$cache = array_fill_keys(array_keys(self::$cache), []); |
|
| 114 | - } |
|
| 111 | + public static function clearCache() |
|
| 112 | + { |
|
| 113 | + self::$cache = array_fill_keys(array_keys(self::$cache), []); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - public static function getValue($path, $translate = false) |
|
| 117 | - { |
|
| 118 | - $key = md5(serialize($path)); |
|
| 116 | + public static function getValue($path, $translate = false) |
|
| 117 | + { |
|
| 118 | + $key = md5(serialize($path)); |
|
| 119 | 119 | |
| 120 | - if (! isset(self::$cache['value'][$key])) { |
|
| 121 | - if(! $id = self::getId($path)) return false; |
|
| 120 | + if (! isset(self::$cache['value'][$key])) { |
|
| 121 | + if(! $id = self::getId($path)) return false; |
|
| 122 | 122 | |
| 123 | - self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value'); |
|
| 124 | - } |
|
| 123 | + self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value'); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key]; |
|
| 127 | - } |
|
| 126 | + return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key]; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Creates new array for common use. |
|
| 131 | - * |
|
| 132 | - * @param $path string |
|
| 133 | - * @param $array array initialization value |
|
| 134 | - * @param $overwrite bool whether method should overwrite if array already exists, otherwise the data will be appended |
|
| 135 | - * @param $readonly bool do not allow user to change this array from GUI |
|
| 136 | - */ |
|
| 137 | - public static function newArray($path, $array, $overwrite = false, $readonly = false) |
|
| 138 | - { |
|
| 139 | - self::validateArrayKeys($array); |
|
| 129 | + /** |
|
| 130 | + * Creates new array for common use. |
|
| 131 | + * |
|
| 132 | + * @param $path string |
|
| 133 | + * @param $array array initialization value |
|
| 134 | + * @param $overwrite bool whether method should overwrite if array already exists, otherwise the data will be appended |
|
| 135 | + * @param $readonly bool do not allow user to change this array from GUI |
|
| 136 | + */ |
|
| 137 | + public static function newArray($path, $array, $overwrite = false, $readonly = false) |
|
| 138 | + { |
|
| 139 | + self::validateArrayKeys($array); |
|
| 140 | 140 | |
| 141 | - $path = trim($path, '/'); |
|
| 141 | + $path = trim($path, '/'); |
|
| 142 | 142 | |
| 143 | 143 | if ($id = self::getId($path)) { |
| 144 | - if (! $overwrite) { |
|
| 145 | - self::extendArray($path, $array); |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 144 | + if (! $overwrite) { |
|
| 145 | + self::extendArray($path, $array); |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - self::create()->delete($id); |
|
| 150 | - } |
|
| 149 | + self::create()->delete($id); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - if(! $id = self::newId($path, $readonly)) return false; |
|
| 152 | + if(! $id = self::newId($path, $readonly)) return false; |
|
| 153 | 153 | |
| 154 | - if ($overwrite) { |
|
| 155 | - self::create()->tryLoad($id)->save(compact('readonly')); |
|
| 156 | - } |
|
| 154 | + if ($overwrite) { |
|
| 155 | + self::create()->tryLoad($id)->save(compact('readonly')); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - foreach ($array as $key => $value) { |
|
| 159 | - self::setValue($path . '/' . $key, $value, true, $readonly); |
|
| 160 | - } |
|
| 158 | + foreach ($array as $key => $value) { |
|
| 159 | + self::setValue($path . '/' . $key, $value, true, $readonly); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return true; |
|
| 163 | - } |
|
| 162 | + return true; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Extends common data array. |
|
| 167 | - * |
|
| 168 | - * @param $path string |
|
| 169 | - * @param $array array values to insert |
|
| 170 | - * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved |
|
| 171 | - */ |
|
| 172 | - public static function extendArray($path, $array, $overwrite=false, $readonly=false) |
|
| 173 | - { |
|
| 174 | - self::validateArrayKeys($array); |
|
| 165 | + /** |
|
| 166 | + * Extends common data array. |
|
| 167 | + * |
|
| 168 | + * @param $path string |
|
| 169 | + * @param $array array values to insert |
|
| 170 | + * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved |
|
| 171 | + */ |
|
| 172 | + public static function extendArray($path, $array, $overwrite=false, $readonly=false) |
|
| 173 | + { |
|
| 174 | + self::validateArrayKeys($array); |
|
| 175 | 175 | |
| 176 | - $path = trim($path, '/'); |
|
| 176 | + $path = trim($path, '/'); |
|
| 177 | 177 | |
| 178 | - if (! self::getId($path)){ |
|
| 179 | - return self::newArray($path, $array, $overwrite, $readonly); |
|
| 180 | - } |
|
| 178 | + if (! self::getId($path)){ |
|
| 179 | + return self::newArray($path, $array, $overwrite, $readonly); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - foreach ($array as $key => $value) { |
|
| 183 | - self::setValue($path . '/' . $key, $value, $overwrite, $readonly); |
|
| 184 | - } |
|
| 185 | - } |
|
| 182 | + foreach ($array as $key => $value) { |
|
| 183 | + self::setValue($path . '/' . $key, $value, $overwrite, $readonly); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Returns common data array. |
|
| 189 | - * |
|
| 190 | - * @param string array name |
|
| 191 | - * @return mixed returns an array if such array exists, false otherwise |
|
| 192 | - */ |
|
| 193 | - public static function getArray($path, $sortColumn = 'position', $silent = false) |
|
| 194 | - { |
|
| 195 | - return self::getCollection($path, $silent)->sortBy($sortColumn)->pluck('value', 'key')->all(); |
|
| 196 | - } |
|
| 187 | + /** |
|
| 188 | + * Returns common data array. |
|
| 189 | + * |
|
| 190 | + * @param string array name |
|
| 191 | + * @return mixed returns an array if such array exists, false otherwise |
|
| 192 | + */ |
|
| 193 | + public static function getArray($path, $sortColumn = 'position', $silent = false) |
|
| 194 | + { |
|
| 195 | + return self::getCollection($path, $silent)->sortBy($sortColumn)->pluck('value', 'key')->all(); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Removes common data array or entry. |
|
| 200 | - * |
|
| 201 | - * @param $path string |
|
| 202 | - * @return true on success, false otherwise |
|
| 203 | - */ |
|
| 204 | - public static function deleteArray($path){ |
|
| 205 | - if (! $id = self::getId($path, true)) return false; |
|
| 198 | + /** |
|
| 199 | + * Removes common data array or entry. |
|
| 200 | + * |
|
| 201 | + * @param $path string |
|
| 202 | + * @return true on success, false otherwise |
|
| 203 | + */ |
|
| 204 | + public static function deleteArray($path){ |
|
| 205 | + if (! $id = self::getId($path, true)) return false; |
|
| 206 | 206 | |
| 207 | - self::create()->delete($id); |
|
| 207 | + self::create()->delete($id); |
|
| 208 | 208 | |
| 209 | - self::clearCache(); |
|
| 210 | - } |
|
| 209 | + self::clearCache(); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - public static function siblings($parent = null) |
|
| 213 | - { |
|
| 214 | - $parentId = is_numeric($parent)? $parent: self::getId($parent); |
|
| 212 | + public static function siblings($parent = null) |
|
| 213 | + { |
|
| 214 | + $parentId = is_numeric($parent)? $parent: self::getId($parent); |
|
| 215 | 215 | |
| 216 | - $model = self::create(); |
|
| 216 | + $model = self::create(); |
|
| 217 | 217 | |
| 218 | - //@TODO: remove below when adding null condition fixed |
|
| 219 | - return $parentId? $model->addCondition('parent', $parentId): $model->addCondition($model->expr('parent is NULL')); |
|
| 220 | - } |
|
| 218 | + //@TODO: remove below when adding null condition fixed |
|
| 219 | + return $parentId? $model->addCondition('parent', $parentId): $model->addCondition($model->expr('parent is NULL')); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - public static function ancestors($node) |
|
| 223 | - { |
|
| 224 | - $node = is_numeric($node)? self::create()->tryLoad($node): $node; |
|
| 222 | + public static function ancestors($node) |
|
| 223 | + { |
|
| 224 | + $node = is_numeric($node)? self::create()->tryLoad($node): $node; |
|
| 225 | 225 | |
| 226 | - if (! $node['parent']) return []; |
|
| 226 | + if (! $node['parent']) return []; |
|
| 227 | 227 | |
| 228 | - return array_filter(array_merge([$node['parent']], self::ancestors($node['parent']))); |
|
| 229 | - } |
|
| 228 | + return array_filter(array_merge([$node['parent']], self::ancestors($node['parent']))); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - public static function ancestorsAndSelf($node) |
|
| 232 | - { |
|
| 233 | - $node = is_numeric($node)? self::create()->tryLoad($node): $node; |
|
| 231 | + public static function ancestorsAndSelf($node) |
|
| 232 | + { |
|
| 233 | + $node = is_numeric($node)? self::create()->tryLoad($node): $node; |
|
| 234 | 234 | |
| 235 | - return array_filter(array_merge([$node['id']], self::ancestors($node))); |
|
| 236 | - } |
|
| 235 | + return array_filter(array_merge([$node['id']], self::ancestors($node))); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Returns common data collection. |
|
| 240 | - * |
|
| 241 | - * @param $path string |
|
| 242 | - * @return Collection |
|
| 243 | - */ |
|
| 244 | - public static function getCollection($path, $silent = false) |
|
| 245 | - { |
|
| 246 | - if(isset(self::$cache['array'][$path])) { |
|
| 247 | - return self::$cache['array'][$path]; |
|
| 248 | - } |
|
| 238 | + /** |
|
| 239 | + * Returns common data collection. |
|
| 240 | + * |
|
| 241 | + * @param $path string |
|
| 242 | + * @return Collection |
|
| 243 | + */ |
|
| 244 | + public static function getCollection($path, $silent = false) |
|
| 245 | + { |
|
| 246 | + if(isset(self::$cache['array'][$path])) { |
|
| 247 | + return self::$cache['array'][$path]; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - if (! $id = self::getId($path)) { |
|
| 251 | - if ($silent) return collect(); |
|
| 250 | + if (! $id = self::getId($path)) { |
|
| 251 | + if ($silent) return collect(); |
|
| 252 | 252 | |
| 253 | - throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
|
| 254 | - } |
|
| 253 | + throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - return self::$cache['array'][$path] = collect(self::siblings($id)->export()); |
|
| 257 | - } |
|
| 256 | + return self::$cache['array'][$path] = collect(self::siblings($id)->export()); |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - protected static function validateArrayKeys($array) |
|
| 260 | - { |
|
| 261 | - foreach($array as $key => $value) { |
|
| 262 | - if (strpos($key, '/') === false) continue; |
|
| 259 | + protected static function validateArrayKeys($array) |
|
| 260 | + { |
|
| 261 | + foreach($array as $key => $value) { |
|
| 262 | + if (strpos($key, '/') === false) continue; |
|
| 263 | 263 | |
| 264 | - \Exception('Invalid common data key: '. $key); |
|
| 265 | - } |
|
| 266 | - } |
|
| 264 | + \Exception('Invalid common data key: '. $key); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | } |
| 268 | 268 | \ No newline at end of file |
@@ -50,12 +50,17 @@ discard block |
||
| 50 | 50 | foreach(explode('/', trim($path,'/')) as $nodeKey) { |
| 51 | 51 | $parentId = $id; |
| 52 | 52 | |
| 53 | - if ($nodeKey === '') continue; //ignore empty paths |
|
| 53 | + if ($nodeKey === '') { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + //ignore empty paths |
|
| 54 | 57 | |
| 55 | 58 | if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
| 56 | 59 | $node = self::siblings($parentId)->addCondition('key', $nodeKey)->tryLoadAny(); |
| 57 | 60 | |
| 58 | - if (! $node->loaded()) return false; |
|
| 61 | + if (! $node->loaded()) { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 59 | 64 | |
| 60 | 65 | self::$cache['id'][$parentId][$nodeKey] = $node->id; |
| 61 | 66 | } |
@@ -68,11 +73,15 @@ discard block |
||
| 68 | 73 | |
| 69 | 74 | public static function newId($path, $readonly = false) |
| 70 | 75 | { |
| 71 | - if (! $path = trim($path,'/')) return false; |
|
| 76 | + if (! $path = trim($path,'/')) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 72 | 79 | |
| 73 | 80 | $id = null; |
| 74 | 81 | foreach(explode('/', $path) as $nodeKey) { |
| 75 | - if ($nodeKey === '') continue; |
|
| 82 | + if ($nodeKey === '') { |
|
| 83 | + continue; |
|
| 84 | + } |
|
| 76 | 85 | |
| 77 | 86 | $parentId = $id; |
| 78 | 87 | |
@@ -80,8 +89,7 @@ discard block |
||
| 80 | 89 | |
| 81 | 90 | if ($node->loaded()) { |
| 82 | 91 | $id = $node->id; |
| 83 | - } |
|
| 84 | - else { |
|
| 92 | + } else { |
|
| 85 | 93 | $id = $node->insert([ |
| 86 | 94 | 'parent' => $parentId, |
| 87 | 95 | 'key' => $nodeKey, |
@@ -96,9 +104,13 @@ discard block |
||
| 96 | 104 | public static function setValue($path, $value, $overwrite = true, $readonly = false) |
| 97 | 105 | { |
| 98 | 106 | if (! $id = self::getId($path)) { |
| 99 | - if (! $id = self::newId($path, $readonly)) return false; |
|
| 107 | + if (! $id = self::newId($path, $readonly)) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 100 | 110 | } else { |
| 101 | - if (! $overwrite) return false; |
|
| 111 | + if (! $overwrite) { |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 102 | 114 | } |
| 103 | 115 | |
| 104 | 116 | self::create()->tryLoad($id)->save(compact('value', 'readonly')); |
@@ -118,7 +130,9 @@ discard block |
||
| 118 | 130 | $key = md5(serialize($path)); |
| 119 | 131 | |
| 120 | 132 | if (! isset(self::$cache['value'][$key])) { |
| 121 | - if(! $id = self::getId($path)) return false; |
|
| 133 | + if(! $id = self::getId($path)) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 122 | 136 | |
| 123 | 137 | self::$cache['value'][$key] = self::create()->tryLoad($id)->get('value'); |
| 124 | 138 | } |
@@ -149,7 +163,9 @@ discard block |
||
| 149 | 163 | self::create()->delete($id); |
| 150 | 164 | } |
| 151 | 165 | |
| 152 | - if(! $id = self::newId($path, $readonly)) return false; |
|
| 166 | + if(! $id = self::newId($path, $readonly)) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 153 | 169 | |
| 154 | 170 | if ($overwrite) { |
| 155 | 171 | self::create()->tryLoad($id)->save(compact('readonly')); |
@@ -202,7 +218,9 @@ discard block |
||
| 202 | 218 | * @return true on success, false otherwise |
| 203 | 219 | */ |
| 204 | 220 | public static function deleteArray($path){ |
| 205 | - if (! $id = self::getId($path, true)) return false; |
|
| 221 | + if (! $id = self::getId($path, true)) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 206 | 224 | |
| 207 | 225 | self::create()->delete($id); |
| 208 | 226 | |
@@ -223,7 +241,9 @@ discard block |
||
| 223 | 241 | { |
| 224 | 242 | $node = is_numeric($node)? self::create()->tryLoad($node): $node; |
| 225 | 243 | |
| 226 | - if (! $node['parent']) return []; |
|
| 244 | + if (! $node['parent']) { |
|
| 245 | + return []; |
|
| 246 | + } |
|
| 227 | 247 | |
| 228 | 248 | return array_filter(array_merge([$node['parent']], self::ancestors($node['parent']))); |
| 229 | 249 | } |
@@ -248,7 +268,9 @@ discard block |
||
| 248 | 268 | } |
| 249 | 269 | |
| 250 | 270 | if (! $id = self::getId($path)) { |
| 251 | - if ($silent) return collect(); |
|
| 271 | + if ($silent) { |
|
| 272 | + return collect(); |
|
| 273 | + } |
|
| 252 | 274 | |
| 253 | 275 | throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
| 254 | 276 | } |
@@ -259,7 +281,9 @@ discard block |
||
| 259 | 281 | protected static function validateArrayKeys($array) |
| 260 | 282 | { |
| 261 | 283 | foreach($array as $key => $value) { |
| 262 | - if (strpos($key, '/') === false) continue; |
|
| 284 | + if (strpos($key, '/') === false) { |
|
| 285 | + continue; |
|
| 286 | + } |
|
| 263 | 287 | |
| 264 | 288 | \Exception('Invalid common data key: '. $key); |
| 265 | 289 | } |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | public $path = ''; |
| 18 | 18 | |
| 19 | 19 | public $serialize = [ |
| 20 | - [__CLASS__, 'serialize'], |
|
| 21 | - [__CLASS__, 'unserialize'], |
|
| 20 | + [__CLASS__, 'serialize'], |
|
| 21 | + [__CLASS__, 'unserialize'], |
|
| 22 | 22 | ]; |
| 23 | 23 | |
| 24 | 24 | public $multiple = false; |
@@ -33,75 +33,75 @@ discard block |
||
| 33 | 33 | $this->_init(); |
| 34 | 34 | |
| 35 | 35 | if ($this->getDependency()) { |
| 36 | - $this->ui['form'] = [ |
|
| 37 | - 'AutoComplete', |
|
| 38 | - 'model' => CommonDataModel::create(), |
|
| 39 | - 'dependency' => function($model, $data) { |
|
| 40 | - $model->addCondition('parent', CommonDataModel::getId($this->getDependencyPath($data))); |
|
| 41 | - }, |
|
| 42 | - 'renderRowFunction' => function($field, $row) { |
|
| 43 | - return [ |
|
| 44 | - 'value' => $row['key'], |
|
| 45 | - 'title' => $row['value'] ?: $row['key'], |
|
| 46 | - ]; |
|
| 47 | - }, |
|
| 48 | - 'multiple' => $this->multiple |
|
| 49 | - ]; |
|
| 36 | + $this->ui['form'] = [ |
|
| 37 | + 'AutoComplete', |
|
| 38 | + 'model' => CommonDataModel::create(), |
|
| 39 | + 'dependency' => function($model, $data) { |
|
| 40 | + $model->addCondition('parent', CommonDataModel::getId($this->getDependencyPath($data))); |
|
| 41 | + }, |
|
| 42 | + 'renderRowFunction' => function($field, $row) { |
|
| 43 | + return [ |
|
| 44 | + 'value' => $row['key'], |
|
| 45 | + 'title' => $row['value'] ?: $row['key'], |
|
| 46 | + ]; |
|
| 47 | + }, |
|
| 48 | + 'multiple' => $this->multiple |
|
| 49 | + ]; |
|
| 50 | 50 | } else { |
| 51 | - $this->values = CommonDataModel::getArray($this->path); |
|
| 51 | + $this->values = CommonDataModel::getArray($this->path); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $this->ui = array_merge([ |
| 55 | - 'table' => ['Multiformat', [$this, 'format']], |
|
| 56 | - 'form' => ['isMultiple' => $this->multiple] |
|
| 55 | + 'table' => ['Multiformat', [$this, 'format']], |
|
| 56 | + 'form' => ['isMultiple' => $this->multiple] |
|
| 57 | 57 | ], $this->ui); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function getDependency() |
| 61 | 61 | { |
| 62 | - $fields = (array) $this->path; |
|
| 62 | + $fields = (array) $this->path; |
|
| 63 | 63 | |
| 64 | - $path = array_shift($fields); |
|
| 64 | + $path = array_shift($fields); |
|
| 65 | 65 | |
| 66 | - return $fields? compact('path', 'fields'): false; |
|
| 66 | + return $fields? compact('path', 'fields'): false; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function getDependencyPath($data) |
| 70 | 70 | { |
| 71 | - if (! $dependency = $this->getDependency()) return false; |
|
| 71 | + if (! $dependency = $this->getDependency()) return false; |
|
| 72 | 72 | |
| 73 | - return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields'])))); |
|
| 73 | + return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields'])))); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | public function getValues($data) |
| 77 | 77 | { |
| 78 | - $path = $this->getDependencyPath($data) ?: $this->path; |
|
| 78 | + $path = $this->getDependencyPath($data) ?: $this->path; |
|
| 79 | 79 | |
| 80 | - return CommonDataModel::getArray($path); |
|
| 80 | + return CommonDataModel::getArray($path); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public static function serialize($field, $value, $persistence) |
| 84 | 84 | { |
| 85 | - return $field->multiple? implode(',', (array) $value): $value; |
|
| 85 | + return $field->multiple? implode(',', (array) $value): $value; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | public static function unserialize($field, $value, $persistence) |
| 89 | 89 | { |
| 90 | - return $field->multiple? explode(',', $value): $value; |
|
| 90 | + return $field->multiple? explode(',', $value): $value; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | public function format($row, $field) |
| 94 | 94 | { |
| 95 | - $values = array_intersect_key($this->getValues($row->get()), array_flip((array) $row[$field])); |
|
| 95 | + $values = array_intersect_key($this->getValues($row->get()), array_flip((array) $row[$field])); |
|
| 96 | 96 | |
| 97 | - return [[ |
|
| 98 | - 'Template', |
|
| 99 | - implode('<br>', $values), |
|
| 100 | - ]]; |
|
| 97 | + return [[ |
|
| 98 | + 'Template', |
|
| 99 | + implode('<br>', $values), |
|
| 100 | + ]]; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public function normalize($value) |
| 104 | 104 | { |
| 105 | - return $this->multiple? parent::normalize($value): $value; |
|
| 105 | + return $this->multiple? parent::normalize($value): $value; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | \ No newline at end of file |
@@ -68,7 +68,9 @@ |
||
| 68 | 68 | |
| 69 | 69 | public function getDependencyPath($data) |
| 70 | 70 | { |
| 71 | - if (! $dependency = $this->getDependency()) return false; |
|
| 71 | + if (! $dependency = $this->getDependency()) { |
|
| 72 | + return false; |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | return implode('/', array_merge([$dependency['path']], array_intersect_key($data, array_flip($dependency['fields'])))); |
| 74 | 76 | } |
@@ -7,21 +7,21 @@ |
||
| 7 | 7 | |
| 8 | 8 | class DashboardApplet extends Model |
| 9 | 9 | { |
| 10 | - use HasEpesiConnection; |
|
| 10 | + use HasEpesiConnection; |
|
| 11 | 11 | |
| 12 | - public $table = 'dashboard_applets'; |
|
| 12 | + public $table = 'dashboard_applets'; |
|
| 13 | 13 | |
| 14 | - public function init() |
|
| 15 | - { |
|
| 16 | - parent::init(); |
|
| 14 | + public function init() |
|
| 15 | + { |
|
| 16 | + parent::init(); |
|
| 17 | 17 | |
| 18 | - $this->addFields([ |
|
| 19 | - 'class' => ['type' => 'string'], |
|
| 20 | - 'column' => ['type' => 'integer', 'default' => 1], |
|
| 21 | - 'row' => ['type' => 'integer', 'default' => 0], |
|
| 22 | - 'options' => ['type' => 'array', 'default' => []] |
|
| 23 | - ]); |
|
| 18 | + $this->addFields([ |
|
| 19 | + 'class' => ['type' => 'string'], |
|
| 20 | + 'column' => ['type' => 'integer', 'default' => 1], |
|
| 21 | + 'row' => ['type' => 'integer', 'default' => 0], |
|
| 22 | + 'options' => ['type' => 'array', 'default' => []] |
|
| 23 | + ]); |
|
| 24 | 24 | |
| 25 | - $this->hasOne('dashboard', [Dashboard::class, 'our_field' => 'dashboard_id']); |
|
| 26 | - } |
|
| 25 | + $this->hasOne('dashboard', [Dashboard::class, 'our_field' => 'dashboard_id']); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -8,25 +8,25 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Dashboard extends Model |
| 10 | 10 | { |
| 11 | - use HasEpesiConnection; |
|
| 11 | + use HasEpesiConnection; |
|
| 12 | 12 | |
| 13 | - public $table = 'dashboards'; |
|
| 13 | + public $table = 'dashboards'; |
|
| 14 | 14 | |
| 15 | - public function init() |
|
| 16 | - { |
|
| 17 | - parent::init(); |
|
| 15 | + public function init() |
|
| 16 | + { |
|
| 17 | + parent::init(); |
|
| 18 | 18 | |
| 19 | - $this->addFields([ |
|
| 20 | - 'name' => ['type' => 'string'], |
|
| 21 | - 'position' => ['type' => 'integer', 'default' => 0] |
|
| 22 | - ]); |
|
| 19 | + $this->addFields([ |
|
| 20 | + 'name' => ['type' => 'string'], |
|
| 21 | + 'position' => ['type' => 'integer', 'default' => 0] |
|
| 22 | + ]); |
|
| 23 | 23 | |
| 24 | - $this->hasOne('user', [User::class, 'our_field' => 'user_id']); |
|
| 24 | + $this->hasOne('user', [User::class, 'our_field' => 'user_id']); |
|
| 25 | 25 | |
| 26 | - $this->hasMany('applets', [DashboardApplet::class, 'their_field' => 'dashboard_id']); |
|
| 26 | + $this->hasMany('applets', [DashboardApplet::class, 'their_field' => 'dashboard_id']); |
|
| 27 | 27 | |
| 28 | - $this->addHook('beforeDelete', function($id) { |
|
| 29 | - $this->withID($id)->ref('applets')->action('delete')->execute(); |
|
| 30 | - }); |
|
| 31 | - } |
|
| 28 | + $this->addHook('beforeDelete', function($id) { |
|
| 29 | + $this->withID($id)->ref('applets')->action('delete')->execute(); |
|
| 30 | + }); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -18,23 +18,23 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function install() |
| 20 | 20 | { |
| 21 | - Models\Dashboard::migrate(); |
|
| 22 | - Models\DashboardApplet::migrate(); |
|
| 21 | + Models\Dashboard::migrate(); |
|
| 22 | + Models\DashboardApplet::migrate(); |
|
| 23 | 23 | |
| 24 | 24 | // setup default dashboard |
| 25 | - $dashboardId = (int) Models\Dashboard::create()->insert([ |
|
| 25 | + $dashboardId = (int) Models\Dashboard::create()->insert([ |
|
| 26 | 26 | 'user_id' => 0, |
| 27 | 27 | 'name' => __('Admin Default') |
| 28 | 28 | ]); |
| 29 | 29 | |
| 30 | - Models\DashboardApplet::create()->insert([ |
|
| 31 | - [ |
|
| 32 | - 'dashboard_id' => $dashboardId, |
|
| 33 | - 'class' => 'Epesi\\Applets\\Clock\\ClockApplet', |
|
| 34 | - 'row' => 0, |
|
| 35 | - 'column' => 3, |
|
| 36 | - ] |
|
| 37 | - ]); |
|
| 30 | + Models\DashboardApplet::create()->insert([ |
|
| 31 | + [ |
|
| 32 | + 'dashboard_id' => $dashboardId, |
|
| 33 | + 'class' => 'Epesi\\Applets\\Clock\\ClockApplet', |
|
| 34 | + 'row' => 0, |
|
| 35 | + 'column' => 3, |
|
| 36 | + ] |
|
| 37 | + ]); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public static function info() |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | // create user default dashboard as copy of the system default |
| 53 | 53 | User::created(function(User $user) { |
| 54 | - if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return; |
|
| 54 | + if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return; |
|
| 55 | 55 | $userDefaultDashboard = (clone $defaultDashboard)->duplicate()->save([ |
| 56 | - 'name' => __('Default'), |
|
| 57 | - 'user_id' => $user->id |
|
| 56 | + 'name' => __('Default'), |
|
| 57 | + 'user_id' => $user->id |
|
| 58 | 58 | ]); |
| 59 | 59 | |
| 60 | 60 | foreach ($defaultDashboard->ref('applets') as $defaultApplet) { |
| 61 | - $defaultApplet->duplicate()->saveAndUnload(['dashboard_id' => $userDefaultDashboard->id]); |
|
| 61 | + $defaultApplet->duplicate()->saveAndUnload(['dashboard_id' => $userDefaultDashboard->id]); |
|
| 62 | 62 | } |
| 63 | 63 | }); |
| 64 | 64 | } |
@@ -51,7 +51,9 @@ |
||
| 51 | 51 | { |
| 52 | 52 | // create user default dashboard as copy of the system default |
| 53 | 53 | User::created(function(User $user) { |
| 54 | - if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) return; |
|
| 54 | + if (! $defaultDashboard = Models\Dashboard::create()->addCondition('user_id', 0)->tryLoadAny()) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 55 | 57 | $userDefaultDashboard = (clone $defaultDashboard)->duplicate()->save([ |
| 56 | 58 | 'name' => __('Default'), |
| 57 | 59 | 'user_id' => $user->id |