Completed
Push — master ( 8edafe...cb9f87 )
by Charles
08:15
created
protected/models/Content.php 3 patches
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -31,621 +31,621 @@
 block discarded – undo
31 31
  */
32 32
 class Content extends CiiModel
33 33
 {
34
-	public $pageSize = 9;
35
-
36
-	public $viewFile = 'blog';
37
-
38
-	public $layoutFile = 'blog';
39
-
40
-	public $autosavedata = false;
41
-
42
-	/**
43
-	 * Returns the static model of the specified AR class.
44
-	 * @param string $className active record class name.
45
-	 * @return Content the static model class
46
-	 */
47
-	public static function model($className=__CLASS__)
48
-	{
49
-		return parent::model($className);
50
-	}
51
-
52
-	/**
53
-	 * @return string the associated database table name
54
-	 */
55
-	public function tableName()
56
-	{
57
-		return 'content';
58
-	}
59
-
60
-	/**
61
-	 * @return string[] primary key of the table
62
-	 **/
63
-	public function primaryKey()
64
-	{
65
-		return array('id');
66
-	}
67
-
68
-	/**
69
-	 * @return array validation rules for model attributes.
70
-	 */
71
-	public function rules()
72
-	{
73
-		// NOTE: you should only define rules for those attributes that
74
-		// will receive user inputs.
75
-		return array(
76
-			array('vid, author_id, title, content, status, commentable, category_id', 'required'),
77
-			array('vid, author_id, status, commentable, category_id, type_id, like_count', 'numerical', 'integerOnly'=>true),
78
-			array('title, password, slug', 'length', 'max'=>150),
79
-			// The following rule is used by search().
80
-			array('id, vid, author_id, title, content, excerpt, status, commentable, category_id, type_id, password, like_count, slug, published, created, updated', 'safe', 'on'=>'search'),
81
-		);
82
-	}
83
-
84
-	/**
85
-	 * @return array relational rules.
86
-	 */
87
-	public function relations()
88
-	{
89
-		// NOTE: you may need to adjust the relation name and the related
90
-		// class name for the relations automatically generated below.
91
-		return array(
92
-			'comments' 	=> array(self::HAS_MANY, 'Comments', 'content_id'),
93
-			'author' 	=> array(self::BELONGS_TO, 'Users', 'author_id'),
94
-			'category' 	=> array(self::BELONGS_TO, 'Categories', 'category_id'),
95
-			'metadata' 	=> array(self::HAS_MANY, 'ContentMetadata', 'content_id'),
96
-		);
97
-	}
98
-
99
-	/**
100
-	 * @return array customized attribute labels (name=>label)
101
-	 */
102
-	public function attributeLabels()
103
-	{
104
-		return array(
105
-			'id' 			=> Yii::t('ciims.models.Content', 'ID'),
106
-			'vid' 			=> Yii::t('ciims.models.Content', 'Version'),
107
-			'author_id' 	=> Yii::t('ciims.models.Content', 'Author'),
108
-			'title' 		=> Yii::t('ciims.models.Content', 'Title'),
109
-			'content' 		=> Yii::t('ciims.models.Content', 'Content'),
110
-			'excerpt' 		=> Yii::t('ciims.models.Content', 'excerpt'),
111
-			'status' 		=> Yii::t('ciims.models.Content', 'Status'),
112
-			'commentable' 	=> Yii::t('ciims.models.Content', 'Commentable'),
113
-			'category_id' 	=> Yii::t('ciims.models.Content', 'Category'),
114
-			'type_id' 		=> Yii::t('ciims.models.Content', 'Type'),
115
-			'password' 		=> Yii::t('ciims.models.Content', 'Password'),
116
-			'like_count' 	=> Yii::t('ciims.models.Content', 'Likes'),
117
-			'tags' 			=> Yii::t('ciims.models.Content', 'Tags'),
118
-			'slug' 			=> Yii::t('ciims.models.Content', 'Slug'),
119
-			'published' 	=> Yii::t('ciims.models.Content', 'Published'),
120
-			'created' 		=> Yii::t('ciims.models.Content', 'Created'),
121
-			'updated' 		=> Yii::t('ciims.models.Content', 'Updated'),
122
-		);
123
-	}
124
-
125
-	/**
126
-	 * Returns a safe output to the theme
127
-	 * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text
128
-	 * @return string
129
-	 */
130
-	public function getSafeOutput()
131
-	{
132
-		$md = new CMarkdownParser;
133
-		$dom = new DOMDocument();
134
-		$dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
135
-		$x = new DOMXPath($dom);
136
-
137
-		foreach ($x->query('//a') as $node)
138
-		{
139
-			$element = $node->getAttribute('href');
140
-			if (isset($element[0]) && $element[0] !== "/")
141
-			{
142
-				$node->setAttribute('rel', 'nofollow');
143
-				$node->setAttribute('target', '_blank');
144
-			}
145
-		}
146
-
147
-		return $md->safeTransform($dom->saveHtml());
148
-	}
149
-
150
-	public function getExtract()
151
-	{
152
-		Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
153
-		return $this->excerpt;
154
-	}
155
-
156
-	/**
157
-	 * Correctly retrieves the number of likes for a particular post.
158
-	 *
159
-	 * This was added to address an issue with the like count changing if an article was updated
160
-	 * @return int    The number of likes for this post
161
-	 */
162
-
163
-	public function getLikeCount()
164
-	{
165
-		$meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
166
-		if ($meta === NULL)
167
-			return 0;
168
-
169
-		return $meta->value;
170
-	}
171
-
172
-	/**
173
-	 * Gets keyword tags for this entry
174
-	 * @return array
175
-	 */
176
-	public function getTags()
177
-	{
178
-		$tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
179
-		return $tags === NULL ? array() : json_decode($tags->value, true);
180
-	}
181
-
182
-	/**
183
-	 * Adds a tag to the model
184
-	 * @param string $tag	The tag to add
185
-	 * @return bool			If the insert was successful or not
186
-	 */
187
-	public function addTag($tag)
188
-	{
189
-		$tags = $this->tags;
190
-		if (in_array($tag, $tags)  || $tag == "")
191
-			return false;
192
-
193
-		$tags[] = $tag;
194
-		$tags = json_encode($tags);
195
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
196
-
197
-		$meta->value = $tags;
198
-		return $meta->save();
199
-	}
200
-
201
-	/**
202
-	 * Removes a tag from the model
203
-	 * @param string $tag	The tag to remove
204
-	 * @return bool			If the removal was successful
205
-	 */
206
-	public function removeTag($tag)
207
-	{
208
-		$tags = $this->tags;
209
-		if (!in_array($tag, $tags) || $tag == "")
210
-			return false;
211
-
212
-		$key = array_search($tag, $tags);
213
-		unset($tags[$key]);
214
-		$tags = json_encode($tags);
215
-
216
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
217
-		$meta->value = $tags;
218
-		return $meta->save();
219
-	}
220
-
221
-	/**
222
-	 * Provides a base criteria for status, uniqueness, and published states
223
-	 * @return CDBCriteria
224
-	 */
225
-	public function getBaseCriteria()
226
-	{
227
-		$criteria = new CDbCriteria();
228
-		return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
229
-					    ->addCondition('status = 1')
230
-					    ->addCondition('UNIX_TIMESTAMP() >= published');
231
-	}	
232
-
233
-	/**
234
-	 * Returns the appropriate status' depending up the user's role
235
-	 * @return string[]
236
-	 */
237
-	public function getStatuses()
238
-	{
239
-
240
-		if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7)
241
-			return array(0 => Yii::t('ciims.models.Content', 'Draft'));
242
-
243
-		return array(
244
-			1 => Yii::t('ciims.models.Content', 'Published'),
245
-			2 => Yii::t('ciims.models.Content', 'Ready for Review'),
246
-			0 => Yii::t('ciims.models.Content', 'Draft')
247
-		);
248
-	}
249
-
250
-	/**
251
-	 * Determines if an article is published or not
252
-	 * @return boolean
253
-	 */
254
-	public function isPublished()
255
-	{
256
-		return ($this->status == 1 && ($this->published <= time())) ? true : false;
257
-	}
258
-
259
-	/**
260
-	 * Determines if a given articled is scheduled or not
261
-	 * @return boolean
262
-	 */
263
-	public function isScheduled()
264
-	{
265
-		return ($this->status == 1 && ($this->published > time())) ? true : false;
266
-	}
267
-
268
-	/**
269
-	 * Gets a flattened list of keyword tags for jQuery.tag.js
270
-	 * @return string
271
-	 */
272
-	public function getTagsFlat()
273
-	{
274
-		return implode(',', $this->tags);
275
-	}
276
-
277
-	/**
278
-	 * Retrieves the layout used from Metadata
279
-	 * We cache this to speed up the viewfile
280
-	 */
281
-	public function getLayout()
282
-	{
283
-		$model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
284
-		return $model === NULL ? 'blog' : $model->value;
285
-	}
286
-
287
-	/**
288
-	 * Sets the layout
289
-	 * @param string $data  the layout file
290
-	 * @return boolean
291
-	 */
292
-	public function setLayout($data)
293
-	{
294
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
295
-		$meta->value = $data;
296
-		return $meta->save();
297
-	}
298
-
299
-	/**
300
-	 * Sets the view
301
-	 * @param string $data  The view file
302
-	 * @return boolean
303
-	 */
304
-	public function setView($data)
305
-	{
306
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
307
-		$meta->value = $data;
308
-		return $meta->save();
309
-	}
310
-
311
-	/**
312
-	 * Retrieves the viewfile used from Metadata
313
-	 * We cache this to speed up the viewfile
314
-	 */
315
-	public function getView()
316
-	{
317
-		$model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
318
-		return $model === NULL ? 'blog' : $model->value;
319
-	}
320
-
321
-	/**
322
-	 * Updates the like_count after finding new data
323
-	 */
324
-	protected function afterFind()
325
-	{
326
-		parent::afterFind();
327
-		$this->like_count = $this->getLikeCount();
328
-	}
329
-
330
-	/**
331
-	 * Retrieves a list of models based on the current search/filter conditions.
332
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
333
-	 */
334
-	public function search()
335
-	{
336
-		$criteria=new CDbCriteria;
337
-
338
-		$criteria->compare('id',$this->id);
339
-		$criteria->compare('title',$this->title,true);
340
-		$criteria->compare('slug',$this->slug,true);
341
-		$criteria->compare('author_id',$this->author_id,true);
342
-		$criteria->compare('category_id',$this->category_id,true);
343
-		$criteria->compare('content',$this->content,true);
344
-		$criteria->compare('password', $this->password, true);
345
-		$criteria->compare('created',$this->created,true);
346
-		$criteria->compare('updated',$this->updated,true);
347
-		$criteria->compare('status', $this->status, true);
348
-
349
-		// Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare
350
-		if (is_bool($this->published))
351
-		{
352
-			if ($this->published)
353
-				$criteria->addCondition('published <= UNIX_TIMESTAMP()');
354
-			else
355
-				$criteria->addCondition('published > UNIX_TIMESTAMP()');
356
-		}
357
-		else
358
-			$criteria->compare('published', $this->published,true);
359
-		$criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
360
-
361
-		// TODO: Figure out how to restore CActiveDataProvidor by getCommentCount
362
-		return new CActiveDataProvider($this, array(
363
-			'criteria' => $criteria,
364
-			'sort' => array(
365
-				'defaultOrder' => 'published DESC'
366
-			),
367
-			'pagination' => array(
368
-				'pageSize' => $this->pageSize
369
-			)
370
-		));
371
-	}
372
-
373
-	/**
374
-	 * Finds all active records with the specified primary keys.
375
-	 * Overloaded to support composite primary keys. For our content, we want to find the latest version of that primary key, defined as MAX(vid) WHERE id = pk
376
-	 * See {@link find()} for detailed explanation about $condition and $params.
377
-	 * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
378
-	 * @param mixed $condition query condition or criteria.
379
-	 * @param array $params parameters to be bound to an SQL statement.
380
-	 * @return array the records found. An empty array is returned if none is found.
381
-	 */
382
-	public function findByPk($pk, $condition='', $params=array())
383
-	{
384
-		// If we do not supply a condition or parameters, use our overwritten method
385
-		if ($condition == '' && empty($params) && $pk != null)
386
-		{
387
-			if (!is_numeric($pk))
388
-				throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
34
+    public $pageSize = 9;
35
+
36
+    public $viewFile = 'blog';
37
+
38
+    public $layoutFile = 'blog';
39
+
40
+    public $autosavedata = false;
41
+
42
+    /**
43
+     * Returns the static model of the specified AR class.
44
+     * @param string $className active record class name.
45
+     * @return Content the static model class
46
+     */
47
+    public static function model($className=__CLASS__)
48
+    {
49
+        return parent::model($className);
50
+    }
51
+
52
+    /**
53
+     * @return string the associated database table name
54
+     */
55
+    public function tableName()
56
+    {
57
+        return 'content';
58
+    }
59
+
60
+    /**
61
+     * @return string[] primary key of the table
62
+     **/
63
+    public function primaryKey()
64
+    {
65
+        return array('id');
66
+    }
67
+
68
+    /**
69
+     * @return array validation rules for model attributes.
70
+     */
71
+    public function rules()
72
+    {
73
+        // NOTE: you should only define rules for those attributes that
74
+        // will receive user inputs.
75
+        return array(
76
+            array('vid, author_id, title, content, status, commentable, category_id', 'required'),
77
+            array('vid, author_id, status, commentable, category_id, type_id, like_count', 'numerical', 'integerOnly'=>true),
78
+            array('title, password, slug', 'length', 'max'=>150),
79
+            // The following rule is used by search().
80
+            array('id, vid, author_id, title, content, excerpt, status, commentable, category_id, type_id, password, like_count, slug, published, created, updated', 'safe', 'on'=>'search'),
81
+        );
82
+    }
83
+
84
+    /**
85
+     * @return array relational rules.
86
+     */
87
+    public function relations()
88
+    {
89
+        // NOTE: you may need to adjust the relation name and the related
90
+        // class name for the relations automatically generated below.
91
+        return array(
92
+            'comments' 	=> array(self::HAS_MANY, 'Comments', 'content_id'),
93
+            'author' 	=> array(self::BELONGS_TO, 'Users', 'author_id'),
94
+            'category' 	=> array(self::BELONGS_TO, 'Categories', 'category_id'),
95
+            'metadata' 	=> array(self::HAS_MANY, 'ContentMetadata', 'content_id'),
96
+        );
97
+    }
98
+
99
+    /**
100
+     * @return array customized attribute labels (name=>label)
101
+     */
102
+    public function attributeLabels()
103
+    {
104
+        return array(
105
+            'id' 			=> Yii::t('ciims.models.Content', 'ID'),
106
+            'vid' 			=> Yii::t('ciims.models.Content', 'Version'),
107
+            'author_id' 	=> Yii::t('ciims.models.Content', 'Author'),
108
+            'title' 		=> Yii::t('ciims.models.Content', 'Title'),
109
+            'content' 		=> Yii::t('ciims.models.Content', 'Content'),
110
+            'excerpt' 		=> Yii::t('ciims.models.Content', 'excerpt'),
111
+            'status' 		=> Yii::t('ciims.models.Content', 'Status'),
112
+            'commentable' 	=> Yii::t('ciims.models.Content', 'Commentable'),
113
+            'category_id' 	=> Yii::t('ciims.models.Content', 'Category'),
114
+            'type_id' 		=> Yii::t('ciims.models.Content', 'Type'),
115
+            'password' 		=> Yii::t('ciims.models.Content', 'Password'),
116
+            'like_count' 	=> Yii::t('ciims.models.Content', 'Likes'),
117
+            'tags' 			=> Yii::t('ciims.models.Content', 'Tags'),
118
+            'slug' 			=> Yii::t('ciims.models.Content', 'Slug'),
119
+            'published' 	=> Yii::t('ciims.models.Content', 'Published'),
120
+            'created' 		=> Yii::t('ciims.models.Content', 'Created'),
121
+            'updated' 		=> Yii::t('ciims.models.Content', 'Updated'),
122
+        );
123
+    }
124
+
125
+    /**
126
+     * Returns a safe output to the theme
127
+     * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text
128
+     * @return string
129
+     */
130
+    public function getSafeOutput()
131
+    {
132
+        $md = new CMarkdownParser;
133
+        $dom = new DOMDocument();
134
+        $dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
135
+        $x = new DOMXPath($dom);
136
+
137
+        foreach ($x->query('//a') as $node)
138
+        {
139
+            $element = $node->getAttribute('href');
140
+            if (isset($element[0]) && $element[0] !== "/")
141
+            {
142
+                $node->setAttribute('rel', 'nofollow');
143
+                $node->setAttribute('target', '_blank');
144
+            }
145
+        }
146
+
147
+        return $md->safeTransform($dom->saveHtml());
148
+    }
149
+
150
+    public function getExtract()
151
+    {
152
+        Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
153
+        return $this->excerpt;
154
+    }
155
+
156
+    /**
157
+     * Correctly retrieves the number of likes for a particular post.
158
+     *
159
+     * This was added to address an issue with the like count changing if an article was updated
160
+     * @return int    The number of likes for this post
161
+     */
162
+
163
+    public function getLikeCount()
164
+    {
165
+        $meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
166
+        if ($meta === NULL)
167
+            return 0;
168
+
169
+        return $meta->value;
170
+    }
171
+
172
+    /**
173
+     * Gets keyword tags for this entry
174
+     * @return array
175
+     */
176
+    public function getTags()
177
+    {
178
+        $tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
179
+        return $tags === NULL ? array() : json_decode($tags->value, true);
180
+    }
181
+
182
+    /**
183
+     * Adds a tag to the model
184
+     * @param string $tag	The tag to add
185
+     * @return bool			If the insert was successful or not
186
+     */
187
+    public function addTag($tag)
188
+    {
189
+        $tags = $this->tags;
190
+        if (in_array($tag, $tags)  || $tag == "")
191
+            return false;
192
+
193
+        $tags[] = $tag;
194
+        $tags = json_encode($tags);
195
+        $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
196
+
197
+        $meta->value = $tags;
198
+        return $meta->save();
199
+    }
200
+
201
+    /**
202
+     * Removes a tag from the model
203
+     * @param string $tag	The tag to remove
204
+     * @return bool			If the removal was successful
205
+     */
206
+    public function removeTag($tag)
207
+    {
208
+        $tags = $this->tags;
209
+        if (!in_array($tag, $tags) || $tag == "")
210
+            return false;
211
+
212
+        $key = array_search($tag, $tags);
213
+        unset($tags[$key]);
214
+        $tags = json_encode($tags);
215
+
216
+        $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
217
+        $meta->value = $tags;
218
+        return $meta->save();
219
+    }
220
+
221
+    /**
222
+     * Provides a base criteria for status, uniqueness, and published states
223
+     * @return CDBCriteria
224
+     */
225
+    public function getBaseCriteria()
226
+    {
227
+        $criteria = new CDbCriteria();
228
+        return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
229
+                        ->addCondition('status = 1')
230
+                        ->addCondition('UNIX_TIMESTAMP() >= published');
231
+    }	
232
+
233
+    /**
234
+     * Returns the appropriate status' depending up the user's role
235
+     * @return string[]
236
+     */
237
+    public function getStatuses()
238
+    {
239
+
240
+        if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7)
241
+            return array(0 => Yii::t('ciims.models.Content', 'Draft'));
242
+
243
+        return array(
244
+            1 => Yii::t('ciims.models.Content', 'Published'),
245
+            2 => Yii::t('ciims.models.Content', 'Ready for Review'),
246
+            0 => Yii::t('ciims.models.Content', 'Draft')
247
+        );
248
+    }
249
+
250
+    /**
251
+     * Determines if an article is published or not
252
+     * @return boolean
253
+     */
254
+    public function isPublished()
255
+    {
256
+        return ($this->status == 1 && ($this->published <= time())) ? true : false;
257
+    }
258
+
259
+    /**
260
+     * Determines if a given articled is scheduled or not
261
+     * @return boolean
262
+     */
263
+    public function isScheduled()
264
+    {
265
+        return ($this->status == 1 && ($this->published > time())) ? true : false;
266
+    }
267
+
268
+    /**
269
+     * Gets a flattened list of keyword tags for jQuery.tag.js
270
+     * @return string
271
+     */
272
+    public function getTagsFlat()
273
+    {
274
+        return implode(',', $this->tags);
275
+    }
276
+
277
+    /**
278
+     * Retrieves the layout used from Metadata
279
+     * We cache this to speed up the viewfile
280
+     */
281
+    public function getLayout()
282
+    {
283
+        $model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
284
+        return $model === NULL ? 'blog' : $model->value;
285
+    }
286
+
287
+    /**
288
+     * Sets the layout
289
+     * @param string $data  the layout file
290
+     * @return boolean
291
+     */
292
+    public function setLayout($data)
293
+    {
294
+        $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
295
+        $meta->value = $data;
296
+        return $meta->save();
297
+    }
298
+
299
+    /**
300
+     * Sets the view
301
+     * @param string $data  The view file
302
+     * @return boolean
303
+     */
304
+    public function setView($data)
305
+    {
306
+        $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
307
+        $meta->value = $data;
308
+        return $meta->save();
309
+    }
310
+
311
+    /**
312
+     * Retrieves the viewfile used from Metadata
313
+     * We cache this to speed up the viewfile
314
+     */
315
+    public function getView()
316
+    {
317
+        $model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
318
+        return $model === NULL ? 'blog' : $model->value;
319
+    }
320
+
321
+    /**
322
+     * Updates the like_count after finding new data
323
+     */
324
+    protected function afterFind()
325
+    {
326
+        parent::afterFind();
327
+        $this->like_count = $this->getLikeCount();
328
+    }
329
+
330
+    /**
331
+     * Retrieves a list of models based on the current search/filter conditions.
332
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
333
+     */
334
+    public function search()
335
+    {
336
+        $criteria=new CDbCriteria;
337
+
338
+        $criteria->compare('id',$this->id);
339
+        $criteria->compare('title',$this->title,true);
340
+        $criteria->compare('slug',$this->slug,true);
341
+        $criteria->compare('author_id',$this->author_id,true);
342
+        $criteria->compare('category_id',$this->category_id,true);
343
+        $criteria->compare('content',$this->content,true);
344
+        $criteria->compare('password', $this->password, true);
345
+        $criteria->compare('created',$this->created,true);
346
+        $criteria->compare('updated',$this->updated,true);
347
+        $criteria->compare('status', $this->status, true);
348
+
349
+        // Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare
350
+        if (is_bool($this->published))
351
+        {
352
+            if ($this->published)
353
+                $criteria->addCondition('published <= UNIX_TIMESTAMP()');
354
+            else
355
+                $criteria->addCondition('published > UNIX_TIMESTAMP()');
356
+        }
357
+        else
358
+            $criteria->compare('published', $this->published,true);
359
+        $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
360
+
361
+        // TODO: Figure out how to restore CActiveDataProvidor by getCommentCount
362
+        return new CActiveDataProvider($this, array(
363
+            'criteria' => $criteria,
364
+            'sort' => array(
365
+                'defaultOrder' => 'published DESC'
366
+            ),
367
+            'pagination' => array(
368
+                'pageSize' => $this->pageSize
369
+            )
370
+        ));
371
+    }
372
+
373
+    /**
374
+     * Finds all active records with the specified primary keys.
375
+     * Overloaded to support composite primary keys. For our content, we want to find the latest version of that primary key, defined as MAX(vid) WHERE id = pk
376
+     * See {@link find()} for detailed explanation about $condition and $params.
377
+     * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
378
+     * @param mixed $condition query condition or criteria.
379
+     * @param array $params parameters to be bound to an SQL statement.
380
+     * @return array the records found. An empty array is returned if none is found.
381
+     */
382
+    public function findByPk($pk, $condition='', $params=array())
383
+    {
384
+        // If we do not supply a condition or parameters, use our overwritten method
385
+        if ($condition == '' && empty($params) && $pk != null)
386
+        {
387
+            if (!is_numeric($pk))
388
+                throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
389 389
 				
390
-			$criteria = new CDbCriteria;
391
-			$criteria->addCondition("t.id=:pk");
392
-			$criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
393
-			$criteria->params = array(
394
-				':pk' => $pk
395
-			);
396
-			return $this->query($criteria);
397
-		}
398
-
399
-		return parent::findByPk($pk, $condition, $params);
400
-	}
401
-
402
-	/**
403
-	 * Lists all revisions in the database for a givenid
404
-	 * @param  int $id [description]
405
-	 * @return array
406
-	 */
407
-	public function findRevisions($id)
408
-	{
409
-		if (!is_numeric($id))
410
-			throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
390
+            $criteria = new CDbCriteria;
391
+            $criteria->addCondition("t.id=:pk");
392
+            $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
393
+            $criteria->params = array(
394
+                ':pk' => $pk
395
+            );
396
+            return $this->query($criteria);
397
+        }
398
+
399
+        return parent::findByPk($pk, $condition, $params);
400
+    }
401
+
402
+    /**
403
+     * Lists all revisions in the database for a givenid
404
+     * @param  int $id [description]
405
+     * @return array
406
+     */
407
+    public function findRevisions($id)
408
+    {
409
+        if (!is_numeric($id))
410
+            throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
411 411
 				
412
-		$criteria = new CDbCriteria;
413
-		$criteria->addCondition("id=:id");
414
-		$criteria->params = array(
415
-			':id' => $id
416
-		);
417
-		$criteria->order = 'vid DESC';
418
-
419
-		return $this->query($criteria, true);
420
-	}
421
-
422
-	/**
423
-	 * BeforeValidate
424
-	 * @see CActiveRecord::beforeValidate
425
-	 */
426
-	public function beforeValidate()
427
-	{
428
-		// Allow publication times to be set automatically
429
-		if (empty($this->published))
430
-			$this->published = time();
431
-
432
-		if (strlen($this->excerpt) == 0)
433
-			$this->excerpt = $this->myTruncate($this->content, 250, '.', '');
434
-
435
-		return parent::beforeValidate();
436
-	}
437
-
438
-	/**
439
-	 * Saves a prototype copy of the model so that we can get an id back to work with
440
-	 * @return boolean 	$model->save(false) without any validation rules
441
-	 */
442
-	public function savePrototype($author_id)
443
-	{
444
-		$this->title = '';
445
-		$this->content = '';
446
-		$this->excerpt = '';
447
-		$this->commentable = 1;
448
-		$this->status = 0;
449
-		$this->category_id = 1;
450
-		$this->type_id = 2;
451
-		$this->password = null;
452
-		$this->created = time();
453
-		$this->updated = time();
454
-		$this->published = time();
455
-		$this->vid = 1;
456
-		$this->slug = "";
457
-		$this->author_id = $author_id;
458
-
459
-		// TODO: Why doesn't Yii return the PK id field? But it does return VID? AutoIncriment bug?
460
-		if ($this->save(false))
461
-		{
462
-			$data = Content::model()->findByAttributes(array('created' => $this->created));
463
-			$this->id = $data->id;
464
-			return true;
465
-		}
466
-
467
-		return false;
468
-	}
469
-
470
-	/**
471
-	 * BeforeSave
472
-	 * Clears caches for rebuilding, creates the end slug that we are going to use
473
-	 * @see CActiveRecord::beforeSave();
474
-	 */
475
-	public function beforeSave()
476
-	{
477
-		$this->slug = $this->verifySlug($this->slug, $this->title);
478
-		Yii::app()->cache->delete('CiiMS::Content::list');
479
-		Yii::app()->cache->delete('CiiMS::Routes');
480
-
481
-		Yii::app()->cache->set('content-' . $this->id . '-layout', $this->layoutFile);
482
-		Yii::app()->cache->set('content-' . $this->id . '-view', $this->viewFile);
483
-
484
-		return parent::beforeSave();
485
-	}
486
-
487
-	/**
488
-	 * AfterSave
489
-	 * Updates the layout and view if necessary
490
-	 * @see CActiveRecord::afterSave()
491
-	 */
492
-	public function afterSave()
493
-	{
494
-		// Delete the AutoSave document on update
495
-		if ($this->isPublished())
496
-		{
497
-			$autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
498
-			if ($autosaveModel != NULL)
499
-				$autosaveModel->delete();
500
-		}
501
-
502
-		return parent::afterSave();
503
-	}
504
-
505
-	/**
506
-	 * BeforeDelete
507
-	 * Clears caches for rebuilding
508
-	 * @see CActiveRecord::beforeDelete
509
-	 */
510
-	public function beforeDelete()
511
-	{
512
-		Yii::app()->cache->delete('CiiMS::Content::list');
513
-		Yii::app()->cache->delete('CiiMS::Routes');
514
-		Yii::app()->cache->delete('content-' . $this->id . '-layout');
515
-		Yii::app()->cache->delete('content-' . $this->id . '-view');
516
-
517
-		return parent::beforeDelete();
518
-	}
519
-
520
-
521
-	/**
522
-	 * Retrieves the available view files under the current theme
523
-	 * @return array    A list of files by name
524
-	 */
525
-	public function getViewFiles($theme=null)
526
-	{
527
-		return $this->getFiles($theme, 'views.content');
528
-	}
529
-
530
-	/**
531
-	 * Retrieves the available layouts under the current theme
532
-	 * @return array    A list of files by name
533
-	 */
534
-	public function getLayoutFiles($theme=null)
535
-	{
536
-		return $this->getFiles($theme, 'views.layouts');
537
-	}
538
-
539
-	/**
540
-	 * Retrieves view files for a particular path
541
-	 * @param  string $theme  The theme to reference
542
-	 * @param  string $type   The view type to lookup
543
-	 * @return array $files   An array of files
544
-	 */
545
-	private function getFiles($theme=null, $type='views')
546
-	{
547
-		if ($theme === null)
548
-			$theme = Cii::getConfig('theme', 'default');
549
-
550
-		$folder = $type;
551
-
552
-		if ($type == 'view')
553
-			$folder = 'content';
554
-
555
-		$returnFiles = array();
556
-
557
-		if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
558
-			$theme = 'default';
559
-
560
-		$files = Yii::app()->cache->get($theme.'-available-' . $type);
561
-
562
-		if ($files === false)
563
-		{
564
-			$fileHelper = new CFileHelper;
565
-			$files = $fileHelper->findFiles(Yii::getPathOfAlias('base.themes.' . $theme .'.' . $folder), array('fileTypes'=>array('php'), 'level'=>0));
566
-			Yii::app()->cache->set($theme.'-available-' . $type, $files);
567
-		}
568
-
569
-		foreach ($files as $file)
570
-		{
571
-			$f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
572
-
573
-			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
574
-				$f = trim(substr($f, strrpos($f, '\\') + 1));
575
-
576
-			if (!in_array($f, array('all', 'password', '_post')))
577
-				$returnFiles[$f] = $f;
578
-		}
579
-
580
-		return $returnFiles;
581
-	}
582
-
583
-	/**
584
-	 * Fancy truncate function to help clean up our strings for the excerpt
585
-	 * @param string $string    The string we want to apply the text to
586
-	 * @param int    $limit     How many characters we want to break into
587
-	 * @param string $break     Characters we want to break on if possible
588
-	 * @param string $pad       The padding we want to apply
589
-	 * @return string           Truncated string
590
-	 */
591
-	private function myTruncate($string, $limit, $break=".", $pad="...")
592
-	{
593
-		// return with no change if string is shorter than $limit
594
-		if(strlen($string) <= $limit)
595
-			return $string;
596
-
597
-		// is $break present between $limit and the end of the string?
598
-		if(false !== ($breakpoint = strpos($string, $break, $limit)))
599
-		{
600
-			if($breakpoint < strlen($string) - 1)
601
-			{
602
-				$string = substr($string, 0, $breakpoint) . $pad;
603
-			}
604
-		}
605
-
606
-		return $string;
607
-	}
608
-
609
-	/**
610
-	 * checkSlug - Recursive method to verify that the slug can be used
611
-	 * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
612
-	 * @param string $slug - the slug to be checked
613
-	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
614
-	 * @return string $slug - the final slug to be used
615
-	 */
616
-	public function checkSlug($slug, $id=NULL)
617
-	{
618
-		$category = false;
619
-
620
-		// Find the number of items that have the same slug as this one
621
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
622
-
623
-		// Make sure we don't have a collision with a Category
624
-		if ($count == 0)
625
-		{
626
-			$category = true;
627
-			$count = Categories::model()->countByAttributes(array('slug'=>$slug . $id));
628
-		}
629
-
630
-		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
631
-		// in which case we don't need to alter the slug
632
-		if ($count)
633
-		{
634
-			// Ensures we don't have a collision on category
635
-			if ($category)
636
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
637
-
638
-			// Pull the data that matches
639
-			$data = $this->findByPk($this->id);
640
-
641
-			// Check the pulled data id to the current item
642
-			if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug)
643
-				return $slug;
644
-		}
645
-
646
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
647
-			return $slug . $id;
648
-		else
649
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
650
-	}
412
+        $criteria = new CDbCriteria;
413
+        $criteria->addCondition("id=:id");
414
+        $criteria->params = array(
415
+            ':id' => $id
416
+        );
417
+        $criteria->order = 'vid DESC';
418
+
419
+        return $this->query($criteria, true);
420
+    }
421
+
422
+    /**
423
+     * BeforeValidate
424
+     * @see CActiveRecord::beforeValidate
425
+     */
426
+    public function beforeValidate()
427
+    {
428
+        // Allow publication times to be set automatically
429
+        if (empty($this->published))
430
+            $this->published = time();
431
+
432
+        if (strlen($this->excerpt) == 0)
433
+            $this->excerpt = $this->myTruncate($this->content, 250, '.', '');
434
+
435
+        return parent::beforeValidate();
436
+    }
437
+
438
+    /**
439
+     * Saves a prototype copy of the model so that we can get an id back to work with
440
+     * @return boolean 	$model->save(false) without any validation rules
441
+     */
442
+    public function savePrototype($author_id)
443
+    {
444
+        $this->title = '';
445
+        $this->content = '';
446
+        $this->excerpt = '';
447
+        $this->commentable = 1;
448
+        $this->status = 0;
449
+        $this->category_id = 1;
450
+        $this->type_id = 2;
451
+        $this->password = null;
452
+        $this->created = time();
453
+        $this->updated = time();
454
+        $this->published = time();
455
+        $this->vid = 1;
456
+        $this->slug = "";
457
+        $this->author_id = $author_id;
458
+
459
+        // TODO: Why doesn't Yii return the PK id field? But it does return VID? AutoIncriment bug?
460
+        if ($this->save(false))
461
+        {
462
+            $data = Content::model()->findByAttributes(array('created' => $this->created));
463
+            $this->id = $data->id;
464
+            return true;
465
+        }
466
+
467
+        return false;
468
+    }
469
+
470
+    /**
471
+     * BeforeSave
472
+     * Clears caches for rebuilding, creates the end slug that we are going to use
473
+     * @see CActiveRecord::beforeSave();
474
+     */
475
+    public function beforeSave()
476
+    {
477
+        $this->slug = $this->verifySlug($this->slug, $this->title);
478
+        Yii::app()->cache->delete('CiiMS::Content::list');
479
+        Yii::app()->cache->delete('CiiMS::Routes');
480
+
481
+        Yii::app()->cache->set('content-' . $this->id . '-layout', $this->layoutFile);
482
+        Yii::app()->cache->set('content-' . $this->id . '-view', $this->viewFile);
483
+
484
+        return parent::beforeSave();
485
+    }
486
+
487
+    /**
488
+     * AfterSave
489
+     * Updates the layout and view if necessary
490
+     * @see CActiveRecord::afterSave()
491
+     */
492
+    public function afterSave()
493
+    {
494
+        // Delete the AutoSave document on update
495
+        if ($this->isPublished())
496
+        {
497
+            $autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
498
+            if ($autosaveModel != NULL)
499
+                $autosaveModel->delete();
500
+        }
501
+
502
+        return parent::afterSave();
503
+    }
504
+
505
+    /**
506
+     * BeforeDelete
507
+     * Clears caches for rebuilding
508
+     * @see CActiveRecord::beforeDelete
509
+     */
510
+    public function beforeDelete()
511
+    {
512
+        Yii::app()->cache->delete('CiiMS::Content::list');
513
+        Yii::app()->cache->delete('CiiMS::Routes');
514
+        Yii::app()->cache->delete('content-' . $this->id . '-layout');
515
+        Yii::app()->cache->delete('content-' . $this->id . '-view');
516
+
517
+        return parent::beforeDelete();
518
+    }
519
+
520
+
521
+    /**
522
+     * Retrieves the available view files under the current theme
523
+     * @return array    A list of files by name
524
+     */
525
+    public function getViewFiles($theme=null)
526
+    {
527
+        return $this->getFiles($theme, 'views.content');
528
+    }
529
+
530
+    /**
531
+     * Retrieves the available layouts under the current theme
532
+     * @return array    A list of files by name
533
+     */
534
+    public function getLayoutFiles($theme=null)
535
+    {
536
+        return $this->getFiles($theme, 'views.layouts');
537
+    }
538
+
539
+    /**
540
+     * Retrieves view files for a particular path
541
+     * @param  string $theme  The theme to reference
542
+     * @param  string $type   The view type to lookup
543
+     * @return array $files   An array of files
544
+     */
545
+    private function getFiles($theme=null, $type='views')
546
+    {
547
+        if ($theme === null)
548
+            $theme = Cii::getConfig('theme', 'default');
549
+
550
+        $folder = $type;
551
+
552
+        if ($type == 'view')
553
+            $folder = 'content';
554
+
555
+        $returnFiles = array();
556
+
557
+        if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
558
+            $theme = 'default';
559
+
560
+        $files = Yii::app()->cache->get($theme.'-available-' . $type);
561
+
562
+        if ($files === false)
563
+        {
564
+            $fileHelper = new CFileHelper;
565
+            $files = $fileHelper->findFiles(Yii::getPathOfAlias('base.themes.' . $theme .'.' . $folder), array('fileTypes'=>array('php'), 'level'=>0));
566
+            Yii::app()->cache->set($theme.'-available-' . $type, $files);
567
+        }
568
+
569
+        foreach ($files as $file)
570
+        {
571
+            $f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
572
+
573
+            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
574
+                $f = trim(substr($f, strrpos($f, '\\') + 1));
575
+
576
+            if (!in_array($f, array('all', 'password', '_post')))
577
+                $returnFiles[$f] = $f;
578
+        }
579
+
580
+        return $returnFiles;
581
+    }
582
+
583
+    /**
584
+     * Fancy truncate function to help clean up our strings for the excerpt
585
+     * @param string $string    The string we want to apply the text to
586
+     * @param int    $limit     How many characters we want to break into
587
+     * @param string $break     Characters we want to break on if possible
588
+     * @param string $pad       The padding we want to apply
589
+     * @return string           Truncated string
590
+     */
591
+    private function myTruncate($string, $limit, $break=".", $pad="...")
592
+    {
593
+        // return with no change if string is shorter than $limit
594
+        if(strlen($string) <= $limit)
595
+            return $string;
596
+
597
+        // is $break present between $limit and the end of the string?
598
+        if(false !== ($breakpoint = strpos($string, $break, $limit)))
599
+        {
600
+            if($breakpoint < strlen($string) - 1)
601
+            {
602
+                $string = substr($string, 0, $breakpoint) . $pad;
603
+            }
604
+        }
605
+
606
+        return $string;
607
+    }
608
+
609
+    /**
610
+     * checkSlug - Recursive method to verify that the slug can be used
611
+     * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
612
+     * @param string $slug - the slug to be checked
613
+     * @param int $id - the numeric id to be appended to the slug if a conflict exists
614
+     * @return string $slug - the final slug to be used
615
+     */
616
+    public function checkSlug($slug, $id=NULL)
617
+    {
618
+        $category = false;
619
+
620
+        // Find the number of items that have the same slug as this one
621
+        $count = $this->countByAttributes(array('slug'=>$slug . $id));
622
+
623
+        // Make sure we don't have a collision with a Category
624
+        if ($count == 0)
625
+        {
626
+            $category = true;
627
+            $count = Categories::model()->countByAttributes(array('slug'=>$slug . $id));
628
+        }
629
+
630
+        // If we found an item that matched, it's possible that it is the current item (or a previous version of it)
631
+        // in which case we don't need to alter the slug
632
+        if ($count)
633
+        {
634
+            // Ensures we don't have a collision on category
635
+            if ($category)
636
+                return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
637
+
638
+            // Pull the data that matches
639
+            $data = $this->findByPk($this->id);
640
+
641
+            // Check the pulled data id to the current item
642
+            if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug)
643
+                return $slug;
644
+        }
645
+
646
+        if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
647
+            return $slug . $id;
648
+        else
649
+            return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
650
+    }
651 651
 }
Please login to merge, or discard this patch.
Braces   +136 added lines, -117 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
  * @property Categories $category
30 30
  * @property ContentMetadata[] $contentMetadatas
31 31
  */
32
-class Content extends CiiModel
33
-{
32
+class Content extends CiiModel
33
+{
34 34
 	public $pageSize = 9;
35 35
 
36 36
 	public $viewFile = 'blog';
@@ -44,32 +44,32 @@  discard block
 block discarded – undo
44 44
 	 * @param string $className active record class name.
45 45
 	 * @return Content the static model class
46 46
 	 */
47
-	public static function model($className=__CLASS__)
48
-	{
47
+	public static function model($className=__CLASS__)
48
+	{
49 49
 		return parent::model($className);
50 50
 	}
51 51
 
52 52
 	/**
53 53
 	 * @return string the associated database table name
54 54
 	 */
55
-	public function tableName()
56
-	{
55
+	public function tableName()
56
+	{
57 57
 		return 'content';
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * @return string[] primary key of the table
62 62
 	 **/
63
-	public function primaryKey()
64
-	{
63
+	public function primaryKey()
64
+	{
65 65
 		return array('id');
66 66
 	}
67 67
 
68 68
 	/**
69 69
 	 * @return array validation rules for model attributes.
70 70
 	 */
71
-	public function rules()
72
-	{
71
+	public function rules()
72
+	{
73 73
 		// NOTE: you should only define rules for those attributes that
74 74
 		// will receive user inputs.
75 75
 		return array(
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	/**
85 85
 	 * @return array relational rules.
86 86
 	 */
87
-	public function relations()
88
-	{
87
+	public function relations()
88
+	{
89 89
 		// NOTE: you may need to adjust the relation name and the related
90 90
 		// class name for the relations automatically generated below.
91 91
 		return array(
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	/**
100 100
 	 * @return array customized attribute labels (name=>label)
101 101
 	 */
102
-	public function attributeLabels()
103
-	{
102
+	public function attributeLabels()
103
+	{
104 104
 		return array(
105 105
 			'id' 			=> Yii::t('ciims.models.Content', 'ID'),
106 106
 			'vid' 			=> Yii::t('ciims.models.Content', 'Version'),
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
 	 * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text
128 128
 	 * @return string
129 129
 	 */
130
-	public function getSafeOutput()
131
-	{
130
+	public function getSafeOutput()
131
+	{
132 132
 		$md = new CMarkdownParser;
133 133
 		$dom = new DOMDocument();
134 134
 		$dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 		return $md->safeTransform($dom->saveHtml());
148 148
 	}
149 149
 
150
-	public function getExtract()
151
-	{
150
+	public function getExtract()
151
+	{
152 152
 		Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
153 153
 		return $this->excerpt;
154 154
 	}
@@ -160,11 +160,12 @@  discard block
 block discarded – undo
160 160
 	 * @return int    The number of likes for this post
161 161
 	 */
162 162
 
163
-	public function getLikeCount()
164
-	{
163
+	public function getLikeCount()
164
+	{
165 165
 		$meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
166
-		if ($meta === NULL)
167
-			return 0;
166
+		if ($meta === NULL) {
167
+					return 0;
168
+		}
168 169
 
169 170
 		return $meta->value;
170 171
 	}
@@ -173,8 +174,8 @@  discard block
 block discarded – undo
173 174
 	 * Gets keyword tags for this entry
174 175
 	 * @return array
175 176
 	 */
176
-	public function getTags()
177
-	{
177
+	public function getTags()
178
+	{
178 179
 		$tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
179 180
 		return $tags === NULL ? array() : json_decode($tags->value, true);
180 181
 	}
@@ -184,11 +185,12 @@  discard block
 block discarded – undo
184 185
 	 * @param string $tag	The tag to add
185 186
 	 * @return bool			If the insert was successful or not
186 187
 	 */
187
-	public function addTag($tag)
188
-	{
188
+	public function addTag($tag)
189
+	{
189 190
 		$tags = $this->tags;
190
-		if (in_array($tag, $tags)  || $tag == "")
191
-			return false;
191
+		if (in_array($tag, $tags)  || $tag == "") {
192
+					return false;
193
+		}
192 194
 
193 195
 		$tags[] = $tag;
194 196
 		$tags = json_encode($tags);
@@ -203,11 +205,12 @@  discard block
 block discarded – undo
203 205
 	 * @param string $tag	The tag to remove
204 206
 	 * @return bool			If the removal was successful
205 207
 	 */
206
-	public function removeTag($tag)
207
-	{
208
+	public function removeTag($tag)
209
+	{
208 210
 		$tags = $this->tags;
209
-		if (!in_array($tag, $tags) || $tag == "")
210
-			return false;
211
+		if (!in_array($tag, $tags) || $tag == "") {
212
+					return false;
213
+		}
211 214
 
212 215
 		$key = array_search($tag, $tags);
213 216
 		unset($tags[$key]);
@@ -222,8 +225,8 @@  discard block
 block discarded – undo
222 225
 	 * Provides a base criteria for status, uniqueness, and published states
223 226
 	 * @return CDBCriteria
224 227
 	 */
225
-	public function getBaseCriteria()
226
-	{
228
+	public function getBaseCriteria()
229
+	{
227 230
 		$criteria = new CDbCriteria();
228 231
 		return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
229 232
 					    ->addCondition('status = 1')
@@ -234,11 +237,12 @@  discard block
 block discarded – undo
234 237
 	 * Returns the appropriate status' depending up the user's role
235 238
 	 * @return string[]
236 239
 	 */
237
-	public function getStatuses()
238
-	{
240
+	public function getStatuses()
241
+	{
239 242
 
240
-		if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7)
241
-			return array(0 => Yii::t('ciims.models.Content', 'Draft'));
243
+		if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7) {
244
+					return array(0 => Yii::t('ciims.models.Content', 'Draft'));
245
+		}
242 246
 
243 247
 		return array(
244 248
 			1 => Yii::t('ciims.models.Content', 'Published'),
@@ -251,8 +255,8 @@  discard block
 block discarded – undo
251 255
 	 * Determines if an article is published or not
252 256
 	 * @return boolean
253 257
 	 */
254
-	public function isPublished()
255
-	{
258
+	public function isPublished()
259
+	{
256 260
 		return ($this->status == 1 && ($this->published <= time())) ? true : false;
257 261
 	}
258 262
 
@@ -260,8 +264,8 @@  discard block
 block discarded – undo
260 264
 	 * Determines if a given articled is scheduled or not
261 265
 	 * @return boolean
262 266
 	 */
263
-	public function isScheduled()
264
-	{
267
+	public function isScheduled()
268
+	{
265 269
 		return ($this->status == 1 && ($this->published > time())) ? true : false;
266 270
 	}
267 271
 
@@ -269,8 +273,8 @@  discard block
 block discarded – undo
269 273
 	 * Gets a flattened list of keyword tags for jQuery.tag.js
270 274
 	 * @return string
271 275
 	 */
272
-	public function getTagsFlat()
273
-	{
276
+	public function getTagsFlat()
277
+	{
274 278
 		return implode(',', $this->tags);
275 279
 	}
276 280
 
@@ -278,8 +282,8 @@  discard block
 block discarded – undo
278 282
 	 * Retrieves the layout used from Metadata
279 283
 	 * We cache this to speed up the viewfile
280 284
 	 */
281
-	public function getLayout()
282
-	{
285
+	public function getLayout()
286
+	{
283 287
 		$model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
284 288
 		return $model === NULL ? 'blog' : $model->value;
285 289
 	}
@@ -289,8 +293,8 @@  discard block
 block discarded – undo
289 293
 	 * @param string $data  the layout file
290 294
 	 * @return boolean
291 295
 	 */
292
-	public function setLayout($data)
293
-	{
296
+	public function setLayout($data)
297
+	{
294 298
 		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
295 299
 		$meta->value = $data;
296 300
 		return $meta->save();
@@ -301,8 +305,8 @@  discard block
 block discarded – undo
301 305
 	 * @param string $data  The view file
302 306
 	 * @return boolean
303 307
 	 */
304
-	public function setView($data)
305
-	{
308
+	public function setView($data)
309
+	{
306 310
 		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
307 311
 		$meta->value = $data;
308 312
 		return $meta->save();
@@ -312,8 +316,8 @@  discard block
 block discarded – undo
312 316
 	 * Retrieves the viewfile used from Metadata
313 317
 	 * We cache this to speed up the viewfile
314 318
 	 */
315
-	public function getView()
316
-	{
319
+	public function getView()
320
+	{
317 321
 		$model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
318 322
 		return $model === NULL ? 'blog' : $model->value;
319 323
 	}
@@ -321,8 +325,8 @@  discard block
 block discarded – undo
321 325
 	/**
322 326
 	 * Updates the like_count after finding new data
323 327
 	 */
324
-	protected function afterFind()
325
-	{
328
+	protected function afterFind()
329
+	{
326 330
 		parent::afterFind();
327 331
 		$this->like_count = $this->getLikeCount();
328 332
 	}
@@ -331,8 +335,8 @@  discard block
 block discarded – undo
331 335
 	 * Retrieves a list of models based on the current search/filter conditions.
332 336
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
333 337
 	 */
334
-	public function search()
335
-	{
338
+	public function search()
339
+	{
336 340
 		$criteria=new CDbCriteria;
337 341
 
338 342
 		$criteria->compare('id',$this->id);
@@ -349,13 +353,14 @@  discard block
 block discarded – undo
349 353
 		// Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare
350 354
 		if (is_bool($this->published))
351 355
 		{
352
-			if ($this->published)
353
-				$criteria->addCondition('published <= UNIX_TIMESTAMP()');
354
-			else
355
-				$criteria->addCondition('published > UNIX_TIMESTAMP()');
356
-		}
357
-		else
358
-			$criteria->compare('published', $this->published,true);
356
+			if ($this->published) {
357
+							$criteria->addCondition('published <= UNIX_TIMESTAMP()');
358
+			} else {
359
+							$criteria->addCondition('published > UNIX_TIMESTAMP()');
360
+			}
361
+		} else {
362
+					$criteria->compare('published', $this->published,true);
363
+		}
359 364
 		$criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
360 365
 
361 366
 		// TODO: Figure out how to restore CActiveDataProvidor by getCommentCount
@@ -379,13 +384,14 @@  discard block
 block discarded – undo
379 384
 	 * @param array $params parameters to be bound to an SQL statement.
380 385
 	 * @return array the records found. An empty array is returned if none is found.
381 386
 	 */
382
-	public function findByPk($pk, $condition='', $params=array())
383
-	{
387
+	public function findByPk($pk, $condition='', $params=array())
388
+	{
384 389
 		// If we do not supply a condition or parameters, use our overwritten method
385 390
 		if ($condition == '' && empty($params) && $pk != null)
386 391
 		{
387
-			if (!is_numeric($pk))
388
-				throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
392
+			if (!is_numeric($pk)) {
393
+							throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
394
+			}
389 395
 				
390 396
 			$criteria = new CDbCriteria;
391 397
 			$criteria->addCondition("t.id=:pk");
@@ -404,10 +410,11 @@  discard block
 block discarded – undo
404 410
 	 * @param  int $id [description]
405 411
 	 * @return array
406 412
 	 */
407
-	public function findRevisions($id)
408
-	{
409
-		if (!is_numeric($id))
410
-			throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
413
+	public function findRevisions($id)
414
+	{
415
+		if (!is_numeric($id)) {
416
+					throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
417
+		}
411 418
 				
412 419
 		$criteria = new CDbCriteria;
413 420
 		$criteria->addCondition("id=:id");
@@ -423,14 +430,16 @@  discard block
 block discarded – undo
423 430
 	 * BeforeValidate
424 431
 	 * @see CActiveRecord::beforeValidate
425 432
 	 */
426
-	public function beforeValidate()
427
-	{
433
+	public function beforeValidate()
434
+	{
428 435
 		// Allow publication times to be set automatically
429
-		if (empty($this->published))
430
-			$this->published = time();
436
+		if (empty($this->published)) {
437
+					$this->published = time();
438
+		}
431 439
 
432
-		if (strlen($this->excerpt) == 0)
433
-			$this->excerpt = $this->myTruncate($this->content, 250, '.', '');
440
+		if (strlen($this->excerpt) == 0) {
441
+					$this->excerpt = $this->myTruncate($this->content, 250, '.', '');
442
+		}
434 443
 
435 444
 		return parent::beforeValidate();
436 445
 	}
@@ -439,8 +448,8 @@  discard block
 block discarded – undo
439 448
 	 * Saves a prototype copy of the model so that we can get an id back to work with
440 449
 	 * @return boolean 	$model->save(false) without any validation rules
441 450
 	 */
442
-	public function savePrototype($author_id)
443
-	{
451
+	public function savePrototype($author_id)
452
+	{
444 453
 		$this->title = '';
445 454
 		$this->content = '';
446 455
 		$this->excerpt = '';
@@ -472,8 +481,8 @@  discard block
 block discarded – undo
472 481
 	 * Clears caches for rebuilding, creates the end slug that we are going to use
473 482
 	 * @see CActiveRecord::beforeSave();
474 483
 	 */
475
-	public function beforeSave()
476
-	{
484
+	public function beforeSave()
485
+	{
477 486
 		$this->slug = $this->verifySlug($this->slug, $this->title);
478 487
 		Yii::app()->cache->delete('CiiMS::Content::list');
479 488
 		Yii::app()->cache->delete('CiiMS::Routes');
@@ -489,14 +498,15 @@  discard block
 block discarded – undo
489 498
 	 * Updates the layout and view if necessary
490 499
 	 * @see CActiveRecord::afterSave()
491 500
 	 */
492
-	public function afterSave()
493
-	{
501
+	public function afterSave()
502
+	{
494 503
 		// Delete the AutoSave document on update
495 504
 		if ($this->isPublished())
496 505
 		{
497 506
 			$autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
498
-			if ($autosaveModel != NULL)
499
-				$autosaveModel->delete();
507
+			if ($autosaveModel != NULL) {
508
+							$autosaveModel->delete();
509
+			}
500 510
 		}
501 511
 
502 512
 		return parent::afterSave();
@@ -507,8 +517,8 @@  discard block
 block discarded – undo
507 517
 	 * Clears caches for rebuilding
508 518
 	 * @see CActiveRecord::beforeDelete
509 519
 	 */
510
-	public function beforeDelete()
511
-	{
520
+	public function beforeDelete()
521
+	{
512 522
 		Yii::app()->cache->delete('CiiMS::Content::list');
513 523
 		Yii::app()->cache->delete('CiiMS::Routes');
514 524
 		Yii::app()->cache->delete('content-' . $this->id . '-layout');
@@ -522,8 +532,8 @@  discard block
 block discarded – undo
522 532
 	 * Retrieves the available view files under the current theme
523 533
 	 * @return array    A list of files by name
524 534
 	 */
525
-	public function getViewFiles($theme=null)
526
-	{
535
+	public function getViewFiles($theme=null)
536
+	{
527 537
 		return $this->getFiles($theme, 'views.content');
528 538
 	}
529 539
 
@@ -531,8 +541,8 @@  discard block
 block discarded – undo
531 541
 	 * Retrieves the available layouts under the current theme
532 542
 	 * @return array    A list of files by name
533 543
 	 */
534
-	public function getLayoutFiles($theme=null)
535
-	{
544
+	public function getLayoutFiles($theme=null)
545
+	{
536 546
 		return $this->getFiles($theme, 'views.layouts');
537 547
 	}
538 548
 
@@ -542,20 +552,23 @@  discard block
 block discarded – undo
542 552
 	 * @param  string $type   The view type to lookup
543 553
 	 * @return array $files   An array of files
544 554
 	 */
545
-	private function getFiles($theme=null, $type='views')
546
-	{
547
-		if ($theme === null)
548
-			$theme = Cii::getConfig('theme', 'default');
555
+	private function getFiles($theme=null, $type='views')
556
+	{
557
+		if ($theme === null) {
558
+					$theme = Cii::getConfig('theme', 'default');
559
+		}
549 560
 
550 561
 		$folder = $type;
551 562
 
552
-		if ($type == 'view')
553
-			$folder = 'content';
563
+		if ($type == 'view') {
564
+					$folder = 'content';
565
+		}
554 566
 
555 567
 		$returnFiles = array();
556 568
 
557
-		if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
558
-			$theme = 'default';
569
+		if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme))) {
570
+					$theme = 'default';
571
+		}
559 572
 
560 573
 		$files = Yii::app()->cache->get($theme.'-available-' . $type);
561 574
 
@@ -570,11 +583,13 @@  discard block
 block discarded – undo
570 583
 		{
571 584
 			$f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
572 585
 
573
-			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
574
-				$f = trim(substr($f, strrpos($f, '\\') + 1));
586
+			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
587
+							$f = trim(substr($f, strrpos($f, '\\') + 1));
588
+			}
575 589
 
576
-			if (!in_array($f, array('all', 'password', '_post')))
577
-				$returnFiles[$f] = $f;
590
+			if (!in_array($f, array('all', 'password', '_post'))) {
591
+							$returnFiles[$f] = $f;
592
+			}
578 593
 		}
579 594
 
580 595
 		return $returnFiles;
@@ -588,11 +603,12 @@  discard block
 block discarded – undo
588 603
 	 * @param string $pad       The padding we want to apply
589 604
 	 * @return string           Truncated string
590 605
 	 */
591
-	private function myTruncate($string, $limit, $break=".", $pad="...")
592
-	{
606
+	private function myTruncate($string, $limit, $break=".", $pad="...")
607
+	{
593 608
 		// return with no change if string is shorter than $limit
594
-		if(strlen($string) <= $limit)
595
-			return $string;
609
+		if(strlen($string) <= $limit) {
610
+					return $string;
611
+		}
596 612
 
597 613
 		// is $break present between $limit and the end of the string?
598 614
 		if(false !== ($breakpoint = strpos($string, $break, $limit)))
@@ -613,8 +629,8 @@  discard block
 block discarded – undo
613 629
 	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
614 630
 	 * @return string $slug - the final slug to be used
615 631
 	 */
616
-	public function checkSlug($slug, $id=NULL)
617
-	{
632
+	public function checkSlug($slug, $id=NULL)
633
+	{
618 634
 		$category = false;
619 635
 
620 636
 		// Find the number of items that have the same slug as this one
@@ -632,20 +648,23 @@  discard block
 block discarded – undo
632 648
 		if ($count)
633 649
 		{
634 650
 			// Ensures we don't have a collision on category
635
-			if ($category)
636
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
651
+			if ($category) {
652
+							return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
653
+			}
637 654
 
638 655
 			// Pull the data that matches
639 656
 			$data = $this->findByPk($this->id);
640 657
 
641 658
 			// Check the pulled data id to the current item
642
-			if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug)
643
-				return $slug;
659
+			if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug) {
660
+							return $slug;
661
+			}
644 662
 		}
645 663
 
646
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
647
-			return $slug . $id;
648
-		else
649
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
664
+		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) {
665
+					return $slug . $id;
666
+		} else {
667
+					return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
668
+		}
650 669
 	}
651 670
 }
Please login to merge, or discard this patch.
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 	 * @param string $className active record class name.
45 45
 	 * @return Content the static model class
46 46
 	 */
47
-	public static function model($className=__CLASS__)
47
+	public static function model ($className = __CLASS__)
48 48
 	{
49
-		return parent::model($className);
49
+		return parent::model ($className);
50 50
 	}
51 51
 
52 52
 	/**
53 53
 	 * @return string the associated database table name
54 54
 	 */
55
-	public function tableName()
55
+	public function tableName ()
56 56
 	{
57 57
 		return 'content';
58 58
 	}
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	 * @return string[] primary key of the table
62 62
 	 **/
63
-	public function primaryKey()
63
+	public function primaryKey ()
64 64
 	{
65 65
 		return array('id');
66 66
 	}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	/**
69 69
 	 * @return array validation rules for model attributes.
70 70
 	 */
71
-	public function rules()
71
+	public function rules ()
72 72
 	{
73 73
 		// NOTE: you should only define rules for those attributes that
74 74
 		// will receive user inputs.
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	/**
85 85
 	 * @return array relational rules.
86 86
 	 */
87
-	public function relations()
87
+	public function relations ()
88 88
 	{
89 89
 		// NOTE: you may need to adjust the relation name and the related
90 90
 		// class name for the relations automatically generated below.
@@ -99,26 +99,26 @@  discard block
 block discarded – undo
99 99
 	/**
100 100
 	 * @return array customized attribute labels (name=>label)
101 101
 	 */
102
-	public function attributeLabels()
102
+	public function attributeLabels ()
103 103
 	{
104 104
 		return array(
105
-			'id' 			=> Yii::t('ciims.models.Content', 'ID'),
106
-			'vid' 			=> Yii::t('ciims.models.Content', 'Version'),
107
-			'author_id' 	=> Yii::t('ciims.models.Content', 'Author'),
108
-			'title' 		=> Yii::t('ciims.models.Content', 'Title'),
109
-			'content' 		=> Yii::t('ciims.models.Content', 'Content'),
110
-			'excerpt' 		=> Yii::t('ciims.models.Content', 'excerpt'),
111
-			'status' 		=> Yii::t('ciims.models.Content', 'Status'),
112
-			'commentable' 	=> Yii::t('ciims.models.Content', 'Commentable'),
113
-			'category_id' 	=> Yii::t('ciims.models.Content', 'Category'),
114
-			'type_id' 		=> Yii::t('ciims.models.Content', 'Type'),
115
-			'password' 		=> Yii::t('ciims.models.Content', 'Password'),
116
-			'like_count' 	=> Yii::t('ciims.models.Content', 'Likes'),
117
-			'tags' 			=> Yii::t('ciims.models.Content', 'Tags'),
118
-			'slug' 			=> Yii::t('ciims.models.Content', 'Slug'),
119
-			'published' 	=> Yii::t('ciims.models.Content', 'Published'),
120
-			'created' 		=> Yii::t('ciims.models.Content', 'Created'),
121
-			'updated' 		=> Yii::t('ciims.models.Content', 'Updated'),
105
+			'id' 			=> Yii::t ('ciims.models.Content', 'ID'),
106
+			'vid' 			=> Yii::t ('ciims.models.Content', 'Version'),
107
+			'author_id' 	=> Yii::t ('ciims.models.Content', 'Author'),
108
+			'title' 		=> Yii::t ('ciims.models.Content', 'Title'),
109
+			'content' 		=> Yii::t ('ciims.models.Content', 'Content'),
110
+			'excerpt' 		=> Yii::t ('ciims.models.Content', 'excerpt'),
111
+			'status' 		=> Yii::t ('ciims.models.Content', 'Status'),
112
+			'commentable' 	=> Yii::t ('ciims.models.Content', 'Commentable'),
113
+			'category_id' 	=> Yii::t ('ciims.models.Content', 'Category'),
114
+			'type_id' 		=> Yii::t ('ciims.models.Content', 'Type'),
115
+			'password' 		=> Yii::t ('ciims.models.Content', 'Password'),
116
+			'like_count' 	=> Yii::t ('ciims.models.Content', 'Likes'),
117
+			'tags' 			=> Yii::t ('ciims.models.Content', 'Tags'),
118
+			'slug' 			=> Yii::t ('ciims.models.Content', 'Slug'),
119
+			'published' 	=> Yii::t ('ciims.models.Content', 'Published'),
120
+			'created' 		=> Yii::t ('ciims.models.Content', 'Created'),
121
+			'updated' 		=> Yii::t ('ciims.models.Content', 'Updated'),
122 122
 		);
123 123
 	}
124 124
 
@@ -127,29 +127,29 @@  discard block
 block discarded – undo
127 127
 	 * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text
128 128
 	 * @return string
129 129
 	 */
130
-	public function getSafeOutput()
130
+	public function getSafeOutput ()
131 131
 	{
132 132
 		$md = new CMarkdownParser;
133
-		$dom = new DOMDocument();
134
-		$dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
135
-		$x = new DOMXPath($dom);
133
+		$dom = new DOMDocument ();
134
+		$dom->loadHtml ('<?xml encoding="UTF-8">'.$md->safeTransform ($this->content));
135
+		$x = new DOMXPath ($dom);
136 136
 
137
-		foreach ($x->query('//a') as $node)
137
+		foreach ($x->query ('//a') as $node)
138 138
 		{
139
-			$element = $node->getAttribute('href');
139
+			$element = $node->getAttribute ('href');
140 140
 			if (isset($element[0]) && $element[0] !== "/")
141 141
 			{
142
-				$node->setAttribute('rel', 'nofollow');
143
-				$node->setAttribute('target', '_blank');
142
+				$node->setAttribute ('rel', 'nofollow');
143
+				$node->setAttribute ('target', '_blank');
144 144
 			}
145 145
 		}
146 146
 
147
-		return $md->safeTransform($dom->saveHtml());
147
+		return $md->safeTransform ($dom->saveHtml ());
148 148
 	}
149 149
 
150
-	public function getExtract()
150
+	public function getExtract ()
151 151
 	{
152
-		Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
152
+		Yii::log (Yii::t ('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
153 153
 		return $this->excerpt;
154 154
 	}
155 155
 
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	 * @return int    The number of likes for this post
161 161
 	 */
162 162
 
163
-	public function getLikeCount()
163
+	public function getLikeCount ()
164 164
 	{
165
-		$meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
165
+		$meta = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'likes'));
166 166
 		if ($meta === NULL)
167 167
 			return 0;
168 168
 
@@ -173,10 +173,10 @@  discard block
 block discarded – undo
173 173
 	 * Gets keyword tags for this entry
174 174
 	 * @return array
175 175
 	 */
176
-	public function getTags()
176
+	public function getTags ()
177 177
 	{
178
-		$tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
179
-		return $tags === NULL ? array() : json_decode($tags->value, true);
178
+		$tags = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'keywords'));
179
+		return $tags === NULL ? array() : json_decode ($tags->value, true);
180 180
 	}
181 181
 
182 182
 	/**
@@ -184,18 +184,18 @@  discard block
 block discarded – undo
184 184
 	 * @param string $tag	The tag to add
185 185
 	 * @return bool			If the insert was successful or not
186 186
 	 */
187
-	public function addTag($tag)
187
+	public function addTag ($tag)
188 188
 	{
189 189
 		$tags = $this->tags;
190
-		if (in_array($tag, $tags)  || $tag == "")
190
+		if (in_array ($tag, $tags) || $tag == "")
191 191
 			return false;
192 192
 
193 193
 		$tags[] = $tag;
194
-		$tags = json_encode($tags);
195
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
194
+		$tags = json_encode ($tags);
195
+		$meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
196 196
 
197 197
 		$meta->value = $tags;
198
-		return $meta->save();
198
+		return $meta->save ();
199 199
 	}
200 200
 
201 201
 	/**
@@ -203,47 +203,47 @@  discard block
 block discarded – undo
203 203
 	 * @param string $tag	The tag to remove
204 204
 	 * @return bool			If the removal was successful
205 205
 	 */
206
-	public function removeTag($tag)
206
+	public function removeTag ($tag)
207 207
 	{
208 208
 		$tags = $this->tags;
209
-		if (!in_array($tag, $tags) || $tag == "")
209
+		if (!in_array ($tag, $tags) || $tag == "")
210 210
 			return false;
211 211
 
212
-		$key = array_search($tag, $tags);
212
+		$key = array_search ($tag, $tags);
213 213
 		unset($tags[$key]);
214
-		$tags = json_encode($tags);
214
+		$tags = json_encode ($tags);
215 215
 
216
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
216
+		$meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
217 217
 		$meta->value = $tags;
218
-		return $meta->save();
218
+		return $meta->save ();
219 219
 	}
220 220
 
221 221
 	/**
222 222
 	 * Provides a base criteria for status, uniqueness, and published states
223 223
 	 * @return CDBCriteria
224 224
 	 */
225
-	public function getBaseCriteria()
225
+	public function getBaseCriteria ()
226 226
 	{
227
-		$criteria = new CDbCriteria();
228
-		return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
229
-					    ->addCondition('status = 1')
230
-					    ->addCondition('UNIX_TIMESTAMP() >= published');
227
+		$criteria = new CDbCriteria ();
228
+		return $criteria->addCondition ("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
229
+					    ->addCondition ('status = 1')
230
+					    ->addCondition ('UNIX_TIMESTAMP() >= published');
231 231
 	}	
232 232
 
233 233
 	/**
234 234
 	 * Returns the appropriate status' depending up the user's role
235 235
 	 * @return string[]
236 236
 	 */
237
-	public function getStatuses()
237
+	public function getStatuses ()
238 238
 	{
239 239
 
240
-		if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7)
241
-			return array(0 => Yii::t('ciims.models.Content', 'Draft'));
240
+		if (Yii::app ()->user->role == 5 || Yii::app ()->user->role == 7)
241
+			return array(0 => Yii::t ('ciims.models.Content', 'Draft'));
242 242
 
243 243
 		return array(
244
-			1 => Yii::t('ciims.models.Content', 'Published'),
245
-			2 => Yii::t('ciims.models.Content', 'Ready for Review'),
246
-			0 => Yii::t('ciims.models.Content', 'Draft')
244
+			1 => Yii::t ('ciims.models.Content', 'Published'),
245
+			2 => Yii::t ('ciims.models.Content', 'Ready for Review'),
246
+			0 => Yii::t ('ciims.models.Content', 'Draft')
247 247
 		);
248 248
 	}
249 249
 
@@ -251,36 +251,36 @@  discard block
 block discarded – undo
251 251
 	 * Determines if an article is published or not
252 252
 	 * @return boolean
253 253
 	 */
254
-	public function isPublished()
254
+	public function isPublished ()
255 255
 	{
256
-		return ($this->status == 1 && ($this->published <= time())) ? true : false;
256
+		return ($this->status == 1 && ($this->published <= time ())) ? true : false;
257 257
 	}
258 258
 
259 259
 	/**
260 260
 	 * Determines if a given articled is scheduled or not
261 261
 	 * @return boolean
262 262
 	 */
263
-	public function isScheduled()
263
+	public function isScheduled ()
264 264
 	{
265
-		return ($this->status == 1 && ($this->published > time())) ? true : false;
265
+		return ($this->status == 1 && ($this->published > time ())) ? true : false;
266 266
 	}
267 267
 
268 268
 	/**
269 269
 	 * Gets a flattened list of keyword tags for jQuery.tag.js
270 270
 	 * @return string
271 271
 	 */
272
-	public function getTagsFlat()
272
+	public function getTagsFlat ()
273 273
 	{
274
-		return implode(',', $this->tags);
274
+		return implode (',', $this->tags);
275 275
 	}
276 276
 
277 277
 	/**
278 278
 	 * Retrieves the layout used from Metadata
279 279
 	 * We cache this to speed up the viewfile
280 280
 	 */
281
-	public function getLayout()
281
+	public function getLayout ()
282 282
 	{
283
-		$model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
283
+		$model = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'layout'));
284 284
 		return $model === NULL ? 'blog' : $model->value;
285 285
 	}
286 286
 
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
 	 * @param string $data  the layout file
290 290
 	 * @return boolean
291 291
 	 */
292
-	public function setLayout($data)
292
+	public function setLayout ($data)
293 293
 	{
294
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
294
+		$meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
295 295
 		$meta->value = $data;
296
-		return $meta->save();
296
+		return $meta->save ();
297 297
 	}
298 298
 
299 299
 	/**
@@ -301,65 +301,65 @@  discard block
 block discarded – undo
301 301
 	 * @param string $data  The view file
302 302
 	 * @return boolean
303 303
 	 */
304
-	public function setView($data)
304
+	public function setView ($data)
305 305
 	{
306
-		$meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
306
+		$meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
307 307
 		$meta->value = $data;
308
-		return $meta->save();
308
+		return $meta->save ();
309 309
 	}
310 310
 
311 311
 	/**
312 312
 	 * Retrieves the viewfile used from Metadata
313 313
 	 * We cache this to speed up the viewfile
314 314
 	 */
315
-	public function getView()
315
+	public function getView ()
316 316
 	{
317
-		$model  = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
317
+		$model = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'view'));
318 318
 		return $model === NULL ? 'blog' : $model->value;
319 319
 	}
320 320
 
321 321
 	/**
322 322
 	 * Updates the like_count after finding new data
323 323
 	 */
324
-	protected function afterFind()
324
+	protected function afterFind ()
325 325
 	{
326
-		parent::afterFind();
327
-		$this->like_count = $this->getLikeCount();
326
+		parent::afterFind ();
327
+		$this->like_count = $this->getLikeCount ();
328 328
 	}
329 329
 
330 330
 	/**
331 331
 	 * Retrieves a list of models based on the current search/filter conditions.
332 332
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
333 333
 	 */
334
-	public function search()
334
+	public function search ()
335 335
 	{
336
-		$criteria=new CDbCriteria;
336
+		$criteria = new CDbCriteria;
337 337
 
338
-		$criteria->compare('id',$this->id);
339
-		$criteria->compare('title',$this->title,true);
340
-		$criteria->compare('slug',$this->slug,true);
341
-		$criteria->compare('author_id',$this->author_id,true);
342
-		$criteria->compare('category_id',$this->category_id,true);
343
-		$criteria->compare('content',$this->content,true);
344
-		$criteria->compare('password', $this->password, true);
345
-		$criteria->compare('created',$this->created,true);
346
-		$criteria->compare('updated',$this->updated,true);
347
-		$criteria->compare('status', $this->status, true);
338
+		$criteria->compare ('id', $this->id);
339
+		$criteria->compare ('title', $this->title, true);
340
+		$criteria->compare ('slug', $this->slug, true);
341
+		$criteria->compare ('author_id', $this->author_id, true);
342
+		$criteria->compare ('category_id', $this->category_id, true);
343
+		$criteria->compare ('content', $this->content, true);
344
+		$criteria->compare ('password', $this->password, true);
345
+		$criteria->compare ('created', $this->created, true);
346
+		$criteria->compare ('updated', $this->updated, true);
347
+		$criteria->compare ('status', $this->status, true);
348 348
 
349 349
 		// Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare
350
-		if (is_bool($this->published))
350
+		if (is_bool ($this->published))
351 351
 		{
352 352
 			if ($this->published)
353
-				$criteria->addCondition('published <= UNIX_TIMESTAMP()');
353
+				$criteria->addCondition ('published <= UNIX_TIMESTAMP()');
354 354
 			else
355
-				$criteria->addCondition('published > UNIX_TIMESTAMP()');
355
+				$criteria->addCondition ('published > UNIX_TIMESTAMP()');
356 356
 		}
357 357
 		else
358
-			$criteria->compare('published', $this->published,true);
359
-		$criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
358
+			$criteria->compare ('published', $this->published, true);
359
+		$criteria->addCondition ("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
360 360
 
361 361
 		// TODO: Figure out how to restore CActiveDataProvidor by getCommentCount
362
-		return new CActiveDataProvider($this, array(
362
+		return new CActiveDataProvider ($this, array(
363 363
 			'criteria' => $criteria,
364 364
 			'sort' => array(
365 365
 				'defaultOrder' => 'published DESC'
@@ -379,24 +379,24 @@  discard block
 block discarded – undo
379 379
 	 * @param array $params parameters to be bound to an SQL statement.
380 380
 	 * @return array the records found. An empty array is returned if none is found.
381 381
 	 */
382
-	public function findByPk($pk, $condition='', $params=array())
382
+	public function findByPk ($pk, $condition = '', $params = array())
383 383
 	{
384 384
 		// If we do not supply a condition or parameters, use our overwritten method
385 385
 		if ($condition == '' && empty($params) && $pk != null)
386 386
 		{
387
-			if (!is_numeric($pk))
388
-				throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
387
+			if (!is_numeric ($pk))
388
+				throw new CHttpException (400, Yii::t ('ciims.models.Content', 'The content ID provided was invalid.'));
389 389
 				
390 390
 			$criteria = new CDbCriteria;
391
-			$criteria->addCondition("t.id=:pk");
392
-			$criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
391
+			$criteria->addCondition ("t.id=:pk");
392
+			$criteria->addCondition ("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
393 393
 			$criteria->params = array(
394 394
 				':pk' => $pk
395 395
 			);
396
-			return $this->query($criteria);
396
+			return $this->query ($criteria);
397 397
 		}
398 398
 
399
-		return parent::findByPk($pk, $condition, $params);
399
+		return parent::findByPk ($pk, $condition, $params);
400 400
 	}
401 401
 
402 402
 	/**
@@ -404,42 +404,42 @@  discard block
 block discarded – undo
404 404
 	 * @param  int $id [description]
405 405
 	 * @return array
406 406
 	 */
407
-	public function findRevisions($id)
407
+	public function findRevisions ($id)
408 408
 	{
409
-		if (!is_numeric($id))
410
-			throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
409
+		if (!is_numeric ($id))
410
+			throw new CHttpException (400, Yii::t ('ciims.models.Content', 'The content ID provided was invalid.'));
411 411
 				
412 412
 		$criteria = new CDbCriteria;
413
-		$criteria->addCondition("id=:id");
413
+		$criteria->addCondition ("id=:id");
414 414
 		$criteria->params = array(
415 415
 			':id' => $id
416 416
 		);
417 417
 		$criteria->order = 'vid DESC';
418 418
 
419
-		return $this->query($criteria, true);
419
+		return $this->query ($criteria, true);
420 420
 	}
421 421
 
422 422
 	/**
423 423
 	 * BeforeValidate
424 424
 	 * @see CActiveRecord::beforeValidate
425 425
 	 */
426
-	public function beforeValidate()
426
+	public function beforeValidate ()
427 427
 	{
428 428
 		// Allow publication times to be set automatically
429 429
 		if (empty($this->published))
430
-			$this->published = time();
430
+			$this->published = time ();
431 431
 
432
-		if (strlen($this->excerpt) == 0)
433
-			$this->excerpt = $this->myTruncate($this->content, 250, '.', '');
432
+		if (strlen ($this->excerpt) == 0)
433
+			$this->excerpt = $this->myTruncate ($this->content, 250, '.', '');
434 434
 
435
-		return parent::beforeValidate();
435
+		return parent::beforeValidate ();
436 436
 	}
437 437
 
438 438
 	/**
439 439
 	 * Saves a prototype copy of the model so that we can get an id back to work with
440 440
 	 * @return boolean 	$model->save(false) without any validation rules
441 441
 	 */
442
-	public function savePrototype($author_id)
442
+	public function savePrototype ($author_id)
443 443
 	{
444 444
 		$this->title = '';
445 445
 		$this->content = '';
@@ -449,17 +449,17 @@  discard block
 block discarded – undo
449 449
 		$this->category_id = 1;
450 450
 		$this->type_id = 2;
451 451
 		$this->password = null;
452
-		$this->created = time();
453
-		$this->updated = time();
454
-		$this->published = time();
452
+		$this->created = time ();
453
+		$this->updated = time ();
454
+		$this->published = time ();
455 455
 		$this->vid = 1;
456 456
 		$this->slug = "";
457 457
 		$this->author_id = $author_id;
458 458
 
459 459
 		// TODO: Why doesn't Yii return the PK id field? But it does return VID? AutoIncriment bug?
460
-		if ($this->save(false))
460
+		if ($this->save (false))
461 461
 		{
462
-			$data = Content::model()->findByAttributes(array('created' => $this->created));
462
+			$data = Content::model ()->findByAttributes (array('created' => $this->created));
463 463
 			$this->id = $data->id;
464 464
 			return true;
465 465
 		}
@@ -472,16 +472,16 @@  discard block
 block discarded – undo
472 472
 	 * Clears caches for rebuilding, creates the end slug that we are going to use
473 473
 	 * @see CActiveRecord::beforeSave();
474 474
 	 */
475
-	public function beforeSave()
475
+	public function beforeSave ()
476 476
 	{
477
-		$this->slug = $this->verifySlug($this->slug, $this->title);
478
-		Yii::app()->cache->delete('CiiMS::Content::list');
479
-		Yii::app()->cache->delete('CiiMS::Routes');
477
+		$this->slug = $this->verifySlug ($this->slug, $this->title);
478
+		Yii::app ()->cache->delete ('CiiMS::Content::list');
479
+		Yii::app ()->cache->delete ('CiiMS::Routes');
480 480
 
481
-		Yii::app()->cache->set('content-' . $this->id . '-layout', $this->layoutFile);
482
-		Yii::app()->cache->set('content-' . $this->id . '-view', $this->viewFile);
481
+		Yii::app ()->cache->set ('content-'.$this->id.'-layout', $this->layoutFile);
482
+		Yii::app ()->cache->set ('content-'.$this->id.'-view', $this->viewFile);
483 483
 
484
-		return parent::beforeSave();
484
+		return parent::beforeSave ();
485 485
 	}
486 486
 
487 487
 	/**
@@ -489,17 +489,17 @@  discard block
 block discarded – undo
489 489
 	 * Updates the layout and view if necessary
490 490
 	 * @see CActiveRecord::afterSave()
491 491
 	 */
492
-	public function afterSave()
492
+	public function afterSave ()
493 493
 	{
494 494
 		// Delete the AutoSave document on update
495
-		if ($this->isPublished())
495
+		if ($this->isPublished ())
496 496
 		{
497
-			$autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
497
+			$autosaveModel = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'autosave'));
498 498
 			if ($autosaveModel != NULL)
499
-				$autosaveModel->delete();
499
+				$autosaveModel->delete ();
500 500
 		}
501 501
 
502
-		return parent::afterSave();
502
+		return parent::afterSave ();
503 503
 	}
504 504
 
505 505
 	/**
@@ -507,14 +507,14 @@  discard block
 block discarded – undo
507 507
 	 * Clears caches for rebuilding
508 508
 	 * @see CActiveRecord::beforeDelete
509 509
 	 */
510
-	public function beforeDelete()
510
+	public function beforeDelete ()
511 511
 	{
512
-		Yii::app()->cache->delete('CiiMS::Content::list');
513
-		Yii::app()->cache->delete('CiiMS::Routes');
514
-		Yii::app()->cache->delete('content-' . $this->id . '-layout');
515
-		Yii::app()->cache->delete('content-' . $this->id . '-view');
512
+		Yii::app ()->cache->delete ('CiiMS::Content::list');
513
+		Yii::app ()->cache->delete ('CiiMS::Routes');
514
+		Yii::app ()->cache->delete ('content-'.$this->id.'-layout');
515
+		Yii::app ()->cache->delete ('content-'.$this->id.'-view');
516 516
 
517
-		return parent::beforeDelete();
517
+		return parent::beforeDelete ();
518 518
 	}
519 519
 
520 520
 
@@ -522,18 +522,18 @@  discard block
 block discarded – undo
522 522
 	 * Retrieves the available view files under the current theme
523 523
 	 * @return array    A list of files by name
524 524
 	 */
525
-	public function getViewFiles($theme=null)
525
+	public function getViewFiles ($theme = null)
526 526
 	{
527
-		return $this->getFiles($theme, 'views.content');
527
+		return $this->getFiles ($theme, 'views.content');
528 528
 	}
529 529
 
530 530
 	/**
531 531
 	 * Retrieves the available layouts under the current theme
532 532
 	 * @return array    A list of files by name
533 533
 	 */
534
-	public function getLayoutFiles($theme=null)
534
+	public function getLayoutFiles ($theme = null)
535 535
 	{
536
-		return $this->getFiles($theme, 'views.layouts');
536
+		return $this->getFiles ($theme, 'views.layouts');
537 537
 	}
538 538
 
539 539
 	/**
@@ -542,10 +542,10 @@  discard block
 block discarded – undo
542 542
 	 * @param  string $type   The view type to lookup
543 543
 	 * @return array $files   An array of files
544 544
 	 */
545
-	private function getFiles($theme=null, $type='views')
545
+	private function getFiles ($theme = null, $type = 'views')
546 546
 	{
547 547
 		if ($theme === null)
548
-			$theme = Cii::getConfig('theme', 'default');
548
+			$theme = Cii::getConfig ('theme', 'default');
549 549
 
550 550
 		$folder = $type;
551 551
 
@@ -554,26 +554,26 @@  discard block
 block discarded – undo
554 554
 
555 555
 		$returnFiles = array();
556 556
 
557
-		if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
557
+		if (!file_exists (YiiBase::getPathOfAlias ('base.themes.'.$theme)))
558 558
 			$theme = 'default';
559 559
 
560
-		$files = Yii::app()->cache->get($theme.'-available-' . $type);
560
+		$files = Yii::app ()->cache->get ($theme.'-available-'.$type);
561 561
 
562 562
 		if ($files === false)
563 563
 		{
564 564
 			$fileHelper = new CFileHelper;
565
-			$files = $fileHelper->findFiles(Yii::getPathOfAlias('base.themes.' . $theme .'.' . $folder), array('fileTypes'=>array('php'), 'level'=>0));
566
-			Yii::app()->cache->set($theme.'-available-' . $type, $files);
565
+			$files = $fileHelper->findFiles (Yii::getPathOfAlias ('base.themes.'.$theme.'.'.$folder), array('fileTypes'=>array('php'), 'level'=>0));
566
+			Yii::app ()->cache->set ($theme.'-available-'.$type, $files);
567 567
 		}
568 568
 
569 569
 		foreach ($files as $file)
570 570
 		{
571
-			$f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
571
+			$f = str_replace ('content', '', str_replace ('/', '', str_replace ('.php', '', substr ($file, strrpos ($file, '/') + 1))));
572 572
 
573
-			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
574
-				$f = trim(substr($f, strrpos($f, '\\') + 1));
573
+			if (strtoupper (substr (PHP_OS, 0, 3)) === 'WIN')
574
+				$f = trim (substr ($f, strrpos ($f, '\\') + 1));
575 575
 
576
-			if (!in_array($f, array('all', 'password', '_post')))
576
+			if (!in_array ($f, array('all', 'password', '_post')))
577 577
 				$returnFiles[$f] = $f;
578 578
 		}
579 579
 
@@ -588,18 +588,18 @@  discard block
 block discarded – undo
588 588
 	 * @param string $pad       The padding we want to apply
589 589
 	 * @return string           Truncated string
590 590
 	 */
591
-	private function myTruncate($string, $limit, $break=".", $pad="...")
591
+	private function myTruncate ($string, $limit, $break = ".", $pad = "...")
592 592
 	{
593 593
 		// return with no change if string is shorter than $limit
594
-		if(strlen($string) <= $limit)
594
+		if (strlen ($string) <= $limit)
595 595
 			return $string;
596 596
 
597 597
 		// is $break present between $limit and the end of the string?
598
-		if(false !== ($breakpoint = strpos($string, $break, $limit)))
598
+		if (false !== ($breakpoint = strpos ($string, $break, $limit)))
599 599
 		{
600
-			if($breakpoint < strlen($string) - 1)
600
+			if ($breakpoint < strlen ($string) - 1)
601 601
 			{
602
-				$string = substr($string, 0, $breakpoint) . $pad;
602
+				$string = substr ($string, 0, $breakpoint).$pad;
603 603
 			}
604 604
 		}
605 605
 
@@ -613,18 +613,18 @@  discard block
 block discarded – undo
613 613
 	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
614 614
 	 * @return string $slug - the final slug to be used
615 615
 	 */
616
-	public function checkSlug($slug, $id=NULL)
616
+	public function checkSlug ($slug, $id = NULL)
617 617
 	{
618 618
 		$category = false;
619 619
 
620 620
 		// Find the number of items that have the same slug as this one
621
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
621
+		$count = $this->countByAttributes (array('slug'=>$slug.$id));
622 622
 
623 623
 		// Make sure we don't have a collision with a Category
624 624
 		if ($count == 0)
625 625
 		{
626 626
 			$category = true;
627
-			$count = Categories::model()->countByAttributes(array('slug'=>$slug . $id));
627
+			$count = Categories::model ()->countByAttributes (array('slug'=>$slug.$id));
628 628
 		}
629 629
 
630 630
 		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
@@ -633,19 +633,19 @@  discard block
 block discarded – undo
633 633
 		{
634 634
 			// Ensures we don't have a collision on category
635 635
 			if ($category)
636
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
636
+				return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1)));
637 637
 
638 638
 			// Pull the data that matches
639
-			$data = $this->findByPk($this->id);
639
+			$data = $this->findByPk ($this->id);
640 640
 
641 641
 			// Check the pulled data id to the current item
642 642
 			if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug)
643 643
 				return $slug;
644 644
 		}
645 645
 
646
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
647
-			return $slug . $id;
646
+		if ($count == 0 && !in_array ($slug, $this->forbiddenRoutes))
647
+			return $slug.$id;
648 648
 		else
649
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
649
+			return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1)));
650 650
 	}
651 651
 }
Please login to merge, or discard this patch.
protected/models/ContentMetadata.php 3 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -16,82 +16,82 @@
 block discarded – undo
16 16
  */
17 17
 class ContentMetadata extends CiiModel
18 18
 {
19
-	/**
20
-	 * Returns the static model of the specified AR class.
21
-	 * @param string $className active record class name.
22
-	 * @return ContentMetadata the static model class
23
-	 */
24
-	public static function model($className=__CLASS__)
25
-	{
26
-		return parent::model($className);
27
-	}
19
+    /**
20
+     * Returns the static model of the specified AR class.
21
+     * @param string $className active record class name.
22
+     * @return ContentMetadata the static model class
23
+     */
24
+    public static function model($className=__CLASS__)
25
+    {
26
+        return parent::model($className);
27
+    }
28 28
 
29
-	/**
30
-	 * @return string the associated database table name
31
-	 */
32
-	public function tableName()
33
-	{
34
-		return 'content_metadata';
35
-	}
29
+    /**
30
+     * @return string the associated database table name
31
+     */
32
+    public function tableName()
33
+    {
34
+        return 'content_metadata';
35
+    }
36 36
 
37
-	/**
38
-	 * @return array validation rules for model attributes.
39
-	 */
40
-	public function rules()
41
-	{
42
-		// NOTE: you should only define rules for those attributes that
43
-		// will receive user inputs.
44
-		return array(
45
-			array('content_id, key, value', 'required'),
46
-			array('content_id', 'numerical', 'integerOnly'=>true),
47
-			array('key', 'length', 'max'=>50),
48
-			// The following rule is used by search().
49
-			array('id, content_id, key, value, created, updated', 'safe', 'on'=>'search'),
50
-		);
51
-	}
37
+    /**
38
+     * @return array validation rules for model attributes.
39
+     */
40
+    public function rules()
41
+    {
42
+        // NOTE: you should only define rules for those attributes that
43
+        // will receive user inputs.
44
+        return array(
45
+            array('content_id, key, value', 'required'),
46
+            array('content_id', 'numerical', 'integerOnly'=>true),
47
+            array('key', 'length', 'max'=>50),
48
+            // The following rule is used by search().
49
+            array('id, content_id, key, value, created, updated', 'safe', 'on'=>'search'),
50
+        );
51
+    }
52 52
 
53
-	/**
54
-	 * @return array relational rules.
55
-	 */
56
-	public function relations()
57
-	{
58
-		// NOTE: you may need to adjust the relation name and the related
59
-		// class name for the relations automatically generated below.
60
-		return array(
61
-			'content' => array(self::BELONGS_TO, 'Content', 'content_id'),
62
-		);
63
-	}
53
+    /**
54
+     * @return array relational rules.
55
+     */
56
+    public function relations()
57
+    {
58
+        // NOTE: you may need to adjust the relation name and the related
59
+        // class name for the relations automatically generated below.
60
+        return array(
61
+            'content' => array(self::BELONGS_TO, 'Content', 'content_id'),
62
+        );
63
+    }
64 64
 
65
-	/**
66
-	 * @return array customized attribute labels (name=>label)
67
-	 */
68
-	public function attributeLabels()
69
-	{
70
-		return array(
71
-			'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
72
-			'key' 		 => Yii::t('ciims.models.ContentMetadata', 'Key'),
73
-			'value' 	 => Yii::t('ciims.models.ContentMetadata', 'Value'),
74
-			'created'	 => Yii::t('ciims.models.ContentMetadata', 'Created'),
75
-			'updated' 	 => Yii::t('ciims.models.ContentMetadata', 'Updated')
76
-		);
77
-	}
65
+    /**
66
+     * @return array customized attribute labels (name=>label)
67
+     */
68
+    public function attributeLabels()
69
+    {
70
+        return array(
71
+            'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
72
+            'key' 		 => Yii::t('ciims.models.ContentMetadata', 'Key'),
73
+            'value' 	 => Yii::t('ciims.models.ContentMetadata', 'Value'),
74
+            'created'	 => Yii::t('ciims.models.ContentMetadata', 'Created'),
75
+            'updated' 	 => Yii::t('ciims.models.ContentMetadata', 'Updated')
76
+        );
77
+    }
78 78
 
79
-	/**
80
-	 * Retrieves a list of models based on the current search/filter conditions.
81
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
82
-	 */
83
-	public function search()
84
-	{
85
-		$criteria=new CDbCriteria;
79
+    /**
80
+     * Retrieves a list of models based on the current search/filter conditions.
81
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
82
+     */
83
+    public function search()
84
+    {
85
+        $criteria=new CDbCriteria;
86 86
 
87
-		$criteria->compare('content_id',$this->content_id);
88
-		$criteria->compare('t.key',$this->key,true);
89
-		$criteria->compare('value',$this->value,true);
90
-		$criteria->compare('created',$this->created,true);
91
-		$criteria->compare('updated',$this->updated,true);
87
+        $criteria->compare('content_id',$this->content_id);
88
+        $criteria->compare('t.key',$this->key,true);
89
+        $criteria->compare('value',$this->value,true);
90
+        $criteria->compare('created',$this->created,true);
91
+        $criteria->compare('updated',$this->updated,true);
92 92
 
93
-		return new CActiveDataProvider($this, array(
94
-			'criteria'=>$criteria,
95
-		));
96
-	}
93
+        return new CActiveDataProvider($this, array(
94
+            'criteria'=>$criteria,
95
+        ));
96
+    }
97 97
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param string $className active record class name.
22 22
 	 * @return ContentMetadata the static model class
23 23
 	 */
24
-	public static function model($className=__CLASS__)
24
+	public static function model ($className = __CLASS__)
25 25
 	{
26
-		return parent::model($className);
26
+		return parent::model ($className);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @return string the associated database table name
31 31
 	 */
32
-	public function tableName()
32
+	public function tableName ()
33 33
 	{
34 34
 		return 'content_metadata';
35 35
 	}
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @return array validation rules for model attributes.
39 39
 	 */
40
-	public function rules()
40
+	public function rules ()
41 41
 	{
42 42
 		// NOTE: you should only define rules for those attributes that
43 43
 		// will receive user inputs.
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * @return array relational rules.
55 55
 	 */
56
-	public function relations()
56
+	public function relations ()
57 57
 	{
58 58
 		// NOTE: you may need to adjust the relation name and the related
59 59
 		// class name for the relations automatically generated below.
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 	/**
66 66
 	 * @return array customized attribute labels (name=>label)
67 67
 	 */
68
-	public function attributeLabels()
68
+	public function attributeLabels ()
69 69
 	{
70 70
 		return array(
71
-			'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
72
-			'key' 		 => Yii::t('ciims.models.ContentMetadata', 'Key'),
73
-			'value' 	 => Yii::t('ciims.models.ContentMetadata', 'Value'),
74
-			'created'	 => Yii::t('ciims.models.ContentMetadata', 'Created'),
75
-			'updated' 	 => Yii::t('ciims.models.ContentMetadata', 'Updated')
71
+			'content_id' => Yii::t ('ciims.models.ContentMetadata', 'Content ID'),
72
+			'key' 		 => Yii::t ('ciims.models.ContentMetadata', 'Key'),
73
+			'value' 	 => Yii::t ('ciims.models.ContentMetadata', 'Value'),
74
+			'created'	 => Yii::t ('ciims.models.ContentMetadata', 'Created'),
75
+			'updated' 	 => Yii::t ('ciims.models.ContentMetadata', 'Updated')
76 76
 		);
77 77
 	}
78 78
 
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 	 * Retrieves a list of models based on the current search/filter conditions.
81 81
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
82 82
 	 */
83
-	public function search()
83
+	public function search ()
84 84
 	{
85
-		$criteria=new CDbCriteria;
85
+		$criteria = new CDbCriteria;
86 86
 
87
-		$criteria->compare('content_id',$this->content_id);
88
-		$criteria->compare('t.key',$this->key,true);
89
-		$criteria->compare('value',$this->value,true);
90
-		$criteria->compare('created',$this->created,true);
91
-		$criteria->compare('updated',$this->updated,true);
87
+		$criteria->compare ('content_id', $this->content_id);
88
+		$criteria->compare ('t.key', $this->key, true);
89
+		$criteria->compare ('value', $this->value, true);
90
+		$criteria->compare ('created', $this->created, true);
91
+		$criteria->compare ('updated', $this->updated, true);
92 92
 
93
-		return new CActiveDataProvider($this, array(
93
+		return new CActiveDataProvider ($this, array(
94 94
 			'criteria'=>$criteria,
95 95
 		));
96 96
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -14,31 +14,31 @@  discard block
 block discarded – undo
14 14
  * The followings are the available model relations:
15 15
  * @property Content $content
16 16
  */
17
-class ContentMetadata extends CiiModel
18
-{
17
+class ContentMetadata extends CiiModel
18
+{
19 19
 	/**
20 20
 	 * Returns the static model of the specified AR class.
21 21
 	 * @param string $className active record class name.
22 22
 	 * @return ContentMetadata the static model class
23 23
 	 */
24
-	public static function model($className=__CLASS__)
25
-	{
24
+	public static function model($className=__CLASS__)
25
+	{
26 26
 		return parent::model($className);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @return string the associated database table name
31 31
 	 */
32
-	public function tableName()
33
-	{
32
+	public function tableName()
33
+	{
34 34
 		return 'content_metadata';
35 35
 	}
36 36
 
37 37
 	/**
38 38
 	 * @return array validation rules for model attributes.
39 39
 	 */
40
-	public function rules()
41
-	{
40
+	public function rules()
41
+	{
42 42
 		// NOTE: you should only define rules for those attributes that
43 43
 		// will receive user inputs.
44 44
 		return array(
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * @return array relational rules.
55 55
 	 */
56
-	public function relations()
57
-	{
56
+	public function relations()
57
+	{
58 58
 		// NOTE: you may need to adjust the relation name and the related
59 59
 		// class name for the relations automatically generated below.
60 60
 		return array(
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	/**
66 66
 	 * @return array customized attribute labels (name=>label)
67 67
 	 */
68
-	public function attributeLabels()
69
-	{
68
+	public function attributeLabels()
69
+	{
70 70
 		return array(
71 71
 			'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
72 72
 			'key' 		 => Yii::t('ciims.models.ContentMetadata', 'Key'),
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 	 * Retrieves a list of models based on the current search/filter conditions.
81 81
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
82 82
 	 */
83
-	public function search()
84
-	{
83
+	public function search()
84
+	{
85 85
 		$criteria=new CDbCriteria;
86 86
 
87 87
 		$criteria->compare('content_id',$this->content_id);
Please login to merge, or discard this patch.
protected/models/ContentTypes.php 3 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -2,78 +2,78 @@
 block discarded – undo
2 2
 
3 3
 class ContentTypes extends CiiModel
4 4
 {
5
-	/**
6
-	 * Returns the static model of the specified AR class.
7
-	 * @param string $className active record class name.
8
-	 * @return ContentMetadata the static model class
9
-	 */
10
-	public static function model($className=__CLASS__)
11
-	{
12
-		return parent::model($className);
13
-	}
5
+    /**
6
+     * Returns the static model of the specified AR class.
7
+     * @param string $className active record class name.
8
+     * @return ContentMetadata the static model class
9
+     */
10
+    public static function model($className=__CLASS__)
11
+    {
12
+        return parent::model($className);
13
+    }
14 14
 
15
-	/**
16
-	 * @return string the associated database table name
17
-	 */
18
-	public function tableName()
19
-	{
20
-		return 'content_types';
21
-	}
15
+    /**
16
+     * @return string the associated database table name
17
+     */
18
+    public function tableName()
19
+    {
20
+        return 'content_types';
21
+    }
22 22
 
23
-	/**
24
-	 * @return array validation rules for model attributes.
25
-	 */
26
-	public function rules()
27
-	{
28
-		// NOTE: you should only define rules for those attributes that
29
-		// will receive user inputs.
30
-		return array(
31
-			array('name', 'required'),
32
-			array('name', 'length', 'max'=>255),
33
-			array('id, name, created, updated', 'safe', 'on'=>'search'),
34
-		);
35
-	}
23
+    /**
24
+     * @return array validation rules for model attributes.
25
+     */
26
+    public function rules()
27
+    {
28
+        // NOTE: you should only define rules for those attributes that
29
+        // will receive user inputs.
30
+        return array(
31
+            array('name', 'required'),
32
+            array('name', 'length', 'max'=>255),
33
+            array('id, name, created, updated', 'safe', 'on'=>'search'),
34
+        );
35
+    }
36 36
 
37
-	/**
38
-	 * @return array relational rules.
39
-	 */
40
-	public function relations()
41
-	{
42
-		// NOTE: you may need to adjust the relation name and the related
43
-		// class name for the relations automatically generated below.
44
-		return array(
45
-			'content' => array(self::HAS_MANY, 'Content', 'id'),
46
-		);
47
-	}
37
+    /**
38
+     * @return array relational rules.
39
+     */
40
+    public function relations()
41
+    {
42
+        // NOTE: you may need to adjust the relation name and the related
43
+        // class name for the relations automatically generated below.
44
+        return array(
45
+            'content' => array(self::HAS_MANY, 'Content', 'id'),
46
+        );
47
+    }
48 48
 
49
-	/**
50
-	 * @return array customized attribute labels (name=>label)
51
-	 */
52
-	public function attributeLabels()
53
-	{
54
-		return array(
55
-			'id'	     => Yii::t('ciims.models.ContentTypes', 'ID'),
56
-			'name' 		 => Yii::t('ciims.models.ContentTypes', 'Name'),
57
-			'created'	 => Yii::t('ciims.models.ContentTypes', 'Created'),
58
-			'updated' 	 => Yii::t('ciims.models.ContentTypes', 'Updated')
59
-		);
60
-	}
49
+    /**
50
+     * @return array customized attribute labels (name=>label)
51
+     */
52
+    public function attributeLabels()
53
+    {
54
+        return array(
55
+            'id'	     => Yii::t('ciims.models.ContentTypes', 'ID'),
56
+            'name' 		 => Yii::t('ciims.models.ContentTypes', 'Name'),
57
+            'created'	 => Yii::t('ciims.models.ContentTypes', 'Created'),
58
+            'updated' 	 => Yii::t('ciims.models.ContentTypes', 'Updated')
59
+        );
60
+    }
61 61
 
62
-	/**
63
-	 * Retrieves a list of models based on the current search/filter conditions.
64
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
65
-	 */
66
-	public function search()
67
-	{
68
-		$criteria=new CDbCriteria;
62
+    /**
63
+     * Retrieves a list of models based on the current search/filter conditions.
64
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
65
+     */
66
+    public function search()
67
+    {
68
+        $criteria=new CDbCriteria;
69 69
 
70
-		$criteria->compare('id',$this->id);
71
-		$criteria->compare('name',$this->name,true);
72
-		$criteria->compare('created',$this->created,true);
73
-		$criteria->compare('updated',$this->updated,true);
70
+        $criteria->compare('id',$this->id);
71
+        $criteria->compare('name',$this->name,true);
72
+        $criteria->compare('created',$this->created,true);
73
+        $criteria->compare('updated',$this->updated,true);
74 74
 
75
-		return new CActiveDataProvider($this, array(
76
-			'criteria'=>$criteria,
77
-		));
78
-	}
75
+        return new CActiveDataProvider($this, array(
76
+            'criteria'=>$criteria,
77
+        ));
78
+    }
79 79
 }
80 80
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
 	 * @param string $className active record class name.
8 8
 	 * @return ContentMetadata the static model class
9 9
 	 */
10
-	public static function model($className=__CLASS__)
10
+	public static function model ($className = __CLASS__)
11 11
 	{
12
-		return parent::model($className);
12
+		return parent::model ($className);
13 13
 	}
14 14
 
15 15
 	/**
16 16
 	 * @return string the associated database table name
17 17
 	 */
18
-	public function tableName()
18
+	public function tableName ()
19 19
 	{
20 20
 		return 'content_types';
21 21
 	}
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	 * @return array validation rules for model attributes.
25 25
 	 */
26
-	public function rules()
26
+	public function rules ()
27 27
 	{
28 28
 		// NOTE: you should only define rules for those attributes that
29 29
 		// will receive user inputs.
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @return array relational rules.
39 39
 	 */
40
-	public function relations()
40
+	public function relations ()
41 41
 	{
42 42
 		// NOTE: you may need to adjust the relation name and the related
43 43
 		// class name for the relations automatically generated below.
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	/**
50 50
 	 * @return array customized attribute labels (name=>label)
51 51
 	 */
52
-	public function attributeLabels()
52
+	public function attributeLabels ()
53 53
 	{
54 54
 		return array(
55
-			'id'	     => Yii::t('ciims.models.ContentTypes', 'ID'),
56
-			'name' 		 => Yii::t('ciims.models.ContentTypes', 'Name'),
57
-			'created'	 => Yii::t('ciims.models.ContentTypes', 'Created'),
58
-			'updated' 	 => Yii::t('ciims.models.ContentTypes', 'Updated')
55
+			'id'	     => Yii::t ('ciims.models.ContentTypes', 'ID'),
56
+			'name' 		 => Yii::t ('ciims.models.ContentTypes', 'Name'),
57
+			'created'	 => Yii::t ('ciims.models.ContentTypes', 'Created'),
58
+			'updated' 	 => Yii::t ('ciims.models.ContentTypes', 'Updated')
59 59
 		);
60 60
 	}
61 61
 
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
 	 * Retrieves a list of models based on the current search/filter conditions.
64 64
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
65 65
 	 */
66
-	public function search()
66
+	public function search ()
67 67
 	{
68
-		$criteria=new CDbCriteria;
68
+		$criteria = new CDbCriteria;
69 69
 
70
-		$criteria->compare('id',$this->id);
71
-		$criteria->compare('name',$this->name,true);
72
-		$criteria->compare('created',$this->created,true);
73
-		$criteria->compare('updated',$this->updated,true);
70
+		$criteria->compare ('id', $this->id);
71
+		$criteria->compare ('name', $this->name, true);
72
+		$criteria->compare ('created', $this->created, true);
73
+		$criteria->compare ('updated', $this->updated, true);
74 74
 
75
-		return new CActiveDataProvider($this, array(
75
+		return new CActiveDataProvider ($this, array(
76 76
 			'criteria'=>$criteria,
77 77
 		));
78 78
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class ContentTypes extends CiiModel
4
-{
3
+class ContentTypes extends CiiModel
4
+{
5 5
 	/**
6 6
 	 * Returns the static model of the specified AR class.
7 7
 	 * @param string $className active record class name.
8 8
 	 * @return ContentMetadata the static model class
9 9
 	 */
10
-	public static function model($className=__CLASS__)
11
-	{
10
+	public static function model($className=__CLASS__)
11
+	{
12 12
 		return parent::model($className);
13 13
 	}
14 14
 
15 15
 	/**
16 16
 	 * @return string the associated database table name
17 17
 	 */
18
-	public function tableName()
19
-	{
18
+	public function tableName()
19
+	{
20 20
 		return 'content_types';
21 21
 	}
22 22
 
23 23
 	/**
24 24
 	 * @return array validation rules for model attributes.
25 25
 	 */
26
-	public function rules()
27
-	{
26
+	public function rules()
27
+	{
28 28
 		// NOTE: you should only define rules for those attributes that
29 29
 		// will receive user inputs.
30 30
 		return array(
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @return array relational rules.
39 39
 	 */
40
-	public function relations()
41
-	{
40
+	public function relations()
41
+	{
42 42
 		// NOTE: you may need to adjust the relation name and the related
43 43
 		// class name for the relations automatically generated below.
44 44
 		return array(
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	/**
50 50
 	 * @return array customized attribute labels (name=>label)
51 51
 	 */
52
-	public function attributeLabels()
53
-	{
52
+	public function attributeLabels()
53
+	{
54 54
 		return array(
55 55
 			'id'	     => Yii::t('ciims.models.ContentTypes', 'ID'),
56 56
 			'name' 		 => Yii::t('ciims.models.ContentTypes', 'Name'),
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * Retrieves a list of models based on the current search/filter conditions.
64 64
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
65 65
 	 */
66
-	public function search()
67
-	{
66
+	public function search()
67
+	{
68 68
 		$criteria=new CDbCriteria;
69 69
 
70 70
 		$criteria->compare('id',$this->id);
Please login to merge, or discard this patch.
protected/models/Events.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -12,121 +12,121 @@
 block discarded – undo
12 12
  */
13 13
 class Events extends CiiModel
14 14
 {
15
-	/**
16
-	 * Adds the CTimestampBehavior to this class
17
-	 * @return array
18
-	 */
19
-	public function behaviors()
20
-	{
21
-		return array(
22
-			'CTimestampBehavior' => array(
23
-				'class' 			=> 'zii.behaviors.CTimestampBehavior',
24
-				'createAttribute' 	=> 'created',
25
-				'updateAttribute' 	=> 'created',
26
-				'timestampExpression' => time(),
27
-				'setUpdateOnCreate' => false
28
-			)
29
-		);
30
-	}
15
+    /**
16
+     * Adds the CTimestampBehavior to this class
17
+     * @return array
18
+     */
19
+    public function behaviors()
20
+    {
21
+        return array(
22
+            'CTimestampBehavior' => array(
23
+                'class' 			=> 'zii.behaviors.CTimestampBehavior',
24
+                'createAttribute' 	=> 'created',
25
+                'updateAttribute' 	=> 'created',
26
+                'timestampExpression' => time(),
27
+                'setUpdateOnCreate' => false
28
+            )
29
+        );
30
+    }
31 31
 
32
-	/**
33
-	 * Query Scoping
34
-	 */
35
-	public function scopes()
36
-	{
37
-		return array(
38
-			'groupByUrl' => array(
39
-				'group'   => 't.uri',
40
-				'select'  => 't.uri, COUNT(*) as id',
41
-				'order'   => 't.id ASC',
42
-				'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago")
43
-			),
44
-		);
45
-	}
32
+    /**
33
+     * Query Scoping
34
+     */
35
+    public function scopes()
36
+    {
37
+        return array(
38
+            'groupByUrl' => array(
39
+                'group'   => 't.uri',
40
+                'select'  => 't.uri, COUNT(*) as id',
41
+                'order'   => 't.id ASC',
42
+                'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago")
43
+            ),
44
+        );
45
+    }
46 46
 
47
-	/**
48
-	 * @return string the associated database table name
49
-	 */
50
-	public function tableName()
51
-	{
52
-		return 'events';
53
-	}
47
+    /**
48
+     * @return string the associated database table name
49
+     */
50
+    public function tableName()
51
+    {
52
+        return 'events';
53
+    }
54 54
 
55
-	/**
56
-	 * @return array validation rules for model attributes.
57
-	 */
58
-	public function rules()
59
-	{
60
-		// NOTE: you should only define rules for those attributes that
61
-		// will receive user inputs.
62
-		return array(
63
-			array('event, uri', 'required'),
64
-			array('id', 'numerical', 'integerOnly'=>true),
65
-			array('event, uri, ', 'length', 'max'=>255),
66
-			array('event_data, created', 'safe'),
67
-			array('id, content_id, page_title, event, event_data, uri,  created', 'safe', 'on'=>'search'),
68
-		);
69
-	}
55
+    /**
56
+     * @return array validation rules for model attributes.
57
+     */
58
+    public function rules()
59
+    {
60
+        // NOTE: you should only define rules for those attributes that
61
+        // will receive user inputs.
62
+        return array(
63
+            array('event, uri', 'required'),
64
+            array('id', 'numerical', 'integerOnly'=>true),
65
+            array('event, uri, ', 'length', 'max'=>255),
66
+            array('event_data, created', 'safe'),
67
+            array('id, content_id, page_title, event, event_data, uri,  created', 'safe', 'on'=>'search'),
68
+        );
69
+    }
70 70
 
71
-	/**
72
-	 * @return array customized attribute labels (name=>label)
73
-	 */
74
-	public function attributeLabels()
75
-	{
76
-		return array(
77
-			'id' => 'ID',
78
-			'event' => 'Event',
79
-			'event_data' => 'Event Data',
80
-			'uri' => 'URI',
81
-			'content_id' => 'Content ID',
82
-			'created' => 'Created',
83
-		);
84
-	}
71
+    /**
72
+     * @return array customized attribute labels (name=>label)
73
+     */
74
+    public function attributeLabels()
75
+    {
76
+        return array(
77
+            'id' => 'ID',
78
+            'event' => 'Event',
79
+            'event_data' => 'Event Data',
80
+            'uri' => 'URI',
81
+            'content_id' => 'Content ID',
82
+            'created' => 'Created',
83
+        );
84
+    }
85 85
 
86
-	public function beforeValidate()
87
-	{
88
-		$this->event_data = CJSON::encode($this->event_data);
89
-		return parent::beforeValidate();
90
-	}
86
+    public function beforeValidate()
87
+    {
88
+        $this->event_data = CJSON::encode($this->event_data);
89
+        return parent::beforeValidate();
90
+    }
91 91
 
92
-	/**
93
-	 * Retrieves a list of models based on the current search/filter conditions.
94
-	 *
95
-	 * Typical usecase:
96
-	 * - Initialize the model fields with values from filter form.
97
-	 * - Execute this method to get CActiveDataProvider instance which will filter
98
-	 * models according to data in model fields.
99
-	 * - Pass data provider to CGridView, CListView or any similar widget.
100
-	 *
101
-	 * @return CActiveDataProvider the data provider that can return the models
102
-	 * based on the search/filter conditions.
103
-	 */
104
-	public function search()
105
-	{
106
-		// @todo Please modify the following code to remove attributes that should not be searched.
92
+    /**
93
+     * Retrieves a list of models based on the current search/filter conditions.
94
+     *
95
+     * Typical usecase:
96
+     * - Initialize the model fields with values from filter form.
97
+     * - Execute this method to get CActiveDataProvider instance which will filter
98
+     * models according to data in model fields.
99
+     * - Pass data provider to CGridView, CListView or any similar widget.
100
+     *
101
+     * @return CActiveDataProvider the data provider that can return the models
102
+     * based on the search/filter conditions.
103
+     */
104
+    public function search()
105
+    {
106
+        // @todo Please modify the following code to remove attributes that should not be searched.
107 107
 
108
-		$criteria=new CDbCriteria;
108
+        $criteria=new CDbCriteria;
109 109
 
110
-		$criteria->compare('id',$this->id);
111
-		$criteria->compare('event',$this->event,true);
112
-		$criteria->compare('event_data',$this->event_data,true);
113
-		$criteria->compare('uri',$this->uri,true);
114
-		$criteria->compare('content_id',$this->content_id,true);
115
-		$criteria->compare('created',$this->created,true);
110
+        $criteria->compare('id',$this->id);
111
+        $criteria->compare('event',$this->event,true);
112
+        $criteria->compare('event_data',$this->event_data,true);
113
+        $criteria->compare('uri',$this->uri,true);
114
+        $criteria->compare('content_id',$this->content_id,true);
115
+        $criteria->compare('created',$this->created,true);
116 116
 
117
-		return new CActiveDataProvider($this, array(
118
-			'criteria'=>$criteria,
119
-		));
120
-	}
117
+        return new CActiveDataProvider($this, array(
118
+            'criteria'=>$criteria,
119
+        ));
120
+    }
121 121
 
122
-	/**
123
-	 * Returns the static model of the specified AR class.
124
-	 * Please note that you should have this exact method in all your CActiveRecord descendants!
125
-	 * @param string $className active record class name.
126
-	 * @return Events the static model class
127
-	 */
128
-	public static function model($className=__CLASS__)
129
-	{
130
-		return parent::model($className);
131
-	}
122
+    /**
123
+     * Returns the static model of the specified AR class.
124
+     * Please note that you should have this exact method in all your CActiveRecord descendants!
125
+     * @param string $className active record class name.
126
+     * @return Events the static model class
127
+     */
128
+    public static function model($className=__CLASS__)
129
+    {
130
+        return parent::model($className);
131
+    }
132 132
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 	 * Adds the CTimestampBehavior to this class
17 17
 	 * @return array
18 18
 	 */
19
-	public function behaviors()
19
+	public function behaviors ()
20 20
 	{
21 21
 		return array(
22 22
 			'CTimestampBehavior' => array(
23 23
 				'class' 			=> 'zii.behaviors.CTimestampBehavior',
24 24
 				'createAttribute' 	=> 'created',
25 25
 				'updateAttribute' 	=> 'created',
26
-				'timestampExpression' => time(),
26
+				'timestampExpression' => time (),
27 27
 				'setUpdateOnCreate' => false
28 28
 			)
29 29
 		);
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * Query Scoping
34 34
 	 */
35
-	public function scopes()
35
+	public function scopes ()
36 36
 	{
37 37
 		return array(
38 38
 			'groupByUrl' => array(
39 39
 				'group'   => 't.uri',
40 40
 				'select'  => 't.uri, COUNT(*) as id',
41 41
 				'order'   => 't.id ASC',
42
-				'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago")
42
+				'condition' => 't.event = "_trackPageView" AND t.created >= '.strtotime ("24 hours ago")
43 43
 			),
44 44
 		);
45 45
 	}
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	/**
48 48
 	 * @return string the associated database table name
49 49
 	 */
50
-	public function tableName()
50
+	public function tableName ()
51 51
 	{
52 52
 		return 'events';
53 53
 	}
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * @return array validation rules for model attributes.
57 57
 	 */
58
-	public function rules()
58
+	public function rules ()
59 59
 	{
60 60
 		// NOTE: you should only define rules for those attributes that
61 61
 		// will receive user inputs.
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	/**
72 72
 	 * @return array customized attribute labels (name=>label)
73 73
 	 */
74
-	public function attributeLabels()
74
+	public function attributeLabels ()
75 75
 	{
76 76
 		return array(
77 77
 			'id' => 'ID',
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 		);
84 84
 	}
85 85
 
86
-	public function beforeValidate()
86
+	public function beforeValidate ()
87 87
 	{
88
-		$this->event_data = CJSON::encode($this->event_data);
89
-		return parent::beforeValidate();
88
+		$this->event_data = CJSON::encode ($this->event_data);
89
+		return parent::beforeValidate ();
90 90
 	}
91 91
 
92 92
 	/**
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	 * @return CActiveDataProvider the data provider that can return the models
102 102
 	 * based on the search/filter conditions.
103 103
 	 */
104
-	public function search()
104
+	public function search ()
105 105
 	{
106 106
 		// @todo Please modify the following code to remove attributes that should not be searched.
107 107
 
108
-		$criteria=new CDbCriteria;
108
+		$criteria = new CDbCriteria;
109 109
 
110
-		$criteria->compare('id',$this->id);
111
-		$criteria->compare('event',$this->event,true);
112
-		$criteria->compare('event_data',$this->event_data,true);
113
-		$criteria->compare('uri',$this->uri,true);
114
-		$criteria->compare('content_id',$this->content_id,true);
115
-		$criteria->compare('created',$this->created,true);
110
+		$criteria->compare ('id', $this->id);
111
+		$criteria->compare ('event', $this->event, true);
112
+		$criteria->compare ('event_data', $this->event_data, true);
113
+		$criteria->compare ('uri', $this->uri, true);
114
+		$criteria->compare ('content_id', $this->content_id, true);
115
+		$criteria->compare ('created', $this->created, true);
116 116
 
117
-		return new CActiveDataProvider($this, array(
117
+		return new CActiveDataProvider ($this, array(
118 118
 			'criteria'=>$criteria,
119 119
 		));
120 120
 	}
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 	 * @param string $className active record class name.
126 126
 	 * @return Events the static model class
127 127
 	 */
128
-	public static function model($className=__CLASS__)
128
+	public static function model ($className = __CLASS__)
129 129
 	{
130
-		return parent::model($className);
130
+		return parent::model ($className);
131 131
 	}
132 132
 }
Please login to merge, or discard this patch.
protected/models/UserMetadata.php 3 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -16,86 +16,86 @@
 block discarded – undo
16 16
  */
17 17
 class UserMetadata extends CiiModel
18 18
 {
19
-	/**
20
-	 * Returns the static model of the specified AR class.
21
-	 * @param string $className active record class name.
22
-	 * @return UserMetadata the static model class
23
-	 */
24
-	public static function model($className=__CLASS__)
25
-	{
26
-		return parent::model($className);
27
-	}
19
+    /**
20
+     * Returns the static model of the specified AR class.
21
+     * @param string $className active record class name.
22
+     * @return UserMetadata the static model class
23
+     */
24
+    public static function model($className=__CLASS__)
25
+    {
26
+        return parent::model($className);
27
+    }
28 28
 
29
-	/**
30
-	 * @return string the associated database table name
31
-	 */
32
-	public function tableName()
33
-	{
34
-		return 'user_metadata';
35
-	}
29
+    /**
30
+     * @return string the associated database table name
31
+     */
32
+    public function tableName()
33
+    {
34
+        return 'user_metadata';
35
+    }
36 36
 
37
-	/**
38
-	 * @return array validation rules for model attributes.
39
-	 */
40
-	public function rules()
41
-	{
42
-		// NOTE: you should only define rules for those attributes that
43
-		// will receive user inputs.
44
-		return array(
45
-			array('user_id, key, value', 'required'),
46
-			array('user_id, entity_type', 'numerical', 'integerOnly'=>true),
47
-			array('key', 'length', 'max'=>50),
48
-			// The following rule is used by search().
49
-			array('id, user_id, key, value, entity_type, created, updated', 'safe', 'on'=>'search'),
50
-		);
51
-	}
37
+    /**
38
+     * @return array validation rules for model attributes.
39
+     */
40
+    public function rules()
41
+    {
42
+        // NOTE: you should only define rules for those attributes that
43
+        // will receive user inputs.
44
+        return array(
45
+            array('user_id, key, value', 'required'),
46
+            array('user_id, entity_type', 'numerical', 'integerOnly'=>true),
47
+            array('key', 'length', 'max'=>50),
48
+            // The following rule is used by search().
49
+            array('id, user_id, key, value, entity_type, created, updated', 'safe', 'on'=>'search'),
50
+        );
51
+    }
52 52
 
53
-	/**
54
-	 * @return array relational rules.
55
-	 */
56
-	public function relations()
57
-	{
58
-		// NOTE: you may need to adjust the relation name and the related
59
-		// class name for the relations automatically generated below.
60
-		return array(
61
-			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
62
-		);
63
-	}
53
+    /**
54
+     * @return array relational rules.
55
+     */
56
+    public function relations()
57
+    {
58
+        // NOTE: you may need to adjust the relation name and the related
59
+        // class name for the relations automatically generated below.
60
+        return array(
61
+            'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
62
+        );
63
+    }
64 64
 
65
-	/**
66
-	 * @return array customized attribute labels (name=>label)
67
-	 */
68
-	public function attributeLabels()
69
-	{
70
-		return array(
71
-			'id' 		  => Yii::t('ciims.models.UserMetadata', 'ID'),
72
-			'user_id' 	  => Yii::t('ciims.models.UserMetadata', 'User'),
73
-			'key' 		  => Yii::t('ciims.models.UserMetadata', 'Key'),
74
-			'value' 	  => Yii::t('ciims.models.UserMetadata', 'Value'),
75
-			'entity_type' => Yii::t('ciims.models.UserMetadata', 'Entity Type'),
76
-			'created' 	  => Yii::t('ciims.models.UserMetadata', 'Created'),
77
-			'updated'     => Yii::t('ciims.models.UserMetadata', 'Updated'),
78
-		);
79
-	}
65
+    /**
66
+     * @return array customized attribute labels (name=>label)
67
+     */
68
+    public function attributeLabels()
69
+    {
70
+        return array(
71
+            'id' 		  => Yii::t('ciims.models.UserMetadata', 'ID'),
72
+            'user_id' 	  => Yii::t('ciims.models.UserMetadata', 'User'),
73
+            'key' 		  => Yii::t('ciims.models.UserMetadata', 'Key'),
74
+            'value' 	  => Yii::t('ciims.models.UserMetadata', 'Value'),
75
+            'entity_type' => Yii::t('ciims.models.UserMetadata', 'Entity Type'),
76
+            'created' 	  => Yii::t('ciims.models.UserMetadata', 'Created'),
77
+            'updated'     => Yii::t('ciims.models.UserMetadata', 'Updated'),
78
+        );
79
+    }
80 80
 
81
-	/**
82
-	 * Retrieves a list of models based on the current search/filter conditions.
83
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
84
-	 */
85
-	public function search()
86
-	{
87
-		$criteria=new CDbCriteria;
81
+    /**
82
+     * Retrieves a list of models based on the current search/filter conditions.
83
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
84
+     */
85
+    public function search()
86
+    {
87
+        $criteria=new CDbCriteria;
88 88
 
89
-		$criteria->compare('id',$this->id);
90
-		$criteria->compare('user_id',$this->user_id);
91
-		$criteria->compare('key',$this->key,true);
92
-		$criteria->compare('value',$this->value,true);
93
-		$criteria->compare('entity_type',$this->entity_type,true);
94
-		$criteria->compare('created',$this->created,true);
95
-		$criteria->compare('updated',$this->updated,true);
89
+        $criteria->compare('id',$this->id);
90
+        $criteria->compare('user_id',$this->user_id);
91
+        $criteria->compare('key',$this->key,true);
92
+        $criteria->compare('value',$this->value,true);
93
+        $criteria->compare('entity_type',$this->entity_type,true);
94
+        $criteria->compare('created',$this->created,true);
95
+        $criteria->compare('updated',$this->updated,true);
96 96
 
97
-		return new CActiveDataProvider($this, array(
98
-			'criteria'=>$criteria,
99
-		));
100
-	}
97
+        return new CActiveDataProvider($this, array(
98
+            'criteria'=>$criteria,
99
+        ));
100
+    }
101 101
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param string $className active record class name.
22 22
 	 * @return UserMetadata the static model class
23 23
 	 */
24
-	public static function model($className=__CLASS__)
24
+	public static function model ($className = __CLASS__)
25 25
 	{
26
-		return parent::model($className);
26
+		return parent::model ($className);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @return string the associated database table name
31 31
 	 */
32
-	public function tableName()
32
+	public function tableName ()
33 33
 	{
34 34
 		return 'user_metadata';
35 35
 	}
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @return array validation rules for model attributes.
39 39
 	 */
40
-	public function rules()
40
+	public function rules ()
41 41
 	{
42 42
 		// NOTE: you should only define rules for those attributes that
43 43
 		// will receive user inputs.
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * @return array relational rules.
55 55
 	 */
56
-	public function relations()
56
+	public function relations ()
57 57
 	{
58 58
 		// NOTE: you may need to adjust the relation name and the related
59 59
 		// class name for the relations automatically generated below.
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
 	/**
66 66
 	 * @return array customized attribute labels (name=>label)
67 67
 	 */
68
-	public function attributeLabels()
68
+	public function attributeLabels ()
69 69
 	{
70 70
 		return array(
71
-			'id' 		  => Yii::t('ciims.models.UserMetadata', 'ID'),
72
-			'user_id' 	  => Yii::t('ciims.models.UserMetadata', 'User'),
73
-			'key' 		  => Yii::t('ciims.models.UserMetadata', 'Key'),
74
-			'value' 	  => Yii::t('ciims.models.UserMetadata', 'Value'),
75
-			'entity_type' => Yii::t('ciims.models.UserMetadata', 'Entity Type'),
76
-			'created' 	  => Yii::t('ciims.models.UserMetadata', 'Created'),
77
-			'updated'     => Yii::t('ciims.models.UserMetadata', 'Updated'),
71
+			'id' 		  => Yii::t ('ciims.models.UserMetadata', 'ID'),
72
+			'user_id' 	  => Yii::t ('ciims.models.UserMetadata', 'User'),
73
+			'key' 		  => Yii::t ('ciims.models.UserMetadata', 'Key'),
74
+			'value' 	  => Yii::t ('ciims.models.UserMetadata', 'Value'),
75
+			'entity_type' => Yii::t ('ciims.models.UserMetadata', 'Entity Type'),
76
+			'created' 	  => Yii::t ('ciims.models.UserMetadata', 'Created'),
77
+			'updated'     => Yii::t ('ciims.models.UserMetadata', 'Updated'),
78 78
 		);
79 79
 	}
80 80
 
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
 	 * Retrieves a list of models based on the current search/filter conditions.
83 83
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
84 84
 	 */
85
-	public function search()
85
+	public function search ()
86 86
 	{
87
-		$criteria=new CDbCriteria;
87
+		$criteria = new CDbCriteria;
88 88
 
89
-		$criteria->compare('id',$this->id);
90
-		$criteria->compare('user_id',$this->user_id);
91
-		$criteria->compare('key',$this->key,true);
92
-		$criteria->compare('value',$this->value,true);
93
-		$criteria->compare('entity_type',$this->entity_type,true);
94
-		$criteria->compare('created',$this->created,true);
95
-		$criteria->compare('updated',$this->updated,true);
89
+		$criteria->compare ('id', $this->id);
90
+		$criteria->compare ('user_id', $this->user_id);
91
+		$criteria->compare ('key', $this->key, true);
92
+		$criteria->compare ('value', $this->value, true);
93
+		$criteria->compare ('entity_type', $this->entity_type, true);
94
+		$criteria->compare ('created', $this->created, true);
95
+		$criteria->compare ('updated', $this->updated, true);
96 96
 
97
-		return new CActiveDataProvider($this, array(
97
+		return new CActiveDataProvider ($this, array(
98 98
 			'criteria'=>$criteria,
99 99
 		));
100 100
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -14,31 +14,31 @@  discard block
 block discarded – undo
14 14
  * The followings are the available model relations:
15 15
  * @property Users $user
16 16
  */
17
-class UserMetadata extends CiiModel
18
-{
17
+class UserMetadata extends CiiModel
18
+{
19 19
 	/**
20 20
 	 * Returns the static model of the specified AR class.
21 21
 	 * @param string $className active record class name.
22 22
 	 * @return UserMetadata the static model class
23 23
 	 */
24
-	public static function model($className=__CLASS__)
25
-	{
24
+	public static function model($className=__CLASS__)
25
+	{
26 26
 		return parent::model($className);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @return string the associated database table name
31 31
 	 */
32
-	public function tableName()
33
-	{
32
+	public function tableName()
33
+	{
34 34
 		return 'user_metadata';
35 35
 	}
36 36
 
37 37
 	/**
38 38
 	 * @return array validation rules for model attributes.
39 39
 	 */
40
-	public function rules()
41
-	{
40
+	public function rules()
41
+	{
42 42
 		// NOTE: you should only define rules for those attributes that
43 43
 		// will receive user inputs.
44 44
 		return array(
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * @return array relational rules.
55 55
 	 */
56
-	public function relations()
57
-	{
56
+	public function relations()
57
+	{
58 58
 		// NOTE: you may need to adjust the relation name and the related
59 59
 		// class name for the relations automatically generated below.
60 60
 		return array(
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	/**
66 66
 	 * @return array customized attribute labels (name=>label)
67 67
 	 */
68
-	public function attributeLabels()
69
-	{
68
+	public function attributeLabels()
69
+	{
70 70
 		return array(
71 71
 			'id' 		  => Yii::t('ciims.models.UserMetadata', 'ID'),
72 72
 			'user_id' 	  => Yii::t('ciims.models.UserMetadata', 'User'),
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * Retrieves a list of models based on the current search/filter conditions.
83 83
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
84 84
 	 */
85
-	public function search()
86
-	{
85
+	public function search()
86
+	{
87 87
 		$criteria=new CDbCriteria;
88 88
 
89 89
 		$criteria->compare('id',$this->id);
Please login to merge, or discard this patch.
protected/models/UserRoles.php 3 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -15,184 +15,184 @@
 block discarded – undo
15 15
 class UserRoles extends CiiModel
16 16
 {
17 17
 
18
-	/**
19
-	 * Returns a key => value array of userRole => bitwise permissions
20
-	 *
21
-	 * Permissions apply per role, with the exception of publisher and admin, whose permissions apply to everything
22
-	 * Note that these permissions only apply to content, and management of CiiMS' settings
23
-	 *
24
-	 * --------------------------------------------------------------------------------
25
-	 * | role/id | manage | publish other | publish | delete | update | create | read |
26
-	 * --------------------------------------------------------------------------------
27
-	 * |  user/1 |   0    |        0      |    0    |    0   |    0   |    0   |  1   |
28
-	 * --------------------------------------------------------------------------------
29
-	 * | clb/5   |   0    |        0      |    0    |    0   |    1   |    1   |  1   |
30
-	 * --------------------------------------------------------------------------------
31
-	 * | auth/7  |   0    |        0      |    1    |    1   |    1   |    1   |  1   |
32
-	 * --------------------------------------------------------------------------------
33
-	 * | pub/8   |   0    |        1      |    1    |    1   |    1   |    1   |  1   |
34
-	 * --------------------------------------------------------------------------------
35
-	 * | admin/9 |   1    |        1      |    1    |    1   |    1   |    1   |  1   |
36
-	 * --------------------------------------------------------------------------------
37
-	 * @return array
38
-	 */
39
-	public function getPermissions()
40
-	{
41
-		return array(
42
-			'1' => 1,		// User
43
-			'2' => 0,		// Pending
44
-			'3' => 0,		// Suspended
45
-			'5' => 7,		// Collaborator
46
-			'7' => 16,		// Author
47
-			'8' => 32,		// Publisher
48
-			'9' => 64		// Admin
49
-		);
50
-	}
51
-
52
-	public function isA($roleName, $role=false)
53
-	{
54
-		if ($role === false)
55
-			$role = Yii::app()->user->role;
56
-
57
-		$roleName = strtolower($roleName);
58
-
59
-		switch ($roleName)
60
-		{
61
-			case 'user':
62
-				return $role <= 1;
63
-			case 'collaborator':
64
-				return $role == 5;
65
-			case 'author':
66
-				return $role == 7;
67
-			case 'publisher':
68
-				return $role == 8;
69
-			case 'admin':
70
-				return $role == 9;
71
-		}
72
-
73
-		return false;
74
-	}
75
-
76
-	/**
77
-	 * Returns the bitwise permissions associated to each activity
78
-	 * @return array
79
-	 */
80
-	public function getActivities()
81
-	{
82
-		return array(
83
-			'read' 			=> 1,
84
-			'comment' 		=> 1,
85
-			'create' 		=> 3,
86
-			'update' 		=> 4,
87
-			'modify' 		=> 7,
88
-			'delete' 		=> 8,
89
-			'publish' 		=> 16,
90
-			'publishOther' 	=> 32,
91
-			'manage' 		=> 64
92
-		);
93
-	}
94
-
95
-	/**
96
-	 * Determines if a user with a given role has permission to perform a given activity
97
-	 * @param string $permission   The permissions we want to lookup
98
-	 * @param int 	 $role 			The user role. If not provided, will be applied to the current user
99
-	 * @return boolean
100
-	 */
101
-	public function hasPermission($permission, $role=NULL)
102
-	{
103
-		if ($role === NULL)
104
-		{
105
-			if (isset($this->id))
106
-				$role = $this->id;
107
-			else if (Yii::app()->user->isGuest)
108
-				$role = 1;
109
-			else
110
-				$role = Yii::app()->user->role;
111
-		}
112
-
113
-		$permissions = $this->getPermissions();
114
-		$activities = $this->getActivities();
115
-
116
-		// If the permission doesn't exist for that role, return false;
117
-		if (!isset($permissions[$role]))
118
-			return false;
119
-
120
-		return $activities[$permission] <= $permissions[$role];
121
-	}
122
-
123
-	/**
124
-	 * Returns the static model of the specified AR class.
125
-	 * @param string $className active record class name.
126
-	 * @return UserRoles the static model class
127
-	 */
128
-	public static function model($className=__CLASS__)
129
-	{
130
-		return parent::model($className);
131
-	}
132
-
133
-	/**
134
-	 * @return string the associated database table name
135
-	 */
136
-	public function tableName()
137
-	{
138
-		return 'user_roles';
139
-	}
140
-
141
-	/**
142
-	 * @return array validation rules for model attributes.
143
-	 */
144
-	public function rules()
145
-	{
146
-		// NOTE: you should only define rules for those attributes that
147
-		// will receive user inputs.
148
-		return array(
149
-			array('name', 'required'),
150
-			array('name', 'length', 'max'=>100),
151
-			// The following rule is used by search().
152
-			array('id, name, created, updated', 'safe', 'on'=>'search'),
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * @return array relational rules.
158
-	 */
159
-	public function relations()
160
-	{
161
-		// NOTE: you may need to adjust the relation name and the related
162
-		// class name for the relations automatically generated below.
163
-		return array(
164
-			'users' => array(self::HAS_MANY, 'Users', 'user_role'),
165
-		);
166
-	}
167
-
168
-	/**
169
-	 * @return array customized attribute labels (name=>label)
170
-	 */
171
-	public function attributeLabels()
172
-	{
173
-		return array(
174
-			'id' 	  => Yii::t('ciims.models.UserRoles', 'ID'),
175
-			'name' 	  => Yii::t('ciims.models.UserRoles', 'Name'),
176
-			'created' => Yii::t('ciims.models.UserRoles', 'Created'),
177
-			'updated' => Yii::t('ciims.models.UserRoles', 'Updated'),
178
-		);
179
-	}
180
-
181
-	/**
182
-	 * Retrieves a list of models based on the current search/filter conditions.
183
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
184
-	 */
185
-	public function search()
186
-	{
187
-		$criteria=new CDbCriteria;
188
-
189
-		$criteria->compare('id',$this->id);
190
-		$criteria->compare('name',$this->name,true);
191
-		$criteria->compare('created',$this->created,true);
192
-		$criteria->compare('updated',$this->updated,true);
193
-
194
-		return new CActiveDataProvider($this, array(
195
-			'criteria'=>$criteria,
196
-		));
197
-	}
18
+    /**
19
+     * Returns a key => value array of userRole => bitwise permissions
20
+     *
21
+     * Permissions apply per role, with the exception of publisher and admin, whose permissions apply to everything
22
+     * Note that these permissions only apply to content, and management of CiiMS' settings
23
+     *
24
+     * --------------------------------------------------------------------------------
25
+     * | role/id | manage | publish other | publish | delete | update | create | read |
26
+     * --------------------------------------------------------------------------------
27
+     * |  user/1 |   0    |        0      |    0    |    0   |    0   |    0   |  1   |
28
+     * --------------------------------------------------------------------------------
29
+     * | clb/5   |   0    |        0      |    0    |    0   |    1   |    1   |  1   |
30
+     * --------------------------------------------------------------------------------
31
+     * | auth/7  |   0    |        0      |    1    |    1   |    1   |    1   |  1   |
32
+     * --------------------------------------------------------------------------------
33
+     * | pub/8   |   0    |        1      |    1    |    1   |    1   |    1   |  1   |
34
+     * --------------------------------------------------------------------------------
35
+     * | admin/9 |   1    |        1      |    1    |    1   |    1   |    1   |  1   |
36
+     * --------------------------------------------------------------------------------
37
+     * @return array
38
+     */
39
+    public function getPermissions()
40
+    {
41
+        return array(
42
+            '1' => 1,		// User
43
+            '2' => 0,		// Pending
44
+            '3' => 0,		// Suspended
45
+            '5' => 7,		// Collaborator
46
+            '7' => 16,		// Author
47
+            '8' => 32,		// Publisher
48
+            '9' => 64		// Admin
49
+        );
50
+    }
51
+
52
+    public function isA($roleName, $role=false)
53
+    {
54
+        if ($role === false)
55
+            $role = Yii::app()->user->role;
56
+
57
+        $roleName = strtolower($roleName);
58
+
59
+        switch ($roleName)
60
+        {
61
+            case 'user':
62
+                return $role <= 1;
63
+            case 'collaborator':
64
+                return $role == 5;
65
+            case 'author':
66
+                return $role == 7;
67
+            case 'publisher':
68
+                return $role == 8;
69
+            case 'admin':
70
+                return $role == 9;
71
+        }
72
+
73
+        return false;
74
+    }
75
+
76
+    /**
77
+     * Returns the bitwise permissions associated to each activity
78
+     * @return array
79
+     */
80
+    public function getActivities()
81
+    {
82
+        return array(
83
+            'read' 			=> 1,
84
+            'comment' 		=> 1,
85
+            'create' 		=> 3,
86
+            'update' 		=> 4,
87
+            'modify' 		=> 7,
88
+            'delete' 		=> 8,
89
+            'publish' 		=> 16,
90
+            'publishOther' 	=> 32,
91
+            'manage' 		=> 64
92
+        );
93
+    }
94
+
95
+    /**
96
+     * Determines if a user with a given role has permission to perform a given activity
97
+     * @param string $permission   The permissions we want to lookup
98
+     * @param int 	 $role 			The user role. If not provided, will be applied to the current user
99
+     * @return boolean
100
+     */
101
+    public function hasPermission($permission, $role=NULL)
102
+    {
103
+        if ($role === NULL)
104
+        {
105
+            if (isset($this->id))
106
+                $role = $this->id;
107
+            else if (Yii::app()->user->isGuest)
108
+                $role = 1;
109
+            else
110
+                $role = Yii::app()->user->role;
111
+        }
112
+
113
+        $permissions = $this->getPermissions();
114
+        $activities = $this->getActivities();
115
+
116
+        // If the permission doesn't exist for that role, return false;
117
+        if (!isset($permissions[$role]))
118
+            return false;
119
+
120
+        return $activities[$permission] <= $permissions[$role];
121
+    }
122
+
123
+    /**
124
+     * Returns the static model of the specified AR class.
125
+     * @param string $className active record class name.
126
+     * @return UserRoles the static model class
127
+     */
128
+    public static function model($className=__CLASS__)
129
+    {
130
+        return parent::model($className);
131
+    }
132
+
133
+    /**
134
+     * @return string the associated database table name
135
+     */
136
+    public function tableName()
137
+    {
138
+        return 'user_roles';
139
+    }
140
+
141
+    /**
142
+     * @return array validation rules for model attributes.
143
+     */
144
+    public function rules()
145
+    {
146
+        // NOTE: you should only define rules for those attributes that
147
+        // will receive user inputs.
148
+        return array(
149
+            array('name', 'required'),
150
+            array('name', 'length', 'max'=>100),
151
+            // The following rule is used by search().
152
+            array('id, name, created, updated', 'safe', 'on'=>'search'),
153
+        );
154
+    }
155
+
156
+    /**
157
+     * @return array relational rules.
158
+     */
159
+    public function relations()
160
+    {
161
+        // NOTE: you may need to adjust the relation name and the related
162
+        // class name for the relations automatically generated below.
163
+        return array(
164
+            'users' => array(self::HAS_MANY, 'Users', 'user_role'),
165
+        );
166
+    }
167
+
168
+    /**
169
+     * @return array customized attribute labels (name=>label)
170
+     */
171
+    public function attributeLabels()
172
+    {
173
+        return array(
174
+            'id' 	  => Yii::t('ciims.models.UserRoles', 'ID'),
175
+            'name' 	  => Yii::t('ciims.models.UserRoles', 'Name'),
176
+            'created' => Yii::t('ciims.models.UserRoles', 'Created'),
177
+            'updated' => Yii::t('ciims.models.UserRoles', 'Updated'),
178
+        );
179
+    }
180
+
181
+    /**
182
+     * Retrieves a list of models based on the current search/filter conditions.
183
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
184
+     */
185
+    public function search()
186
+    {
187
+        $criteria=new CDbCriteria;
188
+
189
+        $criteria->compare('id',$this->id);
190
+        $criteria->compare('name',$this->name,true);
191
+        $criteria->compare('created',$this->created,true);
192
+        $criteria->compare('updated',$this->updated,true);
193
+
194
+        return new CActiveDataProvider($this, array(
195
+            'criteria'=>$criteria,
196
+        ));
197
+    }
198 198
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -36,25 +36,25 @@  discard block
 block discarded – undo
36 36
 	 * --------------------------------------------------------------------------------
37 37
 	 * @return array
38 38
 	 */
39
-	public function getPermissions()
39
+	public function getPermissions ()
40 40
 	{
41 41
 		return array(
42
-			'1' => 1,		// User
43
-			'2' => 0,		// Pending
44
-			'3' => 0,		// Suspended
45
-			'5' => 7,		// Collaborator
46
-			'7' => 16,		// Author
47
-			'8' => 32,		// Publisher
42
+			'1' => 1, // User
43
+			'2' => 0, // Pending
44
+			'3' => 0, // Suspended
45
+			'5' => 7, // Collaborator
46
+			'7' => 16, // Author
47
+			'8' => 32, // Publisher
48 48
 			'9' => 64		// Admin
49 49
 		);
50 50
 	}
51 51
 
52
-	public function isA($roleName, $role=false)
52
+	public function isA ($roleName, $role = false)
53 53
 	{
54 54
 		if ($role === false)
55
-			$role = Yii::app()->user->role;
55
+			$role = Yii::app ()->user->role;
56 56
 
57
-		$roleName = strtolower($roleName);
57
+		$roleName = strtolower ($roleName);
58 58
 
59 59
 		switch ($roleName)
60 60
 		{
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * Returns the bitwise permissions associated to each activity
78 78
 	 * @return array
79 79
 	 */
80
-	public function getActivities()
80
+	public function getActivities ()
81 81
 	{
82 82
 		return array(
83 83
 			'read' 			=> 1,
@@ -98,20 +98,20 @@  discard block
 block discarded – undo
98 98
 	 * @param int 	 $role 			The user role. If not provided, will be applied to the current user
99 99
 	 * @return boolean
100 100
 	 */
101
-	public function hasPermission($permission, $role=NULL)
101
+	public function hasPermission ($permission, $role = NULL)
102 102
 	{
103 103
 		if ($role === NULL)
104 104
 		{
105 105
 			if (isset($this->id))
106 106
 				$role = $this->id;
107
-			else if (Yii::app()->user->isGuest)
107
+			else if (Yii::app ()->user->isGuest)
108 108
 				$role = 1;
109 109
 			else
110
-				$role = Yii::app()->user->role;
110
+				$role = Yii::app ()->user->role;
111 111
 		}
112 112
 
113
-		$permissions = $this->getPermissions();
114
-		$activities = $this->getActivities();
113
+		$permissions = $this->getPermissions ();
114
+		$activities = $this->getActivities ();
115 115
 
116 116
 		// If the permission doesn't exist for that role, return false;
117 117
 		if (!isset($permissions[$role]))
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
 	 * @param string $className active record class name.
126 126
 	 * @return UserRoles the static model class
127 127
 	 */
128
-	public static function model($className=__CLASS__)
128
+	public static function model ($className = __CLASS__)
129 129
 	{
130
-		return parent::model($className);
130
+		return parent::model ($className);
131 131
 	}
132 132
 
133 133
 	/**
134 134
 	 * @return string the associated database table name
135 135
 	 */
136
-	public function tableName()
136
+	public function tableName ()
137 137
 	{
138 138
 		return 'user_roles';
139 139
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	/**
142 142
 	 * @return array validation rules for model attributes.
143 143
 	 */
144
-	public function rules()
144
+	public function rules ()
145 145
 	{
146 146
 		// NOTE: you should only define rules for those attributes that
147 147
 		// will receive user inputs.
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	/**
157 157
 	 * @return array relational rules.
158 158
 	 */
159
-	public function relations()
159
+	public function relations ()
160 160
 	{
161 161
 		// NOTE: you may need to adjust the relation name and the related
162 162
 		// class name for the relations automatically generated below.
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
 	/**
169 169
 	 * @return array customized attribute labels (name=>label)
170 170
 	 */
171
-	public function attributeLabels()
171
+	public function attributeLabels ()
172 172
 	{
173 173
 		return array(
174
-			'id' 	  => Yii::t('ciims.models.UserRoles', 'ID'),
175
-			'name' 	  => Yii::t('ciims.models.UserRoles', 'Name'),
176
-			'created' => Yii::t('ciims.models.UserRoles', 'Created'),
177
-			'updated' => Yii::t('ciims.models.UserRoles', 'Updated'),
174
+			'id' 	  => Yii::t ('ciims.models.UserRoles', 'ID'),
175
+			'name' 	  => Yii::t ('ciims.models.UserRoles', 'Name'),
176
+			'created' => Yii::t ('ciims.models.UserRoles', 'Created'),
177
+			'updated' => Yii::t ('ciims.models.UserRoles', 'Updated'),
178 178
 		);
179 179
 	}
180 180
 
@@ -182,16 +182,16 @@  discard block
 block discarded – undo
182 182
 	 * Retrieves a list of models based on the current search/filter conditions.
183 183
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
184 184
 	 */
185
-	public function search()
185
+	public function search ()
186 186
 	{
187
-		$criteria=new CDbCriteria;
187
+		$criteria = new CDbCriteria;
188 188
 
189
-		$criteria->compare('id',$this->id);
190
-		$criteria->compare('name',$this->name,true);
191
-		$criteria->compare('created',$this->created,true);
192
-		$criteria->compare('updated',$this->updated,true);
189
+		$criteria->compare ('id', $this->id);
190
+		$criteria->compare ('name', $this->name, true);
191
+		$criteria->compare ('created', $this->created, true);
192
+		$criteria->compare ('updated', $this->updated, true);
193 193
 
194
-		return new CActiveDataProvider($this, array(
194
+		return new CActiveDataProvider ($this, array(
195 195
 			'criteria'=>$criteria,
196 196
 		));
197 197
 	}
Please login to merge, or discard this patch.
Braces   +35 added lines, -32 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * The followings are the available model relations:
13 13
  * @property Users[] $users
14 14
  */
15
-class UserRoles extends CiiModel
16
-{
15
+class UserRoles extends CiiModel
16
+{
17 17
 
18 18
 	/**
19 19
 	 * Returns a key => value array of userRole => bitwise permissions
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	 * --------------------------------------------------------------------------------
37 37
 	 * @return array
38 38
 	 */
39
-	public function getPermissions()
40
-	{
39
+	public function getPermissions()
40
+	{
41 41
 		return array(
42 42
 			'1' => 1,		// User
43 43
 			'2' => 0,		// Pending
@@ -49,10 +49,11 @@  discard block
 block discarded – undo
49 49
 		);
50 50
 	}
51 51
 
52
-	public function isA($roleName, $role=false)
53
-	{
54
-		if ($role === false)
55
-			$role = Yii::app()->user->role;
52
+	public function isA($roleName, $role=false)
53
+	{
54
+		if ($role === false) {
55
+					$role = Yii::app()->user->role;
56
+		}
56 57
 
57 58
 		$roleName = strtolower($roleName);
58 59
 
@@ -77,8 +78,8 @@  discard block
 block discarded – undo
77 78
 	 * Returns the bitwise permissions associated to each activity
78 79
 	 * @return array
79 80
 	 */
80
-	public function getActivities()
81
-	{
81
+	public function getActivities()
82
+	{
82 83
 		return array(
83 84
 			'read' 			=> 1,
84 85
 			'comment' 		=> 1,
@@ -98,24 +99,26 @@  discard block
 block discarded – undo
98 99
 	 * @param int 	 $role 			The user role. If not provided, will be applied to the current user
99 100
 	 * @return boolean
100 101
 	 */
101
-	public function hasPermission($permission, $role=NULL)
102
-	{
102
+	public function hasPermission($permission, $role=NULL)
103
+	{
103 104
 		if ($role === NULL)
104 105
 		{
105
-			if (isset($this->id))
106
-				$role = $this->id;
107
-			else if (Yii::app()->user->isGuest)
108
-				$role = 1;
109
-			else
110
-				$role = Yii::app()->user->role;
106
+			if (isset($this->id)) {
107
+							$role = $this->id;
108
+			} else if (Yii::app()->user->isGuest) {
109
+							$role = 1;
110
+			} else {
111
+							$role = Yii::app()->user->role;
112
+			}
111 113
 		}
112 114
 
113 115
 		$permissions = $this->getPermissions();
114 116
 		$activities = $this->getActivities();
115 117
 
116 118
 		// If the permission doesn't exist for that role, return false;
117
-		if (!isset($permissions[$role]))
118
-			return false;
119
+		if (!isset($permissions[$role])) {
120
+					return false;
121
+		}
119 122
 
120 123
 		return $activities[$permission] <= $permissions[$role];
121 124
 	}
@@ -125,24 +128,24 @@  discard block
 block discarded – undo
125 128
 	 * @param string $className active record class name.
126 129
 	 * @return UserRoles the static model class
127 130
 	 */
128
-	public static function model($className=__CLASS__)
129
-	{
131
+	public static function model($className=__CLASS__)
132
+	{
130 133
 		return parent::model($className);
131 134
 	}
132 135
 
133 136
 	/**
134 137
 	 * @return string the associated database table name
135 138
 	 */
136
-	public function tableName()
137
-	{
139
+	public function tableName()
140
+	{
138 141
 		return 'user_roles';
139 142
 	}
140 143
 
141 144
 	/**
142 145
 	 * @return array validation rules for model attributes.
143 146
 	 */
144
-	public function rules()
145
-	{
147
+	public function rules()
148
+	{
146 149
 		// NOTE: you should only define rules for those attributes that
147 150
 		// will receive user inputs.
148 151
 		return array(
@@ -156,8 +159,8 @@  discard block
 block discarded – undo
156 159
 	/**
157 160
 	 * @return array relational rules.
158 161
 	 */
159
-	public function relations()
160
-	{
162
+	public function relations()
163
+	{
161 164
 		// NOTE: you may need to adjust the relation name and the related
162 165
 		// class name for the relations automatically generated below.
163 166
 		return array(
@@ -168,8 +171,8 @@  discard block
 block discarded – undo
168 171
 	/**
169 172
 	 * @return array customized attribute labels (name=>label)
170 173
 	 */
171
-	public function attributeLabels()
172
-	{
174
+	public function attributeLabels()
175
+	{
173 176
 		return array(
174 177
 			'id' 	  => Yii::t('ciims.models.UserRoles', 'ID'),
175 178
 			'name' 	  => Yii::t('ciims.models.UserRoles', 'Name'),
@@ -182,8 +185,8 @@  discard block
 block discarded – undo
182 185
 	 * Retrieves a list of models based on the current search/filter conditions.
183 186
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
184 187
 	 */
185
-	public function search()
186
-	{
188
+	public function search()
189
+	{
187 190
 		$criteria=new CDbCriteria;
188 191
 
189 192
 		$criteria->compare('id',$this->id);
Please login to merge, or discard this patch.
protected/models/Users.php 3 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -25,303 +25,303 @@
 block discarded – undo
25 25
  */
26 26
 class Users extends CiiModel
27 27
 {
28
-	const INACTIVE = 0;
29
-	const ACTIVE = 1;
30
-	const BANNED = 2;
31
-	const PENDING_INVITATION = 3;
32
-
33
-	public $pageSize = 15;
34
-
35
-	/**
36
-	 * Returns the static model of the specified AR class.
37
-	 * @param string $className active record class name.
38
-	 * @return Users the static model class
39
-	 */
40
-	public static function model($className=__CLASS__)
41
-	{
42
-		return parent::model($className);
43
-	}
44
-
45
-	/**
46
-	 * @return string the associated database table name
47
-	 */
48
-	public function tableName()
49
-	{
50
-		return 'users';
51
-	}
52
-
53
-	/**
54
-	 * @return array validation rules for model attributes.
55
-	 */
56
-	public function rules()
57
-	{
58
-		// NOTE: you should only define rules for those attributes that
59
-		// will receive user inputs.
60
-		return array(
61
-			array('email, password, username, user_role, status', 'required'),
62
-			array('email', 'email'),
63
-			array('user_role, status', 'numerical', 'integerOnly'=>true),
64
-			array('email, username', 'length', 'max'=>255),
65
-			array('password', 'length', 'max'=>64),
66
-			// The following rule is used by search().
67
-			array('id, email, password, username, about, user_role, status, created, updated', 'safe', 'on'=>'search'),
68
-		);
69
-	}
70
-
71
-	/**
72
-	 * @return array relational rules.
73
-	 */
74
-	public function relations()
75
-	{
76
-		// NOTE: you may need to adjust the relation name and the related
77
-		// class name for the relations automatically generated below.
78
-		return array(
79
-			'comments' 	=> array(self::HAS_MANY, 'Comments', 'user_id'),
80
-			'content' 	=> array(self::HAS_MANY, 'Content', 'author_id'),
81
-			'metadata' 	=> array(self::HAS_MANY, 'UserMetadata', 'user_id', 'condition' => '`metadata`.`entity_type` = 0'),
82
-			'role' 		=> array(self::BELONGS_TO, 'UserRoles', 'user_role'),
83
-		);
84
-	}
85
-
86
-	/**
87
-	 * @return array customized attribute labels (name=>label)
88
-	 */
89
-	public function attributeLabels()
90
-	{
91
-		return array(
92
-			'id' 		  => Yii::t('ciims.models.Users', 'ID'),
93
-			'email' 	  => Yii::t('ciims.models.Users', 'Email'),
94
-			'password' 	  => Yii::t('ciims.models.Users', 'Password'),
95
-			'username'    => Yii::t('ciims.models.Users', 'User Name'),
96
-			'user_role'   => Yii::t('ciims.models.Users', 'User Role'),
97
-			'status'	  => Yii::t('ciims.models.Users', 'Active'),
98
-			'created' 	  => Yii::t('ciims.models.Users', 'Created'),
99
-			'updated' 	  => Yii::t('ciims.models.Users', 'Updated'),
100
-		);
101
-	}
102
-
103
-	/**
104
-	 * Gets the first and last name instead of the username
105
-	 */
106
-	public function getName()
107
-	{
108
-		return $this->username;
109
-	}
110
-
111
-	/**
112
-	 * Retrieves the username
113
-	 */
114
-	public function getUsername()
115
-	{
116
-		return $this->username;
117
-	}
118
-
119
-	/**
120
-	 * Retrieves the username
121
-	 * @todo This is technical debt. At some point this should be completely depricated
122
-	 */
123
-	public function getDisplayName()
124
-	{
125
-		Yii::log('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users');
126
-		return $this->getUsername();
127
-	}
128
-
129
-	/**
130
-	 * Retrieves the reputation for a given user
131
-	 * @param boolean $model 	Whether an instance of UserMetadata should be returned or not
132
-	 * @return mixed
133
-	 */
134
-	public function getReputation($model=false)
135
-	{
136
-		$reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150));
137
-
138
-		if ($model === true)
139
-			return $reputation;
140
-
141
-		return $reputation->value;
142
-	}
143
-
144
-	/**
145
-	 * Updates a user's reputation
146
-	 * @return boolean
147
-	 */
148
-	public function setReputation($rep = 10)
149
-	{
150
-		$reputation = $this->getReputation(true);
151
-		$reputation->value += $rep;
152
-		return $reputation->save();
153
-	}
154
-
155
-	/**
156
-	 * Retrieves all comments that the user has flagged
157
-	 * @param boolean $model 	Whether an instance of UserMetadata should be returned or not
158
-	 * @return mixed
159
-	 */
160
-	public function getFlaggedComments($model=false)
161
-	{
162
-		$flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array())));
28
+    const INACTIVE = 0;
29
+    const ACTIVE = 1;
30
+    const BANNED = 2;
31
+    const PENDING_INVITATION = 3;
32
+
33
+    public $pageSize = 15;
34
+
35
+    /**
36
+     * Returns the static model of the specified AR class.
37
+     * @param string $className active record class name.
38
+     * @return Users the static model class
39
+     */
40
+    public static function model($className=__CLASS__)
41
+    {
42
+        return parent::model($className);
43
+    }
44
+
45
+    /**
46
+     * @return string the associated database table name
47
+     */
48
+    public function tableName()
49
+    {
50
+        return 'users';
51
+    }
52
+
53
+    /**
54
+     * @return array validation rules for model attributes.
55
+     */
56
+    public function rules()
57
+    {
58
+        // NOTE: you should only define rules for those attributes that
59
+        // will receive user inputs.
60
+        return array(
61
+            array('email, password, username, user_role, status', 'required'),
62
+            array('email', 'email'),
63
+            array('user_role, status', 'numerical', 'integerOnly'=>true),
64
+            array('email, username', 'length', 'max'=>255),
65
+            array('password', 'length', 'max'=>64),
66
+            // The following rule is used by search().
67
+            array('id, email, password, username, about, user_role, status, created, updated', 'safe', 'on'=>'search'),
68
+        );
69
+    }
70
+
71
+    /**
72
+     * @return array relational rules.
73
+     */
74
+    public function relations()
75
+    {
76
+        // NOTE: you may need to adjust the relation name and the related
77
+        // class name for the relations automatically generated below.
78
+        return array(
79
+            'comments' 	=> array(self::HAS_MANY, 'Comments', 'user_id'),
80
+            'content' 	=> array(self::HAS_MANY, 'Content', 'author_id'),
81
+            'metadata' 	=> array(self::HAS_MANY, 'UserMetadata', 'user_id', 'condition' => '`metadata`.`entity_type` = 0'),
82
+            'role' 		=> array(self::BELONGS_TO, 'UserRoles', 'user_role'),
83
+        );
84
+    }
85
+
86
+    /**
87
+     * @return array customized attribute labels (name=>label)
88
+     */
89
+    public function attributeLabels()
90
+    {
91
+        return array(
92
+            'id' 		  => Yii::t('ciims.models.Users', 'ID'),
93
+            'email' 	  => Yii::t('ciims.models.Users', 'Email'),
94
+            'password' 	  => Yii::t('ciims.models.Users', 'Password'),
95
+            'username'    => Yii::t('ciims.models.Users', 'User Name'),
96
+            'user_role'   => Yii::t('ciims.models.Users', 'User Role'),
97
+            'status'	  => Yii::t('ciims.models.Users', 'Active'),
98
+            'created' 	  => Yii::t('ciims.models.Users', 'Created'),
99
+            'updated' 	  => Yii::t('ciims.models.Users', 'Updated'),
100
+        );
101
+    }
102
+
103
+    /**
104
+     * Gets the first and last name instead of the username
105
+     */
106
+    public function getName()
107
+    {
108
+        return $this->username;
109
+    }
110
+
111
+    /**
112
+     * Retrieves the username
113
+     */
114
+    public function getUsername()
115
+    {
116
+        return $this->username;
117
+    }
118
+
119
+    /**
120
+     * Retrieves the username
121
+     * @todo This is technical debt. At some point this should be completely depricated
122
+     */
123
+    public function getDisplayName()
124
+    {
125
+        Yii::log('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users');
126
+        return $this->getUsername();
127
+    }
128
+
129
+    /**
130
+     * Retrieves the reputation for a given user
131
+     * @param boolean $model 	Whether an instance of UserMetadata should be returned or not
132
+     * @return mixed
133
+     */
134
+    public function getReputation($model=false)
135
+    {
136
+        $reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150));
137
+
138
+        if ($model === true)
139
+            return $reputation;
140
+
141
+        return $reputation->value;
142
+    }
143
+
144
+    /**
145
+     * Updates a user's reputation
146
+     * @return boolean
147
+     */
148
+    public function setReputation($rep = 10)
149
+    {
150
+        $reputation = $this->getReputation(true);
151
+        $reputation->value += $rep;
152
+        return $reputation->save();
153
+    }
154
+
155
+    /**
156
+     * Retrieves all comments that the user has flagged
157
+     * @param boolean $model 	Whether an instance of UserMetadata should be returned or not
158
+     * @return mixed
159
+     */
160
+    public function getFlaggedComments($model=false)
161
+    {
162
+        $flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array())));
163 163
 		
164
-		if ($model === true)
165
-			return $flags;
166
-
167
-		return CJSON::decode($flags->value);
168
-	}
169
-
170
-	/**
171
-	 * Flags a comment with a given ID
172
-	 * @return boolean
173
-	 */
174
-	public function flagComment($id)
175
-	{
176
-		$flaggedComments = $this->getFlaggedComments(true);
177
-		$flags = CJSON::decode($flaggedComments->value);
178
-
179
-		// If the comment has already been flagged, just return true
180
-		if (in_array($id, $flags))
181
-			return true;
182
-
183
-		$flags[] = $id;
184
-		$flaggedComments->value = CJSON::encode($flags);
185
-
186
-		return $flaggedComments->save();
187
-	}
188
-
189
-	/**
190
-	 * Retrieves a list of models based on the current search/filter conditions.
191
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
192
-	 */
193
-	public function search()
194
-	{
195
-		$criteria=new CDbCriteria;
196
-
197
-		$criteria->compare('id',$this->id);
198
-		$criteria->compare('email',$this->email,true);
199
-		$criteria->compare('password',$this->password,true);
200
-		$criteria->compare('username',$this->username,true);
201
-		$criteria->compare('user_role',$this->user_role);
202
-		$criteria->compare('status',$this->status);
203
-		$criteria->compare('created',$this->created,true);
204
-		$criteria->compare('updated',$this->updated,true);
205
-		$criteria->order = "user_role DESC, created DESC";
206
-
207
-		return new CActiveDataProvider($this, array(
208
-			'criteria' => $criteria,
209
-			'pagination' => array(
210
-				'pageSize' => $this->pageSize
211
-			)
212
-		));
213
-	}
214
-
215
-	/**
216
-	 * Sets some default values for the user record.
217
-	 * @see CActiveRecord::beforeValidate()
218
-	 **/
219
-	public function beforeValidate()
220
-	{
221
-		// If the password is nulled, or unchanged
222
-		if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false))
223
-		{
224
-			if (!$this->isNewRecord)
225
-				$this->password = $this->_oldAttributes['password'];
226
-		}
227
-		else
228
-		{
229
-			$this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost()));
230
-
231
-			if (!$this->isNewRecord)
232
-			{
233
-				$emailSettings = new EmailSettings;
234
-        		$emailSettings->send(
235
-					$this,
236
-					Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'),
237
-					'base.themes.' . Cii::getConfig('theme', 'default') .'.views.email.passwordchange',
238
-					array('user' => $this)
239
-				);
240
-			}
241
-		}
242
-
243
-		return parent::beforeValidate();
244
-	}
245
-
246
-	/**
247
-	 * Lets us know if the user likes a given content post or not
248
-	 * @param  int $id The id of the content we want to know about
249
-	 * @return bool    Whether or not the user likes the post
250
-	 */
251
-	public function likesPost($id = NULL)
252
-	{
253
-		if ($id === NULL)
254
-			return false;
255
-
256
-		$likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes'));
257
-
258
-		if ($likes === NULL)
259
-			return false;
260
-
261
-		$likesArray = json_decode($likes->value, true);
262
-		if (in_array($id, array_values($likesArray)))
263
-			return true;
264
-
265
-		return false;
266
-	}
267
-
268
-	/**
269
-	 * Helper method to get the usermetadata object rather than calling getPrototype everywhere
270
-	 * @param string $key
271
-	 * @param mixed $value
272
-	 * @return UserMetadata prototype object
273
-	 */
274
-	public function getMetadataObject($key, $value=NULL)
275
-	{
276
-		return UserMetadata::model()->getPrototype('UserMetadata', array(
277
-				'user_id' => $this->id,
278
-				'key' => $key
279
-			),array(
280
-				'user_id' => $this->id,
281
-				'key' => $key,
282
-				'value' => $value,
283
-		));
284
-	}
285
-
286
-	/**
287
-	 * Helper method to set the usermetadata object rather than calling getPrototype everywhere
288
-	 * @param string $key
289
-	 * @param mixed $value
290
-	 * @return UserMetadata prototype object
291
-	 */
292
-	public function setMetadataObject($key, $value)
293
-	{
294
-		$metadata = $this->getMetadataObject();
295
-
296
-		$metadata->value = $value;
297
-
298
-		return $metadata->save();
299
-	}
300
-
301
-	/**
164
+        if ($model === true)
165
+            return $flags;
166
+
167
+        return CJSON::decode($flags->value);
168
+    }
169
+
170
+    /**
171
+     * Flags a comment with a given ID
172
+     * @return boolean
173
+     */
174
+    public function flagComment($id)
175
+    {
176
+        $flaggedComments = $this->getFlaggedComments(true);
177
+        $flags = CJSON::decode($flaggedComments->value);
178
+
179
+        // If the comment has already been flagged, just return true
180
+        if (in_array($id, $flags))
181
+            return true;
182
+
183
+        $flags[] = $id;
184
+        $flaggedComments->value = CJSON::encode($flags);
185
+
186
+        return $flaggedComments->save();
187
+    }
188
+
189
+    /**
190
+     * Retrieves a list of models based on the current search/filter conditions.
191
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
192
+     */
193
+    public function search()
194
+    {
195
+        $criteria=new CDbCriteria;
196
+
197
+        $criteria->compare('id',$this->id);
198
+        $criteria->compare('email',$this->email,true);
199
+        $criteria->compare('password',$this->password,true);
200
+        $criteria->compare('username',$this->username,true);
201
+        $criteria->compare('user_role',$this->user_role);
202
+        $criteria->compare('status',$this->status);
203
+        $criteria->compare('created',$this->created,true);
204
+        $criteria->compare('updated',$this->updated,true);
205
+        $criteria->order = "user_role DESC, created DESC";
206
+
207
+        return new CActiveDataProvider($this, array(
208
+            'criteria' => $criteria,
209
+            'pagination' => array(
210
+                'pageSize' => $this->pageSize
211
+            )
212
+        ));
213
+    }
214
+
215
+    /**
216
+     * Sets some default values for the user record.
217
+     * @see CActiveRecord::beforeValidate()
218
+     **/
219
+    public function beforeValidate()
220
+    {
221
+        // If the password is nulled, or unchanged
222
+        if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false))
223
+        {
224
+            if (!$this->isNewRecord)
225
+                $this->password = $this->_oldAttributes['password'];
226
+        }
227
+        else
228
+        {
229
+            $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost()));
230
+
231
+            if (!$this->isNewRecord)
232
+            {
233
+                $emailSettings = new EmailSettings;
234
+                $emailSettings->send(
235
+                    $this,
236
+                    Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'),
237
+                    'base.themes.' . Cii::getConfig('theme', 'default') .'.views.email.passwordchange',
238
+                    array('user' => $this)
239
+                );
240
+            }
241
+        }
242
+
243
+        return parent::beforeValidate();
244
+    }
245
+
246
+    /**
247
+     * Lets us know if the user likes a given content post or not
248
+     * @param  int $id The id of the content we want to know about
249
+     * @return bool    Whether or not the user likes the post
250
+     */
251
+    public function likesPost($id = NULL)
252
+    {
253
+        if ($id === NULL)
254
+            return false;
255
+
256
+        $likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes'));
257
+
258
+        if ($likes === NULL)
259
+            return false;
260
+
261
+        $likesArray = json_decode($likes->value, true);
262
+        if (in_array($id, array_values($likesArray)))
263
+            return true;
264
+
265
+        return false;
266
+    }
267
+
268
+    /**
269
+     * Helper method to get the usermetadata object rather than calling getPrototype everywhere
270
+     * @param string $key
271
+     * @param mixed $value
272
+     * @return UserMetadata prototype object
273
+     */
274
+    public function getMetadataObject($key, $value=NULL)
275
+    {
276
+        return UserMetadata::model()->getPrototype('UserMetadata', array(
277
+                'user_id' => $this->id,
278
+                'key' => $key
279
+            ),array(
280
+                'user_id' => $this->id,
281
+                'key' => $key,
282
+                'value' => $value,
283
+        ));
284
+    }
285
+
286
+    /**
287
+     * Helper method to set the usermetadata object rather than calling getPrototype everywhere
288
+     * @param string $key
289
+     * @param mixed $value
290
+     * @return UserMetadata prototype object
291
+     */
292
+    public function setMetadataObject($key, $value)
293
+    {
294
+        $metadata = $this->getMetadataObject();
295
+
296
+        $metadata->value = $value;
297
+
298
+        return $metadata->save();
299
+    }
300
+
301
+    /**
302 302
      * Determines if two factor authentication code is required
303 303
      * @return boolean
304 304
      */
305 305
     public function needsTwoFactorAuth()
306 306
     {
307
-    	$metadata = $this->getMetadataObject('OTPSeed', false);
307
+        $metadata = $this->getMetadataObject('OTPSeed', false);
308 308
 
309
-    	if ($metadata->value !== false)
310
-    		return true;
309
+        if ($metadata->value !== false)
310
+            return true;
311 311
 
312
-    	return false;
312
+        return false;
313 313
     }
314 314
 
315
-	/**
316
-	 * Returns the gravatar image url for a particular user
317
-	 * The beauty of this is that you can call User::model()->findByPk()->gravatarImage() and not have to do anything else
318
-	 * Implemention details borrowed from Hypatia Cii User Extensions with permission
319
-	 * @param  integer $size		The size of the image we want to display
320
-	 * @param  string $default	The default image to be displayed if none is found
321
-	 * @return string gravatar api image
322
-	 */
323
-	public function gravatarImage($size=20, $default=NULL)
324
-	{
325
-		return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))).'?s='.$size;
326
-	}
315
+    /**
316
+     * Returns the gravatar image url for a particular user
317
+     * The beauty of this is that you can call User::model()->findByPk()->gravatarImage() and not have to do anything else
318
+     * Implemention details borrowed from Hypatia Cii User Extensions with permission
319
+     * @param  integer $size		The size of the image we want to display
320
+     * @param  string $default	The default image to be displayed if none is found
321
+     * @return string gravatar api image
322
+     */
323
+    public function gravatarImage($size=20, $default=NULL)
324
+    {
325
+        return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))).'?s='.$size;
326
+    }
327 327
 }
Please login to merge, or discard this patch.
Braces   +25 added lines, -18 removed lines patch added patch discarded remove patch
@@ -135,8 +135,9 @@  discard block
 block discarded – undo
135 135
 	{
136 136
 		$reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150));
137 137
 
138
-		if ($model === true)
139
-			return $reputation;
138
+		if ($model === true) {
139
+					return $reputation;
140
+		}
140 141
 
141 142
 		return $reputation->value;
142 143
 	}
@@ -161,8 +162,9 @@  discard block
 block discarded – undo
161 162
 	{
162 163
 		$flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array())));
163 164
 		
164
-		if ($model === true)
165
-			return $flags;
165
+		if ($model === true) {
166
+					return $flags;
167
+		}
166 168
 
167 169
 		return CJSON::decode($flags->value);
168 170
 	}
@@ -177,8 +179,9 @@  discard block
 block discarded – undo
177 179
 		$flags = CJSON::decode($flaggedComments->value);
178 180
 
179 181
 		// If the comment has already been flagged, just return true
180
-		if (in_array($id, $flags))
181
-			return true;
182
+		if (in_array($id, $flags)) {
183
+					return true;
184
+		}
182 185
 
183 186
 		$flags[] = $id;
184 187
 		$flaggedComments->value = CJSON::encode($flags);
@@ -221,10 +224,10 @@  discard block
 block discarded – undo
221 224
 		// If the password is nulled, or unchanged
222 225
 		if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false))
223 226
 		{
224
-			if (!$this->isNewRecord)
225
-				$this->password = $this->_oldAttributes['password'];
226
-		}
227
-		else
227
+			if (!$this->isNewRecord) {
228
+							$this->password = $this->_oldAttributes['password'];
229
+			}
230
+		} else
228 231
 		{
229 232
 			$this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost()));
230 233
 
@@ -250,17 +253,20 @@  discard block
 block discarded – undo
250 253
 	 */
251 254
 	public function likesPost($id = NULL)
252 255
 	{
253
-		if ($id === NULL)
254
-			return false;
256
+		if ($id === NULL) {
257
+					return false;
258
+		}
255 259
 
256 260
 		$likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes'));
257 261
 
258
-		if ($likes === NULL)
259
-			return false;
262
+		if ($likes === NULL) {
263
+					return false;
264
+		}
260 265
 
261 266
 		$likesArray = json_decode($likes->value, true);
262
-		if (in_array($id, array_values($likesArray)))
263
-			return true;
267
+		if (in_array($id, array_values($likesArray))) {
268
+					return true;
269
+		}
264 270
 
265 271
 		return false;
266 272
 	}
@@ -306,8 +312,9 @@  discard block
 block discarded – undo
306 312
     {
307 313
     	$metadata = $this->getMetadataObject('OTPSeed', false);
308 314
 
309
-    	if ($metadata->value !== false)
310
-    		return true;
315
+    	if ($metadata->value !== false) {
316
+    	    		return true;
317
+    	}
311 318
 
312 319
     	return false;
313 320
     }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -37,15 +37,15 @@  discard block
 block discarded – undo
37 37
 	 * @param string $className active record class name.
38 38
 	 * @return Users the static model class
39 39
 	 */
40
-	public static function model($className=__CLASS__)
40
+	public static function model ($className = __CLASS__)
41 41
 	{
42
-		return parent::model($className);
42
+		return parent::model ($className);
43 43
 	}
44 44
 
45 45
 	/**
46 46
 	 * @return string the associated database table name
47 47
 	 */
48
-	public function tableName()
48
+	public function tableName ()
49 49
 	{
50 50
 		return 'users';
51 51
 	}
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * @return array validation rules for model attributes.
55 55
 	 */
56
-	public function rules()
56
+	public function rules ()
57 57
 	{
58 58
 		// NOTE: you should only define rules for those attributes that
59 59
 		// will receive user inputs.
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	/**
72 72
 	 * @return array relational rules.
73 73
 	 */
74
-	public function relations()
74
+	public function relations ()
75 75
 	{
76 76
 		// NOTE: you may need to adjust the relation name and the related
77 77
 		// class name for the relations automatically generated below.
@@ -86,24 +86,24 @@  discard block
 block discarded – undo
86 86
 	/**
87 87
 	 * @return array customized attribute labels (name=>label)
88 88
 	 */
89
-	public function attributeLabels()
89
+	public function attributeLabels ()
90 90
 	{
91 91
 		return array(
92
-			'id' 		  => Yii::t('ciims.models.Users', 'ID'),
93
-			'email' 	  => Yii::t('ciims.models.Users', 'Email'),
94
-			'password' 	  => Yii::t('ciims.models.Users', 'Password'),
95
-			'username'    => Yii::t('ciims.models.Users', 'User Name'),
96
-			'user_role'   => Yii::t('ciims.models.Users', 'User Role'),
97
-			'status'	  => Yii::t('ciims.models.Users', 'Active'),
98
-			'created' 	  => Yii::t('ciims.models.Users', 'Created'),
99
-			'updated' 	  => Yii::t('ciims.models.Users', 'Updated'),
92
+			'id' 		  => Yii::t ('ciims.models.Users', 'ID'),
93
+			'email' 	  => Yii::t ('ciims.models.Users', 'Email'),
94
+			'password' 	  => Yii::t ('ciims.models.Users', 'Password'),
95
+			'username'    => Yii::t ('ciims.models.Users', 'User Name'),
96
+			'user_role'   => Yii::t ('ciims.models.Users', 'User Role'),
97
+			'status'	  => Yii::t ('ciims.models.Users', 'Active'),
98
+			'created' 	  => Yii::t ('ciims.models.Users', 'Created'),
99
+			'updated' 	  => Yii::t ('ciims.models.Users', 'Updated'),
100 100
 		);
101 101
 	}
102 102
 
103 103
 	/**
104 104
 	 * Gets the first and last name instead of the username
105 105
 	 */
106
-	public function getName()
106
+	public function getName ()
107 107
 	{
108 108
 		return $this->username;
109 109
 	}
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	/**
112 112
 	 * Retrieves the username
113 113
 	 */
114
-	public function getUsername()
114
+	public function getUsername ()
115 115
 	{
116 116
 		return $this->username;
117 117
 	}
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
 	 * Retrieves the username
121 121
 	 * @todo This is technical debt. At some point this should be completely depricated
122 122
 	 */
123
-	public function getDisplayName()
123
+	public function getDisplayName ()
124 124
 	{
125
-		Yii::log('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users');
126
-		return $this->getUsername();
125
+		Yii::log ('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users');
126
+		return $this->getUsername ();
127 127
 	}
128 128
 
129 129
 	/**
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @param boolean $model 	Whether an instance of UserMetadata should be returned or not
132 132
 	 * @return mixed
133 133
 	 */
134
-	public function getReputation($model=false)
134
+	public function getReputation ($model = false)
135 135
 	{
136
-		$reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150));
136
+		$reputation = UserMetadata::model ()->getPrototype ('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150));
137 137
 
138 138
 		if ($model === true)
139 139
 			return $reputation;
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 	 * Updates a user's reputation
146 146
 	 * @return boolean
147 147
 	 */
148
-	public function setReputation($rep = 10)
148
+	public function setReputation ($rep = 10)
149 149
 	{
150
-		$reputation = $this->getReputation(true);
150
+		$reputation = $this->getReputation (true);
151 151
 		$reputation->value += $rep;
152
-		return $reputation->save();
152
+		return $reputation->save ();
153 153
 	}
154 154
 
155 155
 	/**
@@ -157,54 +157,54 @@  discard block
 block discarded – undo
157 157
 	 * @param boolean $model 	Whether an instance of UserMetadata should be returned or not
158 158
 	 * @return mixed
159 159
 	 */
160
-	public function getFlaggedComments($model=false)
160
+	public function getFlaggedComments ($model = false)
161 161
 	{
162
-		$flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array())));
162
+		$flags = UserMetadata::model ()->getPrototype ('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode (array())));
163 163
 		
164 164
 		if ($model === true)
165 165
 			return $flags;
166 166
 
167
-		return CJSON::decode($flags->value);
167
+		return CJSON::decode ($flags->value);
168 168
 	}
169 169
 
170 170
 	/**
171 171
 	 * Flags a comment with a given ID
172 172
 	 * @return boolean
173 173
 	 */
174
-	public function flagComment($id)
174
+	public function flagComment ($id)
175 175
 	{
176
-		$flaggedComments = $this->getFlaggedComments(true);
177
-		$flags = CJSON::decode($flaggedComments->value);
176
+		$flaggedComments = $this->getFlaggedComments (true);
177
+		$flags = CJSON::decode ($flaggedComments->value);
178 178
 
179 179
 		// If the comment has already been flagged, just return true
180
-		if (in_array($id, $flags))
180
+		if (in_array ($id, $flags))
181 181
 			return true;
182 182
 
183 183
 		$flags[] = $id;
184
-		$flaggedComments->value = CJSON::encode($flags);
184
+		$flaggedComments->value = CJSON::encode ($flags);
185 185
 
186
-		return $flaggedComments->save();
186
+		return $flaggedComments->save ();
187 187
 	}
188 188
 
189 189
 	/**
190 190
 	 * Retrieves a list of models based on the current search/filter conditions.
191 191
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
192 192
 	 */
193
-	public function search()
193
+	public function search ()
194 194
 	{
195
-		$criteria=new CDbCriteria;
196
-
197
-		$criteria->compare('id',$this->id);
198
-		$criteria->compare('email',$this->email,true);
199
-		$criteria->compare('password',$this->password,true);
200
-		$criteria->compare('username',$this->username,true);
201
-		$criteria->compare('user_role',$this->user_role);
202
-		$criteria->compare('status',$this->status);
203
-		$criteria->compare('created',$this->created,true);
204
-		$criteria->compare('updated',$this->updated,true);
195
+		$criteria = new CDbCriteria;
196
+
197
+		$criteria->compare ('id', $this->id);
198
+		$criteria->compare ('email', $this->email, true);
199
+		$criteria->compare ('password', $this->password, true);
200
+		$criteria->compare ('username', $this->username, true);
201
+		$criteria->compare ('user_role', $this->user_role);
202
+		$criteria->compare ('status', $this->status);
203
+		$criteria->compare ('created', $this->created, true);
204
+		$criteria->compare ('updated', $this->updated, true);
205 205
 		$criteria->order = "user_role DESC, created DESC";
206 206
 
207
-		return new CActiveDataProvider($this, array(
207
+		return new CActiveDataProvider ($this, array(
208 208
 			'criteria' => $criteria,
209 209
 			'pagination' => array(
210 210
 				'pageSize' => $this->pageSize
@@ -216,31 +216,31 @@  discard block
 block discarded – undo
216 216
 	 * Sets some default values for the user record.
217 217
 	 * @see CActiveRecord::beforeValidate()
218 218
 	 **/
219
-	public function beforeValidate()
219
+	public function beforeValidate ()
220 220
 	{
221 221
 		// If the password is nulled, or unchanged
222
-		if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false))
222
+		if ($this->password == NULL || $this->password == Cii::get ($this->_oldAttributes, 'password', false))
223 223
 		{
224 224
 			if (!$this->isNewRecord)
225 225
 				$this->password = $this->_oldAttributes['password'];
226 226
 		}
227 227
 		else
228 228
 		{
229
-			$this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost()));
229
+			$this->password = password_hash ($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost ()));
230 230
 
231 231
 			if (!$this->isNewRecord)
232 232
 			{
233 233
 				$emailSettings = new EmailSettings;
234
-        		$emailSettings->send(
234
+        		$emailSettings->send (
235 235
 					$this,
236
-					Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'),
237
-					'base.themes.' . Cii::getConfig('theme', 'default') .'.views.email.passwordchange',
236
+					Yii::t ('ciims.models.Users', 'CiiMS Password Change Notification'),
237
+					'base.themes.'.Cii::getConfig ('theme', 'default').'.views.email.passwordchange',
238 238
 					array('user' => $this)
239 239
 				);
240 240
 			}
241 241
 		}
242 242
 
243
-		return parent::beforeValidate();
243
+		return parent::beforeValidate ();
244 244
 	}
245 245
 
246 246
 	/**
@@ -248,18 +248,18 @@  discard block
 block discarded – undo
248 248
 	 * @param  int $id The id of the content we want to know about
249 249
 	 * @return bool    Whether or not the user likes the post
250 250
 	 */
251
-	public function likesPost($id = NULL)
251
+	public function likesPost ($id = NULL)
252 252
 	{
253 253
 		if ($id === NULL)
254 254
 			return false;
255 255
 
256
-		$likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes'));
256
+		$likes = UserMetadata::model ()->findByAttributes (array('user_id' => $this->id, 'key' => 'likes'));
257 257
 
258 258
 		if ($likes === NULL)
259 259
 			return false;
260 260
 
261
-		$likesArray = json_decode($likes->value, true);
262
-		if (in_array($id, array_values($likesArray)))
261
+		$likesArray = json_decode ($likes->value, true);
262
+		if (in_array ($id, array_values ($likesArray)))
263 263
 			return true;
264 264
 
265 265
 		return false;
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 	 * @param mixed $value
272 272
 	 * @return UserMetadata prototype object
273 273
 	 */
274
-	public function getMetadataObject($key, $value=NULL)
274
+	public function getMetadataObject ($key, $value = NULL)
275 275
 	{
276
-		return UserMetadata::model()->getPrototype('UserMetadata', array(
276
+		return UserMetadata::model ()->getPrototype ('UserMetadata', array(
277 277
 				'user_id' => $this->id,
278 278
 				'key' => $key
279
-			),array(
279
+			), array(
280 280
 				'user_id' => $this->id,
281 281
 				'key' => $key,
282 282
 				'value' => $value,
@@ -289,22 +289,22 @@  discard block
 block discarded – undo
289 289
 	 * @param mixed $value
290 290
 	 * @return UserMetadata prototype object
291 291
 	 */
292
-	public function setMetadataObject($key, $value)
292
+	public function setMetadataObject ($key, $value)
293 293
 	{
294
-		$metadata = $this->getMetadataObject();
294
+		$metadata = $this->getMetadataObject ();
295 295
 
296 296
 		$metadata->value = $value;
297 297
 
298
-		return $metadata->save();
298
+		return $metadata->save ();
299 299
 	}
300 300
 
301 301
 	/**
302 302
      * Determines if two factor authentication code is required
303 303
      * @return boolean
304 304
      */
305
-    public function needsTwoFactorAuth()
305
+    public function needsTwoFactorAuth ()
306 306
     {
307
-    	$metadata = $this->getMetadataObject('OTPSeed', false);
307
+    	$metadata = $this->getMetadataObject ('OTPSeed', false);
308 308
 
309 309
     	if ($metadata->value !== false)
310 310
     		return true;
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
 	 * @param  string $default	The default image to be displayed if none is found
321 321
 	 * @return string gravatar api image
322 322
 	 */
323
-	public function gravatarImage($size=20, $default=NULL)
323
+	public function gravatarImage ($size = 20, $default = NULL)
324 324
 	{
325
-		return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))).'?s='.$size;
325
+		return "https://www.gravatar.com/avatar/".md5 (strtolower (trim ($this->email))).'?s='.$size;
326 326
 	}
327 327
 }
Please login to merge, or discard this patch.
protected/models/forms/ActivationForm.php 3 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -2,117 +2,117 @@
 block discarded – undo
2 2
 
3 3
 class ActivationForm extends CFormModel
4 4
 {
5
-	/**
6
-	 * The password provided by the user
7
-	 * @var string $password
8
-	 */
9
-	public $password;
10
-
11
-	/**
12
-	 * The activation key originally sent to the user's email
13
-	 * @var string $activationKey
14
-	 */
15
-	public $activationKey;
16
-
17
-	/**
18
-	 * The user model
19
-	 * @var Users $_user
20
-	 */
21
-	private $_user;
22
-
23
-	/**
24
-	 * The activation key metadata model. This is loaded to ensure it gets cleaned up properly
25
-	 * @var UserMetadata $_meta
26
-	 */
27
-	private $_meta;
28
-
29
-	/**
30
-	 * Validation rules
31
-	 * @return array
32
-	 */
33
-	public function rules()
34
-	{
35
-		return array(
36
-			array('password, activationKey', 'required'),
37
-			array('password', 'length', 'min'=>8),
38
-			array('activationKey', 'validateKey'),
39
-			array('password', 'validateUserPassword'),
40
-		);
41
-	}
42
-
43
-	/**
44
-	 * Attribute labels
45
-	 * @return array
46
-	 */
47
-	public function attributeLabels()
48
-	{
49
-		return array(
50
-			'password'      => Yii::t('ciims.models.ActivationForm', 'Your Password'),
51
-			'activationKey' => Yii::t('ciims.models.ActivationForm', 'Your Activation Key')
52
-		);
53
-	}
54
-
55
-	/**
56
-	 * Validates that the activation key belongs to a user and is valid
57
-	 * @param array $attributes
58
-	 * @param array $params
59
-	 * return array
60
-	 */
61
-	public function validateKey($attributes=array(), $params=array())
62
-	{
63
-		$this->_meta = UserMetadata::model()->findByAttributes(array('key'=>'activationKey', 'value'=>$this->activationKey));
64
-
65
-		if ($this->_meta == NULL)
66
-		{
67
-			$this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
68
-			return false;
69
-		}
70
-
71
-		return true;
72
-	}
73
-
74
-	/**
75
-	 * Ensures that the password entered matches the one provided during registration
76
-	 * @param array $attributes
77
-	 * @param array $params
78
-	 * return array
79
-	 */
80
-	public function validateUserPassword($attributes, $params)
81
-	{
82
-		if ($this->_user == NULL)
83
-		{
84
-			$this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
85
-			return false;
86
-		}
87
-
88
-		$result = password_verify($this->password, $this->_user->password);
89
-
90
-		if ($result == false)
91
-		{
92
-			$this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
93
-			return false;
94
-		}
95
-
96
-		return true;
97
-	}
98
-
99
-	/**
100
-	 * Makes the user an active user in the database, and deletes their activation token
101
-	 * @return boolean
102
-	 */
103
-	public function save()
104
-	{
105
-		$userId = $this->_meta->user_id;
106
-		$this->_user = Users::model()->findByPk($userId);
107
-
108
-		if (!$this->validate())
109
-			return false;
110
-
111
-		$this->_user->status = Users::ACTIVE;
5
+    /**
6
+     * The password provided by the user
7
+     * @var string $password
8
+     */
9
+    public $password;
10
+
11
+    /**
12
+     * The activation key originally sent to the user's email
13
+     * @var string $activationKey
14
+     */
15
+    public $activationKey;
16
+
17
+    /**
18
+     * The user model
19
+     * @var Users $_user
20
+     */
21
+    private $_user;
22
+
23
+    /**
24
+     * The activation key metadata model. This is loaded to ensure it gets cleaned up properly
25
+     * @var UserMetadata $_meta
26
+     */
27
+    private $_meta;
28
+
29
+    /**
30
+     * Validation rules
31
+     * @return array
32
+     */
33
+    public function rules()
34
+    {
35
+        return array(
36
+            array('password, activationKey', 'required'),
37
+            array('password', 'length', 'min'=>8),
38
+            array('activationKey', 'validateKey'),
39
+            array('password', 'validateUserPassword'),
40
+        );
41
+    }
42
+
43
+    /**
44
+     * Attribute labels
45
+     * @return array
46
+     */
47
+    public function attributeLabels()
48
+    {
49
+        return array(
50
+            'password'      => Yii::t('ciims.models.ActivationForm', 'Your Password'),
51
+            'activationKey' => Yii::t('ciims.models.ActivationForm', 'Your Activation Key')
52
+        );
53
+    }
54
+
55
+    /**
56
+     * Validates that the activation key belongs to a user and is valid
57
+     * @param array $attributes
58
+     * @param array $params
59
+     * return array
60
+     */
61
+    public function validateKey($attributes=array(), $params=array())
62
+    {
63
+        $this->_meta = UserMetadata::model()->findByAttributes(array('key'=>'activationKey', 'value'=>$this->activationKey));
64
+
65
+        if ($this->_meta == NULL)
66
+        {
67
+            $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
68
+            return false;
69
+        }
70
+
71
+        return true;
72
+    }
73
+
74
+    /**
75
+     * Ensures that the password entered matches the one provided during registration
76
+     * @param array $attributes
77
+     * @param array $params
78
+     * return array
79
+     */
80
+    public function validateUserPassword($attributes, $params)
81
+    {
82
+        if ($this->_user == NULL)
83
+        {
84
+            $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
85
+            return false;
86
+        }
87
+
88
+        $result = password_verify($this->password, $this->_user->password);
89
+
90
+        if ($result == false)
91
+        {
92
+            $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
93
+            return false;
94
+        }
95
+
96
+        return true;
97
+    }
98
+
99
+    /**
100
+     * Makes the user an active user in the database, and deletes their activation token
101
+     * @return boolean
102
+     */
103
+    public function save()
104
+    {
105
+        $userId = $this->_meta->user_id;
106
+        $this->_user = Users::model()->findByPk($userId);
107
+
108
+        if (!$this->validate())
109
+            return false;
110
+
111
+        $this->_user->status = Users::ACTIVE;
112 112
 		
113
-		if ($this->_user->save())
114
-			return $this->_meta->delete();
113
+        if ($this->_user->save())
114
+            return $this->_meta->delete();
115 115
 
116
-		return false;
117
-	}
116
+        return false;
117
+    }
118 118
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * Validation rules
31 31
 	 * @return array
32 32
 	 */
33
-	public function rules()
33
+	public function rules ()
34 34
 	{
35 35
 		return array(
36 36
 			array('password, activationKey', 'required'),
@@ -44,11 +44,11 @@  discard block
 block discarded – undo
44 44
 	 * Attribute labels
45 45
 	 * @return array
46 46
 	 */
47
-	public function attributeLabels()
47
+	public function attributeLabels ()
48 48
 	{
49 49
 		return array(
50
-			'password'      => Yii::t('ciims.models.ActivationForm', 'Your Password'),
51
-			'activationKey' => Yii::t('ciims.models.ActivationForm', 'Your Activation Key')
50
+			'password'      => Yii::t ('ciims.models.ActivationForm', 'Your Password'),
51
+			'activationKey' => Yii::t ('ciims.models.ActivationForm', 'Your Activation Key')
52 52
 		);
53 53
 	}
54 54
 
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 	 * @param array $params
59 59
 	 * return array
60 60
 	 */
61
-	public function validateKey($attributes=array(), $params=array())
61
+	public function validateKey ($attributes = array(), $params = array())
62 62
 	{
63
-		$this->_meta = UserMetadata::model()->findByAttributes(array('key'=>'activationKey', 'value'=>$this->activationKey));
63
+		$this->_meta = UserMetadata::model ()->findByAttributes (array('key'=>'activationKey', 'value'=>$this->activationKey));
64 64
 
65 65
 		if ($this->_meta == NULL)
66 66
 		{
67
-			$this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
67
+			$this->addError ('activationKey', Yii::t ('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
68 68
 			return false;
69 69
 		}
70 70
 
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
 	 * @param array $params
78 78
 	 * return array
79 79
 	 */
80
-	public function validateUserPassword($attributes, $params)
80
+	public function validateUserPassword ($attributes, $params)
81 81
 	{
82 82
 		if ($this->_user == NULL)
83 83
 		{
84
-			$this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
84
+			$this->addError ('activationKey', Yii::t ('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
85 85
 			return false;
86 86
 		}
87 87
 
88
-		$result = password_verify($this->password, $this->_user->password);
88
+		$result = password_verify ($this->password, $this->_user->password);
89 89
 
90 90
 		if ($result == false)
91 91
 		{
92
-			$this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
92
+			$this->addError ('password', Yii::t ('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
93 93
 			return false;
94 94
 		}
95 95
 
@@ -100,18 +100,18 @@  discard block
 block discarded – undo
100 100
 	 * Makes the user an active user in the database, and deletes their activation token
101 101
 	 * @return boolean
102 102
 	 */
103
-	public function save()
103
+	public function save ()
104 104
 	{
105 105
 		$userId = $this->_meta->user_id;
106
-		$this->_user = Users::model()->findByPk($userId);
106
+		$this->_user = Users::model ()->findByPk ($userId);
107 107
 
108
-		if (!$this->validate())
108
+		if (!$this->validate ())
109 109
 			return false;
110 110
 
111 111
 		$this->_user->status = Users::ACTIVE;
112 112
 		
113
-		if ($this->_user->save())
114
-			return $this->_meta->delete();
113
+		if ($this->_user->save ())
114
+			return $this->_meta->delete ();
115 115
 
116 116
 		return false;
117 117
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -105,13 +105,15 @@
 block discarded – undo
105 105
 		$userId = $this->_meta->user_id;
106 106
 		$this->_user = Users::model()->findByPk($userId);
107 107
 
108
-		if (!$this->validate())
109
-			return false;
108
+		if (!$this->validate()) {
109
+					return false;
110
+		}
110 111
 
111 112
 		$this->_user->status = Users::ACTIVE;
112 113
 		
113
-		if ($this->_user->save())
114
-			return $this->_meta->delete();
114
+		if ($this->_user->save()) {
115
+					return $this->_meta->delete();
116
+		}
115 117
 
116 118
 		return false;
117 119
 	}
Please login to merge, or discard this patch.
protected/models/forms/EmailChangeForm.php 3 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -2,154 +2,154 @@
 block discarded – undo
2 2
 
3 3
 class EmailChangeForm extends CFormModel
4 4
 {
5
-	/**
6
-	 * The user's existing password
7
-	 * @var string $password
8
-	 */
9
-	public $password;
10
-
11
-	/**
12
-	 * The veification key
13
-	 * @var string $verificationKey
14
-	 */
15
-	public $verificationKey;
16
-
17
-	/**
18
-	 * The user model
19
-	 * @var Users $_user
20
-	 */
21
-	private $_user;
22
-
23
-	/**
24
-	 * The new email address change key
25
-	 * @var UserMetadata $_newEmailAddressChangeKey
26
-	 */
27
-	private $_newEmailAddressChangeKey;
28
-
29
-	/**
30
-	 * The new email address record on file
31
-	 * @var UserMetadata $_newEmailAddress
32
-	 */
33
-	private $_newEmailAddress;
34
-
35
-	/**
36
-	 * Validation rules
37
-	 * @return array
38
-	 */
39
-	public function rules()
40
-	{
41
-		return array(
42
-			array('password, verificationKey', 'required'),
43
-			array('password', 'length', 'min' => 8),
44
-			array('password', 'validateUserPassword'),
45
-			array('verificationKey', 'validateVerificationKey')
46
-		);
47
-	}
48
-
49
-	/**
50
-	 * Attribute labels
51
-	 * @return array
52
-	 */
53
-	public function attributeLabels()
54
-	{
55
-		return array(
56
-			'password'         => Yii::t('ciims.models.EmailChangeForm', 'Your Password'),
57
-			'verificationKey'  => Yii::t('ciims.models.EmailChangeForm', 'The Verification Key')
58
-		);
59
-	}
60
-
61
-	/**
62
- 	 * Sets the user model
63
-	 * @param Users $user
64
-	 */
65
-	public function setUser($user)
66
-	{
67
-		$this->_user = $user;
68
-	}
69
-
70
-	/**
71
-	 * Validates the tokens supplied and that the request hasn't expired
72
-	 * @param array $attributes
73
-	 * @param array $params
74
-	 * return array
75
-	 */
76
-	public function validateVerificationKey($attributes = array(), $params = array())
77
-	{
78
-		$this->_newEmailAddressChangeKey =  UserMetadata::model()->findByAttributes(array(
79
-												'user_id' => $this->_user->id,
80
-												'key' => 'newEmailAddressChangeKey',
81
-												'value' => $this->verificationKey
82
-										    ));
83
-
84
-		if ($this->_newEmailAddressChangeKey == NULL)
85
-		{
86
-			$this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
87
-			return false;
88
-		}
89
-
90
-		$this->_newEmailAddress = UserMetadata::model()->findByAttributes(array(
91
-									  'user_id' => $this->_user->id,
92
-									  'key' => 'newEmailAddress'
93
-								  ));
94
-
95
-		if ($this->_newEmailAddress == NULL)
96
-		{
97
-			$this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
98
-			return false;
99
-		}
100
-
101
-		return true;
102
-	}
103
-
104
-	/**
105
-	 * Ensures that the password entered matches the one provided during registration
106
-	 * @param array $attributes
107
-	 * @param array $params
108
-	 * return array
109
-	 */
110
-	public function validateUserPassword($attributes, $params)
111
-	{
112
-		$result = password_verify($this->password, $this->_user->password);
113
-
114
-		if ($result == false)
115
-		{
116
-			$this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
117
-			return false;
118
-		}
119
-
120
-		return true;
121
-	}
122
-
123
-	/**
124
-	 * Updates the user's email address and rehashes their password since the password is bound to the email
125
-	 * @return boolean
126
-	 */
127
-	public function save()
128
-	{
129
-		if (!$this->validate())
130
-			return false;
131
-
132
-		// This is super buggy for some reason
133
-		$this->_user->email = $this->_newEmailAddress->value;
134
-
135
-		// Save the model
136
-		if ($this->_user->save())
137
-		{
138
-			// Delete the metadata
139
-			$this->_newEmailAddressChangeKey->delete();
140
-			$this->_newEmailAddress->delete();
141
-			return true;
142
-		}
143
-
144
-		return false;
145
-	}
146
-
147
-	/**
148
-	 * Retrieves the user's email address from the model
149
-	 * @return string
150
-	 */
151
-	public function getEmail()
152
-	{
153
-		return $this->_user->email;
154
-	}
5
+    /**
6
+     * The user's existing password
7
+     * @var string $password
8
+     */
9
+    public $password;
10
+
11
+    /**
12
+     * The veification key
13
+     * @var string $verificationKey
14
+     */
15
+    public $verificationKey;
16
+
17
+    /**
18
+     * The user model
19
+     * @var Users $_user
20
+     */
21
+    private $_user;
22
+
23
+    /**
24
+     * The new email address change key
25
+     * @var UserMetadata $_newEmailAddressChangeKey
26
+     */
27
+    private $_newEmailAddressChangeKey;
28
+
29
+    /**
30
+     * The new email address record on file
31
+     * @var UserMetadata $_newEmailAddress
32
+     */
33
+    private $_newEmailAddress;
34
+
35
+    /**
36
+     * Validation rules
37
+     * @return array
38
+     */
39
+    public function rules()
40
+    {
41
+        return array(
42
+            array('password, verificationKey', 'required'),
43
+            array('password', 'length', 'min' => 8),
44
+            array('password', 'validateUserPassword'),
45
+            array('verificationKey', 'validateVerificationKey')
46
+        );
47
+    }
48
+
49
+    /**
50
+     * Attribute labels
51
+     * @return array
52
+     */
53
+    public function attributeLabels()
54
+    {
55
+        return array(
56
+            'password'         => Yii::t('ciims.models.EmailChangeForm', 'Your Password'),
57
+            'verificationKey'  => Yii::t('ciims.models.EmailChangeForm', 'The Verification Key')
58
+        );
59
+    }
60
+
61
+    /**
62
+     * Sets the user model
63
+     * @param Users $user
64
+     */
65
+    public function setUser($user)
66
+    {
67
+        $this->_user = $user;
68
+    }
69
+
70
+    /**
71
+     * Validates the tokens supplied and that the request hasn't expired
72
+     * @param array $attributes
73
+     * @param array $params
74
+     * return array
75
+     */
76
+    public function validateVerificationKey($attributes = array(), $params = array())
77
+    {
78
+        $this->_newEmailAddressChangeKey =  UserMetadata::model()->findByAttributes(array(
79
+                                                'user_id' => $this->_user->id,
80
+                                                'key' => 'newEmailAddressChangeKey',
81
+                                                'value' => $this->verificationKey
82
+                                            ));
83
+
84
+        if ($this->_newEmailAddressChangeKey == NULL)
85
+        {
86
+            $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
87
+            return false;
88
+        }
89
+
90
+        $this->_newEmailAddress = UserMetadata::model()->findByAttributes(array(
91
+                                        'user_id' => $this->_user->id,
92
+                                        'key' => 'newEmailAddress'
93
+                                    ));
94
+
95
+        if ($this->_newEmailAddress == NULL)
96
+        {
97
+            $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
98
+            return false;
99
+        }
100
+
101
+        return true;
102
+    }
103
+
104
+    /**
105
+     * Ensures that the password entered matches the one provided during registration
106
+     * @param array $attributes
107
+     * @param array $params
108
+     * return array
109
+     */
110
+    public function validateUserPassword($attributes, $params)
111
+    {
112
+        $result = password_verify($this->password, $this->_user->password);
113
+
114
+        if ($result == false)
115
+        {
116
+            $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
117
+            return false;
118
+        }
119
+
120
+        return true;
121
+    }
122
+
123
+    /**
124
+     * Updates the user's email address and rehashes their password since the password is bound to the email
125
+     * @return boolean
126
+     */
127
+    public function save()
128
+    {
129
+        if (!$this->validate())
130
+            return false;
131
+
132
+        // This is super buggy for some reason
133
+        $this->_user->email = $this->_newEmailAddress->value;
134
+
135
+        // Save the model
136
+        if ($this->_user->save())
137
+        {
138
+            // Delete the metadata
139
+            $this->_newEmailAddressChangeKey->delete();
140
+            $this->_newEmailAddress->delete();
141
+            return true;
142
+        }
143
+
144
+        return false;
145
+    }
146
+
147
+    /**
148
+     * Retrieves the user's email address from the model
149
+     * @return string
150
+     */
151
+    public function getEmail()
152
+    {
153
+        return $this->_user->email;
154
+    }
155 155
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * Validation rules
37 37
 	 * @return array
38 38
 	 */
39
-	public function rules()
39
+	public function rules ()
40 40
 	{
41 41
 		return array(
42 42
 			array('password, verificationKey', 'required'),
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 * Attribute labels
51 51
 	 * @return array
52 52
 	 */
53
-	public function attributeLabels()
53
+	public function attributeLabels ()
54 54
 	{
55 55
 		return array(
56
-			'password'         => Yii::t('ciims.models.EmailChangeForm', 'Your Password'),
57
-			'verificationKey'  => Yii::t('ciims.models.EmailChangeForm', 'The Verification Key')
56
+			'password'         => Yii::t ('ciims.models.EmailChangeForm', 'Your Password'),
57
+			'verificationKey'  => Yii::t ('ciims.models.EmailChangeForm', 'The Verification Key')
58 58
 		);
59 59
 	}
60 60
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
  	 * Sets the user model
63 63
 	 * @param Users $user
64 64
 	 */
65
-	public function setUser($user)
65
+	public function setUser ($user)
66 66
 	{
67 67
 		$this->_user = $user;
68 68
 	}
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 	 * @param array $params
74 74
 	 * return array
75 75
 	 */
76
-	public function validateVerificationKey($attributes = array(), $params = array())
76
+	public function validateVerificationKey ($attributes = array(), $params = array())
77 77
 	{
78
-		$this->_newEmailAddressChangeKey =  UserMetadata::model()->findByAttributes(array(
78
+		$this->_newEmailAddressChangeKey = UserMetadata::model ()->findByAttributes (array(
79 79
 												'user_id' => $this->_user->id,
80 80
 												'key' => 'newEmailAddressChangeKey',
81 81
 												'value' => $this->verificationKey
@@ -83,18 +83,18 @@  discard block
 block discarded – undo
83 83
 
84 84
 		if ($this->_newEmailAddressChangeKey == NULL)
85 85
 		{
86
-			$this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
86
+			$this->addError ('verificationKey', Yii::t ('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
87 87
 			return false;
88 88
 		}
89 89
 
90
-		$this->_newEmailAddress = UserMetadata::model()->findByAttributes(array(
90
+		$this->_newEmailAddress = UserMetadata::model ()->findByAttributes (array(
91 91
 									  'user_id' => $this->_user->id,
92 92
 									  'key' => 'newEmailAddress'
93 93
 								  ));
94 94
 
95 95
 		if ($this->_newEmailAddress == NULL)
96 96
 		{
97
-			$this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
97
+			$this->addError ('verificationKey', Yii::t ('ciims.models.EmailChangeForm', 'The activation key you provided is invalid'));
98 98
 			return false;
99 99
 		}
100 100
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
 	 * @param array $params
108 108
 	 * return array
109 109
 	 */
110
-	public function validateUserPassword($attributes, $params)
110
+	public function validateUserPassword ($attributes, $params)
111 111
 	{
112
-		$result = password_verify($this->password, $this->_user->password);
112
+		$result = password_verify ($this->password, $this->_user->password);
113 113
 
114 114
 		if ($result == false)
115 115
 		{
116
-			$this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
116
+			$this->addError ('password', Yii::t ('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.'));
117 117
 			return false;
118 118
 		}
119 119
 
@@ -124,20 +124,20 @@  discard block
 block discarded – undo
124 124
 	 * Updates the user's email address and rehashes their password since the password is bound to the email
125 125
 	 * @return boolean
126 126
 	 */
127
-	public function save()
127
+	public function save ()
128 128
 	{
129
-		if (!$this->validate())
129
+		if (!$this->validate ())
130 130
 			return false;
131 131
 
132 132
 		// This is super buggy for some reason
133 133
 		$this->_user->email = $this->_newEmailAddress->value;
134 134
 
135 135
 		// Save the model
136
-		if ($this->_user->save())
136
+		if ($this->_user->save ())
137 137
 		{
138 138
 			// Delete the metadata
139
-			$this->_newEmailAddressChangeKey->delete();
140
-			$this->_newEmailAddress->delete();
139
+			$this->_newEmailAddressChangeKey->delete ();
140
+			$this->_newEmailAddress->delete ();
141 141
 			return true;
142 142
 		}
143 143
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * Retrieves the user's email address from the model
149 149
 	 * @return string
150 150
 	 */
151
-	public function getEmail()
151
+	public function getEmail ()
152 152
 	{
153 153
 		return $this->_user->email;
154 154
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -126,8 +126,9 @@
 block discarded – undo
126 126
 	 */
127 127
 	public function save()
128 128
 	{
129
-		if (!$this->validate())
130
-			return false;
129
+		if (!$this->validate()) {
130
+					return false;
131
+		}
131 132
 
132 133
 		// This is super buggy for some reason
133 134
 		$this->_user->email = $this->_newEmailAddress->value;
Please login to merge, or discard this patch.