Completed
Push — master ( b69d36...99d479 )
by Klochok
07:59
created

Reminder::reminderNextTimeOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 2
rs 9.4285
1
<?php
2
3
namespace hipanel\models;
4
5
use hipanel\base\Model;
6
use hipanel\base\ModelTrait;
7
use Yii;
8
9
class Reminder extends Model
10
{
11
    use ModelTrait;
12
13
    public static $i18nDictionary = 'hipanel/reminder';
14
15
    const REMINDER_SCENARIO_CREATE = 'create';
16
    const REMINDER_SCENARIO_UPDATE = 'update';
17
    const REMINDER_SCENARIO_DELETE = 'delete';
18
19
    const REMINDER_TYPE_SITE = 'site';
20
    const REMINDER_TYPE_MAIL = 'mail';
21
22
    public static function reminderNextTimeOptions()
23
    {
24
        return [
25
            '+ 15 minutes' => Yii::t('hipanel/reminder', '15m'),
26
            '+ 30 minutes' => Yii::t('hipanel/reminder', '30m'),
27
            '+ 1 hour' => Yii::t('hipanel/reminder', '1h'),
28
            '+ 12 hour' => Yii::t('hipanel/reminder', '12h'),
29
            '+ 1 day' => Yii::t('hipanel/reminder', '1d'),
30
        ];
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function rules()
37
    {
38
        return [
39
            [['id', 'object_id', 'client_id', 'state_id', 'type_id'], 'integer'],
40
            [['class_name', 'periodicity', 'from_time', 'till_time', 'next_time'], 'string'],
41
            [['to_site'], 'boolean'],
42
43
            // Create
44
            [['object_id', 'type', 'periodicity', 'from_time', 'message'], 'required', 'on' => self::REMINDER_SCENARIO_CREATE],
45
46
            // Update
47
            [['id'], 'required', 'on' => 'update'],
48
            [['object_id', 'state_id', 'type_id'], 'integer', 'on' => self::REMINDER_SCENARIO_UPDATE],
49
            [['from_time', 'next_time', 'till_time'], 'string', 'on' => self::REMINDER_SCENARIO_UPDATE],
50
51
            // Delete
52
            [['id'], 'required', 'on' => self::REMINDER_SCENARIO_DELETE]
53
        ];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function attributeLabels()
60
    {
61
        return $this->mergeAttributeLabels([
62
            'periodicity' => Yii::t('hipanel/reminder', 'Periodicity'),
63
            'from_time' => Yii::t('hipanel/reminder', 'When the recall?'),
64
            'next_time' => Yii::t('hipanel/reminder', 'Next remind'),
65
            'till_time' => Yii::t('hipanel/reminder', 'Remind till'),
66
            'message' => Yii::t('hipanel/reminder', 'Message'),
67
        ]);
68
    }
69
70
    public function getObjectName()
71
    {
72
        $result = '';
73
        if ($this->class_name) {
0 ignored issues
show
Documentation introduced by
The property class_name does not exist on object<hipanel\models\Reminder>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
74
            switch ($this->class_name) {
0 ignored issues
show
Documentation introduced by
The property class_name does not exist on object<hipanel\models\Reminder>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
75
                case 'thread':
76
                    $result = 'ticket';
77
                    break;
78
            }
79
        }
80
81
        return $result;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     * @return ReminderQuery
87
     */
88
    public static function find($options = [])
89
    {
90
        return new ReminderQuery(get_called_class(), [
91
            'options' => $options,
92
        ]);
93
    }
94
}
95