PluginProbe ʕ •ᴥ•ʔ
AI Copilot – Content Generator / 1.5.4
AI Copilot – Content Generator v1.5.4
1.5.4 1.4.21 1.4.18 1.4.19 1.4.20 trunk 1.0.4 1.1.0 1.2.0 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.17 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.9
ai-copilot-content-generator / modules / postsfields / controller.php
ai-copilot-content-generator / modules / postsfields Last commit date
assets 1 week ago models 1 week ago views 1 week ago controller.php 1 week ago mod.php 1 week ago
controller.php
106 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 class WaicPostsfieldsController extends WaicController {
6
7 protected $_code = 'postsfields';
8
9 public function getNoncedMethods() {
10 return array('startGeneration', 'getPostsResultsBulk', 'doActionTask', 'searchPostsList');
11 }
12
13 public function searchPostsList() {
14 $res = new WaicResponse();
15 $res->ignoreShellData();
16
17 $params = WaicReq::get('post');
18 $result = $this->getModel()->searchPostsList($params);
19
20 if ($result) {
21 $res->data = $result['data'];
22
23 $res->recordsFiltered = $result['total'];
24 $res->recordsTotal = $result['total'];
25 $res->draw = WaicUtils::getArrayValue($params, 'draw', 0, 1);
26
27 } else {
28 $res->pushError(WaicFrame::_()->getErrors());
29 }
30 $res->ajaxExec();
31 }
32
33 public function startGeneration() {
34 $res = new WaicResponse();
35 $params = WaicReq::getVar('params', 'post');
36 $error = '';
37 if (!$this->getModel()->controlTaskParameters($params, $error)) {
38 $res->pushError($error);
39 } else {
40 $workspace = WaicFrame::_()->getModule('workspace');
41 $params = $this->getModel()->convertTaskParameters($params);
42
43 $id = $workspace->getModel('tasks')->saveTask($this->_code, WaicReq::getVar('task_id', 'post'), $params);
44
45 if (empty($id) || !$workspace->getModel()->startGeneration($id)) {
46 $res->pushError(WaicFrame::_()->getErrors());
47 } else {
48 $res->addData('taskUrl', WaicFrame::_()->getModule('workspace')->getTaskUrl($id, $this->_code));
49 }
50
51 }
52 return $res->ajaxExec();
53 }
54
55 public function getPostsResultsBulk() {
56 $res = new WaicResponse();
57 $res->ignoreShellData();
58
59 $params = WaicReq::get('post');
60 $result = $this->getModel()->getBulkResultsList($params, WaicReq::getVar('param'));
61
62 if ($result) {
63 $res->data = $result['data'];
64
65 $res->recordsFiltered = $result['total'];
66 $res->recordsTotal = $result['total'];
67 $res->draw = WaicUtils::getArrayValue($params, 'draw', 0, 1);
68
69 $taskId = WaicUtils::getArrayValue($params, 'task_id', 0, 1);
70 $taskModel = WaicFrame::_()->getModule('workspace')->getModel('tasks');
71 $task = $taskModel->getTask($taskId);
72 $res->task = $task;
73 $res->actions = $taskModel->getTaskActions($taskId, $task['status']);
74
75 } else {
76 $res->pushError(WaicFrame::_()->getErrors());
77 }
78 $res->ajaxExec();
79 }
80
81 public function doActionTask() {
82 $res = new WaicResponse();
83 $taskId = WaicReq::getVar('task_id', 'post');
84 $action = WaicReq::getVar('task_action', 'post');
85 $param = WaicReq::getVar('param', 'post');
86
87 switch ($action) {
88 case 'cancel':
89 $cancelled = WaicReq::getVar('deleted', 'post');
90 $result = empty($cancelled) ? true : $this->getModel()->cancelTaskEtaps($taskId, $cancelled);
91 break;
92 default:
93 //$result = WaicDispatcher::applyFilters('doActionTask_' . $feature, true);
94
95 $result = true;
96 break;
97 }
98 if (-1 === $result) {
99 $res->confirm = WaicFrame::_()->getErrors();
100 } else if (!$result) {
101 $res->pushError(WaicFrame::_()->getErrors());
102 }
103 return $res->ajaxExec();
104 }
105 }
106