|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\v1\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use app\core\exceptions\InvalidArgumentException; |
|
6
|
|
|
use app\core\models\Recurrence; |
|
7
|
|
|
use app\core\requests\RecurrenceUpdateStatusRequest; |
|
8
|
|
|
use app\core\traits\ServiceTrait; |
|
9
|
|
|
use app\core\types\RecurrenceFrequency; |
|
10
|
|
|
use Yii; |
|
11
|
|
|
use yii\base\InvalidConfigException; |
|
12
|
|
|
use yii\db\Exception; |
|
13
|
|
|
use yii\web\NotFoundHttpException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Recurrence controller for the `v1` module |
|
17
|
|
|
*/ |
|
18
|
|
|
class RecurrenceController extends ActiveController |
|
19
|
|
|
{ |
|
20
|
|
|
use ServiceTrait; |
|
21
|
|
|
|
|
22
|
|
|
public $modelClass = Recurrence::class; |
|
23
|
|
|
public $partialMatchAttributes = ['name']; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param int $id |
|
27
|
|
|
* @return Recurrence |
|
28
|
|
|
* @throws Exception |
|
29
|
|
|
* @throws InvalidArgumentException |
|
30
|
|
|
* @throws NotFoundHttpException |
|
31
|
|
|
* @throws InvalidConfigException |
|
32
|
|
|
*/ |
|
33
|
|
|
public function actionUpdateStatus(int $id): Recurrence |
|
34
|
|
|
{ |
|
35
|
|
|
$params = Yii::$app->request->bodyParams; |
|
36
|
|
|
$model = new RecurrenceUpdateStatusRequest(); |
|
37
|
|
|
/** @var RecurrenceUpdateStatusRequest $model */ |
|
38
|
|
|
$model = $this->validate($model, $params); |
|
39
|
|
|
|
|
40
|
|
|
return $this->recurrenceService->updateStatus($id, $model->status); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return array |
|
46
|
|
|
* @throws \Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public function actionFrequencyTypes() |
|
49
|
|
|
{ |
|
50
|
|
|
$items = []; |
|
51
|
|
|
$texts = RecurrenceFrequency::texts(); |
|
52
|
|
|
foreach (RecurrenceFrequency::names() as $key => $name) { |
|
53
|
|
|
$items[] = ['type' => $name, 'name' => data_get($texts, $key)]; |
|
54
|
|
|
} |
|
55
|
|
|
return $items; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|