1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Phpsa\Datastore\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
6
|
|
|
use Phpsa\Datastore\Datastore; |
7
|
|
|
use Phpsa\Datastore\Asset; |
8
|
|
|
use Phpsa\Datastore\Helpers; |
9
|
|
|
use Phpsa\Datastore\DatastoreException; |
10
|
|
|
use Phpsa\Datastore\Repositories\DatastoreRepository; |
11
|
|
|
|
12
|
|
|
use Phpsa\Datastore\Models\Datastore as DatastoreModel; |
13
|
|
|
use Phpsa\Datastore\Models\DatastorePages; |
14
|
|
|
|
15
|
|
|
Class DatastoreController extends Controller { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var DatastoreRepository |
19
|
|
|
*/ |
20
|
|
|
protected $datastoreRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* UserController constructor. |
24
|
|
|
* |
25
|
|
|
* @param DatastoreRepository $datastoreRepository |
26
|
|
|
*/ |
27
|
|
|
public function __construct(DatastoreRepository $datastoreRepository) |
28
|
|
|
{ |
29
|
|
|
$this->datastoreRepository = $datastoreRepository; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function iCan($permission, $then, $else){ |
33
|
|
|
$user = auth()->user(); |
34
|
|
|
return $user && $user->can($permission) ? $then : $else; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function canViewAll($status = 'published'){ |
38
|
|
|
return $this->iCan('manage datastore', null , $status); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function getPageBySlug($slug){ |
42
|
|
|
$page = DatastorePages::where('slug', $slug)->first(); |
43
|
|
|
if(!$page){ |
44
|
|
|
abort(404); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$datastore = $page->datastore; |
48
|
|
|
$user = auth()->user(); |
49
|
|
|
|
50
|
|
|
if(!$datastore->statusIsActive() && (!$user || !$user->can('manage datastore'))) { |
|
|
|
|
51
|
|
|
abort(404); |
52
|
|
|
} |
53
|
|
|
return $page; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function page($slug){ |
57
|
|
|
|
58
|
|
|
$page = $this->getPageBySlug($slug); |
59
|
|
|
|
60
|
|
|
$acceptedAssets = $page->datastore->accept ? $this->datastoreRepository->paginateAccepted($page->asset, $this->canViewAll(Helpers::getStatusEquals($page->datastore->accept))) : false; |
|
|
|
|
61
|
|
|
|
62
|
|
|
return view($page->datastore->getViewName()) |
|
|
|
|
63
|
|
|
->withDatastore($page->datastore) |
64
|
|
|
->withChildren($page->datastore->children()) |
65
|
|
|
->withAccepted($acceptedAssets) |
66
|
|
|
->withPage($page); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function childPage($parent_slug, $slug){ |
71
|
|
|
return $this->page($slug); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function articleByAuthor($author_id, $slug){ |
75
|
|
|
$this->datastoreRepository->paginateSearchProp('author', $author_id, Phpsa\Datastore\Ams\Article\ItemAsset::class, $this->canViewAll('published')); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function ___tests() |
79
|
|
|
{ |
80
|
|
|
|
81
|
|
|
//ok we need a list of objects we can usse:: |
82
|
|
|
|
83
|
|
|
// $assets = Helpers::getAssetList(true); |
84
|
|
|
|
85
|
|
|
// echo '<pre>'; |
86
|
|
|
// print_r($assets); |
87
|
|
|
// exit; |
88
|
|
|
$tester = Datastore::getAsset(ContentAsset::class); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$tester->prop('title', 'Moe Title'); |
91
|
|
|
$tester->prop('content', '<p>Rhoncus hac aliquam aliquam! Et mauris, et quis platea ut elementum natoque sit natoque lectus augue integer aliquam porta rhoncus nec, cursus diam a parturient augue ut! Tincidunt eros urna lacus lorem, sit scelerisque. Proin duis auctor ut. Turpis? Sed, diam elit sed velit dapibus phasellus, pulvinar mattis! Sociis augue in parturient sed ultricies et.</p>'); |
92
|
|
|
$tester->prop('status', 'published'); |
93
|
|
|
|
94
|
|
|
//echo '<pre>$tester->val(): '; print_r($tester->val()); echo '</pre>'; die(); |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
$tester->store(); |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
echo '<pre>$tester->export(): '; print_r($tester->export()); echo '</pre>'; die(); |
|
|
|
|
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/*$tester = Datastore::getAssetById(11); |
104
|
|
|
echo $tester->render('title'); |
105
|
|
|
|
106
|
|
|
echo $tester->form('title'); |
107
|
|
|
|
108
|
|
|
echo $tester->getMetadataForm(); |
109
|
|
|
|
110
|
|
|
echo $tester->getForm(); |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
print_r($tester->getFieldValues());*/ |
114
|
|
|
|
115
|
|
|
/* |
116
|
|
|
$tester = Datastore::getAsset(ContentAsset::class); |
117
|
|
|
|
118
|
|
|
$tester->prop('content', '<p>Rhoncus hac aliquam aliquam! Et mauris, et quis platea ut elementum natoque sit natoque lectus augue integer aliquam porta rhoncus nec, cursus diam a parturient augue ut! Tincidunt eros urna lacus lorem, sit scelerisque. Proin duis auctor ut. Turpis? Sed, diam elit sed velit dapibus phasellus, pulvinar mattis! Sociis augue in parturient sed ultricies et.</p>'); |
119
|
|
|
$tester->prop('status', 'published'); |
120
|
|
|
|
121
|
|
|
//$tester->prop('title', 'Moe Title'); |
122
|
|
|
|
123
|
|
|
try { |
124
|
|
|
$tester->validate($tester->getFieldValues()); |
125
|
|
|
}catch(\Exception $e){ |
126
|
|
|
echo $e->getMessage(); |
127
|
|
|
print_r($e->errors()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$tester->prop('title', 'Moe Title'); |
131
|
|
|
try { |
132
|
|
|
$tester->validate($tester->getFieldValues()); |
133
|
|
|
echo "Form is valid"; |
134
|
|
|
}catch(\Exception $e){ |
135
|
|
|
echo $e->getMessage(); |
136
|
|
|
print_r($e->errors()); |
137
|
|
|
} |
138
|
|
|
(*/ |
139
|
|
|
|
140
|
|
|
/* |
141
|
|
|
if( $this->input->post('page_title') && $this->input->post('page_slug')) |
142
|
|
|
{ |
143
|
|
|
$this->load->model('database/datastore_pages_model'); |
144
|
|
|
|
145
|
|
|
$page = $this->datastore_pages_model->get_where(array('asset' => $newasset->id), null, 1); |
146
|
|
|
|
147
|
|
|
if( ! empty($page)) |
148
|
|
|
{ |
149
|
|
|
$this->datastore_pages_model->update(array( |
150
|
|
|
'title' => $this->input->post('page_title'), |
151
|
|
|
'slug' => $this->input->post('page_slug'), |
152
|
|
|
'asset' => $newasset->id |
153
|
|
|
), $page->id); |
154
|
|
|
} |
155
|
|
|
else |
156
|
|
|
{ |
157
|
|
|
$this->datastore_pages_model->insert(array( |
158
|
|
|
'title' => $this->input->post('page_title'), |
159
|
|
|
'slug' => $this->input->post('page_slug'), |
160
|
|
|
'asset' => $newasset->id |
161
|
|
|
)); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
*/ |
166
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths