Commit 8bd1d03c98c381a6c3f95a1f0ddd9dde7624095d
1 parent
66494280
create project model
Showing
3 changed files
with
101 additions
and
0 deletions
Show diff stats
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Alex Savenko | |
5 | + * Date: 06.02.2017 | |
6 | + * Time: 15:40 | |
7 | + */ | |
8 | + | |
9 | +namespace App\Model; | |
10 | + | |
11 | + | |
12 | +class Project extends \App\Mvc\DateTrackingModel { | |
13 | + | |
14 | + public $id; | |
15 | + public $name; | |
16 | + public $user_id; | |
17 | + | |
18 | + public function getSource() | |
19 | + { | |
20 | + return 'project'; | |
21 | + } | |
22 | + | |
23 | + public function columnMap() | |
24 | + { | |
25 | + return parent::columnMap() + [ | |
26 | + 'id' => 'id', | |
27 | + 'name' => 'name', | |
28 | + 'user_id' => 'user_id' | |
29 | + ]; | |
30 | + } | |
31 | + | |
32 | + public function initialize() { | |
33 | + | |
34 | + $this->belongsTo('user_id', User::class, 'id', [ | |
35 | + 'alias' => 'User', | |
36 | + ]); | |
37 | + } | |
38 | + | |
39 | +} | |
0 | 40 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Alex Savenko | |
5 | + * Date: 06.02.2017 | |
6 | + * Time: 15:57 | |
7 | + */ | |
8 | + | |
9 | +namespace App\Resources; | |
10 | + | |
11 | +use PhalconRest\Api\ApiResource; | |
12 | +use PhalconRest\Api\ApiEndpoint; | |
13 | +use App\Model\Project; | |
14 | +use App\Model\User; | |
15 | +use App\Transformers\UserTransformer; | |
16 | +use App\Controllers\UserController; | |
17 | +use App\Constants\AclRoles; | |
18 | + | |
19 | + | |
20 | +class ProjectResource extends ApiResource { | |
21 | + | |
22 | + public function initialize() { | |
23 | + | |
24 | + $this | |
25 | + ->name('Project') | |
26 | + ->model(Project::class) | |
27 | + ->expectsJsonData() | |
28 | + ->transformer(ProjectTransformer::class) | |
29 | + ->handler(CrudResourceController::class) | |
30 | + ->itemKey('project') | |
31 | + ->collectionKey('projects') | |
32 | + ->deny(AclRoles::UNAUTHORIZED) | |
33 | + | |
34 | + ->endpoint(ApiEndpoint::all() | |
35 | + ->description('Returns all projects') | |
36 | + ) | |
37 | + ->endpoint(ApiEndpoint::create()) | |
38 | + ->endpoint(ApiEndpoint::find()) | |
39 | + ->endpoint(ApiEndpoint::update()) | |
40 | + ->endpoint(ApiEndpoint::remove()); | |
41 | + | |
42 | + } | |
43 | + | |
44 | +} | |
0 | 45 | \ No newline at end of file | ... | ... |
app/library/App/Transformers/ProjectTransformer.php
0 โ 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Alex Savenko | |
5 | + * Date: 06.02.2017 | |
6 | + * Time: 16:00 | |
7 | + */ | |
8 | + | |
9 | +namespace App\Transformers; | |
10 | + | |
11 | +use App\Model\Project; | |
12 | +use PhalconRest\Transformers\ModelTransformer; | |
13 | + | |
14 | +class ProjectTransformer extends ModelTransformer { | |
15 | + | |
16 | + protected $modelClass = Project::class; | |
17 | + | |
18 | +} | |
0 | 19 | \ No newline at end of file | ... | ... |