-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvents.php
More file actions
executable file
·62 lines (54 loc) · 1.19 KB
/
Events.php
File metadata and controls
executable file
·62 lines (54 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Events class
*
* Menangani event-event yang ada pada modul ppid.
*
* @author Putra Sudaryanto <putra@ommu.id>
* @contact (+62)811-2540-432
* @copyright Copyright (c) 2019 OMMU (www.ommu.id)
* @created date 20 June 2019, 18:13 WIB
* @link https://github.com/ommu/mod-ppid
*
*/
namespace ommu\ppid;
use Yii;
use ommu\ppid\models\PpidFormat;
class Events extends \yii\base\BaseObject
{
/**
* {@inheritdoc}
*/
public static function onBeforeSavePpids($event)
{
$ppid = $event->sender;
self::setPpidFormat($ppid);
}
/**
* {@inheritdoc}
*/
public static function setPpidFormat($ppid)
{
$oldFormat = array_flip($ppid->getFormats(true));
$format = $ppid->format;
// insert difference format
if (is_array($format)) {
foreach ($format as $val) {
if (in_array($val, $oldFormat)) {
unset($oldFormat[array_keys($oldFormat, $val)[0]]);
continue;
}
$model = new PpidFormat();
$model->ppid_id = $ppid->ppid_id;
$model->type = $val;
$model->save();
}
}
// drop difference format
if (!empty($oldFormat)) {
foreach ($oldFormat as $key => $val) {
PpidFormat::findOne($key)->delete();
}
}
}
}