diff --git a/application/models/Options/Row.php b/application/models/Options/Row.php index f643f7d..17d3f68 100644 --- a/application/models/Options/Row.php +++ b/application/models/Options/Row.php @@ -8,20 +8,33 @@ namespace Application\Options; +use Bluz\Proxy\Auth; use Bluz\Validator\Traits\Validator; +use Application\Users; /** * Options Row * + * @package Application\Options + * * @property string $namespace * @property string $key + * @property integer $userId * @property string $value * @property string $description * @property string $created * @property string $updated * - * @category Application - * @package Options + * @SWG\Definition(definition="options", title="option", required={"namespace", "key"}) + * @SWG\Property(property="namespace", type="string", description="Options namespace", example="default") + * @SWG\Property(property="key", type="string", description="Key", example="Some key") + * @SWG\Property(property="userId", type="integer", description="Author ID", example=2) + * @SWG\Property(property="value", type="string", description="Value", example="Some Value") + * @SWG\Property(property="description", type="string", description="Description", example="Some description for key") + * @SWG\Property(property="created", type="string", format="date-time", description="Created date", + * example="2017-03-17 19:06:28") + * @SWG\Property(property="updated", type="string", format="date-time", description="Last updated date", + * example="2017-03-17 19:06:28") */ class Row extends \Bluz\Db\Row { @@ -33,7 +46,7 @@ class Row extends \Bluz\Db\Row protected function afterRead() { if ($this->value) { - $this->value = unserialize($this->value); + $this->value = unserialize($this->value, ['allowed_classes' => false]); } } @@ -65,6 +78,13 @@ function () { }, 'Key name is already exists' ); + + /* @var \Application\Users\Row $user */ + if ($user = Auth::getIdentity()) { + $this->userId = $user->id; + } else { + $this->userId = Users\Table::SYSTEM_USER; + } } /** diff --git a/application/modules/api/controllers/options.php b/application/modules/api/controllers/options.php new file mode 100644 index 0000000..56bb741 --- /dev/null +++ b/application/modules/api/controllers/options.php @@ -0,0 +1,83 @@ +get('system', 'rest/get') + ->acl('Options/Read'); + $rest->post('system', 'rest/post') + ->acl('Options/Edit'); + $rest->put('system', 'rest/put') + ->acl('Options/Edit'); + $rest->patch('system', 'rest/put') + ->acl('Options/Edit'); + $rest->delete('system', 'rest/delete') + ->acl('Options/Edit'); + + return $rest->run(); +}; diff --git a/application/modules/options/controllers/crud.php b/application/modules/options/controllers/crud.php index 5d288b4..a9cfa84 100644 --- a/application/modules/options/controllers/crud.php +++ b/application/modules/options/controllers/crud.php @@ -25,8 +25,8 @@ $crud = new Crud(Options\Crud::getInstance()); $crud->get('system', 'crud/get'); - $crud->post('options', 'crud/post'); - $crud->put('system', 'crud/put'); + $crud->post('options', 'crud/post')->fields(['namespace', 'key', 'value', 'description']); + $crud->put('system', 'crud/put')->fields(['value', 'description']); $crud->delete('system', 'crud/delete'); return $crud->run(); diff --git a/application/modules/options/controllers/crud/post.php b/application/modules/options/controllers/crud/post.php index 301cf03..4a57d25 100644 --- a/application/modules/options/controllers/crud/post.php +++ b/application/modules/options/controllers/crud/post.php @@ -28,7 +28,7 @@ try { $crud->createOne($data); - Messages::addSuccess("Record was created"); + Messages::addSuccess('The record was successfully created'); return [ 'row' => $data, diff --git a/application/modules/options/controllers/grid.php b/application/modules/options/controllers/grid.php index c20b0d3..928d91f 100644 --- a/application/modules/options/controllers/grid.php +++ b/application/modules/options/controllers/grid.php @@ -27,6 +27,7 @@ ] ); $grid = new Options\Grid(); + $grid->processSource(); $this->assign('grid', $grid); }; diff --git a/application/modules/options/views/crud.phtml b/application/modules/options/views/crud.phtml index 63040dd..68eea2d 100644 --- a/application/modules/options/views/crud.phtml +++ b/application/modules/options/views/crud.phtml @@ -1,34 +1,42 @@ - +
- +