Completed
Push — master ( 88a580...076511 )
by Alexander
04:13
created

Page::setMetaTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Page\Model;
4
5
use Application\Mvc\Model\Model;
6
use Phalcon\Mvc\Model\Validator\Uniqueness;
7
use Phalcon\Mvc\Model\Validator\PresenceOf;
8
use Application\Localization\Transliterator;
9
10
class Page extends Model
11
{
12
13
    public function getSource()
14
    {
15
        return "page";
16
    }
17
18
    protected $translateModel = 'Page\Model\Translate\PageTranslate'; // translate
19
20
    public $id;
21
    public $slug;
22
    public $title; // translate
23
    public $text; // translate
24
    public $meta_title; // translate
25
    public $meta_description; // translate
26
    public $meta_keywords; // translate
27
    public $created_at;
28
    public $updated_at;
29
30
    public function initialize()
31
    {
32
        $this->hasMany("id", $this->translateModel, "foreign_id"); // translate
33
    }
34
35
    public function beforeCreate()
36
    {
37
        $this->created_at = date("Y-m-d H:i:s");
38
    }
39
40
    public function beforeUpdate()
41
    {
42
        $this->updated_at = date("Y-m-d H:i:s");
43
    }
44
45
    public function updateFields($data)
46
    {
47
        if (!$this->getSlug()) {
48
            $this->setSlug(Transliterator::slugify($data['title']));
49
        }
50
        if (!$this->getMetaTitle()) {
51
            $this->setMetaTitle($data['title']);
52
        }
53
    }
54
55
    public function validation()
56
    {
57
        $this->validate(new Uniqueness(
58
            array(
59
                "field" => "slug",
60
                "message" => "Page with slug is already exists"
61
            )
62
        ));
63
64
        return $this->validationHasFailed() != true;
65
    }
66
67 View Code Duplication
    public static function findCachedBySlug($slug)
68
    {
69
        $query = "slug = '$slug'";
70
        $key = HOST_HASH . md5("Page::findFirst($query)");
71
        $page = self::findFirst(array($query, 'cache' => array('key' => $key, 'lifetime' => 60)));
72
        return $page;
73
    }
74
75
    /**
76
     * @param mixed $created_at
77
     */
78
    public function setCreatedAt($created_at)
79
    {
80
        $this->created_at = $created_at;
81
        return $this;
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getCreatedAt()
88
    {
89
        return $this->created_at;
90
    }
91
92
    /**
93
     * @param mixed $id
94
     */
95
    public function setId($id)
96
    {
97
        $this->id = $id;
98
        return $this;
99
    }
100
101
    /**
102
     * @return mixed
103
     */
104
    public function getId()
105
    {
106
        return $this->id;
107
    }
108
109
    /**
110
     * @param mixed $meta_description
111
     */
112
    public function setMetaDescription($meta_description)
113
    {
114
        $this->setMLVariable('meta_description', $meta_description);
115
        return $this;
116
    }
117
118
    /**
119
     * @return mixed
120
     */
121
    public function getMetaDescription()
122
    {
123
        return $this->getMLVariable('meta_description');
124
    }
125
126
    /**
127
     * @param mixed $meta_keywords
128
     */
129
    public function setMetaKeywords($meta_keywords)
130
    {
131
        $this->setMLVariable('meta_keywords', $meta_keywords);
132
        return $this;
133
    }
134
135
    /**
136
     * @return mixed
137
     */
138
    public function getMetaKeywords()
139
    {
140
        return $this->getMLVariable('meta_keywords');
141
    }
142
143
    /**
144
     * @param mixed $meta_title
145
     */
146
    public function setMetaTitle($meta_title)
147
    {
148
        $this->setMLVariable('meta_title', $meta_title);
149
        return $this;
150
    }
151
152
    /**
153
     * @return mixed
154
     */
155
    public function getMetaTitle()
156
    {
157
        return $this->getMLVariable('meta_title');
158
    }
159
160
    /**
161
     * @param mixed $slug
162
     */
163
    public function setSlug($slug)
164
    {
165
        $this->slug = $slug;
166
        return $this;
167
    }
168
169
    /**
170
     * @return mixed
171
     */
172
    public function getSlug()
173
    {
174
        return $this->slug;
175
    }
176
177
    /**
178
     * @param mixed $text
179
     */
180
    public function setText($text)
181
    {
182
        $this->setMLVariable('text', $text);
183
        return $this;
184
    }
185
186
    /**
187
     * @return mixed
188
     */
189
    public function getText()
190
    {
191
        return $this->getMLVariable('text');
192
    }
193
194
    /**
195
     * @param mixed $title
196
     */
197
    public function setTitle($title)
198
    {
199
        $this->setMLVariable('title', $title);
200
        return $this;
201
    }
202
203
    /**
204
     * @return mixed
205
     */
206
    public function getTitle()
207
    {
208
        return $this->getMLVariable('title');
209
    }
210
211
    /**
212
     * @param mixed $updated_at
213
     */
214
    public function setUpdatedAt($updated_at)
215
    {
216
        $this->updated_at = $updated_at;
217
        return $this;
218
    }
219
220
    /**
221
     * @return mixed
222
     */
223
    public function getUpdatedAt()
224
    {
225
        return $this->updated_at;
226
    }
227
228
}
229