1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* App admin controller |
5
|
|
|
* |
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
7
|
|
|
* @link http://inji.ru/ |
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
10
|
|
|
*/ |
11
|
|
|
class adminController extends Controller { |
12
|
|
|
|
13
|
|
|
public function indexAction() { |
14
|
|
|
$args = func_get_args(); |
15
|
|
|
call_user_func_array([$this, 'dataManagerAction'], $args); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function dataManagerAction($model = '', $dataManager = 'manager') { |
19
|
|
|
if (!$model) { |
20
|
|
|
$modulePath = Module::getModulePath($this->module->moduleName); |
21
|
|
|
$path = $modulePath . '/models'; |
22
|
|
|
if (file_exists($path)) { |
23
|
|
|
$files = array_slice(scandir($path), 2); |
24
|
|
|
foreach ($files as $file) { |
25
|
|
|
if (is_dir($path . '/' . $file)) { |
26
|
|
|
continue; |
27
|
|
|
} |
28
|
|
|
$model = pathinfo($file, PATHINFO_FILENAME); |
29
|
|
|
break; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
$fullModelName = $this->module->moduleName . '\\' . ucfirst($model); |
34
|
|
|
$dataManager = new Ui\DataManager($fullModelName, $dataManager); |
35
|
|
|
$title = !empty($dataManager->managerOptions['name']) ? $dataManager->managerOptions['name'] : $fullModelName::objectName(); |
36
|
|
|
$this->view->setTitle($title); |
37
|
|
|
$this->view->page(['module' => 'Ui', 'content' => 'dataManager/manager', 'data' => compact('dataManager')]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function viewAction($model, $pk) { |
|
|
|
|
41
|
|
|
$fullModelName = $this->module->moduleName . '\\' . ucfirst($model); |
42
|
|
|
if (Users\User::$cur->group_id != 3 && (empty($fullModelName::$views['manager']['access']) || !in_array(Users\User::$cur->group_id, $fullModelName::$views['manager']['access']['groups']))) { |
43
|
|
|
Tools::redirect('/admin', 'У вас нет прав доступа для просмотра этого объекта', 'danger'); |
44
|
|
|
} |
45
|
|
|
$item = $fullModelName::get($pk); |
46
|
|
|
$this->view->setTitle(($fullModelName::$objectName ? $fullModelName::$objectName : $fullModelName) . ($item ? ( ' - ' . $item->name()) : '')); |
47
|
|
|
if (!empty($_POST['comment'])) { |
48
|
|
|
$comment = new Dashboard\Comment(); |
49
|
|
|
$comment->text = $_POST['comment']; |
50
|
|
|
$comment->user_id = \Users\User::$cur->id; |
51
|
|
|
$comment->model = $fullModelName; |
52
|
|
|
$comment->item_id = $item->pk(); |
53
|
|
|
$comment->save(); |
54
|
|
|
Tools::redirect($_SERVER['REQUEST_URI']); |
55
|
|
|
} |
56
|
|
|
$moduleName = $this->module->moduleName; |
57
|
|
|
$pageParam = ['module' => 'Ui', 'content' => 'dataManager/view', 'data' => compact('item', 'moduleName')]; |
58
|
|
|
if (isset($_GET['print'])) { |
59
|
|
|
$pageParam['page'] = 'print'; |
60
|
|
|
} |
61
|
|
|
$this->view->page($pageParam); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: