|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use hipanel\actions\IndexAction; |
|
7
|
|
|
use hipanel\actions\OrientationAction; |
|
8
|
|
|
use hipanel\actions\RedirectAction; |
|
9
|
|
|
use hipanel\actions\RenderAction; |
|
10
|
|
|
use hipanel\actions\RenderJsonAction; |
|
11
|
|
|
use hipanel\actions\SmartCreateAction; |
|
12
|
|
|
use hipanel\actions\SmartDeleteAction; |
|
13
|
|
|
use hipanel\actions\SmartUpdateAction; |
|
14
|
|
|
use hipanel\actions\ValidateFormAction; |
|
15
|
|
|
use hipanel\actions\ViewAction; |
|
16
|
|
|
use hipanel\models\Reminder; |
|
17
|
|
|
use hipanel\widgets\ReminderTop; |
|
18
|
|
|
use Symfony\Component\EventDispatcher\Event; |
|
19
|
|
|
use Yii; |
|
20
|
|
|
use yii\base\Widget; |
|
21
|
|
|
use yii\helpers\ArrayHelper; |
|
22
|
|
|
use yii\web\NotFoundHttpException; |
|
23
|
|
|
|
|
24
|
|
|
class ReminderController extends \hipanel\base\CrudController |
|
25
|
|
|
{ |
|
26
|
|
|
public function init() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->viewPath = '@hipanel/views/reminder'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function actions() |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
|
|
'set-orientation' => [ |
|
35
|
|
|
'class' => OrientationAction::class, |
|
36
|
|
|
'allowedRoutes' => [ |
|
37
|
|
|
'reminder/index' |
|
38
|
|
|
] |
|
39
|
|
|
], |
|
40
|
|
|
'validate-form' => [ |
|
41
|
|
|
'class' => ValidateFormAction::class, |
|
42
|
|
|
], |
|
43
|
|
|
'view' => [ |
|
44
|
|
|
'class' => ViewAction::class, |
|
45
|
|
|
], |
|
46
|
|
|
'index' => [ |
|
47
|
|
|
'class' => IndexAction::class, |
|
48
|
|
|
'data' => function ($action, $data) { |
|
|
|
|
|
|
49
|
|
|
return [ |
|
50
|
|
|
|
|
51
|
|
|
]; |
|
52
|
|
|
}, |
|
53
|
|
|
], |
|
54
|
|
|
'create-modal' => [ |
|
55
|
|
|
'class' => SmartCreateAction::class, |
|
56
|
|
|
'scenario' => 'create', |
|
57
|
|
|
'view' => 'create-modal', |
|
58
|
|
|
'data' => function ($action, $data) { |
|
59
|
|
|
$object_id = \Yii::$app->request->get('object_id'); |
|
60
|
|
|
if (empty($object_id)) { |
|
61
|
|
|
throw new NotFoundHttpException('Object ID is missing'); |
|
62
|
|
|
} |
|
63
|
|
|
$data['model']->object_id = $object_id; |
|
64
|
|
|
|
|
65
|
|
|
return $data; |
|
66
|
|
|
}, |
|
67
|
|
|
], |
|
68
|
|
|
'create' => [ |
|
69
|
|
|
'class' => SmartCreateAction::class, |
|
70
|
|
|
'view' => 'create-modal', |
|
71
|
|
|
], |
|
72
|
|
|
'update' => [ |
|
73
|
|
|
'class' => SmartUpdateAction::class, |
|
74
|
|
|
'on beforeSave' => function ($event) { |
|
75
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
76
|
|
|
$action = $event->sender; |
|
77
|
|
|
if (Yii::$app->request->isAjax) { |
|
78
|
|
|
$reminder = Yii::$app->request->post('Reminder'); |
|
79
|
|
|
$action->collection->set(Reminder::find()->where(['id' => $reminder['id']])->one()); |
|
|
|
|
|
|
80
|
|
|
foreach ($action->collection->models as $model) { |
|
81
|
|
|
$model->next_time = (new DateTime($model->next_time))->modify($reminder['next_time'])->format('Y-m-d H:i:s'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
}, |
|
85
|
|
|
'POST ajax' => [ |
|
86
|
|
|
'save' => true, |
|
87
|
|
|
'success' => [ |
|
88
|
|
|
'class' => RenderJsonAction::class, |
|
89
|
|
|
'return' => function ($action) { |
|
|
|
|
|
|
90
|
|
|
return [ |
|
91
|
|
|
'success' => true, |
|
92
|
|
|
'widget' => ReminderTop::widget() |
|
93
|
|
|
]; // todo: wise resulting |
|
94
|
|
|
}, |
|
95
|
|
|
], |
|
96
|
|
|
], |
|
97
|
|
|
], |
|
98
|
|
|
'delete' => [ |
|
99
|
|
|
'class' => SmartDeleteAction::class, |
|
100
|
|
|
'POST html | POST pjax' => [ |
|
101
|
|
|
'save' => true, |
|
102
|
|
|
'success' => [ |
|
103
|
|
|
'class' => RedirectAction::class, |
|
104
|
|
|
], |
|
105
|
|
|
], |
|
106
|
|
|
] |
|
107
|
|
|
]; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getPeriodicityOptions() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->getRefs('type,periodicity', 'hipanel/reminder'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getTypeReminder() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->getRefs('type,reminder', 'hipanel/reminder'); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.