|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin\Content; |
|
4
|
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\Content as ContentEntity; |
|
6
|
|
|
use Apps\Model\Admin\Content\FormContentPublish; |
|
7
|
|
|
use Ffcms\Core\App; |
|
8
|
|
|
use Ffcms\Core\Arch\View; |
|
9
|
|
|
use Ffcms\Core\Exception\NotFoundException; |
|
10
|
|
|
use Ffcms\Core\Helper\Type\Any; |
|
11
|
|
|
use Ffcms\Core\Network\Request; |
|
12
|
|
|
use Ffcms\Core\Network\Response; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait ActionPublish |
|
16
|
|
|
* @package Apps\Controller\Admin\Content |
|
17
|
|
|
* @property Request $request |
|
18
|
|
|
* @property Response $response |
|
19
|
|
|
* @property View $view |
|
20
|
|
|
*/ |
|
21
|
|
|
trait ActionPublish |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Publish content on moderate stage |
|
25
|
|
|
* @return string |
|
26
|
|
|
* @throws NotFoundException |
|
27
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function publish(): ?string |
|
30
|
|
|
{ |
|
31
|
|
|
// get ids as array from GET |
|
32
|
|
|
$ids = $this->request->query->get('selected'); |
|
33
|
|
|
if (!Any::isArray($ids) || count($ids) < 1) { |
|
34
|
|
|
throw new NotFoundException(__('Items to publish is not found')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// try to find items in db |
|
38
|
|
|
$records = ContentEntity::whereIn('id', $ids)->where('display', 0); |
|
39
|
|
|
if ($records->count() < 1) { |
|
40
|
|
|
throw new NotFoundException(__('Items to publish is not found')); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// initialize model and operate submit |
|
44
|
|
|
$model = new FormContentPublish($records); |
|
|
|
|
|
|
45
|
|
|
if ($model->send() && $model->validate()) { |
|
46
|
|
|
$model->make(); |
|
47
|
|
|
App::$Session->getFlashBag()->add('success', __('Content is successful published')); |
|
48
|
|
|
$this->response->redirect('content/index'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// draw view output |
|
52
|
|
|
return $this->view->render('content/publish', [ |
|
53
|
|
|
'records' => $records->get(), |
|
54
|
|
|
'model' => $model |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|