@@ -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'])); |
@@ -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 | } |
@@ -31,7 +31,9 @@ |
||
| 31 | 31 | { |
| 32 | 32 | // create user default dashboard as copy of the system default |
| 33 | 33 | User::created(function(User $user) { |
| 34 | - if (! $defaultDashboard = Dashboard::where('user_id', 0)->first()) return; |
|
| 34 | + if (! $defaultDashboard = Dashboard::where('user_id', 0)->first()) { |
|
| 35 | + return; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $userDefaultDashboard = $defaultDashboard->replicate(); |
| 37 | 39 | |
@@ -6,42 +6,42 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CreateDashboardTables extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - $this->down(); |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + $this->down(); |
|
| 17 | 17 | |
| 18 | - Schema::create('dashboards', function (Blueprint $table) { |
|
| 19 | - $table->increments('id'); |
|
| 20 | - $table->unsignedInteger('user_id'); |
|
| 21 | - $table->string('name', 64); |
|
| 22 | - $table->smallInteger('position')->default(0); |
|
| 23 | - }); |
|
| 18 | + Schema::create('dashboards', function (Blueprint $table) { |
|
| 19 | + $table->increments('id'); |
|
| 20 | + $table->unsignedInteger('user_id'); |
|
| 21 | + $table->string('name', 64); |
|
| 22 | + $table->smallInteger('position')->default(0); |
|
| 23 | + }); |
|
| 24 | 24 | |
| 25 | - Schema::create('dashboard_applets', function (Blueprint $table) { |
|
| 26 | - $table->increments('id'); |
|
| 27 | - $table->unsignedInteger('dashboard_id'); |
|
| 28 | - $table->string('class', 512); |
|
| 29 | - $table->smallInteger('column')->default(1); |
|
| 30 | - $table->smallInteger('row')->default(0); |
|
| 31 | - $table->text('options')->nullable(); |
|
| 25 | + Schema::create('dashboard_applets', function (Blueprint $table) { |
|
| 26 | + $table->increments('id'); |
|
| 27 | + $table->unsignedInteger('dashboard_id'); |
|
| 28 | + $table->string('class', 512); |
|
| 29 | + $table->smallInteger('column')->default(1); |
|
| 30 | + $table->smallInteger('row')->default(0); |
|
| 31 | + $table->text('options')->nullable(); |
|
| 32 | 32 | |
| 33 | - $table->foreign('dashboard_id')->references('id')->on('dashboards'); |
|
| 34 | - }); |
|
| 35 | - } |
|
| 33 | + $table->foreign('dashboard_id')->references('id')->on('dashboards'); |
|
| 34 | + }); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Reverse the migrations. |
|
| 39 | - * |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function down() |
|
| 43 | - { |
|
| 44 | - Schema::dropIfExists('dashboard_applets'); |
|
| 45 | - Schema::dropIfExists('dashboards'); |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * Reverse the migrations. |
|
| 39 | + * |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function down() |
|
| 43 | + { |
|
| 44 | + Schema::dropIfExists('dashboard_applets'); |
|
| 45 | + Schema::dropIfExists('dashboards'); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -6,31 +6,31 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CreateCommondataTable extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - Schema::create('commondata', function (Blueprint $table) { |
|
| 17 | - $table->bigIncrements('id'); |
|
| 18 | - $table->nestedSet(); |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + Schema::create('commondata', function (Blueprint $table) { |
|
| 17 | + $table->bigIncrements('id'); |
|
| 18 | + $table->nestedSet(); |
|
| 19 | 19 | |
| 20 | - $table->string('key', 64); |
|
| 21 | - $table->text('value')->nullable(); |
|
| 22 | - $table->integer('position')->nullable()->default(0); |
|
| 23 | - $table->smallInteger('readonly')->nullable()->default(0); |
|
| 24 | - }); |
|
| 25 | - } |
|
| 20 | + $table->string('key', 64); |
|
| 21 | + $table->text('value')->nullable(); |
|
| 22 | + $table->integer('position')->nullable()->default(0); |
|
| 23 | + $table->smallInteger('readonly')->nullable()->default(0); |
|
| 24 | + }); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Reverse the migrations. |
|
| 29 | - * |
|
| 30 | - * @return void |
|
| 31 | - */ |
|
| 32 | - public function down() |
|
| 33 | - { |
|
| 34 | - Schema::dropIfExists('commondata'); |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Reverse the migrations. |
|
| 29 | + * |
|
| 30 | + * @return void |
|
| 31 | + */ |
|
| 32 | + public function down() |
|
| 33 | + { |
|
| 34 | + Schema::dropIfExists('commondata'); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -112,7 +112,9 @@ |
||
| 112 | 112 | |
| 113 | 113 | public function getControlButtonsHtml($row) |
| 114 | 114 | { |
| 115 | - if ($row['readonly']) return ''; |
|
| 115 | + if ($row['readonly']) { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 116 | 118 | |
| 117 | 119 | $ret = ''; |
| 118 | 120 | foreach ($this->buttons as $button) { |
@@ -25,81 +25,81 @@ |
||
| 25 | 25 | $this->loadMigrationsFrom(__DIR__ . '../../src/CommonData/Database/Migrations'); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function testStoreRetrieve() |
|
| 29 | - { |
|
| 30 | - // creating - retrieving array |
|
| 31 | - $arrayExpected = ['c' => 'cc', 'b' => 'bb', 'a' => 'aa', ]; |
|
| 28 | + public function testStoreRetrieve() |
|
| 29 | + { |
|
| 30 | + // creating - retrieving array |
|
| 31 | + $arrayExpected = ['c' => 'cc', 'b' => 'bb', 'a' => 'aa', ]; |
|
| 32 | 32 | |
| 33 | - CommonData::newArray('abc/def', $arrayExpected); |
|
| 33 | + CommonData::newArray('abc/def', $arrayExpected); |
|
| 34 | 34 | |
| 35 | - $arrayActual = CommonData::getArray('abc/def'); |
|
| 35 | + $arrayActual = CommonData::getArray('abc/def'); |
|
| 36 | 36 | |
| 37 | - $this->assertEquals($arrayExpected, $arrayActual, 'Problem retrieving commondata sorted by position!'); |
|
| 37 | + $this->assertEquals($arrayExpected, $arrayActual, 'Problem retrieving commondata sorted by position!'); |
|
| 38 | 38 | |
| 39 | - // retrieving sorted array by key |
|
| 40 | - $arraySortKey = $arrayExpected; |
|
| 41 | - ksort($arraySortKey); |
|
| 39 | + // retrieving sorted array by key |
|
| 40 | + $arraySortKey = $arrayExpected; |
|
| 41 | + ksort($arraySortKey); |
|
| 42 | 42 | |
| 43 | - $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'key'), 'Problem retrieving commondata sorted by key!'); |
|
| 43 | + $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'key'), 'Problem retrieving commondata sorted by key!'); |
|
| 44 | 44 | |
| 45 | - // retrieving sorted array by value |
|
| 46 | - $arraySortValue = $arrayExpected; |
|
| 47 | - sort($arraySortValue); |
|
| 45 | + // retrieving sorted array by value |
|
| 46 | + $arraySortValue = $arrayExpected; |
|
| 47 | + sort($arraySortValue); |
|
| 48 | 48 | |
| 49 | - $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'value'), 'Problem retrieving commondata sorted by value!'); |
|
| 49 | + $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'value'), 'Problem retrieving commondata sorted by value!'); |
|
| 50 | 50 | |
| 51 | - // retrieving array value |
|
| 52 | - $valueActual = CommonData::getValue('abc/def/a'); |
|
| 51 | + // retrieving array value |
|
| 52 | + $valueActual = CommonData::getValue('abc/def/a'); |
|
| 53 | 53 | |
| 54 | - $this->assertEquals($arrayExpected['a'], $valueActual, 'Problem retrieving commondata value!'); |
|
| 54 | + $this->assertEquals($arrayExpected['a'], $valueActual, 'Problem retrieving commondata value!'); |
|
| 55 | 55 | |
| 56 | - // setting array values |
|
| 57 | - $arrayChanged = ['a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc']; |
|
| 56 | + // setting array values |
|
| 57 | + $arrayChanged = ['a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc']; |
|
| 58 | 58 | |
| 59 | - foreach ($arrayChanged as $key => $value) { |
|
| 60 | - CommonData::setValue('abc/def/' . $key, $value); |
|
| 61 | - } |
|
| 59 | + foreach ($arrayChanged as $key => $value) { |
|
| 60 | + CommonData::setValue('abc/def/' . $key, $value); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $arrayActual = CommonData::getArray('abc/def'); |
|
| 63 | + $arrayActual = CommonData::getArray('abc/def'); |
|
| 64 | 64 | |
| 65 | - $this->assertEquals($arrayChanged, $arrayActual, 'Problem setting commondata value!'); |
|
| 65 | + $this->assertEquals($arrayChanged, $arrayActual, 'Problem setting commondata value!'); |
|
| 66 | 66 | |
| 67 | - // deleting array node |
|
| 68 | - unset($arrayChanged['a']); |
|
| 67 | + // deleting array node |
|
| 68 | + unset($arrayChanged['a']); |
|
| 69 | 69 | |
| 70 | - CommonData::deleteArray('abc/def/a'); |
|
| 70 | + CommonData::deleteArray('abc/def/a'); |
|
| 71 | 71 | |
| 72 | - $arrayActual = CommonData::getArray('abc/def'); |
|
| 72 | + $arrayActual = CommonData::getArray('abc/def'); |
|
| 73 | 73 | |
| 74 | - $this->assertEquals($arrayChanged, $arrayActual, 'Problem deleting commondata node!'); |
|
| 74 | + $this->assertEquals($arrayChanged, $arrayActual, 'Problem deleting commondata node!'); |
|
| 75 | 75 | |
| 76 | - // extending array |
|
| 77 | - $arrayExtension = ['a' => 'aaa']; |
|
| 76 | + // extending array |
|
| 77 | + $arrayExtension = ['a' => 'aaa']; |
|
| 78 | 78 | |
| 79 | - $arrayChanged = array_merge($arrayChanged, $arrayExtension); |
|
| 79 | + $arrayChanged = array_merge($arrayChanged, $arrayExtension); |
|
| 80 | 80 | |
| 81 | - CommonData::extendArray('abc/def', $arrayExtension); |
|
| 81 | + CommonData::extendArray('abc/def', $arrayExtension); |
|
| 82 | 82 | |
| 83 | - $arrayActual = CommonData::getArray('abc/def'); |
|
| 83 | + $arrayActual = CommonData::getArray('abc/def'); |
|
| 84 | 84 | |
| 85 | - $this->assertEquals($arrayChanged, $arrayActual, 'Problem extending commondata array!'); |
|
| 86 | - } |
|
| 85 | + $this->assertEquals($arrayChanged, $arrayActual, 'Problem extending commondata array!'); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function testNonExistingArrayException() |
|
| 89 | - { |
|
| 90 | - $this->expectException(CommonDataNotFound::class); |
|
| 88 | + public function testNonExistingArrayException() |
|
| 89 | + { |
|
| 90 | + $this->expectException(CommonDataNotFound::class); |
|
| 91 | 91 | |
| 92 | - CommonData::getArray('abc/d/ef'); |
|
| 93 | - } |
|
| 92 | + CommonData::getArray('abc/d/ef'); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function testNonExistingArraySilent() |
|
| 96 | - { |
|
| 97 | - $this->assertEquals([], CommonData::getArray('abc/d/ef', 'position', true), 'Problem retrieving non-existent commondata array silently!'); |
|
| 98 | - } |
|
| 95 | + public function testNonExistingArraySilent() |
|
| 96 | + { |
|
| 97 | + $this->assertEquals([], CommonData::getArray('abc/d/ef', 'position', true), 'Problem retrieving non-existent commondata array silently!'); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - public function testNonExistingValue() |
|
| 101 | - { |
|
| 102 | - $this->assertFalse(CommonData::getValue('abc/d/ef'), 'Problem retrieving non-existent commondata value!'); |
|
| 103 | - } |
|
| 100 | + public function testNonExistingValue() |
|
| 101 | + { |
|
| 102 | + $this->assertFalse(CommonData::getValue('abc/d/ef'), 'Problem retrieving non-existent commondata value!'); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | } |
@@ -9,204 +9,204 @@ |
||
| 9 | 9 | class CommonDataNotFound extends \Exception {} |
| 10 | 10 | |
| 11 | 11 | class CommonData extends Model { |
| 12 | - use NodeTrait; |
|
| 12 | + use NodeTrait; |
|
| 13 | 13 | |
| 14 | - protected $table = 'commondata'; |
|
| 15 | - public $timestamps = false; |
|
| 16 | - protected static $unguarded = true; |
|
| 14 | + protected $table = 'commondata'; |
|
| 15 | + public $timestamps = false; |
|
| 16 | + protected static $unguarded = true; |
|
| 17 | 17 | |
| 18 | - protected static $cache = [ |
|
| 19 | - 'id' => [], |
|
| 20 | - 'value' => [], |
|
| 21 | - 'array' => [] |
|
| 22 | - ]; |
|
| 18 | + protected static $cache = [ |
|
| 19 | + 'id' => [], |
|
| 20 | + 'value' => [], |
|
| 21 | + 'array' => [] |
|
| 22 | + ]; |
|
| 23 | 23 | |
| 24 | - public static function getId($path, $clearCache = false) |
|
| 25 | - { |
|
| 26 | - $parentId = null; |
|
| 27 | - foreach(explode('/', trim($path,'/')) as $nodeKey) { |
|
| 28 | - if ($nodeKey === '') continue; //ignore empty paths |
|
| 24 | + public static function getId($path, $clearCache = false) |
|
| 25 | + { |
|
| 26 | + $parentId = null; |
|
| 27 | + foreach(explode('/', trim($path,'/')) as $nodeKey) { |
|
| 28 | + if ($nodeKey === '') continue; //ignore empty paths |
|
| 29 | 29 | |
| 30 | - if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
|
| 31 | - if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
|
| 32 | - return false; |
|
| 33 | - } |
|
| 30 | + if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
|
| 31 | + if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
|
| 32 | + return false; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - self::$cache['id'][$parentId][$nodeKey] = $node->id; |
|
| 36 | - } |
|
| 35 | + self::$cache['id'][$parentId][$nodeKey] = $node->id; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $parentId = $id = self::$cache['id'][$parentId][$nodeKey]; |
|
| 39 | - } |
|
| 38 | + $parentId = $id = self::$cache['id'][$parentId][$nodeKey]; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $id; |
|
| 42 | - } |
|
| 41 | + return $id; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public static function newId($path, $readonly = false) |
|
| 45 | - { |
|
| 46 | - if (! $path = trim($path,'/')) return false; |
|
| 44 | + public static function newId($path, $readonly = false) |
|
| 45 | + { |
|
| 46 | + if (! $path = trim($path,'/')) return false; |
|
| 47 | 47 | |
| 48 | - $id = $parentId = null; |
|
| 49 | - foreach(explode('/', $path) as $nodeKey) { |
|
| 50 | - if ($nodeKey === '') continue; |
|
| 48 | + $id = $parentId = null; |
|
| 49 | + foreach(explode('/', $path) as $nodeKey) { |
|
| 50 | + if ($nodeKey === '') continue; |
|
| 51 | 51 | |
| 52 | - if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
|
| 53 | - $node = self::create([ |
|
| 54 | - 'parent_id' => $parentId, |
|
| 55 | - 'key' => $nodeKey, |
|
| 56 | - 'readonly' => $readonly, |
|
| 57 | - 'position' => self::where('parent_id', $parentId)->count() |
|
| 58 | - ], $parentId? self::find($parentId): null); |
|
| 59 | - } |
|
| 52 | + if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
|
| 53 | + $node = self::create([ |
|
| 54 | + 'parent_id' => $parentId, |
|
| 55 | + 'key' => $nodeKey, |
|
| 56 | + 'readonly' => $readonly, |
|
| 57 | + 'position' => self::where('parent_id', $parentId)->count() |
|
| 58 | + ], $parentId? self::find($parentId): null); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $parentId = $id = $node->id; |
|
| 62 | - } |
|
| 61 | + $parentId = $id = $node->id; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $id; |
|
| 65 | - } |
|
| 64 | + return $id; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public static function setValue($path, $value, $overwrite = true, $readonly = false) |
|
| 68 | - { |
|
| 69 | - if (! $id = self::getId($path)) { |
|
| 70 | - if (! $id = self::newId($path, $readonly)) return false; |
|
| 71 | - } else { |
|
| 72 | - if (! $overwrite) return false; |
|
| 73 | - } |
|
| 67 | + public static function setValue($path, $value, $overwrite = true, $readonly = false) |
|
| 68 | + { |
|
| 69 | + if (! $id = self::getId($path)) { |
|
| 70 | + if (! $id = self::newId($path, $readonly)) return false; |
|
| 71 | + } else { |
|
| 72 | + if (! $overwrite) return false; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - self::findOrFail($id)->update(compact('value', 'readonly')); |
|
| 75 | + self::findOrFail($id)->update(compact('value', 'readonly')); |
|
| 76 | 76 | |
| 77 | - self::clearCache(); |
|
| 77 | + self::clearCache(); |
|
| 78 | 78 | |
| 79 | - return true; |
|
| 80 | - } |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public static function clearCache() |
|
| 83 | - { |
|
| 84 | - self::$cache = array_fill_keys(array_keys(self::$cache), []); |
|
| 85 | - } |
|
| 82 | + public static function clearCache() |
|
| 83 | + { |
|
| 84 | + self::$cache = array_fill_keys(array_keys(self::$cache), []); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public static function getValue($path, $translate = false) |
|
| 88 | - { |
|
| 89 | - $key = md5(serialize($path)); |
|
| 87 | + public static function getValue($path, $translate = false) |
|
| 88 | + { |
|
| 89 | + $key = md5(serialize($path)); |
|
| 90 | 90 | |
| 91 | - if (! isset(self::$cache['value'][$key])) { |
|
| 92 | - if(! $id = self::getId($path)) return false; |
|
| 91 | + if (! isset(self::$cache['value'][$key])) { |
|
| 92 | + if(! $id = self::getId($path)) return false; |
|
| 93 | 93 | |
| 94 | - self::$cache['value'][$key] = self::find($id)->value; |
|
| 95 | - } |
|
| 94 | + self::$cache['value'][$key] = self::find($id)->value; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key]; |
|
| 98 | - } |
|
| 97 | + return $translate? __(self::$cache['value'][$key]): self::$cache['value'][$key]; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Creates new array for common use. |
|
| 102 | - * |
|
| 103 | - * @param $path string |
|
| 104 | - * @param $array array initialization value |
|
| 105 | - * @param $overwrite bool whether method should overwrite if array already exists, otherwise the data will be appended |
|
| 106 | - * @param $readonly bool do not allow user to change this array from GUI |
|
| 107 | - */ |
|
| 108 | - public static function newArray($path, $array, $overwrite = false, $readonly = false) |
|
| 109 | - { |
|
| 110 | - self::validateArrayKeys($array); |
|
| 100 | + /** |
|
| 101 | + * Creates new array for common use. |
|
| 102 | + * |
|
| 103 | + * @param $path string |
|
| 104 | + * @param $array array initialization value |
|
| 105 | + * @param $overwrite bool whether method should overwrite if array already exists, otherwise the data will be appended |
|
| 106 | + * @param $readonly bool do not allow user to change this array from GUI |
|
| 107 | + */ |
|
| 108 | + public static function newArray($path, $array, $overwrite = false, $readonly = false) |
|
| 109 | + { |
|
| 110 | + self::validateArrayKeys($array); |
|
| 111 | 111 | |
| 112 | - $path = trim($path, '/'); |
|
| 112 | + $path = trim($path, '/'); |
|
| 113 | 113 | |
| 114 | 114 | if ($id = self::getId($path)) { |
| 115 | - if (! $overwrite) { |
|
| 116 | - self::extendArray($path, $array); |
|
| 117 | - return true; |
|
| 118 | - } |
|
| 115 | + if (! $overwrite) { |
|
| 116 | + self::extendArray($path, $array); |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - self::find($id)->delete(); |
|
| 121 | - } |
|
| 120 | + self::find($id)->delete(); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - if(! $id = self::newId($path, $readonly)) return false; |
|
| 123 | + if(! $id = self::newId($path, $readonly)) return false; |
|
| 124 | 124 | |
| 125 | - if ($overwrite) { |
|
| 126 | - self::find($id)->update(compact('readonly')); |
|
| 127 | - } |
|
| 125 | + if ($overwrite) { |
|
| 126 | + self::find($id)->update(compact('readonly')); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - foreach ($array as $key => $value) { |
|
| 130 | - self::setValue($path . '/' . $key, $value, true, $readonly); |
|
| 131 | - } |
|
| 129 | + foreach ($array as $key => $value) { |
|
| 130 | + self::setValue($path . '/' . $key, $value, true, $readonly); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return true; |
|
| 134 | - } |
|
| 133 | + return true; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Extends common data array. |
|
| 138 | - * |
|
| 139 | - * @param $path string |
|
| 140 | - * @param $array array values to insert |
|
| 141 | - * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved |
|
| 142 | - */ |
|
| 143 | - public static function extendArray($path, $array, $overwrite=false, $readonly=false) |
|
| 144 | - { |
|
| 145 | - self::validateArrayKeys($array); |
|
| 136 | + /** |
|
| 137 | + * Extends common data array. |
|
| 138 | + * |
|
| 139 | + * @param $path string |
|
| 140 | + * @param $array array values to insert |
|
| 141 | + * @param $overwrite bool whether method should overwrite data if array key already exists, otherwise the data will be preserved |
|
| 142 | + */ |
|
| 143 | + public static function extendArray($path, $array, $overwrite=false, $readonly=false) |
|
| 144 | + { |
|
| 145 | + self::validateArrayKeys($array); |
|
| 146 | 146 | |
| 147 | - $path = trim($path, '/'); |
|
| 147 | + $path = trim($path, '/'); |
|
| 148 | 148 | |
| 149 | - if (! self::getId($path)){ |
|
| 150 | - return self::newArray($path, $array, $overwrite, $readonly); |
|
| 151 | - } |
|
| 149 | + if (! self::getId($path)){ |
|
| 150 | + return self::newArray($path, $array, $overwrite, $readonly); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - foreach ($array as $key => $value) { |
|
| 154 | - self::setValue($path . '/' . $key, $value, $overwrite, $readonly); |
|
| 155 | - } |
|
| 156 | - } |
|
| 153 | + foreach ($array as $key => $value) { |
|
| 154 | + self::setValue($path . '/' . $key, $value, $overwrite, $readonly); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Returns common data array. |
|
| 160 | - * |
|
| 161 | - * @param string array name |
|
| 162 | - * @return mixed returns an array if such array exists, false otherwise |
|
| 163 | - */ |
|
| 164 | - public static function getArray($path, $sortColumn = 'position', $silent = false) |
|
| 165 | - { |
|
| 166 | - return self::getCollection($path, $silent)->sortBy($sortColumn)->pluck('value', 'key')->all(); |
|
| 167 | - } |
|
| 158 | + /** |
|
| 159 | + * Returns common data array. |
|
| 160 | + * |
|
| 161 | + * @param string array name |
|
| 162 | + * @return mixed returns an array if such array exists, false otherwise |
|
| 163 | + */ |
|
| 164 | + public static function getArray($path, $sortColumn = 'position', $silent = false) |
|
| 165 | + { |
|
| 166 | + return self::getCollection($path, $silent)->sortBy($sortColumn)->pluck('value', 'key')->all(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Removes common data array or entry. |
|
| 171 | - * |
|
| 172 | - * @param $path string |
|
| 173 | - * @return true on success, false otherwise |
|
| 174 | - */ |
|
| 175 | - public static function deleteArray($path){ |
|
| 176 | - if (! $id = self::getId($path, true)) return false; |
|
| 169 | + /** |
|
| 170 | + * Removes common data array or entry. |
|
| 171 | + * |
|
| 172 | + * @param $path string |
|
| 173 | + * @return true on success, false otherwise |
|
| 174 | + */ |
|
| 175 | + public static function deleteArray($path){ |
|
| 176 | + if (! $id = self::getId($path, true)) return false; |
|
| 177 | 177 | |
| 178 | - self::find($id)->delete(); |
|
| 178 | + self::find($id)->delete(); |
|
| 179 | 179 | |
| 180 | - self::clearCache(); |
|
| 181 | - } |
|
| 180 | + self::clearCache(); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Returns common data collection. |
|
| 185 | - * |
|
| 186 | - * @param $path string |
|
| 187 | - * @return Collection |
|
| 188 | - */ |
|
| 189 | - public static function getCollection($path, $silent = false) |
|
| 190 | - { |
|
| 191 | - if(isset(self::$cache['array'][$path])) { |
|
| 192 | - return self::$cache['array'][$path]; |
|
| 193 | - } |
|
| 183 | + /** |
|
| 184 | + * Returns common data collection. |
|
| 185 | + * |
|
| 186 | + * @param $path string |
|
| 187 | + * @return Collection |
|
| 188 | + */ |
|
| 189 | + public static function getCollection($path, $silent = false) |
|
| 190 | + { |
|
| 191 | + if(isset(self::$cache['array'][$path])) { |
|
| 192 | + return self::$cache['array'][$path]; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - if (! $id = self::getId($path)) { |
|
| 196 | - if ($silent) return collect(); |
|
| 195 | + if (! $id = self::getId($path)) { |
|
| 196 | + if ($silent) return collect(); |
|
| 197 | 197 | |
| 198 | - throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
|
| 199 | - } |
|
| 198 | + throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return self::$cache['array'][$path] = self::where('parent_id', $id)->get(); |
|
| 202 | - } |
|
| 201 | + return self::$cache['array'][$path] = self::where('parent_id', $id)->get(); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - protected static function validateArrayKeys($array) |
|
| 205 | - { |
|
| 206 | - foreach($array as $key => $value) { |
|
| 207 | - if (strpos($key, '/') === false) continue; |
|
| 204 | + protected static function validateArrayKeys($array) |
|
| 205 | + { |
|
| 206 | + foreach($array as $key => $value) { |
|
| 207 | + if (strpos($key, '/') === false) continue; |
|
| 208 | 208 | |
| 209 | - \Exception('Invalid common data key: '. $key); |
|
| 210 | - } |
|
| 211 | - } |
|
| 209 | + \Exception('Invalid common data key: '. $key); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | \ No newline at end of file |
@@ -25,7 +25,10 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | $parentId = null; |
| 27 | 27 | foreach(explode('/', trim($path,'/')) as $nodeKey) { |
| 28 | - if ($nodeKey === '') continue; //ignore empty paths |
|
| 28 | + if ($nodeKey === '') { |
|
| 29 | + continue; |
|
| 30 | + } |
|
| 31 | + //ignore empty paths |
|
| 29 | 32 | |
| 30 | 33 | if ($clearCache || empty(self::$cache['id'][$parentId][$nodeKey])) { |
| 31 | 34 | if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
@@ -43,11 +46,15 @@ discard block |
||
| 43 | 46 | |
| 44 | 47 | public static function newId($path, $readonly = false) |
| 45 | 48 | { |
| 46 | - if (! $path = trim($path,'/')) return false; |
|
| 49 | + if (! $path = trim($path,'/')) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 47 | 52 | |
| 48 | 53 | $id = $parentId = null; |
| 49 | 54 | foreach(explode('/', $path) as $nodeKey) { |
| 50 | - if ($nodeKey === '') continue; |
|
| 55 | + if ($nodeKey === '') { |
|
| 56 | + continue; |
|
| 57 | + } |
|
| 51 | 58 | |
| 52 | 59 | if (! $node = self::where('parent_id', $parentId)->where('key', $nodeKey)->first()) { |
| 53 | 60 | $node = self::create([ |
@@ -67,9 +74,13 @@ discard block |
||
| 67 | 74 | public static function setValue($path, $value, $overwrite = true, $readonly = false) |
| 68 | 75 | { |
| 69 | 76 | if (! $id = self::getId($path)) { |
| 70 | - if (! $id = self::newId($path, $readonly)) return false; |
|
| 77 | + if (! $id = self::newId($path, $readonly)) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 71 | 80 | } else { |
| 72 | - if (! $overwrite) return false; |
|
| 81 | + if (! $overwrite) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | self::findOrFail($id)->update(compact('value', 'readonly')); |
@@ -89,7 +100,9 @@ discard block |
||
| 89 | 100 | $key = md5(serialize($path)); |
| 90 | 101 | |
| 91 | 102 | if (! isset(self::$cache['value'][$key])) { |
| 92 | - if(! $id = self::getId($path)) return false; |
|
| 103 | + if(! $id = self::getId($path)) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 93 | 106 | |
| 94 | 107 | self::$cache['value'][$key] = self::find($id)->value; |
| 95 | 108 | } |
@@ -120,7 +133,9 @@ discard block |
||
| 120 | 133 | self::find($id)->delete(); |
| 121 | 134 | } |
| 122 | 135 | |
| 123 | - if(! $id = self::newId($path, $readonly)) return false; |
|
| 136 | + if(! $id = self::newId($path, $readonly)) { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 124 | 139 | |
| 125 | 140 | if ($overwrite) { |
| 126 | 141 | self::find($id)->update(compact('readonly')); |
@@ -173,7 +188,9 @@ discard block |
||
| 173 | 188 | * @return true on success, false otherwise |
| 174 | 189 | */ |
| 175 | 190 | public static function deleteArray($path){ |
| 176 | - if (! $id = self::getId($path, true)) return false; |
|
| 191 | + if (! $id = self::getId($path, true)) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 177 | 194 | |
| 178 | 195 | self::find($id)->delete(); |
| 179 | 196 | |
@@ -193,7 +210,9 @@ discard block |
||
| 193 | 210 | } |
| 194 | 211 | |
| 195 | 212 | if (! $id = self::getId($path)) { |
| 196 | - if ($silent) return collect(); |
|
| 213 | + if ($silent) { |
|
| 214 | + return collect(); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | throw new CommonDataNotFound('Invalid CommonData::getArray() request: ' . $path); |
| 199 | 218 | } |
@@ -204,7 +223,9 @@ discard block |
||
| 204 | 223 | protected static function validateArrayKeys($array) |
| 205 | 224 | { |
| 206 | 225 | foreach($array as $key => $value) { |
| 207 | - if (strpos($key, '/') === false) continue; |
|
| 226 | + if (strpos($key, '/') === false) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 208 | 229 | |
| 209 | 230 | \Exception('Invalid common data key: '. $key); |
| 210 | 231 | } |