@@ -7,17 +7,17 @@ |
||
| 7 | 7 | |
| 8 | 8 | class SQL extends \atk4\data\Persistence\SQL |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Take a laravel connection and pass it to ATK Data |
|
| 12 | - * |
|
| 13 | - * @param \Illuminate\Database\DatabaseManager $db The Laravel database manager |
|
| 14 | - * |
|
| 15 | - * @return \atk4\data\Persistence_SQL |
|
| 16 | - * @throws \atk4\data\Exception |
|
| 17 | - * @throws \atk4\dsql\Exception |
|
| 18 | - */ |
|
| 19 | - public function __construct(DatabaseManager $database) |
|
| 20 | - { |
|
| 21 | - parent::__construct(Connection::connect($database->connection()->getPdo())); |
|
| 22 | - } |
|
| 10 | + /** |
|
| 11 | + * Take a laravel connection and pass it to ATK Data |
|
| 12 | + * |
|
| 13 | + * @param \Illuminate\Database\DatabaseManager $db The Laravel database manager |
|
| 14 | + * |
|
| 15 | + * @return \atk4\data\Persistence_SQL |
|
| 16 | + * @throws \atk4\data\Exception |
|
| 17 | + * @throws \atk4\dsql\Exception |
|
| 18 | + */ |
|
| 19 | + public function __construct(DatabaseManager $database) |
|
| 20 | + { |
|
| 21 | + parent::__construct(Connection::connect($database->connection()->getPdo())); |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -4,14 +4,14 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Utils |
| 6 | 6 | { |
| 7 | - public static function bytesToHuman($bytes) |
|
| 8 | - { |
|
| 9 | - $units = [__('B'), __('KiB'), __('MiB'), __('GiB'), __('TiB'), __('PiB')]; |
|
| 7 | + public static function bytesToHuman($bytes) |
|
| 8 | + { |
|
| 9 | + $units = [__('B'), __('KiB'), __('MiB'), __('GiB'), __('TiB'), __('PiB')]; |
|
| 10 | 10 | |
| 11 | - for ($i = 0; $bytes > 1024; $i++) { |
|
| 12 | - $bytes /= 1024; |
|
| 13 | - } |
|
| 11 | + for ($i = 0; $bytes > 1024; $i++) { |
|
| 12 | + $bytes /= 1024; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - return round($bytes, 2) . ' ' . $units[$i]; |
|
| 16 | - } |
|
| 15 | + return round($bytes, 2) . ' ' . $units[$i]; |
|
| 16 | + } |
|
| 17 | 17 | } |
| 18 | 18 | \ No newline at end of file |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | protected function showEditPermissions() |
| 37 | 37 | { |
| 38 | - $permissionsData = Permission::all(['id', 'name'])->map(function($permission){ |
|
| 38 | + $permissionsData = Permission::all(['id', 'name'])->map(function($permission) { |
|
| 39 | 39 | $permission['name'] = trans(ucwords($permission['name'])); |
| 40 | 40 | |
| 41 | 41 | return $permission; |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | protected function columns() |
| 101 | 101 | { |
| 102 | - return $this->columns = $this->columns?: $this->add('Columns'); |
|
| 102 | + return $this->columns = $this->columns ?: $this->add('Columns'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | protected function permissionId() |
| 106 | 106 | { |
| 107 | - return $this->app->stickyGet($this->columns()->name)?: $this->getModuleVariable('permission'); |
|
| 107 | + return $this->app->stickyGet($this->columns()->name) ?: $this->getModuleVariable('permission'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | protected function reload($permissionExpression = null) |
| 111 | 111 | { |
| 112 | 112 | $columns = $this->columns(); |
| 113 | 113 | |
| 114 | - return $this->reload = $this->reload?: new jsReload($columns, [$columns->name => $permissionExpression?: '']); |
|
| 114 | + return $this->reload = $this->reload ?: new jsReload($columns, [$columns->name => $permissionExpression ?: '']); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | protected function getModel($array) |
@@ -8,28 +8,28 @@ |
||
| 8 | 8 | |
| 9 | 9 | class ModuleManagerTest extends TestCase |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Setup the test environment. |
|
| 13 | - */ |
|
| 14 | - protected function setUp(): void |
|
| 15 | - { |
|
| 16 | - parent::setUp(); |
|
| 11 | + /** |
|
| 12 | + * Setup the test environment. |
|
| 13 | + */ |
|
| 14 | + protected function setUp(): void |
|
| 15 | + { |
|
| 16 | + parent::setUp(); |
|
| 17 | 17 | |
| 18 | - config([ |
|
| 19 | - 'epesi.modules' => [ |
|
| 20 | - '\\Epesi\\Core\\' => __DIR__ . implode(DIRECTORY_SEPARATOR, ['..', '..', 'src']), |
|
| 21 | - ] |
|
| 22 | - ]); |
|
| 18 | + config([ |
|
| 19 | + 'epesi.modules' => [ |
|
| 20 | + '\\Epesi\\Core\\' => __DIR__ . implode(DIRECTORY_SEPARATOR, ['..', '..', 'src']), |
|
| 21 | + ] |
|
| 22 | + ]); |
|
| 23 | 23 | |
| 24 | - ModuleManager::install('system'); |
|
| 25 | - } |
|
| 24 | + ModuleManager::install('system'); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function testContentStorage() |
|
| 28 | - { |
|
| 29 | - $installedModules = ModuleManager::getInstalled(); |
|
| 27 | + public function testContentStorage() |
|
| 28 | + { |
|
| 29 | + $installedModules = ModuleManager::getInstalled(); |
|
| 30 | 30 | |
| 31 | - $this->assertArrayHasKey('system', $installedModules, 'System module not installed'); |
|
| 32 | - } |
|
| 31 | + $this->assertArrayHasKey('system', $installedModules, 'System module not installed'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -7,41 +7,41 @@ |
||
| 7 | 7 | |
| 8 | 8 | class VariablesTest extends TestCase |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Setup the test environment. |
|
| 12 | - */ |
|
| 13 | - protected function setUp(): void |
|
| 14 | - { |
|
| 15 | - parent::setUp(); |
|
| 10 | + /** |
|
| 11 | + * Setup the test environment. |
|
| 12 | + */ |
|
| 13 | + protected function setUp(): void |
|
| 14 | + { |
|
| 15 | + parent::setUp(); |
|
| 16 | 16 | |
| 17 | - Variable::migrate(); |
|
| 18 | - } |
|
| 17 | + Variable::migrate(); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function testVariableStorage() |
|
| 21 | - { |
|
| 22 | - $varString = 'test'; |
|
| 20 | + public function testVariableStorage() |
|
| 21 | + { |
|
| 22 | + $varString = 'test'; |
|
| 23 | 23 | |
| 24 | - Variable::memorize('testString', $varString); |
|
| 24 | + Variable::memorize('testString', $varString); |
|
| 25 | 25 | |
| 26 | - $this->assertEquals($varString, Variable::recall('testString'), 'String variable not stored correctly in database'); |
|
| 26 | + $this->assertEquals($varString, Variable::recall('testString'), 'String variable not stored correctly in database'); |
|
| 27 | 27 | |
| 28 | - Variable::forget('testString'); |
|
| 28 | + Variable::forget('testString'); |
|
| 29 | 29 | |
| 30 | - $this->assertEmpty(Variable::recall('testString'), 'String variable not cleared correctly from database'); |
|
| 30 | + $this->assertEmpty(Variable::recall('testString'), 'String variable not cleared correctly from database'); |
|
| 31 | 31 | |
| 32 | - $varArray = [ |
|
| 33 | - 'aa' => 'test1', |
|
| 34 | - 'bb' => 'test2' |
|
| 35 | - ]; |
|
| 32 | + $varArray = [ |
|
| 33 | + 'aa' => 'test1', |
|
| 34 | + 'bb' => 'test2' |
|
| 35 | + ]; |
|
| 36 | 36 | |
| 37 | - Variable::memorize('testArray', $varArray); |
|
| 37 | + Variable::memorize('testArray', $varArray); |
|
| 38 | 38 | |
| 39 | - $this->assertEquals($varArray, Variable::recall('testArray'), 'Array variable not stored correctly in database'); |
|
| 39 | + $this->assertEquals($varArray, Variable::recall('testArray'), 'Array variable not stored correctly in database'); |
|
| 40 | 40 | |
| 41 | - Variable::forget('testArray'); |
|
| 41 | + Variable::forget('testArray'); |
|
| 42 | 42 | |
| 43 | - $this->assertEmpty(Variable::recall('testArray'), 'String variable not cleared correctly from database'); |
|
| 44 | - } |
|
| 43 | + $this->assertEmpty(Variable::recall('testArray'), 'String variable not cleared correctly from database'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | $grid->setModel(HomePage::create()); |
| 32 | 32 | |
| 33 | - $grid->addDragHandler()->onReorder(function ($order) { |
|
| 33 | + $grid->addDragHandler()->onReorder(function($order) { |
|
| 34 | 34 | foreach (HomePage::create() as $homepage) { |
| 35 | 35 | $homepage->save(['priority' => array_search($homepage['id'], $order)]); |
| 36 | 36 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class HomePage extends Model |
| 12 | 12 | { |
| 13 | - use HasEpesiConnection; |
|
| 13 | + use HasEpesiConnection; |
|
| 14 | 14 | |
| 15 | 15 | public $table = 'home_pages'; |
| 16 | 16 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | parent::init(); |
| 30 | 30 | |
| 31 | 31 | $this->addFields([ |
| 32 | - 'path' => [ |
|
| 32 | + 'path' => [ |
|
| 33 | 33 | 'type' => 'enum', |
| 34 | 34 | 'caption' => __('Page'), |
| 35 | 35 | 'values' => self::list(), |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | 'filter' => true |
| 41 | 41 | ], |
| 42 | 42 | ], |
| 43 | - 'role' => [ |
|
| 43 | + 'role' => [ |
|
| 44 | 44 | 'type' => 'enum', |
| 45 | 45 | 'caption' => __('Role'), |
| 46 | 46 | 'values' => Role::get()->pluck('name', 'name')->all(), |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | 'filter' => true |
| 49 | 49 | ] |
| 50 | 50 | ], |
| 51 | - 'date' => [ |
|
| 51 | + 'date' => [ |
|
| 52 | 52 | 'type' => 'date', |
| 53 | 53 | 'caption' => __('Date'), |
| 54 | - 'never_persist' => true, |
|
| 54 | + 'never_persist' => true, |
|
| 55 | 55 | 'ui' => [ |
| 56 | 56 | 'filter' => true |
| 57 | 57 | ] |
| 58 | 58 | ], |
| 59 | 59 | 'priority' => [ |
| 60 | - 'default' => 0 |
|
| 60 | + 'default' => 0 |
|
| 61 | 61 | ], |
| 62 | 62 | ]); |
| 63 | 63 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->setOrder('priority'); |
| 65 | 65 | |
| 66 | 66 | $this->addHook('beforeInsert', function($model, & $data) { |
| 67 | - $data['priority'] = $data['priority']?: $this->action('fx', ['max', 'priority'])->getOne() + 1; |
|
| 67 | + $data['priority'] = $data['priority'] ?: $this->action('fx', ['max', 'priority'])->getOne() + 1; |
|
| 68 | 68 | }); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | static $cache; |
| 79 | 79 | |
| 80 | - if (! isset($cache)) { |
|
| 80 | + if (!isset($cache)) { |
|
| 81 | 81 | $cache = []; |
| 82 | 82 | foreach (HomePageJoint::collect() as $joint) { |
| 83 | 83 | $cache[$joint->link()] = $joint->caption(); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public static function ofUser() |
| 96 | 96 | { |
| 97 | - if (! $user = Auth::user()) return; |
|
| 97 | + if (!$user = Auth::user()) return; |
|
| 98 | 98 | |
| 99 | 99 | return self::create()->addCondition('role', $user->roles()->pluck('name')->toArray())->loadAny(); |
| 100 | 100 | } |
@@ -106,6 +106,6 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public static function pathOfUser() |
| 108 | 108 | { |
| 109 | - return HomePage::ofUser()['path']?: self::$defaultPath; |
|
| 109 | + return HomePage::ofUser()['path'] ?: self::$defaultPath; |
|
| 110 | 110 | } |
| 111 | 111 | } |
@@ -94,7 +94,9 @@ |
||
| 94 | 94 | */ |
| 95 | 95 | public static function ofUser() |
| 96 | 96 | { |
| 97 | - if (! $user = Auth::user()) return; |
|
| 97 | + if (! $user = Auth::user()) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 98 | 100 | |
| 99 | 101 | return self::create()->addCondition('role', $user->roles()->pluck('name')->toArray())->loadAny(); |
| 100 | 102 | } |
@@ -21,14 +21,14 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function install() |
| 23 | 23 | { |
| 24 | - Models\HomePage::migrate(); |
|
| 24 | + Models\HomePage::migrate(); |
|
| 25 | 25 | |
| 26 | 26 | // setup default home pages |
| 27 | 27 | Models\HomePage::create()->import([ |
| 28 | - [ |
|
| 29 | - 'path' => 'view/dashboard', |
|
| 30 | - 'role' => 'Super Admin' |
|
| 31 | - ], |
|
| 28 | + [ |
|
| 29 | + 'path' => 'view/dashboard', |
|
| 30 | + 'role' => 'Super Admin' |
|
| 31 | + ], |
|
| 32 | 32 | [ |
| 33 | 33 | 'path' => 'view/dashboard', |
| 34 | 34 | 'role' => 'Employee' |
@@ -41,33 +41,33 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public static function pluck($value, $key = null) |
| 43 | 43 | { |
| 44 | - return collect(self::create()->export())->pluck($value, $key); |
|
| 44 | + return collect(self::create()->export())->pluck($value, $key); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // to be removed for atk4/data 2.0 |
| 48 | 48 | public function addFields($fields = [], $defaults = []) |
| 49 | 49 | { |
| 50 | - foreach ($fields as $key => $field) { |
|
| 51 | - if (!is_int($key)) { |
|
| 52 | - // field name can be passed as array key |
|
| 53 | - $name = $key; |
|
| 54 | - } elseif (is_string($field)) { |
|
| 55 | - // or it can be simple string = field name |
|
| 56 | - $name = $field; |
|
| 57 | - $field = []; |
|
| 58 | - } elseif (is_array($field) && isset($field[0]) && is_string($field[0])) { |
|
| 59 | - // or field name can be passed as first element of seed array (old behaviour) |
|
| 60 | - $name = array_shift($field); |
|
| 61 | - } else { |
|
| 62 | - // some unsupported format, maybe throw exception here? |
|
| 63 | - continue; |
|
| 64 | - } |
|
| 50 | + foreach ($fields as $key => $field) { |
|
| 51 | + if (!is_int($key)) { |
|
| 52 | + // field name can be passed as array key |
|
| 53 | + $name = $key; |
|
| 54 | + } elseif (is_string($field)) { |
|
| 55 | + // or it can be simple string = field name |
|
| 56 | + $name = $field; |
|
| 57 | + $field = []; |
|
| 58 | + } elseif (is_array($field) && isset($field[0]) && is_string($field[0])) { |
|
| 59 | + // or field name can be passed as first element of seed array (old behaviour) |
|
| 60 | + $name = array_shift($field); |
|
| 61 | + } else { |
|
| 62 | + // some unsupported format, maybe throw exception here? |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $seed = array_merge($defaults, (array) $field); |
|
| 66 | + $seed = array_merge($defaults, (array) $field); |
|
| 67 | 67 | |
| 68 | - $this->addField($name, $seed); |
|
| 69 | - } |
|
| 68 | + $this->addField($name, $seed); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $this; |
|
| 71 | + return $this; |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | \ No newline at end of file |