Passed
Push — master ( 682802...46670a )
by Maximo
05:00 queued 10s
created

EmailTemplates   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 41.67%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 91
ccs 5
cts 12
cp 0.4167
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 3 1
A getSource() 0 3 1
A getByName() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Gewaer\Models;
5
6
use Gewaer\Exception\UnprocessableEntityHttpException;
7
use \Phalcon\Di;
8
9
/**
10
 * Classs for Email Templates
11
 * @property Users $userData
12
 * @property Request $request
13
 * @property Config $config
14
 * @property Apps $app
15
 * @property \Phalcon\DI $di
16
 *
17
 */
18
class EmailTemplates extends AbstractModel
19
{
20
    /**
21
     *
22
     * @var integer
23
     */
24
    public $id;
25
26
    /**
27
     *
28
     * @var string
29
     */
30
    public $company_id;
31
32
    /**
33
     *
34
     * @var integer
35
     */
36
    public $app_id;
37
38
    /**
39
     *
40
     * @var integer
41
     */
42
    public $name;
43
44
    /**
45
     *
46
     * @var integer
47
     */
48
    public $template;
49
50
    /**
51
     *
52
     * @var string
53
     */
54
    public $users_id;
55
56
    /**
57
     *
58
     * @var integer
59
     */
60
    public $is_deleted;
61
62
    /**
63
     *
64
     * @var string
65
     */
66
    public $created_at;
67
68
    /**
69
     *
70
     * @var string
71
     */
72
    public $updated_at;
73
74
    /**
75
     * Initialize method for model.
76
     */
77 3
    public function initialize()
78
    {
79 3
        $this->setSource('email_templates');
80 3
    }
81
82
    /**
83
     * Returns table name mapped in the model.
84
     *
85
     * @return string
86
     */
87 3
    public function getSource(): string
88
    {
89 3
        return 'email_templates';
90
    }
91
92
    /**
93
     * Retrieve email template by name
94
     * @param $name
95
     * @return EmailTemplates
96
     */
97
    public function getByName(string $name): EmailTemplates
98
    {
99
        $emailTemplate = self::findFirst([
100
            'conditions' => 'company_id = ?1 and app_id = ?2 and name = ?3 and is_deleted = 0',
101
            'bind' => [Di::getDefault()->getUserData()->default_company, Di::getDefault()->getConfig()->app->id, $name]
102
        ]);
103
104
        if (!is_object($emailTemplate)) {
105
            throw new UnprocessableEntityHttpException((string) current($emailTemplate->getMessages()));
106
        }
107
108
        return $emailTemplate;
109
    }
110
}
111