Completed
Push — master ( 8edafe...cb9f87 )
by Charles
08:15
created
protected/messages/en_us/models/general.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   'Category Post Count' => '',
21 21
   'Content Post Cost' => '',
22 22
   'Date Format' => '',
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -17,30 +17,30 @@
 block discarded – undo
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19 19
 return array (
20
-  'Category Post Count' => '',
21
-  'Content Post Cost' => '',
22
-  'Date Format' => '',
23
-  'Default Language' => '',
24
-  'Discourse' => '',
25
-  'Discourse URL' => '',
26
-  'Display Settings' => '',
27
-  'Disqus' => '',
28
-  'Disqus Shortcode' => '',
29
-  'Force SSL for Secure Areas' => '',
30
-  'Offline Mode' => '',
31
-  'Openstack API Key' => '',
32
-  'Openstack Container Name' => '',
33
-  'Openstack Identity URL' => '',
34
-  'Openstack Region' => '',
35
-  'Openstack Username' => '',
36
-  'Password Strength Settings' => '',
37
-  'Search Post Count' => '',
38
-  'Site Name' => '',
39
-  'Site Settings' => '',
40
-  'Time Format' => '',
41
-  'Upload Settings' => '',
42
-  'Use Discourse Comments' => '',
43
-  'Use Disqus Comments' => '',
44
-  'Use Openstack for Uploads?' => '',
45
-  'Use Rackspace CDN?' => '',
20
+    'Category Post Count' => '',
21
+    'Content Post Cost' => '',
22
+    'Date Format' => '',
23
+    'Default Language' => '',
24
+    'Discourse' => '',
25
+    'Discourse URL' => '',
26
+    'Display Settings' => '',
27
+    'Disqus' => '',
28
+    'Disqus Shortcode' => '',
29
+    'Force SSL for Secure Areas' => '',
30
+    'Offline Mode' => '',
31
+    'Openstack API Key' => '',
32
+    'Openstack Container Name' => '',
33
+    'Openstack Identity URL' => '',
34
+    'Openstack Region' => '',
35
+    'Openstack Username' => '',
36
+    'Password Strength Settings' => '',
37
+    'Search Post Count' => '',
38
+    'Site Name' => '',
39
+    'Site Settings' => '',
40
+    'Time Format' => '',
41
+    'Upload Settings' => '',
42
+    'Use Discourse Comments' => '',
43
+    'Use Disqus Comments' => '',
44
+    'Use Openstack for Uploads?' => '',
45
+    'Use Rackspace CDN?' => '',
46 46
 );
Please login to merge, or discard this patch.
protected/messages/en_us/models/social.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   'Access Token' => '',
21 21
   'Access Token Secret' => '',
22 22
   'AddThis' => '',
Please login to merge, or discard this patch.
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -17,21 +17,21 @@
 block discarded – undo
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19 19
 return array (
20
-  'Access Token' => '',
21
-  'Access Token Secret' => '',
22
-  'AddThis' => '',
23
-  'AddThis Publisher ID' => '',
24
-  'App ID' => '',
25
-  'App Secret' => '',
26
-  'Client ID' => '',
27
-  'Client Secret' => '',
28
-  'Consumer Key' => '',
29
-  'Consumer Secret' => '',
30
-  'Facebook' => '',
31
-  'Google+' => '',
32
-  'LinkedIn' => '',
33
-  'Public Server API Key' => '',
34
-  'Scope' => '',
35
-  'Social Auth' => '',
36
-  'Twitter' => '',
20
+    'Access Token' => '',
21
+    'Access Token Secret' => '',
22
+    'AddThis' => '',
23
+    'AddThis Publisher ID' => '',
24
+    'App ID' => '',
25
+    'App Secret' => '',
26
+    'Client ID' => '',
27
+    'Client Secret' => '',
28
+    'Consumer Key' => '',
29
+    'Consumer Secret' => '',
30
+    'Facebook' => '',
31
+    'Google+' => '',
32
+    'LinkedIn' => '',
33
+    'Public Server API Key' => '',
34
+    'Scope' => '',
35
+    'Social Auth' => '',
36
+    'Twitter' => '',
37 37
 );
Please login to merge, or discard this patch.
protected/messages/en_us/models/theme.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   'All Posts' => '',
21 21
   'Theme' => '',
22 22
 );
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,6 +17,6 @@
 block discarded – undo
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19 19
 return array (
20
-  'All Posts' => '',
21
-  'Theme' => '',
20
+    'All Posts' => '',
21
+    'Theme' => '',
22 22
 );
Please login to merge, or discard this patch.
protected/messages/en_us/module/Dashboard/main.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   'Change Theme Settings' => '',
21 21
   'There are no settings for this section.' => '',
22 22
   'Unable to save uploaded image.' => '',
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19 19
 return array (
20
-  'Change Theme Settings' => '',
21
-  'There are no settings for this section.' => '',
22
-  'Unable to save uploaded image.' => '',
20
+    'Change Theme Settings' => '',
21
+    'There are no settings for this section.' => '',
22
+    'Unable to save uploaded image.' => '',
23 23
 );
Please login to merge, or discard this patch.
protected/messages/en_us/yii.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '< Previous' => '',
21 21
   '<< First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@
 block discarded – undo
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19 19
 return array (
20
-  '< Previous' => '',
21
-  '<< First' => '',
22
-  'CApcCache requires PHP apc extension to be loaded.' => '',
23
-  'CMemCache server configuration must be an array.' => '',
24
-  'CMemCache server configuration must have "host" value.' => '',
25
-  'Go to page: ' => '',
26
-  'Last >>' => '',
27
-  'Next >' => '',
28
-  'The "forceCopy" and "linkAssets" cannot be both true.' => '',
29
-  'The asset "{asset}" to be published does not exist.' => '',
20
+    '< Previous' => '',
21
+    '<< First' => '',
22
+    'CApcCache requires PHP apc extension to be loaded.' => '',
23
+    'CMemCache server configuration must be an array.' => '',
24
+    'CMemCache server configuration must have "host" value.' => '',
25
+    'Go to page: ' => '',
26
+    'Last >>' => '',
27
+    'Next >' => '',
28
+    'The "forceCopy" and "linkAssets" cannot be both true.' => '',
29
+    'The asset "{asset}" to be published does not exist.' => '',
30 30
 );
Please login to merge, or discard this patch.
protected/migrations/m141001_145619_init.php 3 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -3,286 +3,286 @@
 block discarded – undo
3 3
 class m141001_145619_init extends CDbMigration
4 4
 {
5 5
 
6
-	/**
7
-	 * For data insertions, this is the current time.
8
-	 * @var integer
9
-	 */
10
-	private $_moment = 0;
11
-
12
-	public function safeUp()
13
-	{
14
-		$this->_moment = time();
15
-
16
-		// Try to get the table names, if we get something back, do not run this migration
17
-		try
18
-		{
19
-			$test = Yii::app()->db->schema->getTables();
20
-			if (count($test) <= 1)
21
-				throw new Exception('CiiMS doesn\'t exist. Applying base migration');
22
-			return true;
23
-		}
24
-		catch (Exception $e)
25
-		{
26
-			// Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time)
27
-			// This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not.
28
-		}
29
-
30
-		// Otherwise, run the install migration
31
-		$this->createUserTables();
32
-
33
-		$this->createCategories();
34
-
35
-		$this->createContent();
36
-
37
-		$this->createConfiguration();
38
-	}
39
-
40
-	public function safeDown()
41
-	{
42
-		echo "m141001_145619_init does not support migration down.\n";
43
-		return false;
44
-	}
45
-
46
-	/**
47
-	 * Creates the tables, indexes, and relations for users
48
-	 */
49
-	private function createUserTables()
50
-	{
51
-		$this->createTable('users', array(
52
-			'id' 		=> 'pk',
53
-			'email' 	=> 'string NOT NULL',
54
-			'password' 	=> 'string NOT NULL',
55
-			'username'  => 'string NOT NULL',
56
-			'user_role' => 'integer DEFAULT 1',
57
-			'status' 	=> 'integer DEFAULT 1',
58
-			'created' 	=> 'integer',
59
-			'updated' 	=> 'integer'
60
-		));
61
-
62
-		$this->createTable('user_roles', array(
63
-			'id' 		=> 'pk',
64
-			'name' 		=> 'string NOT NULL',
65
-			'created' 	=> 'integer',
66
-			'updated' 	=> 'integer'
67
-		));
68
-
69
-		$this->createTable('user_metadata', array(
70
-			'user_id' 	  => 'integer',
71
-			'key'		  => 'string NOT NULL',
72
-			'value' 	  => 'text NOT NULL',
73
-			'entity_type' => 'integer',
74
-			'created' 	  => 'integer',
75
-			'updated' 	  => 'integer'
76
-		));
77
-
78
-		// Create the necessary indexes on the columns
79
-		$this->createIndex('user_email', 'users', 'email', true);
80
-		$this->createIndex('user_username', 'users', 'username', true);
81
-		$this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false);
82
-
83
-		$this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key');
84
-
85
-		// Setup the foreign key constraints
86
-		$this->addForeignKey('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
87
-
88
-		// Insert data into the tables
89
-		$this->insert('user_roles', array(
90
-			'id'      => 1,
91
-			'name' 	  => 'User',
92
-			'created' => $this->_moment,
93
-			'updated' => $this->_moment
94
-		));
95
-
96
-		$this->insert('user_roles', array(
97
-			'id'      => 2,
98
-			'name'    => 'Pending',
99
-			'created' => $this->_moment,
100
-			'updated' => $this->_moment
101
-		));
102
-
103
-		$this->insert('user_roles', array(
104
-			'id'      => 3,
105
-			'name'    => 'Suspended',
106
-			'created' => $this->_moment,
107
-			'updated' => $this->_moment
108
-		));
109
-
110
-		$this->insert('user_roles', array(
111
-			'id'      => 5,
112
-			'name'    => 'Collaborator',
113
-			'created' => $this->_moment,
114
-			'updated' => $this->_moment
115
-		));
116
-
117
-		$this->insert('user_roles', array(
118
-			'id'      => 6,
119
-			'name'    => 'Author',
120
-			'created' => $this->_moment,
121
-			'updated' => $this->_moment
122
-		));
123
-
124
-		$this->insert('user_roles', array(
125
-			'id'      => 7,
126
-			'name'    => 'User',
127
-			'created' => $this->_moment,
128
-			'updated' => $this->_moment
129
-		));
130
-
131
-		$this->insert('user_roles', array(
132
-			'id'      => 8,
133
-			'name'    => 'Publisher',
134
-			'created' => $this->_moment,
135
-			'updated' => $this->_moment
136
-		));
137
-
138
-		$this->insert('user_roles', array(
139
-			'id'      => 9,
140
-			'name'    => 'Administrator',
141
-			'created' => $this->_moment,
142
-			'updated' => $this->_moment
143
-		));
144
-	}
145
-
146
-	/**
147
-	 * Create the categories and relations
148
-	 */
149
-	private function createCategories()
150
-	{
151
-		// Categories
152
-		$this->createTable('categories', array(
153
-			'id' 		=> 'pk',
154
-			'parent_id' => 'integer DEFAULT 1',
155
-			'name' 		=> 'string NOT NULL',
156
-			'slug' 	    => 'string NOT NULL',
157
-			'created' 	=> 'integer',
158
-			'updated' 	=> 'integer'
159
-		));
160
-
161
-		$this->createTable('categories_metadata', array(
162
-			'category_id' => 'integer',
163
-			'key'		  => 'string NOT NULL',
164
-			'value' 	  => 'text NOT NULL',
165
-			'created' 	  => 'integer',
166
-			'updated' 	  => 'integer'
167
-		));
168
-
169
-		// Insert the first record into the categories table
170
-		$this->insert('categories', array(
171
-			'id'      => 1,
172
-			'name'    => 'Uncategorized',
173
-			'slug'    => 'uncategorized',
174
-			'created' => $this->_moment,
175
-			'updated' => $this->_moment
176
-		));
177
-
178
-		$this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
-		$this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
-		$this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
181
-	}
182
-
183
-	/**
184
-	 * Creates the content, comemnts, and necessary relations
185
-	 */
186
-	private function createContent()
187
-	{
188
-		$this->createTable('content', array(
189
-			'id'		  => 'integer NOT NULL',
190
-			'vid' 		  => 'integer NOT NULL DEFAULT 1',
191
-			'title'		  => 'string  NOT NULL',
192
-			'content'     => 'text NOT NULL',
193
-			'excerpt'     => 'text NOT NULL',
194
-			'slug'        => 'string NOT NULL',
195
-			'category_id' => 'integer DEFAULT 1',
196
-			'author_id'   => 'integer DEFAULT 1',
197
-			'type_id'     => 'integer DEFAULT 2',
198
-			'commentable' => 'integer DEFAULT 1',
199
-			'password' 	  => 'string DEFAULT NULL',
200
-			'status'      => 'integer DEFAULT 0',
201
-			'like_count'  => 'integer DEFAULT 0',
202
-			'published'	  => 'integer',
203
-			'created'     => 'integer',
204
-			'updated' 	  => 'integer'
205
-		));
206
-
207
-		$this->createTable('content_types', array(
208
-			'id'          => 'pk',
209
-			'name'		  => 'string NOT NULL',
210
-			'created'     => 'integer',
211
-			'updated' 	  => 'integer'
212
-		));
213
-
214
-		$this->createTable('content_metadata', array(
215
-			'content_id'  => 'integer',
216
-			'key'		  => 'string NOT NULL',
217
-			'value' 	  => 'text NOT NULL',
218
-			'created' 	  => 'integer',
219
-			'updated' 	  => 'integer'
220
-		));
221
-
222
-		$this->createTable('comments', array(
223
-			'id'		  => 'pk',
224
-			'content_id'  => 'integer',
225
-			'author_id'   => 'integer',
226
-			'comment'     => 'integer',
227
-			'created'     => 'integer',
228
-			'updated' 	  => 'integer'
229
-		));
230
-
231
-		$this->insert('content_types', array(
232
-			'id'          => 1,
233
-			'name'        => 'Static Page',
234
-			'created'     => $this->_moment,
235
-			'updated'     => $this->_moment
236
-		));
237
-
238
-		$this->insert('content_types', array(
239
-			'id'          => 2,
240
-			'name'    	  => 'Blog Post',
241
-			'created'     => $this->_moment,
242
-			'updated'     => $this->_moment
243
-		));
244
-
245
-		$this->addPrimaryKey('content_composite', 'content', 'id, vid');
246
-
247
-		$this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
248
-
249
-		$this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key');
250
-
251
-		$this->createIndex('content_author', 'content', 'author_id', false);
252
-		$this->createIndex('content_category', 'content', 'category_id', false);
253
-		$this->createIndex('content_type', 'content', 'type_id', false);
254
-		$this->createIndex('comment_content', 'comments', 'content_id', false);
255
-		$this->createIndex('comment_author', 'comments', 'author_id', false);
256
-
257
-		$this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
-		$this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
-		$this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
260
-
261
-		$this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
-		$this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
263
-	}
264
-
265
-	/**
266
-	 * Creates the configuration and events tables
267
-	 */
268
-	private function createConfiguration()
269
-	{
270
-		$this->createTable('configuration', array(
271
-			'key'		  => 'string',
272
-			'value' 	  => 'text NOT NULL',
273
-			'created' 	  => 'integer',
274
-			'updated' 	  => 'integer'
275
-		));
276
-
277
-		$this->createTable('events', array(
278
-			'id'		  => 'pk',
279
-			'event'       => 'string NOT NULL',
280
-			'event_data'  => 'text DEFAULT NULL',
281
-			'uri'         => 'string DEFAULT NULL',
282
-			'content_id'  => 'integer DEFAULT NULL',
283
-			'created' 	  => 'integer'
284
-		));
285
-
286
-		$this->addPrimaryKey('configuration_pk', 'configuration', 'key');
287
-	}
6
+    /**
7
+     * For data insertions, this is the current time.
8
+     * @var integer
9
+     */
10
+    private $_moment = 0;
11
+
12
+    public function safeUp()
13
+    {
14
+        $this->_moment = time();
15
+
16
+        // Try to get the table names, if we get something back, do not run this migration
17
+        try
18
+        {
19
+            $test = Yii::app()->db->schema->getTables();
20
+            if (count($test) <= 1)
21
+                throw new Exception('CiiMS doesn\'t exist. Applying base migration');
22
+            return true;
23
+        }
24
+        catch (Exception $e)
25
+        {
26
+            // Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time)
27
+            // This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not.
28
+        }
29
+
30
+        // Otherwise, run the install migration
31
+        $this->createUserTables();
32
+
33
+        $this->createCategories();
34
+
35
+        $this->createContent();
36
+
37
+        $this->createConfiguration();
38
+    }
39
+
40
+    public function safeDown()
41
+    {
42
+        echo "m141001_145619_init does not support migration down.\n";
43
+        return false;
44
+    }
45
+
46
+    /**
47
+     * Creates the tables, indexes, and relations for users
48
+     */
49
+    private function createUserTables()
50
+    {
51
+        $this->createTable('users', array(
52
+            'id' 		=> 'pk',
53
+            'email' 	=> 'string NOT NULL',
54
+            'password' 	=> 'string NOT NULL',
55
+            'username'  => 'string NOT NULL',
56
+            'user_role' => 'integer DEFAULT 1',
57
+            'status' 	=> 'integer DEFAULT 1',
58
+            'created' 	=> 'integer',
59
+            'updated' 	=> 'integer'
60
+        ));
61
+
62
+        $this->createTable('user_roles', array(
63
+            'id' 		=> 'pk',
64
+            'name' 		=> 'string NOT NULL',
65
+            'created' 	=> 'integer',
66
+            'updated' 	=> 'integer'
67
+        ));
68
+
69
+        $this->createTable('user_metadata', array(
70
+            'user_id' 	  => 'integer',
71
+            'key'		  => 'string NOT NULL',
72
+            'value' 	  => 'text NOT NULL',
73
+            'entity_type' => 'integer',
74
+            'created' 	  => 'integer',
75
+            'updated' 	  => 'integer'
76
+        ));
77
+
78
+        // Create the necessary indexes on the columns
79
+        $this->createIndex('user_email', 'users', 'email', true);
80
+        $this->createIndex('user_username', 'users', 'username', true);
81
+        $this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false);
82
+
83
+        $this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key');
84
+
85
+        // Setup the foreign key constraints
86
+        $this->addForeignKey('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
87
+
88
+        // Insert data into the tables
89
+        $this->insert('user_roles', array(
90
+            'id'      => 1,
91
+            'name' 	  => 'User',
92
+            'created' => $this->_moment,
93
+            'updated' => $this->_moment
94
+        ));
95
+
96
+        $this->insert('user_roles', array(
97
+            'id'      => 2,
98
+            'name'    => 'Pending',
99
+            'created' => $this->_moment,
100
+            'updated' => $this->_moment
101
+        ));
102
+
103
+        $this->insert('user_roles', array(
104
+            'id'      => 3,
105
+            'name'    => 'Suspended',
106
+            'created' => $this->_moment,
107
+            'updated' => $this->_moment
108
+        ));
109
+
110
+        $this->insert('user_roles', array(
111
+            'id'      => 5,
112
+            'name'    => 'Collaborator',
113
+            'created' => $this->_moment,
114
+            'updated' => $this->_moment
115
+        ));
116
+
117
+        $this->insert('user_roles', array(
118
+            'id'      => 6,
119
+            'name'    => 'Author',
120
+            'created' => $this->_moment,
121
+            'updated' => $this->_moment
122
+        ));
123
+
124
+        $this->insert('user_roles', array(
125
+            'id'      => 7,
126
+            'name'    => 'User',
127
+            'created' => $this->_moment,
128
+            'updated' => $this->_moment
129
+        ));
130
+
131
+        $this->insert('user_roles', array(
132
+            'id'      => 8,
133
+            'name'    => 'Publisher',
134
+            'created' => $this->_moment,
135
+            'updated' => $this->_moment
136
+        ));
137
+
138
+        $this->insert('user_roles', array(
139
+            'id'      => 9,
140
+            'name'    => 'Administrator',
141
+            'created' => $this->_moment,
142
+            'updated' => $this->_moment
143
+        ));
144
+    }
145
+
146
+    /**
147
+     * Create the categories and relations
148
+     */
149
+    private function createCategories()
150
+    {
151
+        // Categories
152
+        $this->createTable('categories', array(
153
+            'id' 		=> 'pk',
154
+            'parent_id' => 'integer DEFAULT 1',
155
+            'name' 		=> 'string NOT NULL',
156
+            'slug' 	    => 'string NOT NULL',
157
+            'created' 	=> 'integer',
158
+            'updated' 	=> 'integer'
159
+        ));
160
+
161
+        $this->createTable('categories_metadata', array(
162
+            'category_id' => 'integer',
163
+            'key'		  => 'string NOT NULL',
164
+            'value' 	  => 'text NOT NULL',
165
+            'created' 	  => 'integer',
166
+            'updated' 	  => 'integer'
167
+        ));
168
+
169
+        // Insert the first record into the categories table
170
+        $this->insert('categories', array(
171
+            'id'      => 1,
172
+            'name'    => 'Uncategorized',
173
+            'slug'    => 'uncategorized',
174
+            'created' => $this->_moment,
175
+            'updated' => $this->_moment
176
+        ));
177
+
178
+        $this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
+        $this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
+        $this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
181
+    }
182
+
183
+    /**
184
+     * Creates the content, comemnts, and necessary relations
185
+     */
186
+    private function createContent()
187
+    {
188
+        $this->createTable('content', array(
189
+            'id'		  => 'integer NOT NULL',
190
+            'vid' 		  => 'integer NOT NULL DEFAULT 1',
191
+            'title'		  => 'string  NOT NULL',
192
+            'content'     => 'text NOT NULL',
193
+            'excerpt'     => 'text NOT NULL',
194
+            'slug'        => 'string NOT NULL',
195
+            'category_id' => 'integer DEFAULT 1',
196
+            'author_id'   => 'integer DEFAULT 1',
197
+            'type_id'     => 'integer DEFAULT 2',
198
+            'commentable' => 'integer DEFAULT 1',
199
+            'password' 	  => 'string DEFAULT NULL',
200
+            'status'      => 'integer DEFAULT 0',
201
+            'like_count'  => 'integer DEFAULT 0',
202
+            'published'	  => 'integer',
203
+            'created'     => 'integer',
204
+            'updated' 	  => 'integer'
205
+        ));
206
+
207
+        $this->createTable('content_types', array(
208
+            'id'          => 'pk',
209
+            'name'		  => 'string NOT NULL',
210
+            'created'     => 'integer',
211
+            'updated' 	  => 'integer'
212
+        ));
213
+
214
+        $this->createTable('content_metadata', array(
215
+            'content_id'  => 'integer',
216
+            'key'		  => 'string NOT NULL',
217
+            'value' 	  => 'text NOT NULL',
218
+            'created' 	  => 'integer',
219
+            'updated' 	  => 'integer'
220
+        ));
221
+
222
+        $this->createTable('comments', array(
223
+            'id'		  => 'pk',
224
+            'content_id'  => 'integer',
225
+            'author_id'   => 'integer',
226
+            'comment'     => 'integer',
227
+            'created'     => 'integer',
228
+            'updated' 	  => 'integer'
229
+        ));
230
+
231
+        $this->insert('content_types', array(
232
+            'id'          => 1,
233
+            'name'        => 'Static Page',
234
+            'created'     => $this->_moment,
235
+            'updated'     => $this->_moment
236
+        ));
237
+
238
+        $this->insert('content_types', array(
239
+            'id'          => 2,
240
+            'name'    	  => 'Blog Post',
241
+            'created'     => $this->_moment,
242
+            'updated'     => $this->_moment
243
+        ));
244
+
245
+        $this->addPrimaryKey('content_composite', 'content', 'id, vid');
246
+
247
+        $this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
248
+
249
+        $this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key');
250
+
251
+        $this->createIndex('content_author', 'content', 'author_id', false);
252
+        $this->createIndex('content_category', 'content', 'category_id', false);
253
+        $this->createIndex('content_type', 'content', 'type_id', false);
254
+        $this->createIndex('comment_content', 'comments', 'content_id', false);
255
+        $this->createIndex('comment_author', 'comments', 'author_id', false);
256
+
257
+        $this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
+        $this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
+        $this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
260
+
261
+        $this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
+        $this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
263
+    }
264
+
265
+    /**
266
+     * Creates the configuration and events tables
267
+     */
268
+    private function createConfiguration()
269
+    {
270
+        $this->createTable('configuration', array(
271
+            'key'		  => 'string',
272
+            'value' 	  => 'text NOT NULL',
273
+            'created' 	  => 'integer',
274
+            'updated' 	  => 'integer'
275
+        ));
276
+
277
+        $this->createTable('events', array(
278
+            'id'		  => 'pk',
279
+            'event'       => 'string NOT NULL',
280
+            'event_data'  => 'text DEFAULT NULL',
281
+            'uri'         => 'string DEFAULT NULL',
282
+            'content_id'  => 'integer DEFAULT NULL',
283
+            'created' 	  => 'integer'
284
+        ));
285
+
286
+        $this->addPrimaryKey('configuration_pk', 'configuration', 'key');
287
+    }
288 288
 }
289 289
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 	 */
10 10
 	private $_moment = 0;
11 11
 
12
-	public function safeUp()
12
+	public function safeUp ()
13 13
 	{
14
-		$this->_moment = time();
14
+		$this->_moment = time ();
15 15
 
16 16
 		// Try to get the table names, if we get something back, do not run this migration
17 17
 		try
18 18
 		{
19
-			$test = Yii::app()->db->schema->getTables();
20
-			if (count($test) <= 1)
21
-				throw new Exception('CiiMS doesn\'t exist. Applying base migration');
19
+			$test = Yii::app ()->db->schema->getTables ();
20
+			if (count ($test) <= 1)
21
+				throw new Exception ('CiiMS doesn\'t exist. Applying base migration');
22 22
 			return true;
23 23
 		}
24 24
 		catch (Exception $e)
@@ -28,16 +28,16 @@  discard block
 block discarded – undo
28 28
 		}
29 29
 
30 30
 		// Otherwise, run the install migration
31
-		$this->createUserTables();
31
+		$this->createUserTables ();
32 32
 
33
-		$this->createCategories();
33
+		$this->createCategories ();
34 34
 
35
-		$this->createContent();
35
+		$this->createContent ();
36 36
 
37
-		$this->createConfiguration();
37
+		$this->createConfiguration ();
38 38
 	}
39 39
 
40
-	public function safeDown()
40
+	public function safeDown ()
41 41
 	{
42 42
 		echo "m141001_145619_init does not support migration down.\n";
43 43
 		return false;
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 	/**
47 47
 	 * Creates the tables, indexes, and relations for users
48 48
 	 */
49
-	private function createUserTables()
49
+	private function createUserTables ()
50 50
 	{
51
-		$this->createTable('users', array(
51
+		$this->createTable ('users', array(
52 52
 			'id' 		=> 'pk',
53 53
 			'email' 	=> 'string NOT NULL',
54 54
 			'password' 	=> 'string NOT NULL',
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
 			'updated' 	=> 'integer'
60 60
 		));
61 61
 
62
-		$this->createTable('user_roles', array(
62
+		$this->createTable ('user_roles', array(
63 63
 			'id' 		=> 'pk',
64 64
 			'name' 		=> 'string NOT NULL',
65 65
 			'created' 	=> 'integer',
66 66
 			'updated' 	=> 'integer'
67 67
 		));
68 68
 
69
-		$this->createTable('user_metadata', array(
69
+		$this->createTable ('user_metadata', array(
70 70
 			'user_id' 	  => 'integer',
71 71
 			'key'		  => 'string NOT NULL',
72 72
 			'value' 	  => 'text NOT NULL',
@@ -76,66 +76,66 @@  discard block
 block discarded – undo
76 76
 		));
77 77
 
78 78
 		// Create the necessary indexes on the columns
79
-		$this->createIndex('user_email', 'users', 'email', true);
80
-		$this->createIndex('user_username', 'users', 'username', true);
81
-		$this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false);
79
+		$this->createIndex ('user_email', 'users', 'email', true);
80
+		$this->createIndex ('user_username', 'users', 'username', true);
81
+		$this->createIndex ('user_metadata', 'user_metadata', 'user_id, key', false);
82 82
 
83
-		$this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key');
83
+		$this->addPrimaryKey ('user_metadata_composite', 'user_metadata', 'user_id,key');
84 84
 
85 85
 		// Setup the foreign key constraints
86
-		$this->addForeignKey('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
86
+		$this->addForeignKey ('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
87 87
 
88 88
 		// Insert data into the tables
89
-		$this->insert('user_roles', array(
89
+		$this->insert ('user_roles', array(
90 90
 			'id'      => 1,
91 91
 			'name' 	  => 'User',
92 92
 			'created' => $this->_moment,
93 93
 			'updated' => $this->_moment
94 94
 		));
95 95
 
96
-		$this->insert('user_roles', array(
96
+		$this->insert ('user_roles', array(
97 97
 			'id'      => 2,
98 98
 			'name'    => 'Pending',
99 99
 			'created' => $this->_moment,
100 100
 			'updated' => $this->_moment
101 101
 		));
102 102
 
103
-		$this->insert('user_roles', array(
103
+		$this->insert ('user_roles', array(
104 104
 			'id'      => 3,
105 105
 			'name'    => 'Suspended',
106 106
 			'created' => $this->_moment,
107 107
 			'updated' => $this->_moment
108 108
 		));
109 109
 
110
-		$this->insert('user_roles', array(
110
+		$this->insert ('user_roles', array(
111 111
 			'id'      => 5,
112 112
 			'name'    => 'Collaborator',
113 113
 			'created' => $this->_moment,
114 114
 			'updated' => $this->_moment
115 115
 		));
116 116
 
117
-		$this->insert('user_roles', array(
117
+		$this->insert ('user_roles', array(
118 118
 			'id'      => 6,
119 119
 			'name'    => 'Author',
120 120
 			'created' => $this->_moment,
121 121
 			'updated' => $this->_moment
122 122
 		));
123 123
 
124
-		$this->insert('user_roles', array(
124
+		$this->insert ('user_roles', array(
125 125
 			'id'      => 7,
126 126
 			'name'    => 'User',
127 127
 			'created' => $this->_moment,
128 128
 			'updated' => $this->_moment
129 129
 		));
130 130
 
131
-		$this->insert('user_roles', array(
131
+		$this->insert ('user_roles', array(
132 132
 			'id'      => 8,
133 133
 			'name'    => 'Publisher',
134 134
 			'created' => $this->_moment,
135 135
 			'updated' => $this->_moment
136 136
 		));
137 137
 
138
-		$this->insert('user_roles', array(
138
+		$this->insert ('user_roles', array(
139 139
 			'id'      => 9,
140 140
 			'name'    => 'Administrator',
141 141
 			'created' => $this->_moment,
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 	/**
147 147
 	 * Create the categories and relations
148 148
 	 */
149
-	private function createCategories()
149
+	private function createCategories ()
150 150
 	{
151 151
 		// Categories
152
-		$this->createTable('categories', array(
152
+		$this->createTable ('categories', array(
153 153
 			'id' 		=> 'pk',
154 154
 			'parent_id' => 'integer DEFAULT 1',
155 155
 			'name' 		=> 'string NOT NULL',
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			'updated' 	=> 'integer'
159 159
 		));
160 160
 
161
-		$this->createTable('categories_metadata', array(
161
+		$this->createTable ('categories_metadata', array(
162 162
 			'category_id' => 'integer',
163 163
 			'key'		  => 'string NOT NULL',
164 164
 			'value' 	  => 'text NOT NULL',
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		));
168 168
 
169 169
 		// Insert the first record into the categories table
170
-		$this->insert('categories', array(
170
+		$this->insert ('categories', array(
171 171
 			'id'      => 1,
172 172
 			'name'    => 'Uncategorized',
173 173
 			'slug'    => 'uncategorized',
@@ -175,17 +175,17 @@  discard block
 block discarded – undo
175 175
 			'updated' => $this->_moment
176 176
 		));
177 177
 
178
-		$this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
-		$this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
-		$this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
178
+		$this->addPrimaryKey ('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
+		$this->addForeignKey ('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
+		$this->addForeignKey ('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
181 181
 	}
182 182
 
183 183
 	/**
184 184
 	 * Creates the content, comemnts, and necessary relations
185 185
 	 */
186
-	private function createContent()
186
+	private function createContent ()
187 187
 	{
188
-		$this->createTable('content', array(
188
+		$this->createTable ('content', array(
189 189
 			'id'		  => 'integer NOT NULL',
190 190
 			'vid' 		  => 'integer NOT NULL DEFAULT 1',
191 191
 			'title'		  => 'string  NOT NULL',
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 			'updated' 	  => 'integer'
205 205
 		));
206 206
 
207
-		$this->createTable('content_types', array(
207
+		$this->createTable ('content_types', array(
208 208
 			'id'          => 'pk',
209 209
 			'name'		  => 'string NOT NULL',
210 210
 			'created'     => 'integer',
211 211
 			'updated' 	  => 'integer'
212 212
 		));
213 213
 
214
-		$this->createTable('content_metadata', array(
214
+		$this->createTable ('content_metadata', array(
215 215
 			'content_id'  => 'integer',
216 216
 			'key'		  => 'string NOT NULL',
217 217
 			'value' 	  => 'text NOT NULL',
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 			'updated' 	  => 'integer'
220 220
 		));
221 221
 
222
-		$this->createTable('comments', array(
222
+		$this->createTable ('comments', array(
223 223
 			'id'		  => 'pk',
224 224
 			'content_id'  => 'integer',
225 225
 			'author_id'   => 'integer',
@@ -228,53 +228,53 @@  discard block
 block discarded – undo
228 228
 			'updated' 	  => 'integer'
229 229
 		));
230 230
 
231
-		$this->insert('content_types', array(
231
+		$this->insert ('content_types', array(
232 232
 			'id'          => 1,
233 233
 			'name'        => 'Static Page',
234 234
 			'created'     => $this->_moment,
235 235
 			'updated'     => $this->_moment
236 236
 		));
237 237
 
238
-		$this->insert('content_types', array(
238
+		$this->insert ('content_types', array(
239 239
 			'id'          => 2,
240 240
 			'name'    	  => 'Blog Post',
241 241
 			'created'     => $this->_moment,
242 242
 			'updated'     => $this->_moment
243 243
 		));
244 244
 
245
-		$this->addPrimaryKey('content_composite', 'content', 'id, vid');
245
+		$this->addPrimaryKey ('content_composite', 'content', 'id, vid');
246 246
 
247
-		$this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
247
+		$this->execute ('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
248 248
 
249
-		$this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key');
249
+		$this->addPrimaryKey ('content_metadata_composite', 'content_metadata', 'content_id,key');
250 250
 
251
-		$this->createIndex('content_author', 'content', 'author_id', false);
252
-		$this->createIndex('content_category', 'content', 'category_id', false);
253
-		$this->createIndex('content_type', 'content', 'type_id', false);
254
-		$this->createIndex('comment_content', 'comments', 'content_id', false);
255
-		$this->createIndex('comment_author', 'comments', 'author_id', false);
251
+		$this->createIndex ('content_author', 'content', 'author_id', false);
252
+		$this->createIndex ('content_category', 'content', 'category_id', false);
253
+		$this->createIndex ('content_type', 'content', 'type_id', false);
254
+		$this->createIndex ('comment_content', 'comments', 'content_id', false);
255
+		$this->createIndex ('comment_author', 'comments', 'author_id', false);
256 256
 
257
-		$this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
-		$this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
-		$this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
257
+		$this->addForeignKey ('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
+		$this->addForeignKey ('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
+		$this->addForeignKey ('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
260 260
 
261
-		$this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
-		$this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
261
+		$this->addForeignKey ('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
+		$this->addForeignKey ('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
263 263
 	}
264 264
 
265 265
 	/**
266 266
 	 * Creates the configuration and events tables
267 267
 	 */
268
-	private function createConfiguration()
268
+	private function createConfiguration ()
269 269
 	{
270
-		$this->createTable('configuration', array(
270
+		$this->createTable ('configuration', array(
271 271
 			'key'		  => 'string',
272 272
 			'value' 	  => 'text NOT NULL',
273 273
 			'created' 	  => 'integer',
274 274
 			'updated' 	  => 'integer'
275 275
 		));
276 276
 
277
-		$this->createTable('events', array(
277
+		$this->createTable ('events', array(
278 278
 			'id'		  => 'pk',
279 279
 			'event'       => 'string NOT NULL',
280 280
 			'event_data'  => 'text DEFAULT NULL',
@@ -283,6 +283,6 @@  discard block
 block discarded – undo
283 283
 			'created' 	  => 'integer'
284 284
 		));
285 285
 
286
-		$this->addPrimaryKey('configuration_pk', 'configuration', 'key');
286
+		$this->addPrimaryKey ('configuration_pk', 'configuration', 'key');
287 287
 	}
288 288
 }
289 289
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@
 block discarded – undo
17 17
 		try
18 18
 		{
19 19
 			$test = Yii::app()->db->schema->getTables();
20
-			if (count($test) <= 1)
21
-				throw new Exception('CiiMS doesn\'t exist. Applying base migration');
20
+			if (count($test) <= 1) {
21
+							throw new Exception('CiiMS doesn\'t exist. Applying base migration');
22
+			}
22 23
 			return true;
23
-		}
24
-		catch (Exception $e)
24
+		} catch (Exception $e)
25 25
 		{
26 26
 			// Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time)
27 27
 			// This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not.
Please login to merge, or discard this patch.
protected/models/Categories.php 3 patches
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -19,319 +19,319 @@
 block discarded – undo
19 19
  */
20 20
 class Categories extends CiiModel
21 21
 {
22
-	public $pageSize = 15;
23
-
24
-	public $description = NULL;
25
-
26
-	public $keywords = array();
27
-
28
-	/**
29
-	 * Returns the static model of the specified AR class.
30
-	 * @param string $className active record class name.
31
-	 * @return Categories the static model class
32
-	 */
33
-	public static function model($className=__CLASS__)
34
-	{
35
-		return parent::model($className);
36
-	}
37
-
38
-	/**
39
-	 * @return string the associated database table name
40
-	 */
41
-	public function tableName()
42
-	{
43
-		return 'categories';
44
-	}
45
-
46
-	/**
47
-	 * @return array validation rules for model attributes.
48
-	 */
49
-	public function rules()
50
-	{
51
-		// NOTE: you should only define rules for those attributes that
52
-		// will receive user inputs.
53
-		return array(
54
-			array('parent_id, name', 'required'),
55
-			array('parent_id', 'numerical', 'integerOnly'=>true),
56
-			array('name, slug', 'length', 'max'=>150),
57
-			// The following rule is used by search().
58
-			// Please remove those attributes that should not be searched.
59
-			array('id, parent_id, name, slug', 'safe', 'on'=>'search'),
60
-		);
61
-	}
62
-
63
-	/**
64
-	 * @return array relational rules.
65
-	 */
66
-	public function relations()
67
-	{
68
-		// NOTE: you may need to adjust the relation name and the related
69
-		// class name for the relations automatically generated below.
70
-		return array(
71
-			'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
72
-			'metadata' => array(self::HAS_MANY, 'CategoriesMetadata', 'category_id'),
73
-			'content' => array(self::HAS_MANY, 'Content', 'category_id'),
74
-		);
75
-	}
76
-
77
-	/**
78
-	 * @return array customized attribute labels (name=>label)
79
-	 */
80
-	public function attributeLabels()
81
-	{
82
-		return array(
83
-			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
-			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
-			'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
-			'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
-			'description' => Yii::t('ciims.models.Categories', 'Description'),
88
-			'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
-			'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
90
-		);
91
-	}
92
-
93
-	public function getDescription()
94
-	{
95
-		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
-		if ($this->description == null || $this->description == false)
97
-			return NULL;
98
-
99
-		$this->description = $this->description->value;
100
-		return $this->description;
101
-	}
102
-
103
-	/**
104
-	 * Retrieves a list of models based on the current search/filter conditions.
105
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106
-	 */
107
-	public function search()
108
-	{
109
-		$criteria=new CDbCriteria;
110
-
111
-		$criteria->compare('id',$this->id);
112
-		$criteria->compare('parent_id',$this->parent_id);
113
-		$criteria->compare('name',$this->name,true);
114
-		$criteria->compare('slug',$this->slug,true);
115
-		$criteria->compare('created',$this->created,true);
116
-		$criteria->compare('updated',$this->updated,true);
117
-		$criteria->order = "id DESC";
118
-
119
-		return new CActiveDataProvider($this, array(
120
-			'criteria' => $criteria,
121
-			'pagination' => array(
122
-				'pageSize' => $this->pageSize
123
-			)
124
-		));
125
-	}
126
-
127
-	/**
128
-	 * Gets keyword tags for this entry
129
-	 * @return array
130
-	 */
131
-	public function getKeywords()
132
-	{
133
-		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
-		return $tags === NULL ? array() : CJSON::decode($tags->value);
135
-	}
136
-
137
-	/**
138
-	 * Adds a tag to the model
139
-	 * @param string $tag	The tag to add
140
-	 * @return bool			If the insert was successful or not
141
-	 */
142
-	public function addKeyword($tag)
143
-	{
144
-		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
146
-			return false;
147
-
148
-		$tags[] = $tag;
149
-		$tags = CJSON::encode($tags);
150
-		$metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
151
-		if ($metaTag == false || $metaTag == NULL)
152
-		{
153
-			$metaTag = new CategoriestMetadata;
154
-			$metaTag->content_id = $this->id;
155
-			$metaTag->key = 'keywords';
156
-		}
157
-
158
-		$metaTag->value = $tags;
159
-		return $metaTag->save();
160
-	}
161
-
162
-	/**
163
-	 * Removes a tag from the model
164
-	 * @param string $tag	The tag to remove
165
-	 * @return bool			If the removal was successful
166
-	 */
167
-	public function removeKeyword($tag)
168
-	{
169
-		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
171
-			return false;
172
-
173
-		$key = array_search($tag, $tags);
174
-		unset($tags[$key]);
175
-		$tags = CJSON::encode($tags);
176
-
177
-		$metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
178
-		$metaTag->value = $tags;
179
-		return $metaTag->save();
180
-	}
181
-
182
-	/**
183
-	 * Verifies the slug before validating the model
184
-	 */
185
-	public function beforeValidate()
186
-	{
187
-		$this->slug = $this->verifySlug($this->slug, $this->name);
188
-
189
-		return parent::beforeValidate();
190
-	}
191
-
192
-	/**
193
-	 * Flushes URL data from the cache before the model is updated
194
-	 */
195
-	public function afterSave()
196
-	{
197
-		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
-		if ($meta == NULL)
199
-			$meta = new CategoriesMetadata;
200
-
201
-		$meta->category_id = $this->id;
202
-		$meta->key = 'description';
203
-		$meta->value  = $this->description;
204
-
205
-		$meta->save();
206
-
207
-		Yii::app()->cache->delete('CiiMS::Content::list');
208
-		Yii::app()->cache->delete('CiiMS::Routes');
209
-		Yii::app()->cache->delete('categories-pid');
210
-
211
-		return parent::afterSave();
212
-	}
213
-
214
-	/**
215
-	 * Automatically corrects parent tree issues that arise when a parent category node
216
-	 * is deleted.
217
-	 * @return boolean
218
-	 */
219
-	public function beforeDelete()
220
-	{
221
-		// Prevents the main "uncategorized category from being deleted"
222
-		if ($this->id == 1)
223
-		{
224
-			Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
225
-			return false;
226
-		}
227
-
228
-		Yii::app()->cache->delete('CiiMS::Content::list');
229
-		Yii::app()->cache->delete('CiiMS::Routes');
230
-		Yii::app()->cache->delete('categories-pid');
231
-
232
-		$parent = $this->parent_id;
233
-		$id = $this->id;
234
-
235
-		// Reassign all posts to the parent category
236
-		Yii::app()->db
237
-				->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
-				->bindParam(':parent_id', $parent)
239
-				->bindParam(':id', $id)
240
-				->execute();
241
-
242
-		// Reassign all child categories to the parent category
243
-		$data = $this->findAllByAttributes(array('parent_id' => $id));
244
-
245
-		foreach ($data as $row)
246
-		{
247
-			$id = $row->id;
248
-			Yii::app()->db
249
-					->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
-					->bindParam(':parent_id', $parent)
251
-					->bindParam(':id', $id)
252
-					->execute();
253
-		}
254
-
255
-		return parent::beforeDelete();
256
-	}
257
-
258
-	/**
259
-	 * Retrieves the parent categories for a given category_id
260
-	 * @param  int $id
261
-	 * @return array
262
-	 */
263
-	public function getParentCategories($id)
264
-	{
265
-		// Retrieve the data from cache if necessary
266
-		$response = Yii::app()->cache->get('categories-pid');
267
-		if ($response == NULL)
268
-		{
269
-			$response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
-			Yii::app()->cache->set('categories-pid', $response);
271
-		}
272
-
273
-		return $this->_getParentCategories($response, $id);
274
-	}
275
-
276
-	/**
277
-	 * Recursive callback for retrieving parent categories
278
-	 * @param  int  $id      The category we're seeking
279
-	 * @param  array  $stack A stack to hold the entire tree
280
-	 * @return array
281
-	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
283
-	{
284
-		if ($id == 1)
285
-			return array_reverse($stack);
286
-
287
-		foreach ($all_categories as $k=>$v)
288
-		{
289
-			if ($v['id'] == $id)
290
-			{
291
-				$stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
-				return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
293
-			}
294
-		}
295
-	}
296
-
297
-	/**
298
-	 * checkSlug - Recursive method to verify that the slug can be used
299
-	 * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
300
-	 * @param string $slug - the slug to be checked
301
-	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302
-	 * @return string $slug - the final slug to be used
303
-	 */
304
-	public function checkSlug($slug, $id=NULL)
305
-	{
306
-		$content = false;
307
-
308
-		// Find the number of items that have the same slug as this one
309
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
310
-
311
-		if ($count == 0)
312
-		{
313
-			$content = true;
314
-			$count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
315
-		}
316
-
317
-		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
318
-		// in which case we don't need to alter the slug
319
-		if ($count >= 1)
320
-		{
321
-			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
323
-
324
-			// Pull the data that matches
325
-			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326
-
327
-			// Check the pulled data id to the current item
328
-			if ($data !== NULL && $data->id == $this->id)
329
-				return $slug;
330
-		}
331
-
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
-			return $slug . $id;
334
-		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
336
-	}
22
+    public $pageSize = 15;
23
+
24
+    public $description = NULL;
25
+
26
+    public $keywords = array();
27
+
28
+    /**
29
+     * Returns the static model of the specified AR class.
30
+     * @param string $className active record class name.
31
+     * @return Categories the static model class
32
+     */
33
+    public static function model($className=__CLASS__)
34
+    {
35
+        return parent::model($className);
36
+    }
37
+
38
+    /**
39
+     * @return string the associated database table name
40
+     */
41
+    public function tableName()
42
+    {
43
+        return 'categories';
44
+    }
45
+
46
+    /**
47
+     * @return array validation rules for model attributes.
48
+     */
49
+    public function rules()
50
+    {
51
+        // NOTE: you should only define rules for those attributes that
52
+        // will receive user inputs.
53
+        return array(
54
+            array('parent_id, name', 'required'),
55
+            array('parent_id', 'numerical', 'integerOnly'=>true),
56
+            array('name, slug', 'length', 'max'=>150),
57
+            // The following rule is used by search().
58
+            // Please remove those attributes that should not be searched.
59
+            array('id, parent_id, name, slug', 'safe', 'on'=>'search'),
60
+        );
61
+    }
62
+
63
+    /**
64
+     * @return array relational rules.
65
+     */
66
+    public function relations()
67
+    {
68
+        // NOTE: you may need to adjust the relation name and the related
69
+        // class name for the relations automatically generated below.
70
+        return array(
71
+            'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
72
+            'metadata' => array(self::HAS_MANY, 'CategoriesMetadata', 'category_id'),
73
+            'content' => array(self::HAS_MANY, 'Content', 'category_id'),
74
+        );
75
+    }
76
+
77
+    /**
78
+     * @return array customized attribute labels (name=>label)
79
+     */
80
+    public function attributeLabels()
81
+    {
82
+        return array(
83
+            'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
+            'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
+            'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
+            'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
+            'description' => Yii::t('ciims.models.Categories', 'Description'),
88
+            'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
+            'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
90
+        );
91
+    }
92
+
93
+    public function getDescription()
94
+    {
95
+        $this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
+        if ($this->description == null || $this->description == false)
97
+            return NULL;
98
+
99
+        $this->description = $this->description->value;
100
+        return $this->description;
101
+    }
102
+
103
+    /**
104
+     * Retrieves a list of models based on the current search/filter conditions.
105
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106
+     */
107
+    public function search()
108
+    {
109
+        $criteria=new CDbCriteria;
110
+
111
+        $criteria->compare('id',$this->id);
112
+        $criteria->compare('parent_id',$this->parent_id);
113
+        $criteria->compare('name',$this->name,true);
114
+        $criteria->compare('slug',$this->slug,true);
115
+        $criteria->compare('created',$this->created,true);
116
+        $criteria->compare('updated',$this->updated,true);
117
+        $criteria->order = "id DESC";
118
+
119
+        return new CActiveDataProvider($this, array(
120
+            'criteria' => $criteria,
121
+            'pagination' => array(
122
+                'pageSize' => $this->pageSize
123
+            )
124
+        ));
125
+    }
126
+
127
+    /**
128
+     * Gets keyword tags for this entry
129
+     * @return array
130
+     */
131
+    public function getKeywords()
132
+    {
133
+        $tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
+        return $tags === NULL ? array() : CJSON::decode($tags->value);
135
+    }
136
+
137
+    /**
138
+     * Adds a tag to the model
139
+     * @param string $tag	The tag to add
140
+     * @return bool			If the insert was successful or not
141
+     */
142
+    public function addKeyword($tag)
143
+    {
144
+        $tags = $this->keywords;
145
+        if (in_array($tag, $tags)  || $tag == "")
146
+            return false;
147
+
148
+        $tags[] = $tag;
149
+        $tags = CJSON::encode($tags);
150
+        $metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
151
+        if ($metaTag == false || $metaTag == NULL)
152
+        {
153
+            $metaTag = new CategoriestMetadata;
154
+            $metaTag->content_id = $this->id;
155
+            $metaTag->key = 'keywords';
156
+        }
157
+
158
+        $metaTag->value = $tags;
159
+        return $metaTag->save();
160
+    }
161
+
162
+    /**
163
+     * Removes a tag from the model
164
+     * @param string $tag	The tag to remove
165
+     * @return bool			If the removal was successful
166
+     */
167
+    public function removeKeyword($tag)
168
+    {
169
+        $tags = $this->keywords;
170
+        if (!in_array($tag, $tags) || $tag == "")
171
+            return false;
172
+
173
+        $key = array_search($tag, $tags);
174
+        unset($tags[$key]);
175
+        $tags = CJSON::encode($tags);
176
+
177
+        $metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
178
+        $metaTag->value = $tags;
179
+        return $metaTag->save();
180
+    }
181
+
182
+    /**
183
+     * Verifies the slug before validating the model
184
+     */
185
+    public function beforeValidate()
186
+    {
187
+        $this->slug = $this->verifySlug($this->slug, $this->name);
188
+
189
+        return parent::beforeValidate();
190
+    }
191
+
192
+    /**
193
+     * Flushes URL data from the cache before the model is updated
194
+     */
195
+    public function afterSave()
196
+    {
197
+        $meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
+        if ($meta == NULL)
199
+            $meta = new CategoriesMetadata;
200
+
201
+        $meta->category_id = $this->id;
202
+        $meta->key = 'description';
203
+        $meta->value  = $this->description;
204
+
205
+        $meta->save();
206
+
207
+        Yii::app()->cache->delete('CiiMS::Content::list');
208
+        Yii::app()->cache->delete('CiiMS::Routes');
209
+        Yii::app()->cache->delete('categories-pid');
210
+
211
+        return parent::afterSave();
212
+    }
213
+
214
+    /**
215
+     * Automatically corrects parent tree issues that arise when a parent category node
216
+     * is deleted.
217
+     * @return boolean
218
+     */
219
+    public function beforeDelete()
220
+    {
221
+        // Prevents the main "uncategorized category from being deleted"
222
+        if ($this->id == 1)
223
+        {
224
+            Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
225
+            return false;
226
+        }
227
+
228
+        Yii::app()->cache->delete('CiiMS::Content::list');
229
+        Yii::app()->cache->delete('CiiMS::Routes');
230
+        Yii::app()->cache->delete('categories-pid');
231
+
232
+        $parent = $this->parent_id;
233
+        $id = $this->id;
234
+
235
+        // Reassign all posts to the parent category
236
+        Yii::app()->db
237
+                ->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
+                ->bindParam(':parent_id', $parent)
239
+                ->bindParam(':id', $id)
240
+                ->execute();
241
+
242
+        // Reassign all child categories to the parent category
243
+        $data = $this->findAllByAttributes(array('parent_id' => $id));
244
+
245
+        foreach ($data as $row)
246
+        {
247
+            $id = $row->id;
248
+            Yii::app()->db
249
+                    ->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
+                    ->bindParam(':parent_id', $parent)
251
+                    ->bindParam(':id', $id)
252
+                    ->execute();
253
+        }
254
+
255
+        return parent::beforeDelete();
256
+    }
257
+
258
+    /**
259
+     * Retrieves the parent categories for a given category_id
260
+     * @param  int $id
261
+     * @return array
262
+     */
263
+    public function getParentCategories($id)
264
+    {
265
+        // Retrieve the data from cache if necessary
266
+        $response = Yii::app()->cache->get('categories-pid');
267
+        if ($response == NULL)
268
+        {
269
+            $response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
+            Yii::app()->cache->set('categories-pid', $response);
271
+        }
272
+
273
+        return $this->_getParentCategories($response, $id);
274
+    }
275
+
276
+    /**
277
+     * Recursive callback for retrieving parent categories
278
+     * @param  int  $id      The category we're seeking
279
+     * @param  array  $stack A stack to hold the entire tree
280
+     * @return array
281
+     */
282
+    private function _getParentCategories($all_categories, $id, array $stack = array())
283
+    {
284
+        if ($id == 1)
285
+            return array_reverse($stack);
286
+
287
+        foreach ($all_categories as $k=>$v)
288
+        {
289
+            if ($v['id'] == $id)
290
+            {
291
+                $stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
+                return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
293
+            }
294
+        }
295
+    }
296
+
297
+    /**
298
+     * checkSlug - Recursive method to verify that the slug can be used
299
+     * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
300
+     * @param string $slug - the slug to be checked
301
+     * @param int $id - the numeric id to be appended to the slug if a conflict exists
302
+     * @return string $slug - the final slug to be used
303
+     */
304
+    public function checkSlug($slug, $id=NULL)
305
+    {
306
+        $content = false;
307
+
308
+        // Find the number of items that have the same slug as this one
309
+        $count = $this->countByAttributes(array('slug'=>$slug . $id));
310
+
311
+        if ($count == 0)
312
+        {
313
+            $content = true;
314
+            $count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
315
+        }
316
+
317
+        // If we found an item that matched, it's possible that it is the current item (or a previous version of it)
318
+        // in which case we don't need to alter the slug
319
+        if ($count >= 1)
320
+        {
321
+            if ($content)
322
+                return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
323
+
324
+            // Pull the data that matches
325
+            $data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326
+
327
+            // Check the pulled data id to the current item
328
+            if ($data !== NULL && $data->id == $this->id)
329
+                return $slug;
330
+        }
331
+
332
+        if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
+            return $slug . $id;
334
+        else
335
+            return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
336
+    }
337 337
 }
Please login to merge, or discard this patch.
Braces   +60 added lines, -52 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
  * @property CategoriesMetadata[] $categoriesMetadatas
18 18
  * @property Content[] $contents
19 19
  */
20
-class Categories extends CiiModel
21
-{
20
+class Categories extends CiiModel
21
+{
22 22
 	public $pageSize = 15;
23 23
 
24 24
 	public $description = NULL;
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 	 * @param string $className active record class name.
31 31
 	 * @return Categories the static model class
32 32
 	 */
33
-	public static function model($className=__CLASS__)
34
-	{
33
+	public static function model($className=__CLASS__)
34
+	{
35 35
 		return parent::model($className);
36 36
 	}
37 37
 
38 38
 	/**
39 39
 	 * @return string the associated database table name
40 40
 	 */
41
-	public function tableName()
42
-	{
41
+	public function tableName()
42
+	{
43 43
 		return 'categories';
44 44
 	}
45 45
 
46 46
 	/**
47 47
 	 * @return array validation rules for model attributes.
48 48
 	 */
49
-	public function rules()
50
-	{
49
+	public function rules()
50
+	{
51 51
 		// NOTE: you should only define rules for those attributes that
52 52
 		// will receive user inputs.
53 53
 		return array(
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @return array relational rules.
65 65
 	 */
66
-	public function relations()
67
-	{
66
+	public function relations()
67
+	{
68 68
 		// NOTE: you may need to adjust the relation name and the related
69 69
 		// class name for the relations automatically generated below.
70 70
 		return array(
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 * @return array customized attribute labels (name=>label)
79 79
 	 */
80
-	public function attributeLabels()
81
-	{
80
+	public function attributeLabels()
81
+	{
82 82
 		return array(
83 83
 			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84 84
 			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
@@ -90,11 +90,12 @@  discard block
 block discarded – undo
90 90
 		);
91 91
 	}
92 92
 
93
-	public function getDescription()
94
-	{
93
+	public function getDescription()
94
+	{
95 95
 		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
-		if ($this->description == null || $this->description == false)
97
-			return NULL;
96
+		if ($this->description == null || $this->description == false) {
97
+					return NULL;
98
+		}
98 99
 
99 100
 		$this->description = $this->description->value;
100 101
 		return $this->description;
@@ -104,8 +105,8 @@  discard block
 block discarded – undo
104 105
 	 * Retrieves a list of models based on the current search/filter conditions.
105 106
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106 107
 	 */
107
-	public function search()
108
-	{
108
+	public function search()
109
+	{
109 110
 		$criteria=new CDbCriteria;
110 111
 
111 112
 		$criteria->compare('id',$this->id);
@@ -128,8 +129,8 @@  discard block
 block discarded – undo
128 129
 	 * Gets keyword tags for this entry
129 130
 	 * @return array
130 131
 	 */
131
-	public function getKeywords()
132
-	{
132
+	public function getKeywords()
133
+	{
133 134
 		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134 135
 		return $tags === NULL ? array() : CJSON::decode($tags->value);
135 136
 	}
@@ -139,11 +140,12 @@  discard block
 block discarded – undo
139 140
 	 * @param string $tag	The tag to add
140 141
 	 * @return bool			If the insert was successful or not
141 142
 	 */
142
-	public function addKeyword($tag)
143
-	{
143
+	public function addKeyword($tag)
144
+	{
144 145
 		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
146
-			return false;
146
+		if (in_array($tag, $tags)  || $tag == "") {
147
+					return false;
148
+		}
147 149
 
148 150
 		$tags[] = $tag;
149 151
 		$tags = CJSON::encode($tags);
@@ -164,11 +166,12 @@  discard block
 block discarded – undo
164 166
 	 * @param string $tag	The tag to remove
165 167
 	 * @return bool			If the removal was successful
166 168
 	 */
167
-	public function removeKeyword($tag)
168
-	{
169
+	public function removeKeyword($tag)
170
+	{
169 171
 		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
171
-			return false;
172
+		if (!in_array($tag, $tags) || $tag == "") {
173
+					return false;
174
+		}
172 175
 
173 176
 		$key = array_search($tag, $tags);
174 177
 		unset($tags[$key]);
@@ -182,8 +185,8 @@  discard block
 block discarded – undo
182 185
 	/**
183 186
 	 * Verifies the slug before validating the model
184 187
 	 */
185
-	public function beforeValidate()
186
-	{
188
+	public function beforeValidate()
189
+	{
187 190
 		$this->slug = $this->verifySlug($this->slug, $this->name);
188 191
 
189 192
 		return parent::beforeValidate();
@@ -192,11 +195,12 @@  discard block
 block discarded – undo
192 195
 	/**
193 196
 	 * Flushes URL data from the cache before the model is updated
194 197
 	 */
195
-	public function afterSave()
196
-	{
198
+	public function afterSave()
199
+	{
197 200
 		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
-		if ($meta == NULL)
199
-			$meta = new CategoriesMetadata;
201
+		if ($meta == NULL) {
202
+					$meta = new CategoriesMetadata;
203
+		}
200 204
 
201 205
 		$meta->category_id = $this->id;
202 206
 		$meta->key = 'description';
@@ -216,8 +220,8 @@  discard block
 block discarded – undo
216 220
 	 * is deleted.
217 221
 	 * @return boolean
218 222
 	 */
219
-	public function beforeDelete()
220
-	{
223
+	public function beforeDelete()
224
+	{
221 225
 		// Prevents the main "uncategorized category from being deleted"
222 226
 		if ($this->id == 1)
223 227
 		{
@@ -260,8 +264,8 @@  discard block
 block discarded – undo
260 264
 	 * @param  int $id
261 265
 	 * @return array
262 266
 	 */
263
-	public function getParentCategories($id)
264
-	{
267
+	public function getParentCategories($id)
268
+	{
265 269
 		// Retrieve the data from cache if necessary
266 270
 		$response = Yii::app()->cache->get('categories-pid');
267 271
 		if ($response == NULL)
@@ -279,10 +283,11 @@  discard block
 block discarded – undo
279 283
 	 * @param  array  $stack A stack to hold the entire tree
280 284
 	 * @return array
281 285
 	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
283
-	{
284
-		if ($id == 1)
285
-			return array_reverse($stack);
286
+	private function _getParentCategories($all_categories, $id, array $stack = array())
287
+	{
288
+		if ($id == 1) {
289
+					return array_reverse($stack);
290
+		}
286 291
 
287 292
 		foreach ($all_categories as $k=>$v)
288 293
 		{
@@ -301,8 +306,8 @@  discard block
 block discarded – undo
301 306
 	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302 307
 	 * @return string $slug - the final slug to be used
303 308
 	 */
304
-	public function checkSlug($slug, $id=NULL)
305
-	{
309
+	public function checkSlug($slug, $id=NULL)
310
+	{
306 311
 		$content = false;
307 312
 
308 313
 		// Find the number of items that have the same slug as this one
@@ -318,20 +323,23 @@  discard block
 block discarded – undo
318 323
 		// in which case we don't need to alter the slug
319 324
 		if ($count >= 1)
320 325
 		{
321
-			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
326
+			if ($content) {
327
+							return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
328
+			}
323 329
 
324 330
 			// Pull the data that matches
325 331
 			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326 332
 
327 333
 			// Check the pulled data id to the current item
328
-			if ($data !== NULL && $data->id == $this->id)
329
-				return $slug;
334
+			if ($data !== NULL && $data->id == $this->id) {
335
+							return $slug;
336
+			}
330 337
 		}
331 338
 
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
-			return $slug . $id;
334
-		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
339
+		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) {
340
+					return $slug . $id;
341
+		} else {
342
+					return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
343
+		}
336 344
 	}
337 345
 }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@  discard block
 block discarded – undo
30 30
 	 * @param string $className active record class name.
31 31
 	 * @return Categories the static model class
32 32
 	 */
33
-	public static function model($className=__CLASS__)
33
+	public static function model ($className = __CLASS__)
34 34
 	{
35
-		return parent::model($className);
35
+		return parent::model ($className);
36 36
 	}
37 37
 
38 38
 	/**
39 39
 	 * @return string the associated database table name
40 40
 	 */
41
-	public function tableName()
41
+	public function tableName ()
42 42
 	{
43 43
 		return 'categories';
44 44
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	/**
47 47
 	 * @return array validation rules for model attributes.
48 48
 	 */
49
-	public function rules()
49
+	public function rules ()
50 50
 	{
51 51
 		// NOTE: you should only define rules for those attributes that
52 52
 		// will receive user inputs.
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @return array relational rules.
65 65
 	 */
66
-	public function relations()
66
+	public function relations ()
67 67
 	{
68 68
 		// NOTE: you may need to adjust the relation name and the related
69 69
 		// class name for the relations automatically generated below.
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 * @return array customized attribute labels (name=>label)
79 79
 	 */
80
-	public function attributeLabels()
80
+	public function attributeLabels ()
81 81
 	{
82 82
 		return array(
83
-			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
-			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
-			'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
-			'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
-			'description' => Yii::t('ciims.models.Categories', 'Description'),
88
-			'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
-			'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
83
+			'id' 		=> Yii::t ('ciims.models.Categories', 'ID'),
84
+			'parent_id' => Yii::t ('ciims.models.Categories', 'Parent'),
85
+			'name'      => Yii::t ('ciims.models.Categories', 'Name'),
86
+			'slug'      => Yii::t ('ciims.models.Categories', 'Slug'),
87
+			'description' => Yii::t ('ciims.models.Categories', 'Description'),
88
+			'created'   => Yii::t ('ciims.models.Categories', 'Created'),
89
+			'updated'   => Yii::t ('ciims.models.Categories', 'Updated'),
90 90
 		);
91 91
 	}
92 92
 
93
-	public function getDescription()
93
+	public function getDescription ()
94 94
 	{
95
-		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
95
+		$this->description = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'description'));
96 96
 		if ($this->description == null || $this->description == false)
97 97
 			return NULL;
98 98
 
@@ -104,19 +104,19 @@  discard block
 block discarded – undo
104 104
 	 * Retrieves a list of models based on the current search/filter conditions.
105 105
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106 106
 	 */
107
-	public function search()
107
+	public function search ()
108 108
 	{
109
-		$criteria=new CDbCriteria;
110
-
111
-		$criteria->compare('id',$this->id);
112
-		$criteria->compare('parent_id',$this->parent_id);
113
-		$criteria->compare('name',$this->name,true);
114
-		$criteria->compare('slug',$this->slug,true);
115
-		$criteria->compare('created',$this->created,true);
116
-		$criteria->compare('updated',$this->updated,true);
109
+		$criteria = new CDbCriteria;
110
+
111
+		$criteria->compare ('id', $this->id);
112
+		$criteria->compare ('parent_id', $this->parent_id);
113
+		$criteria->compare ('name', $this->name, true);
114
+		$criteria->compare ('slug', $this->slug, true);
115
+		$criteria->compare ('created', $this->created, true);
116
+		$criteria->compare ('updated', $this->updated, true);
117 117
 		$criteria->order = "id DESC";
118 118
 
119
-		return new CActiveDataProvider($this, array(
119
+		return new CActiveDataProvider ($this, array(
120 120
 			'criteria' => $criteria,
121 121
 			'pagination' => array(
122 122
 				'pageSize' => $this->pageSize
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 	 * Gets keyword tags for this entry
129 129
 	 * @return array
130 130
 	 */
131
-	public function getKeywords()
131
+	public function getKeywords ()
132 132
 	{
133
-		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
-		return $tags === NULL ? array() : CJSON::decode($tags->value);
133
+		$tags = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'keywords'));
134
+		return $tags === NULL ? array() : CJSON::decode ($tags->value);
135 135
 	}
136 136
 
137 137
 	/**
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 	 * @param string $tag	The tag to add
140 140
 	 * @return bool			If the insert was successful or not
141 141
 	 */
142
-	public function addKeyword($tag)
142
+	public function addKeyword ($tag)
143 143
 	{
144 144
 		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
145
+		if (in_array ($tag, $tags) || $tag == "")
146 146
 			return false;
147 147
 
148 148
 		$tags[] = $tag;
149
-		$tags = CJSON::encode($tags);
150
-		$metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
149
+		$tags = CJSON::encode ($tags);
150
+		$metaTag = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'keywords'));
151 151
 		if ($metaTag == false || $metaTag == NULL)
152 152
 		{
153 153
 			$metaTag = new CategoriestMetadata;
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		}
157 157
 
158 158
 		$metaTag->value = $tags;
159
-		return $metaTag->save();
159
+		return $metaTag->save ();
160 160
 	}
161 161
 
162 162
 	/**
@@ -164,51 +164,51 @@  discard block
 block discarded – undo
164 164
 	 * @param string $tag	The tag to remove
165 165
 	 * @return bool			If the removal was successful
166 166
 	 */
167
-	public function removeKeyword($tag)
167
+	public function removeKeyword ($tag)
168 168
 	{
169 169
 		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
170
+		if (!in_array ($tag, $tags) || $tag == "")
171 171
 			return false;
172 172
 
173
-		$key = array_search($tag, $tags);
173
+		$key = array_search ($tag, $tags);
174 174
 		unset($tags[$key]);
175
-		$tags = CJSON::encode($tags);
175
+		$tags = CJSON::encode ($tags);
176 176
 
177
-		$metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
177
+		$metaTag = CategoryMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'keywords'));
178 178
 		$metaTag->value = $tags;
179
-		return $metaTag->save();
179
+		return $metaTag->save ();
180 180
 	}
181 181
 
182 182
 	/**
183 183
 	 * Verifies the slug before validating the model
184 184
 	 */
185
-	public function beforeValidate()
185
+	public function beforeValidate ()
186 186
 	{
187
-		$this->slug = $this->verifySlug($this->slug, $this->name);
187
+		$this->slug = $this->verifySlug ($this->slug, $this->name);
188 188
 
189
-		return parent::beforeValidate();
189
+		return parent::beforeValidate ();
190 190
 	}
191 191
 
192 192
 	/**
193 193
 	 * Flushes URL data from the cache before the model is updated
194 194
 	 */
195
-	public function afterSave()
195
+	public function afterSave ()
196 196
 	{
197
-		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
197
+		$meta = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'description'));
198 198
 		if ($meta == NULL)
199 199
 			$meta = new CategoriesMetadata;
200 200
 
201 201
 		$meta->category_id = $this->id;
202 202
 		$meta->key = 'description';
203
-		$meta->value  = $this->description;
203
+		$meta->value = $this->description;
204 204
 
205
-		$meta->save();
205
+		$meta->save ();
206 206
 
207
-		Yii::app()->cache->delete('CiiMS::Content::list');
208
-		Yii::app()->cache->delete('CiiMS::Routes');
209
-		Yii::app()->cache->delete('categories-pid');
207
+		Yii::app ()->cache->delete ('CiiMS::Content::list');
208
+		Yii::app ()->cache->delete ('CiiMS::Routes');
209
+		Yii::app ()->cache->delete ('categories-pid');
210 210
 
211
-		return parent::afterSave();
211
+		return parent::afterSave ();
212 212
 	}
213 213
 
214 214
 	/**
@@ -216,43 +216,43 @@  discard block
 block discarded – undo
216 216
 	 * is deleted.
217 217
 	 * @return boolean
218 218
 	 */
219
-	public function beforeDelete()
219
+	public function beforeDelete ()
220 220
 	{
221 221
 		// Prevents the main "uncategorized category from being deleted"
222 222
 		if ($this->id == 1)
223 223
 		{
224
-			Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
224
+			Yii::app ()->user->setFlash ('error', Yii::t ('ciims.models.Categories', 'This category cannot be deleted'));
225 225
 			return false;
226 226
 		}
227 227
 
228
-		Yii::app()->cache->delete('CiiMS::Content::list');
229
-		Yii::app()->cache->delete('CiiMS::Routes');
230
-		Yii::app()->cache->delete('categories-pid');
228
+		Yii::app ()->cache->delete ('CiiMS::Content::list');
229
+		Yii::app ()->cache->delete ('CiiMS::Routes');
230
+		Yii::app ()->cache->delete ('categories-pid');
231 231
 
232 232
 		$parent = $this->parent_id;
233 233
 		$id = $this->id;
234 234
 
235 235
 		// Reassign all posts to the parent category
236
-		Yii::app()->db
237
-				->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
-				->bindParam(':parent_id', $parent)
239
-				->bindParam(':id', $id)
240
-				->execute();
236
+		Yii::app ()->db
237
+				->createCommand ('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
+				->bindParam (':parent_id', $parent)
239
+				->bindParam (':id', $id)
240
+				->execute ();
241 241
 
242 242
 		// Reassign all child categories to the parent category
243
-		$data = $this->findAllByAttributes(array('parent_id' => $id));
243
+		$data = $this->findAllByAttributes (array('parent_id' => $id));
244 244
 
245 245
 		foreach ($data as $row)
246 246
 		{
247 247
 			$id = $row->id;
248
-			Yii::app()->db
249
-					->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
-					->bindParam(':parent_id', $parent)
251
-					->bindParam(':id', $id)
252
-					->execute();
248
+			Yii::app ()->db
249
+					->createCommand ('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
+					->bindParam (':parent_id', $parent)
251
+					->bindParam (':id', $id)
252
+					->execute ();
253 253
 		}
254 254
 
255
-		return parent::beforeDelete();
255
+		return parent::beforeDelete ();
256 256
 	}
257 257
 
258 258
 	/**
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
 	 * @param  int $id
261 261
 	 * @return array
262 262
 	 */
263
-	public function getParentCategories($id)
263
+	public function getParentCategories ($id)
264 264
 	{
265 265
 		// Retrieve the data from cache if necessary
266
-		$response = Yii::app()->cache->get('categories-pid');
266
+		$response = Yii::app ()->cache->get ('categories-pid');
267 267
 		if ($response == NULL)
268 268
 		{
269
-			$response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
-			Yii::app()->cache->set('categories-pid', $response);
269
+			$response = Yii::app ()->db->createCommand ('SELECT id, parent_id, name, slug FROM categories')->queryAll ();
270
+			Yii::app ()->cache->set ('categories-pid', $response);
271 271
 		}
272 272
 
273
-		return $this->_getParentCategories($response, $id);
273
+		return $this->_getParentCategories ($response, $id);
274 274
 	}
275 275
 
276 276
 	/**
@@ -279,17 +279,17 @@  discard block
 block discarded – undo
279 279
 	 * @param  array  $stack A stack to hold the entire tree
280 280
 	 * @return array
281 281
 	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
282
+	private function _getParentCategories ($all_categories, $id, array $stack = array())
283 283
 	{
284 284
 		if ($id == 1)
285
-			return array_reverse($stack);
285
+			return array_reverse ($stack);
286 286
 
287 287
 		foreach ($all_categories as $k=>$v)
288 288
 		{
289 289
 			if ($v['id'] == $id)
290 290
 			{
291
-				$stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
-				return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
291
+				$stack[$v['name']] = array(str_replace (Yii::app ()->baseUrl, NULL, Yii::app ()->createUrl ($v['slug'])));
292
+				return $this->_getParentCategories ($all_categories, $v['parent_id'], $stack);
293 293
 			}
294 294
 		}
295 295
 	}
@@ -301,17 +301,17 @@  discard block
 block discarded – undo
301 301
 	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302 302
 	 * @return string $slug - the final slug to be used
303 303
 	 */
304
-	public function checkSlug($slug, $id=NULL)
304
+	public function checkSlug ($slug, $id = NULL)
305 305
 	{
306 306
 		$content = false;
307 307
 
308 308
 		// Find the number of items that have the same slug as this one
309
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
309
+		$count = $this->countByAttributes (array('slug'=>$slug.$id));
310 310
 
311 311
 		if ($count == 0)
312 312
 		{
313 313
 			$content = true;
314
-			$count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
314
+			$count = Content::model ()->countByAttributes (array('slug'=>$slug.$id));
315 315
 		}
316 316
 
317 317
 		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
@@ -319,19 +319,19 @@  discard block
 block discarded – undo
319 319
 		if ($count >= 1)
320 320
 		{
321 321
 			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
322
+				return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1)));
323 323
 
324 324
 			// Pull the data that matches
325
-			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
325
+			$data = $this->findByPk ($this->id === NULL ? -1 : $this->id);
326 326
 
327 327
 			// Check the pulled data id to the current item
328 328
 			if ($data !== NULL && $data->id == $this->id)
329 329
 				return $slug;
330 330
 		}
331 331
 
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
-			return $slug . $id;
332
+		if ($count == 0 && !in_array ($slug, $this->forbiddenRoutes))
333
+			return $slug.$id;
334 334
 		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
335
+			return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1)));
336 336
 	}
337 337
 }
Please login to merge, or discard this patch.
protected/models/CategoriesMetadata.php 3 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -16,83 +16,83 @@
 block discarded – undo
16 16
  */
17 17
 class CategoriesMetadata 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 CategoriesMetadata 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 CategoriesMetadata 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 'categories_metadata';
35
-	}
29
+    /**
30
+     * @return string the associated database table name
31
+     */
32
+    public function tableName()
33
+    {
34
+        return 'categories_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('category_id, key, value', 'required'),
46
-			array('category_id', 'numerical', 'integerOnly'=>true),
47
-			array('key, value', 'length', 'max'=>50),
48
-			// The following rule is used by search().
49
-			// Please remove those attributes that should not be searched.
50
-			array('id, category_id, key, value, created, updated', 'safe', 'on'=>'search'),
51
-		);
52
-	}
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('category_id, key, value', 'required'),
46
+            array('category_id', 'numerical', 'integerOnly'=>true),
47
+            array('key, value', 'length', 'max'=>50),
48
+            // The following rule is used by search().
49
+            // Please remove those attributes that should not be searched.
50
+            array('id, category_id, key, value, created, updated', 'safe', 'on'=>'search'),
51
+        );
52
+    }
53 53
 
54
-	/**
55
-	 * @return array relational rules.
56
-	 */
57
-	public function relations()
58
-	{
59
-		// NOTE: you may need to adjust the relation name and the related
60
-		// class name for the relations automatically generated below.
61
-		return array(
62
-			'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
63
-		);
64
-	}
54
+    /**
55
+     * @return array relational rules.
56
+     */
57
+    public function relations()
58
+    {
59
+        // NOTE: you may need to adjust the relation name and the related
60
+        // class name for the relations automatically generated below.
61
+        return array(
62
+            'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
63
+        );
64
+    }
65 65
 
66
-	/**
67
-	 * @return array customized attribute labels (name=>label)
68
-	 */
69
-	public function attributeLabels()
70
-	{
71
-		return array(
72
-			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
-			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
-			'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
-			'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
-			'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
77
-		);
78
-	}
66
+    /**
67
+     * @return array customized attribute labels (name=>label)
68
+     */
69
+    public function attributeLabels()
70
+    {
71
+        return array(
72
+            'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
+            'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
+            'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
+            'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
+            'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
77
+        );
78
+    }
79 79
 
80
-	/**
81
-	 * Retrieves a list of models based on the current search/filter conditions.
82
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83
-	 */
84
-	public function search()
85
-	{
86
-		$criteria=new CDbCriteria;
80
+    /**
81
+     * Retrieves a list of models based on the current search/filter conditions.
82
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83
+     */
84
+    public function search()
85
+    {
86
+        $criteria=new CDbCriteria;
87 87
 
88
-		$criteria->compare('category_id',$this->category_id);
89
-		$criteria->compare('t.key',$this->key,true);
90
-		$criteria->compare('value',$this->value,true);
91
-		$criteria->compare('created',$this->created,true);
92
-		$criteria->compare('updated',$this->updated,true);
88
+        $criteria->compare('category_id',$this->category_id);
89
+        $criteria->compare('t.key',$this->key,true);
90
+        $criteria->compare('value',$this->value,true);
91
+        $criteria->compare('created',$this->created,true);
92
+        $criteria->compare('updated',$this->updated,true);
93 93
 
94
-		return new CActiveDataProvider($this, array(
95
-			'criteria'=>$criteria,
96
-		));
97
-	}
94
+        return new CActiveDataProvider($this, array(
95
+            'criteria'=>$criteria,
96
+        ));
97
+    }
98 98
 }
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 CategoriesMetadata 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 'categories_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.
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * @return array relational rules.
56 56
 	 */
57
-	public function relations()
57
+	public function relations ()
58 58
 	{
59 59
 		// NOTE: you may need to adjust the relation name and the related
60 60
 		// class name for the relations automatically generated below.
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	/**
67 67
 	 * @return array customized attribute labels (name=>label)
68 68
 	 */
69
-	public function attributeLabels()
69
+	public function attributeLabels ()
70 70
 	{
71 71
 		return array(
72
-			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
-			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
-			'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
-			'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
-			'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
72
+			'category_id' => Yii::t ('ciims.models.CategoriesMetadata', 'Category ID'),
73
+			'key' 	      => Yii::t ('ciims.models.CategoriesMetadata', 'Key'),
74
+			'value'       => Yii::t ('ciims.models.CategoriesMetadata', 'Value'),
75
+			'created'	  => Yii::t ('ciims.models.CategoriesMetadata', 'Created'),
76
+			'updated' 	  => Yii::t ('ciims.models.CategoriesMetadata', 'Updated'),
77 77
 		);
78 78
 	}
79 79
 
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
 	 * Retrieves a list of models based on the current search/filter conditions.
82 82
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83 83
 	 */
84
-	public function search()
84
+	public function search ()
85 85
 	{
86
-		$criteria=new CDbCriteria;
86
+		$criteria = new CDbCriteria;
87 87
 
88
-		$criteria->compare('category_id',$this->category_id);
89
-		$criteria->compare('t.key',$this->key,true);
90
-		$criteria->compare('value',$this->value,true);
91
-		$criteria->compare('created',$this->created,true);
92
-		$criteria->compare('updated',$this->updated,true);
88
+		$criteria->compare ('category_id', $this->category_id);
89
+		$criteria->compare ('t.key', $this->key, true);
90
+		$criteria->compare ('value', $this->value, true);
91
+		$criteria->compare ('created', $this->created, true);
92
+		$criteria->compare ('updated', $this->updated, true);
93 93
 
94
-		return new CActiveDataProvider($this, array(
94
+		return new CActiveDataProvider ($this, array(
95 95
 			'criteria'=>$criteria,
96 96
 		));
97 97
 	}
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 Categories $category
16 16
  */
17
-class CategoriesMetadata extends CiiModel
18
-{
17
+class CategoriesMetadata 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 CategoriesMetadata 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 'categories_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(
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * @return array relational rules.
56 56
 	 */
57
-	public function relations()
58
-	{
57
+	public function relations()
58
+	{
59 59
 		// NOTE: you may need to adjust the relation name and the related
60 60
 		// class name for the relations automatically generated below.
61 61
 		return array(
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	/**
67 67
 	 * @return array customized attribute labels (name=>label)
68 68
 	 */
69
-	public function attributeLabels()
70
-	{
69
+	public function attributeLabels()
70
+	{
71 71
 		return array(
72 72
 			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73 73
 			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 	 * Retrieves a list of models based on the current search/filter conditions.
82 82
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83 83
 	 */
84
-	public function search()
85
-	{
84
+	public function search()
85
+	{
86 86
 		$criteria=new CDbCriteria;
87 87
 
88 88
 		$criteria->compare('category_id',$this->category_id);
Please login to merge, or discard this patch.
protected/models/Comments.php 3 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -19,155 +19,155 @@
 block discarded – undo
19 19
  */
20 20
 class Comments extends CiiModel
21 21
 {
22
-	/**
23
-	 * API Attribute for retrieving the counts
24
-	 * @var int
25
-	 */
26
-	public $count = 0;
27
-
28
-	/**
29
-	 * AfterSave IsNewRecord
30
-	 * @var boolean
31
-	 */
32
-	private $_isNewRecord = false;
33
-
34
-	/**
35
-	 * Returns the static model of the specified AR class.
36
-	 * @param string $className active record class name.
37
-	 * @return Comments the static model class
38
-	 */
39
-	public static function model($className=__CLASS__)
40
-	{
41
-		return parent::model($className);
42
-	}
43
-
44
-	/**
45
-	 * @return string the associated database table name
46
-	 */
47
-	public function tableName()
48
-	{
49
-		return 'comments';
50
-	}
51
-
52
-	/**
53
-	 * @return array validation rules for model attributes.
54
-	 */
55
-	public function rules()
56
-	{
57
-		// NOTE: you should only define rules for those attributes that
58
-		// will receive user inputs.
59
-		return array(
60
-			array('content_id, author_id, comment', 'required'),
61
-			array('content_id, author_id', 'numerical', 'integerOnly'=>true),
62
-			// The following rule is used by search().
63
-			array('id, content_id, author_id, comment, created, updated', 'safe', 'on'=>'search'),
64
-		);
65
-	}
66
-
67
-	/**
68
-	 * @return array relational rules.
69
-	 */
70
-	public function relations()
71
-	{
72
-		// NOTE: you may need to adjust the relation name and the related
73
-		// class name for the relations automatically generated below.
74
-		return array(
75
-			'content' => array(self::BELONGS_TO, 'Content', 'content_id'),
76
-			'author' => array(self::BELONGS_TO, 'Users', 'author_id'),
77
-		);
78
-	}
79
-
80
-	/**
81
-	 * @return array customized attribute labels (name=>label)
82
-	 */
83
-	public function attributeLabels()
84
-	{
85
-		return array(
86
-			'id'		 => Yii::t('ciims.models.Comments', 'ID'),
87
-			'content_id' => Yii::t('ciims.models.Comments', 'Content'),
88
-			'author_id'  => Yii::t('ciims.models.Comments', 'User'),
89
-			'comment' 	 => Yii::t('ciims.models.Comments', 'Comment'),
90
-			'created' 	 => Yii::t('ciims.models.Comments', 'Created'),
91
-			'updated' 	 => Yii::t('ciims.models.Comments', 'Updated'),
92
-		);
93
-	}
94
-
95
-	/**
96
-	 * Retrieves a list of models based on the current search/filter conditions.
97
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
98
-	 */
99
-	public function search()
100
-	{
101
-		$criteria=new CDbCriteria;
102
-
103
-		$criteria->compare('id',$this->id);
104
-		$criteria->compare('content_id',$this->content_id);
105
-		$criteria->compare('author_id',$this->author_id);
106
-		$criteria->compare('comment',$this->comment,true);
107
-		$criteria->compare('created',$this->created,true);
108
-		$criteria->compare('updated',$this->updated,true);
109
-
110
-		return new CActiveDataProvider($this, array(
111
-			'criteria'=>$criteria,
112
-		));
113
-	}
114
-
115
-	/**
116
-	 * Returns the API attributes for the model
117
-	 * @return array
118
-	 */
119
-	public function getApiAttributes($params = array(), $relations = false)
120
-	{
121
-		$data = parent::getApiAttributes($params, $relations);
122
-		$user = Users::model()->findByPk($this->author_id);
123
-		$attributes = $user->getApiAttributes();
124
-		$data['user'] = array(
125
-			'firstName' => $attributes['firstName'],
126
-			'lastName' => $attributes['lastName'],
127
-			'username' => $attributes['username'],
128
-		);
129
-
130
-		$content = Content::model()->findByPk($data['content_id']);
131
-		$data['content'] = array(
132
-			'id' => $data['content_id'],
133
-			'title' => $content->title,
134
-			'slug' => $content->slug
135
-		);
136
-
137
-		// If this user cannot comment without approval
138
-		if ($user->getReputation() < 100)
139
-			$data['banned_comment'] = true;
140
-
141
-		return $data;
142
-	}
143
-
144
-	/**
145
-	 * Set the created and updated records
146
-	 * @see CiiModel::beforeSave();
147
-	 */
148
-	public function beforeSave()
149
-	{
150
-		if ($this->isNewRecord)
151
-			$this->_isNewRecord = true;
152
-
153
-		if (Content::model()->findByPk($this->content_id)->commentable)
154
-			return parent::beforeSave();
155
-		else
156
-			return false;
157
-	}
158
-
159
-	/**
160
-	 * After a new comment is posted, set the reputation += 10
161
-	 * @see parent::afterSave();
162
-	 */
163
-	public function afterSave()
164
-	{
165
-		if ($this->_isNewRecord)
166
-		{
167
-			$user = Users::model()->findByPk($this->author_id);
168
-			$user->setReputation(10);
169
-		}
170
-
171
-		return parent::afterSave();
172
-	}
22
+    /**
23
+     * API Attribute for retrieving the counts
24
+     * @var int
25
+     */
26
+    public $count = 0;
27
+
28
+    /**
29
+     * AfterSave IsNewRecord
30
+     * @var boolean
31
+     */
32
+    private $_isNewRecord = false;
33
+
34
+    /**
35
+     * Returns the static model of the specified AR class.
36
+     * @param string $className active record class name.
37
+     * @return Comments the static model class
38
+     */
39
+    public static function model($className=__CLASS__)
40
+    {
41
+        return parent::model($className);
42
+    }
43
+
44
+    /**
45
+     * @return string the associated database table name
46
+     */
47
+    public function tableName()
48
+    {
49
+        return 'comments';
50
+    }
51
+
52
+    /**
53
+     * @return array validation rules for model attributes.
54
+     */
55
+    public function rules()
56
+    {
57
+        // NOTE: you should only define rules for those attributes that
58
+        // will receive user inputs.
59
+        return array(
60
+            array('content_id, author_id, comment', 'required'),
61
+            array('content_id, author_id', 'numerical', 'integerOnly'=>true),
62
+            // The following rule is used by search().
63
+            array('id, content_id, author_id, comment, created, updated', 'safe', 'on'=>'search'),
64
+        );
65
+    }
66
+
67
+    /**
68
+     * @return array relational rules.
69
+     */
70
+    public function relations()
71
+    {
72
+        // NOTE: you may need to adjust the relation name and the related
73
+        // class name for the relations automatically generated below.
74
+        return array(
75
+            'content' => array(self::BELONGS_TO, 'Content', 'content_id'),
76
+            'author' => array(self::BELONGS_TO, 'Users', 'author_id'),
77
+        );
78
+    }
79
+
80
+    /**
81
+     * @return array customized attribute labels (name=>label)
82
+     */
83
+    public function attributeLabels()
84
+    {
85
+        return array(
86
+            'id'		 => Yii::t('ciims.models.Comments', 'ID'),
87
+            'content_id' => Yii::t('ciims.models.Comments', 'Content'),
88
+            'author_id'  => Yii::t('ciims.models.Comments', 'User'),
89
+            'comment' 	 => Yii::t('ciims.models.Comments', 'Comment'),
90
+            'created' 	 => Yii::t('ciims.models.Comments', 'Created'),
91
+            'updated' 	 => Yii::t('ciims.models.Comments', 'Updated'),
92
+        );
93
+    }
94
+
95
+    /**
96
+     * Retrieves a list of models based on the current search/filter conditions.
97
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
98
+     */
99
+    public function search()
100
+    {
101
+        $criteria=new CDbCriteria;
102
+
103
+        $criteria->compare('id',$this->id);
104
+        $criteria->compare('content_id',$this->content_id);
105
+        $criteria->compare('author_id',$this->author_id);
106
+        $criteria->compare('comment',$this->comment,true);
107
+        $criteria->compare('created',$this->created,true);
108
+        $criteria->compare('updated',$this->updated,true);
109
+
110
+        return new CActiveDataProvider($this, array(
111
+            'criteria'=>$criteria,
112
+        ));
113
+    }
114
+
115
+    /**
116
+     * Returns the API attributes for the model
117
+     * @return array
118
+     */
119
+    public function getApiAttributes($params = array(), $relations = false)
120
+    {
121
+        $data = parent::getApiAttributes($params, $relations);
122
+        $user = Users::model()->findByPk($this->author_id);
123
+        $attributes = $user->getApiAttributes();
124
+        $data['user'] = array(
125
+            'firstName' => $attributes['firstName'],
126
+            'lastName' => $attributes['lastName'],
127
+            'username' => $attributes['username'],
128
+        );
129
+
130
+        $content = Content::model()->findByPk($data['content_id']);
131
+        $data['content'] = array(
132
+            'id' => $data['content_id'],
133
+            'title' => $content->title,
134
+            'slug' => $content->slug
135
+        );
136
+
137
+        // If this user cannot comment without approval
138
+        if ($user->getReputation() < 100)
139
+            $data['banned_comment'] = true;
140
+
141
+        return $data;
142
+    }
143
+
144
+    /**
145
+     * Set the created and updated records
146
+     * @see CiiModel::beforeSave();
147
+     */
148
+    public function beforeSave()
149
+    {
150
+        if ($this->isNewRecord)
151
+            $this->_isNewRecord = true;
152
+
153
+        if (Content::model()->findByPk($this->content_id)->commentable)
154
+            return parent::beforeSave();
155
+        else
156
+            return false;
157
+    }
158
+
159
+    /**
160
+     * After a new comment is posted, set the reputation += 10
161
+     * @see parent::afterSave();
162
+     */
163
+    public function afterSave()
164
+    {
165
+        if ($this->_isNewRecord)
166
+        {
167
+            $user = Users::model()->findByPk($this->author_id);
168
+            $user->setReputation(10);
169
+        }
170
+
171
+        return parent::afterSave();
172
+    }
173 173
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 	 * @param string $className active record class name.
37 37
 	 * @return Comments the static model class
38 38
 	 */
39
-	public static function model($className=__CLASS__)
39
+	public static function model ($className = __CLASS__)
40 40
 	{
41
-		return parent::model($className);
41
+		return parent::model ($className);
42 42
 	}
43 43
 
44 44
 	/**
45 45
 	 * @return string the associated database table name
46 46
 	 */
47
-	public function tableName()
47
+	public function tableName ()
48 48
 	{
49 49
 		return 'comments';
50 50
 	}
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	/**
53 53
 	 * @return array validation rules for model attributes.
54 54
 	 */
55
-	public function rules()
55
+	public function rules ()
56 56
 	{
57 57
 		// NOTE: you should only define rules for those attributes that
58 58
 		// will receive user inputs.
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	/**
68 68
 	 * @return array relational rules.
69 69
 	 */
70
-	public function relations()
70
+	public function relations ()
71 71
 	{
72 72
 		// NOTE: you may need to adjust the relation name and the related
73 73
 		// class name for the relations automatically generated below.
@@ -80,15 +80,15 @@  discard block
 block discarded – undo
80 80
 	/**
81 81
 	 * @return array customized attribute labels (name=>label)
82 82
 	 */
83
-	public function attributeLabels()
83
+	public function attributeLabels ()
84 84
 	{
85 85
 		return array(
86
-			'id'		 => Yii::t('ciims.models.Comments', 'ID'),
87
-			'content_id' => Yii::t('ciims.models.Comments', 'Content'),
88
-			'author_id'  => Yii::t('ciims.models.Comments', 'User'),
89
-			'comment' 	 => Yii::t('ciims.models.Comments', 'Comment'),
90
-			'created' 	 => Yii::t('ciims.models.Comments', 'Created'),
91
-			'updated' 	 => Yii::t('ciims.models.Comments', 'Updated'),
86
+			'id'		 => Yii::t ('ciims.models.Comments', 'ID'),
87
+			'content_id' => Yii::t ('ciims.models.Comments', 'Content'),
88
+			'author_id'  => Yii::t ('ciims.models.Comments', 'User'),
89
+			'comment' 	 => Yii::t ('ciims.models.Comments', 'Comment'),
90
+			'created' 	 => Yii::t ('ciims.models.Comments', 'Created'),
91
+			'updated' 	 => Yii::t ('ciims.models.Comments', 'Updated'),
92 92
 		);
93 93
 	}
94 94
 
@@ -96,18 +96,18 @@  discard block
 block discarded – undo
96 96
 	 * Retrieves a list of models based on the current search/filter conditions.
97 97
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
98 98
 	 */
99
-	public function search()
99
+	public function search ()
100 100
 	{
101
-		$criteria=new CDbCriteria;
101
+		$criteria = new CDbCriteria;
102 102
 
103
-		$criteria->compare('id',$this->id);
104
-		$criteria->compare('content_id',$this->content_id);
105
-		$criteria->compare('author_id',$this->author_id);
106
-		$criteria->compare('comment',$this->comment,true);
107
-		$criteria->compare('created',$this->created,true);
108
-		$criteria->compare('updated',$this->updated,true);
103
+		$criteria->compare ('id', $this->id);
104
+		$criteria->compare ('content_id', $this->content_id);
105
+		$criteria->compare ('author_id', $this->author_id);
106
+		$criteria->compare ('comment', $this->comment, true);
107
+		$criteria->compare ('created', $this->created, true);
108
+		$criteria->compare ('updated', $this->updated, true);
109 109
 
110
-		return new CActiveDataProvider($this, array(
110
+		return new CActiveDataProvider ($this, array(
111 111
 			'criteria'=>$criteria,
112 112
 		));
113 113
 	}
@@ -116,18 +116,18 @@  discard block
 block discarded – undo
116 116
 	 * Returns the API attributes for the model
117 117
 	 * @return array
118 118
 	 */
119
-	public function getApiAttributes($params = array(), $relations = false)
119
+	public function getApiAttributes ($params = array(), $relations = false)
120 120
 	{
121
-		$data = parent::getApiAttributes($params, $relations);
122
-		$user = Users::model()->findByPk($this->author_id);
123
-		$attributes = $user->getApiAttributes();
121
+		$data = parent::getApiAttributes ($params, $relations);
122
+		$user = Users::model ()->findByPk ($this->author_id);
123
+		$attributes = $user->getApiAttributes ();
124 124
 		$data['user'] = array(
125 125
 			'firstName' => $attributes['firstName'],
126 126
 			'lastName' => $attributes['lastName'],
127 127
 			'username' => $attributes['username'],
128 128
 		);
129 129
 
130
-		$content = Content::model()->findByPk($data['content_id']);
130
+		$content = Content::model ()->findByPk ($data['content_id']);
131 131
 		$data['content'] = array(
132 132
 			'id' => $data['content_id'],
133 133
 			'title' => $content->title,
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		);
136 136
 
137 137
 		// If this user cannot comment without approval
138
-		if ($user->getReputation() < 100)
138
+		if ($user->getReputation () < 100)
139 139
 			$data['banned_comment'] = true;
140 140
 
141 141
 		return $data;
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 	 * Set the created and updated records
146 146
 	 * @see CiiModel::beforeSave();
147 147
 	 */
148
-	public function beforeSave()
148
+	public function beforeSave ()
149 149
 	{
150 150
 		if ($this->isNewRecord)
151 151
 			$this->_isNewRecord = true;
152 152
 
153
-		if (Content::model()->findByPk($this->content_id)->commentable)
154
-			return parent::beforeSave();
153
+		if (Content::model ()->findByPk ($this->content_id)->commentable)
154
+			return parent::beforeSave ();
155 155
 		else
156 156
 			return false;
157 157
 	}
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 	 * After a new comment is posted, set the reputation += 10
161 161
 	 * @see parent::afterSave();
162 162
 	 */
163
-	public function afterSave()
163
+	public function afterSave ()
164 164
 	{
165 165
 		if ($this->_isNewRecord)
166 166
 		{
167
-			$user = Users::model()->findByPk($this->author_id);
168
-			$user->setReputation(10);
167
+			$user = Users::model ()->findByPk ($this->author_id);
168
+			$user->setReputation (10);
169 169
 		}
170 170
 
171
-		return parent::afterSave();
171
+		return parent::afterSave ();
172 172
 	}
173 173
 }
Please login to merge, or discard this patch.
Braces   +32 added lines, -29 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
  * @property Content $content
18 18
  * @property Users $user
19 19
  */
20
-class Comments extends CiiModel
21
-{
20
+class Comments extends CiiModel
21
+{
22 22
 	/**
23 23
 	 * API Attribute for retrieving the counts
24 24
 	 * @var int
@@ -36,24 +36,24 @@  discard block
 block discarded – undo
36 36
 	 * @param string $className active record class name.
37 37
 	 * @return Comments the static model class
38 38
 	 */
39
-	public static function model($className=__CLASS__)
40
-	{
39
+	public static function model($className=__CLASS__)
40
+	{
41 41
 		return parent::model($className);
42 42
 	}
43 43
 
44 44
 	/**
45 45
 	 * @return string the associated database table name
46 46
 	 */
47
-	public function tableName()
48
-	{
47
+	public function tableName()
48
+	{
49 49
 		return 'comments';
50 50
 	}
51 51
 
52 52
 	/**
53 53
 	 * @return array validation rules for model attributes.
54 54
 	 */
55
-	public function rules()
56
-	{
55
+	public function rules()
56
+	{
57 57
 		// NOTE: you should only define rules for those attributes that
58 58
 		// will receive user inputs.
59 59
 		return array(
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 	/**
68 68
 	 * @return array relational rules.
69 69
 	 */
70
-	public function relations()
71
-	{
70
+	public function relations()
71
+	{
72 72
 		// NOTE: you may need to adjust the relation name and the related
73 73
 		// class name for the relations automatically generated below.
74 74
 		return array(
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 	/**
81 81
 	 * @return array customized attribute labels (name=>label)
82 82
 	 */
83
-	public function attributeLabels()
84
-	{
83
+	public function attributeLabels()
84
+	{
85 85
 		return array(
86 86
 			'id'		 => Yii::t('ciims.models.Comments', 'ID'),
87 87
 			'content_id' => Yii::t('ciims.models.Comments', 'Content'),
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	 * Retrieves a list of models based on the current search/filter conditions.
97 97
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
98 98
 	 */
99
-	public function search()
100
-	{
99
+	public function search()
100
+	{
101 101
 		$criteria=new CDbCriteria;
102 102
 
103 103
 		$criteria->compare('id',$this->id);
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 	 * Returns the API attributes for the model
117 117
 	 * @return array
118 118
 	 */
119
-	public function getApiAttributes($params = array(), $relations = false)
120
-	{
119
+	public function getApiAttributes($params = array(), $relations = false)
120
+	{
121 121
 		$data = parent::getApiAttributes($params, $relations);
122 122
 		$user = Users::model()->findByPk($this->author_id);
123 123
 		$attributes = $user->getApiAttributes();
@@ -135,8 +135,9 @@  discard block
 block discarded – undo
135 135
 		);
136 136
 
137 137
 		// If this user cannot comment without approval
138
-		if ($user->getReputation() < 100)
139
-			$data['banned_comment'] = true;
138
+		if ($user->getReputation() < 100) {
139
+					$data['banned_comment'] = true;
140
+		}
140 141
 
141 142
 		return $data;
142 143
 	}
@@ -145,23 +146,25 @@  discard block
 block discarded – undo
145 146
 	 * Set the created and updated records
146 147
 	 * @see CiiModel::beforeSave();
147 148
 	 */
148
-	public function beforeSave()
149
-	{
150
-		if ($this->isNewRecord)
151
-			$this->_isNewRecord = true;
152
-
153
-		if (Content::model()->findByPk($this->content_id)->commentable)
154
-			return parent::beforeSave();
155
-		else
156
-			return false;
149
+	public function beforeSave()
150
+	{
151
+		if ($this->isNewRecord) {
152
+					$this->_isNewRecord = true;
153
+		}
154
+
155
+		if (Content::model()->findByPk($this->content_id)->commentable) {
156
+					return parent::beforeSave();
157
+		} else {
158
+					return false;
159
+		}
157 160
 	}
158 161
 
159 162
 	/**
160 163
 	 * After a new comment is posted, set the reputation += 10
161 164
 	 * @see parent::afterSave();
162 165
 	 */
163
-	public function afterSave()
164
-	{
166
+	public function afterSave()
167
+	{
165 168
 		if ($this->_isNewRecord)
166 169
 		{
167 170
 			$user = Users::model()->findByPk($this->author_id);
Please login to merge, or discard this patch.