@@ -28,8 +28,9 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function beforeAction($action) |
| 30 | 30 | { |
| 31 | - if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) |
|
| 32 | - $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); |
|
| 31 | + if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) { |
|
| 32 | + $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | return parent::beforeAction($action); |
| 35 | 36 | } |
@@ -43,9 +44,9 @@ discard block |
||
| 43 | 44 | |
| 44 | 45 | if($error=Yii::app()->errorHandler->error) |
| 45 | 46 | { |
| 46 | - if(Yii::app()->request->isAjaxRequest) |
|
| 47 | - echo $error['message']; |
|
| 48 | - else |
|
| 47 | + if(Yii::app()->request->isAjaxRequest) { |
|
| 48 | + echo $error['message']; |
|
| 49 | + } else |
|
| 49 | 50 | { |
| 50 | 51 | $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array( |
| 51 | 52 | '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
@@ -57,8 +58,7 @@ discard block |
||
| 57 | 58 | 'error' => $error |
| 58 | 59 | )); |
| 59 | 60 | } |
| 60 | - } |
|
| 61 | - else |
|
| 61 | + } else |
|
| 62 | 62 | { |
| 63 | 63 | $message = Yii::app()->user->getFlash('error_code'); |
| 64 | 64 | Yii::app()->user->setFlash('error_code', $message); |
@@ -123,8 +123,7 @@ discard block |
||
| 123 | 123 | $criteria->params = array( |
| 124 | 124 | ':author_id' => str_replace('user_id:', '', Cii::get($_GET, 'q', 0)) |
| 125 | 125 | ); |
| 126 | - } |
|
| 127 | - else |
|
| 126 | + } else |
|
| 128 | 127 | { |
| 129 | 128 | $param = Cii::get($_GET, 'q', 0); |
| 130 | 129 | $criteria->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))"); |
@@ -171,8 +170,9 @@ discard block |
||
| 171 | 170 | if (Cii::get($_POST, 'LoginForm', false)) |
| 172 | 171 | { |
| 173 | 172 | $model->attributes = Cii::get($_POST, 'LoginForm', array()); |
| 174 | - if ($model->login()) |
|
| 175 | - $this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl); |
|
| 173 | + if ($model->login()) { |
|
| 174 | + $this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl); |
|
| 175 | + } |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $this->render('login', array( |
@@ -185,16 +185,18 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | public function actionLogout() |
| 187 | 187 | { |
| 188 | - if (Yii::app()->request->getParam('next', false)) |
|
| 189 | - $redirect = $this->createUrl('site/login', array('next' => $this->_getNext())); |
|
| 190 | - else |
|
| 191 | - $redirect = Yii::app()->user->returnUrl; |
|
| 188 | + if (Yii::app()->request->getParam('next', false)) { |
|
| 189 | + $redirect = $this->createUrl('site/login', array('next' => $this->_getNext())); |
|
| 190 | + } else { |
|
| 191 | + $redirect = Yii::app()->user->returnUrl; |
|
| 192 | + } |
|
| 192 | 193 | |
| 193 | 194 | // Purge the active sessions API Key |
| 194 | 195 | $apiKey = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'api_key')); |
| 195 | 196 | |
| 196 | - if ($apiKey != NULL) |
|
| 197 | - $apiKey->delete(); |
|
| 197 | + if ($apiKey != NULL) { |
|
| 198 | + $apiKey->delete(); |
|
| 199 | + } |
|
| 198 | 200 | |
| 199 | 201 | |
| 200 | 202 | Yii::app()->user->logout(); |
@@ -247,8 +249,9 @@ discard block |
||
| 247 | 249 | $model = new PasswordResetForm; |
| 248 | 250 | $model->reset_key = $id; |
| 249 | 251 | |
| 250 | - if (!$model->validateResetKey()) |
|
| 251 | - throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid')); |
|
| 252 | + if (!$model->validateResetKey()) { |
|
| 253 | + throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid')); |
|
| 254 | + } |
|
| 252 | 255 | |
| 253 | 256 | if (Cii::get($_POST, 'PasswordResetForm', false)) |
| 254 | 257 | { |
@@ -283,8 +286,9 @@ discard block |
||
| 283 | 286 | $model->setUser(Users::model()->findByPk(Yii::app()->user->id)); |
| 284 | 287 | $model->verificationKey = $key; |
| 285 | 288 | |
| 286 | - if (!$model->validateVerificationKey()) |
|
| 287 | - throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.')); |
|
| 289 | + if (!$model->validateVerificationKey()) { |
|
| 290 | + throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.')); |
|
| 291 | + } |
|
| 288 | 292 | |
| 289 | 293 | if (Cii::get($_POST, 'EmailChangeForm', false)) |
| 290 | 294 | { |
@@ -300,8 +304,9 @@ discard block |
||
| 300 | 304 | 'password' => $model->password, |
| 301 | 305 | ); |
| 302 | 306 | |
| 303 | - if ($loginForm->login()) |
|
| 304 | - return $this->redirect(Yii::app()->homeUrl); |
|
| 307 | + if ($loginForm->login()) { |
|
| 308 | + return $this->redirect(Yii::app()->homeUrl); |
|
| 309 | + } |
|
| 305 | 310 | |
| 306 | 311 | throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'Unable to re-authenticated user.')); |
| 307 | 312 | } |
@@ -328,8 +333,9 @@ discard block |
||
| 328 | 333 | $model = new ActivationForm; |
| 329 | 334 | $model->activationKey = $id; |
| 330 | 335 | |
| 331 | - if (!$model->validateKey()) |
|
| 332 | - throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
| 336 | + if (!$model->validateKey()) { |
|
| 337 | + throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
| 338 | + } |
|
| 333 | 339 | |
| 334 | 340 | if (Cii::get($_POST, 'ActivationForm', false)) |
| 335 | 341 | { |
@@ -392,13 +398,15 @@ discard block |
||
| 392 | 398 | '{{label}}' => Yii::t('ciims.controllers.Site', 'Accept Invitation') |
| 393 | 399 | ))); |
| 394 | 400 | |
| 395 | - if ($id === NULL) |
|
| 396 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 401 | + if ($id === NULL) { |
|
| 402 | + throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 403 | + } |
|
| 397 | 404 | |
| 398 | 405 | // Make sure we have a user first |
| 399 | 406 | $meta = UserMetadata::model()->findByAttributes(array('key' => 'invitationKey', 'value' => $id)); |
| 400 | - if ($meta === NULL) |
|
| 401 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 407 | + if ($meta === NULL) { |
|
| 408 | + throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 409 | + } |
|
| 402 | 410 | |
| 403 | 411 | $model = new InviteForm; |
| 404 | 412 | $model->email = Users::model()->findByPk($meta->user_id)->email; |
@@ -2,430 +2,430 @@ |
||
| 2 | 2 | |
| 3 | 3 | class SiteController extends CiiController |
| 4 | 4 | { |
| 5 | - public function filters() |
|
| 6 | - { |
|
| 7 | - return CMap::mergeArray(parent::filters(), array('accessControl')); |
|
| 8 | - } |
|
| 9 | - |
|
| 10 | - /** |
|
| 11 | - * Setup access controls to prevent guests from changing their emaila ddress |
|
| 12 | - */ |
|
| 13 | - public function accessRules() |
|
| 14 | - { |
|
| 15 | - return array( |
|
| 16 | - array('deny', // The user mut be authenticated to approve an email address change |
|
| 17 | - 'users'=>array('*'), |
|
| 18 | - 'expression'=>'Yii::app()->user->isGuest==true', |
|
| 19 | - 'actions' => array('emailchange') |
|
| 20 | - ) |
|
| 21 | - ); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * beforeAction method, performs operations before an action is presented |
|
| 26 | - * @param $action, the action being called |
|
| 27 | - * @see http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail |
|
| 28 | - */ |
|
| 29 | - public function beforeAction($action) |
|
| 30 | - { |
|
| 31 | - if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) |
|
| 32 | - $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); |
|
| 33 | - |
|
| 34 | - return parent::beforeAction($action); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * This is the action to handle external exceptions. |
|
| 39 | - */ |
|
| 40 | - public function actionError($code=NULL) |
|
| 41 | - { |
|
| 42 | - $this->layout = '//layouts/main'; |
|
| 43 | - |
|
| 44 | - if($error=Yii::app()->errorHandler->error) |
|
| 45 | - { |
|
| 46 | - if(Yii::app()->request->isAjaxRequest) |
|
| 47 | - echo $error['message']; |
|
| 48 | - else |
|
| 49 | - { |
|
| 50 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array( |
|
| 51 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 52 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Error'), |
|
| 53 | - '{{code}}' => $error['code'] |
|
| 54 | - ))); |
|
| 55 | - |
|
| 56 | - $this->render('error', array( |
|
| 57 | - 'error' => $error |
|
| 58 | - )); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - else |
|
| 62 | - { |
|
| 63 | - $message = Yii::app()->user->getFlash('error_code'); |
|
| 64 | - Yii::app()->user->setFlash('error_code', $message); |
|
| 65 | - throw new CHttpException($code, $message); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Provides basic sitemap functionality via XML |
|
| 71 | - */ |
|
| 72 | - public function actionSitemap() |
|
| 73 | - { |
|
| 74 | - ob_end_clean(); |
|
| 75 | - Yii::app()->log->routes[0]->enabled = false; |
|
| 76 | - header('Content-type: text/xml; charset=utf-8'); |
|
| 77 | - $url = Yii::app()->getBaseUrl(true); |
|
| 78 | - $this->setLayout(null); |
|
| 79 | - $content = Yii::app()->db |
|
| 80 | - ->createCommand('SELECT slug, password, type_id, updated FROM content AS t WHERE vid=(SELECT MAX(vid) FROM content WHERE id=t.id) AND status = 1 AND published <= UTC_TIMESTAMP();') |
|
| 81 | - ->queryAll(); |
|
| 82 | - |
|
| 83 | - $categories = Yii::app()->db |
|
| 84 | - ->createCommand('SELECT slug, updated FROM categories;') |
|
| 85 | - ->queryAll(); |
|
| 86 | - |
|
| 87 | - $this->renderPartial('sitemap', array( |
|
| 88 | - 'content' => $content, |
|
| 89 | - 'categories' => $categories, |
|
| 90 | - 'url' => $url |
|
| 91 | - )); |
|
| 92 | - |
|
| 93 | - Yii::app()->end(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Provides basic searching functionality |
|
| 98 | - * @param int $id The search pagination id |
|
| 99 | - */ |
|
| 100 | - public function actionSearch($id=1) |
|
| 101 | - { |
|
| 102 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 103 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 104 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Search') |
|
| 105 | - ))); |
|
| 106 | - |
|
| 107 | - $this->layout = '//layouts/default'; |
|
| 108 | - $data = array(); |
|
| 109 | - $pages = array(); |
|
| 110 | - $itemCount = 0; |
|
| 111 | - $pageSize = Cii::getConfig('searchPaginationSize', 10); |
|
| 112 | - |
|
| 113 | - if (Cii::get($_GET, 'q', false)) |
|
| 114 | - { |
|
| 115 | - $criteria = new CDbCriteria; |
|
| 116 | - $criteria->addCondition('status = 1') |
|
| 117 | - ->addCondition('published <= UTC_TIMESTAMP()'); |
|
| 118 | - |
|
| 119 | - if (strpos($_GET['q'], 'user_id') !== false) |
|
| 120 | - { |
|
| 121 | - $criteria->addCondition('author_id = :author_id') |
|
| 122 | - ->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id)"); |
|
| 123 | - $criteria->params = array( |
|
| 124 | - ':author_id' => str_replace('user_id:', '', Cii::get($_GET, 'q', 0)) |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - else |
|
| 128 | - { |
|
| 129 | - $param = Cii::get($_GET, 'q', 0); |
|
| 130 | - $criteria->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))"); |
|
| 131 | - $criteria->params = array( |
|
| 132 | - ':param' => '%' . $param . '%', |
|
| 133 | - ':param2' => '%' . $param . '%' |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $criteria->addCondition('password = ""'); |
|
| 138 | - $criteria->limit = $pageSize; |
|
| 139 | - $criteria->order = 'id DESC'; |
|
| 140 | - $itemCount = Content::model()->count($criteria); |
|
| 141 | - $pages = new CPagination($itemCount); |
|
| 142 | - $pages->pageSize=$pageSize; |
|
| 143 | - |
|
| 144 | - $criteria->offset = $criteria->limit*($pages->getCurrentPage()); |
|
| 145 | - $data = Content::model()->findAll($criteria); |
|
| 146 | - $pages->applyLimit($criteria); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $this->render('search', array( |
|
| 150 | - 'url' => 'search', |
|
| 151 | - 'id' => $id, |
|
| 152 | - 'data' => $data, |
|
| 153 | - 'itemCount' => $itemCount, |
|
| 154 | - 'pages' => $pages |
|
| 155 | - )); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Provides functionality to log a user into the system |
|
| 160 | - */ |
|
| 161 | - public function actionLogin() |
|
| 162 | - { |
|
| 163 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 164 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 165 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Login to your account') |
|
| 166 | - ))); |
|
| 167 | - |
|
| 168 | - $this->layout = '//layouts/main'; |
|
| 169 | - $model = new LoginForm; |
|
| 170 | - |
|
| 171 | - if (Cii::get($_POST, 'LoginForm', false)) |
|
| 172 | - { |
|
| 173 | - $model->attributes = Cii::get($_POST, 'LoginForm', array()); |
|
| 174 | - if ($model->login()) |
|
| 175 | - $this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $this->render('login', array( |
|
| 179 | - 'model' => $model |
|
| 180 | - )); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Provides functionality to log a user out |
|
| 185 | - */ |
|
| 186 | - public function actionLogout() |
|
| 187 | - { |
|
| 188 | - if (Yii::app()->request->getParam('next', false)) |
|
| 189 | - $redirect = $this->createUrl('site/login', array('next' => $this->_getNext())); |
|
| 190 | - else |
|
| 191 | - $redirect = Yii::app()->user->returnUrl; |
|
| 192 | - |
|
| 193 | - // Purge the active sessions API Key |
|
| 194 | - $apiKey = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'api_key')); |
|
| 195 | - |
|
| 196 | - if ($apiKey != NULL) |
|
| 197 | - $apiKey->delete(); |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - Yii::app()->user->logout(); |
|
| 201 | - $this->redirect($redirect); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Handles resetting a users password should they forgot it |
|
| 206 | - */ |
|
| 207 | - public function actionForgot() |
|
| 208 | - { |
|
| 209 | - $this->layout = '//layouts/main'; |
|
| 210 | - |
|
| 211 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 212 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 213 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Forgot Your Password?') |
|
| 214 | - ))); |
|
| 215 | - |
|
| 216 | - $model = new ForgotForm; |
|
| 217 | - |
|
| 218 | - if (Cii::get($_POST, 'ForgotForm', false)) |
|
| 219 | - { |
|
| 220 | - $model->attributes = $_POST['ForgotForm']; |
|
| 221 | - |
|
| 222 | - if ($model->initPasswordResetProcess()) |
|
| 223 | - { |
|
| 224 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'A password reset link has been sent to your email address')); |
|
| 225 | - $this->redirect($this->createUrl('site/login')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $this->render('forgot', array( |
|
| 230 | - 'model' => $model |
|
| 231 | - )); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Alows a user to reset their password if they initiated a forgot password request |
|
| 236 | - * @param string $id |
|
| 237 | - */ |
|
| 238 | - public function actionResetPassword($id=NULL) |
|
| 239 | - { |
|
| 240 | - $this->layout = '//layouts/main'; |
|
| 241 | - |
|
| 242 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 243 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 244 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Reset Your password') |
|
| 245 | - ))); |
|
| 246 | - |
|
| 247 | - $model = new PasswordResetForm; |
|
| 248 | - $model->reset_key = $id; |
|
| 249 | - |
|
| 250 | - if (!$model->validateResetKey()) |
|
| 251 | - throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid')); |
|
| 252 | - |
|
| 253 | - if (Cii::get($_POST, 'PasswordResetForm', false)) |
|
| 254 | - { |
|
| 255 | - $model->attributes = $_POST['PasswordResetForm']; |
|
| 256 | - |
|
| 257 | - if ($model->save()) |
|
| 258 | - { |
|
| 259 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your password has been reset, and you may now login with your new password')); |
|
| 260 | - $this->redirect($this->createUrl('site/login')); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $this->render('resetpassword', array( |
|
| 265 | - 'model' => $model |
|
| 266 | - )); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Allows the user to securely change their email address |
|
| 271 | - * @param string $key the user's secure key |
|
| 272 | - */ |
|
| 273 | - public function actionEmailChange($key=null) |
|
| 274 | - { |
|
| 275 | - $this->layout = '//layouts/main'; |
|
| 276 | - |
|
| 277 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 278 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 279 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Change Your Email Address') |
|
| 280 | - ))); |
|
| 281 | - |
|
| 282 | - $model = new EmailChangeForm; |
|
| 283 | - $model->setUser(Users::model()->findByPk(Yii::app()->user->id)); |
|
| 284 | - $model->verificationKey = $key; |
|
| 285 | - |
|
| 286 | - if (!$model->validateVerificationKey()) |
|
| 287 | - throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.')); |
|
| 288 | - |
|
| 289 | - if (Cii::get($_POST, 'EmailChangeForm', false)) |
|
| 290 | - { |
|
| 291 | - $model->attributes = $_POST['EmailChangeForm']; |
|
| 292 | - |
|
| 293 | - if ($model->save()) |
|
| 294 | - { |
|
| 295 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your new email address has been verified.')); |
|
| 296 | - |
|
| 297 | - $loginForm = new LoginForm; |
|
| 298 | - $loginForm->attributes = array( |
|
| 299 | - 'username' => Users::model()->findByPk(Yii::app()->user->id)->email, |
|
| 300 | - 'password' => $model->password, |
|
| 301 | - ); |
|
| 302 | - |
|
| 303 | - if ($loginForm->login()) |
|
| 304 | - return $this->redirect(Yii::app()->homeUrl); |
|
| 305 | - |
|
| 306 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'Unable to re-authenticated user.')); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $this->render('emailchange', array( |
|
| 311 | - 'model' => $model |
|
| 312 | - )); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Activates a new user's account |
|
| 317 | - * @param mixed $id The activation key |
|
| 318 | - */ |
|
| 319 | - public function actionActivation($id=NULL) |
|
| 320 | - { |
|
| 321 | - $this->layout = '//layouts/main'; |
|
| 322 | - |
|
| 323 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 324 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 325 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Activate Your Account') |
|
| 326 | - ))); |
|
| 327 | - |
|
| 328 | - $model = new ActivationForm; |
|
| 329 | - $model->activationKey = $id; |
|
| 330 | - |
|
| 331 | - if (!$model->validateKey()) |
|
| 332 | - throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
| 333 | - |
|
| 334 | - if (Cii::get($_POST, 'ActivationForm', false)) |
|
| 335 | - { |
|
| 336 | - $model->attributes = $_POST['ActivationForm']; |
|
| 337 | - |
|
| 338 | - if ($model->save()) |
|
| 339 | - { |
|
| 340 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your account has successfully been activated. You may now login')); |
|
| 341 | - $this->redirect($this->createUrl('site/login')); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - $this->render('activation', array( |
|
| 346 | - 'model' => $model |
|
| 347 | - )); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Handles the registration of new users on the site |
|
| 352 | - */ |
|
| 353 | - public function actionRegister() |
|
| 354 | - { |
|
| 355 | - $this->layout = '//layouts/main'; |
|
| 356 | - |
|
| 357 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 358 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 359 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Sign Up') |
|
| 360 | - ))); |
|
| 361 | - |
|
| 362 | - $model = new RegisterForm; |
|
| 363 | - |
|
| 364 | - if (Cii::get($_POST, 'RegisterForm', false)) |
|
| 365 | - { |
|
| 366 | - $model->attributes = $_POST['RegisterForm']; |
|
| 367 | - |
|
| 368 | - // Save the user's information |
|
| 369 | - if ($model->save()) |
|
| 370 | - { |
|
| 371 | - // Set a flash message |
|
| 372 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'You have successfully registered an account. Before you can login, please check your email for activation instructions')); |
|
| 373 | - $this->redirect($this->createUrl('site/login')); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $this->render('register', array( |
|
| 378 | - 'model'=>$model |
|
| 379 | - )); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Enables users who have recieved an invitation to setup a new account |
|
| 384 | - * @param string $id The activation id the of the user that we want to activate |
|
| 385 | - */ |
|
| 386 | - public function actionAcceptInvite($id=NULL) |
|
| 387 | - { |
|
| 388 | - $this->layout = '//layouts/main'; |
|
| 389 | - |
|
| 390 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 391 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 392 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Accept Invitation') |
|
| 393 | - ))); |
|
| 394 | - |
|
| 395 | - if ($id === NULL) |
|
| 396 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 397 | - |
|
| 398 | - // Make sure we have a user first |
|
| 399 | - $meta = UserMetadata::model()->findByAttributes(array('key' => 'invitationKey', 'value' => $id)); |
|
| 400 | - if ($meta === NULL) |
|
| 401 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 402 | - |
|
| 403 | - $model = new InviteForm; |
|
| 404 | - $model->email = Users::model()->findByPk($meta->user_id)->email; |
|
| 405 | - |
|
| 406 | - if (Cii::get($_POST, 'InviteForm', NULL) !== NULL) |
|
| 407 | - { |
|
| 408 | - $model->attributes = Cii::get($_POST, 'InviteForm', NULL); |
|
| 409 | - $model->id = $meta->user_id; |
|
| 410 | - |
|
| 411 | - if ($model->acceptInvite()) |
|
| 412 | - { |
|
| 413 | - $meta->delete(); |
|
| 414 | - return $this->render('invitesuccess'); |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - $this->render('acceptinvite', array( |
|
| 419 | - 'model' => $model |
|
| 420 | - )); |
|
| 421 | - } |
|
| 5 | + public function filters() |
|
| 6 | + { |
|
| 7 | + return CMap::mergeArray(parent::filters(), array('accessControl')); |
|
| 8 | + } |
|
| 9 | + |
|
| 10 | + /** |
|
| 11 | + * Setup access controls to prevent guests from changing their emaila ddress |
|
| 12 | + */ |
|
| 13 | + public function accessRules() |
|
| 14 | + { |
|
| 15 | + return array( |
|
| 16 | + array('deny', // The user mut be authenticated to approve an email address change |
|
| 17 | + 'users'=>array('*'), |
|
| 18 | + 'expression'=>'Yii::app()->user->isGuest==true', |
|
| 19 | + 'actions' => array('emailchange') |
|
| 20 | + ) |
|
| 21 | + ); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * beforeAction method, performs operations before an action is presented |
|
| 26 | + * @param $action, the action being called |
|
| 27 | + * @see http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail |
|
| 28 | + */ |
|
| 29 | + public function beforeAction($action) |
|
| 30 | + { |
|
| 31 | + if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) |
|
| 32 | + $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); |
|
| 33 | + |
|
| 34 | + return parent::beforeAction($action); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * This is the action to handle external exceptions. |
|
| 39 | + */ |
|
| 40 | + public function actionError($code=NULL) |
|
| 41 | + { |
|
| 42 | + $this->layout = '//layouts/main'; |
|
| 43 | + |
|
| 44 | + if($error=Yii::app()->errorHandler->error) |
|
| 45 | + { |
|
| 46 | + if(Yii::app()->request->isAjaxRequest) |
|
| 47 | + echo $error['message']; |
|
| 48 | + else |
|
| 49 | + { |
|
| 50 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array( |
|
| 51 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 52 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Error'), |
|
| 53 | + '{{code}}' => $error['code'] |
|
| 54 | + ))); |
|
| 55 | + |
|
| 56 | + $this->render('error', array( |
|
| 57 | + 'error' => $error |
|
| 58 | + )); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + else |
|
| 62 | + { |
|
| 63 | + $message = Yii::app()->user->getFlash('error_code'); |
|
| 64 | + Yii::app()->user->setFlash('error_code', $message); |
|
| 65 | + throw new CHttpException($code, $message); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Provides basic sitemap functionality via XML |
|
| 71 | + */ |
|
| 72 | + public function actionSitemap() |
|
| 73 | + { |
|
| 74 | + ob_end_clean(); |
|
| 75 | + Yii::app()->log->routes[0]->enabled = false; |
|
| 76 | + header('Content-type: text/xml; charset=utf-8'); |
|
| 77 | + $url = Yii::app()->getBaseUrl(true); |
|
| 78 | + $this->setLayout(null); |
|
| 79 | + $content = Yii::app()->db |
|
| 80 | + ->createCommand('SELECT slug, password, type_id, updated FROM content AS t WHERE vid=(SELECT MAX(vid) FROM content WHERE id=t.id) AND status = 1 AND published <= UTC_TIMESTAMP();') |
|
| 81 | + ->queryAll(); |
|
| 82 | + |
|
| 83 | + $categories = Yii::app()->db |
|
| 84 | + ->createCommand('SELECT slug, updated FROM categories;') |
|
| 85 | + ->queryAll(); |
|
| 86 | + |
|
| 87 | + $this->renderPartial('sitemap', array( |
|
| 88 | + 'content' => $content, |
|
| 89 | + 'categories' => $categories, |
|
| 90 | + 'url' => $url |
|
| 91 | + )); |
|
| 92 | + |
|
| 93 | + Yii::app()->end(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Provides basic searching functionality |
|
| 98 | + * @param int $id The search pagination id |
|
| 99 | + */ |
|
| 100 | + public function actionSearch($id=1) |
|
| 101 | + { |
|
| 102 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 103 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 104 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Search') |
|
| 105 | + ))); |
|
| 106 | + |
|
| 107 | + $this->layout = '//layouts/default'; |
|
| 108 | + $data = array(); |
|
| 109 | + $pages = array(); |
|
| 110 | + $itemCount = 0; |
|
| 111 | + $pageSize = Cii::getConfig('searchPaginationSize', 10); |
|
| 112 | + |
|
| 113 | + if (Cii::get($_GET, 'q', false)) |
|
| 114 | + { |
|
| 115 | + $criteria = new CDbCriteria; |
|
| 116 | + $criteria->addCondition('status = 1') |
|
| 117 | + ->addCondition('published <= UTC_TIMESTAMP()'); |
|
| 118 | + |
|
| 119 | + if (strpos($_GET['q'], 'user_id') !== false) |
|
| 120 | + { |
|
| 121 | + $criteria->addCondition('author_id = :author_id') |
|
| 122 | + ->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id)"); |
|
| 123 | + $criteria->params = array( |
|
| 124 | + ':author_id' => str_replace('user_id:', '', Cii::get($_GET, 'q', 0)) |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + else |
|
| 128 | + { |
|
| 129 | + $param = Cii::get($_GET, 'q', 0); |
|
| 130 | + $criteria->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))"); |
|
| 131 | + $criteria->params = array( |
|
| 132 | + ':param' => '%' . $param . '%', |
|
| 133 | + ':param2' => '%' . $param . '%' |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $criteria->addCondition('password = ""'); |
|
| 138 | + $criteria->limit = $pageSize; |
|
| 139 | + $criteria->order = 'id DESC'; |
|
| 140 | + $itemCount = Content::model()->count($criteria); |
|
| 141 | + $pages = new CPagination($itemCount); |
|
| 142 | + $pages->pageSize=$pageSize; |
|
| 143 | + |
|
| 144 | + $criteria->offset = $criteria->limit*($pages->getCurrentPage()); |
|
| 145 | + $data = Content::model()->findAll($criteria); |
|
| 146 | + $pages->applyLimit($criteria); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $this->render('search', array( |
|
| 150 | + 'url' => 'search', |
|
| 151 | + 'id' => $id, |
|
| 152 | + 'data' => $data, |
|
| 153 | + 'itemCount' => $itemCount, |
|
| 154 | + 'pages' => $pages |
|
| 155 | + )); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Provides functionality to log a user into the system |
|
| 160 | + */ |
|
| 161 | + public function actionLogin() |
|
| 162 | + { |
|
| 163 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 164 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 165 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Login to your account') |
|
| 166 | + ))); |
|
| 167 | + |
|
| 168 | + $this->layout = '//layouts/main'; |
|
| 169 | + $model = new LoginForm; |
|
| 170 | + |
|
| 171 | + if (Cii::get($_POST, 'LoginForm', false)) |
|
| 172 | + { |
|
| 173 | + $model->attributes = Cii::get($_POST, 'LoginForm', array()); |
|
| 174 | + if ($model->login()) |
|
| 175 | + $this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $this->render('login', array( |
|
| 179 | + 'model' => $model |
|
| 180 | + )); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Provides functionality to log a user out |
|
| 185 | + */ |
|
| 186 | + public function actionLogout() |
|
| 187 | + { |
|
| 188 | + if (Yii::app()->request->getParam('next', false)) |
|
| 189 | + $redirect = $this->createUrl('site/login', array('next' => $this->_getNext())); |
|
| 190 | + else |
|
| 191 | + $redirect = Yii::app()->user->returnUrl; |
|
| 192 | + |
|
| 193 | + // Purge the active sessions API Key |
|
| 194 | + $apiKey = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'api_key')); |
|
| 195 | + |
|
| 196 | + if ($apiKey != NULL) |
|
| 197 | + $apiKey->delete(); |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + Yii::app()->user->logout(); |
|
| 201 | + $this->redirect($redirect); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Handles resetting a users password should they forgot it |
|
| 206 | + */ |
|
| 207 | + public function actionForgot() |
|
| 208 | + { |
|
| 209 | + $this->layout = '//layouts/main'; |
|
| 210 | + |
|
| 211 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 212 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 213 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Forgot Your Password?') |
|
| 214 | + ))); |
|
| 215 | + |
|
| 216 | + $model = new ForgotForm; |
|
| 217 | + |
|
| 218 | + if (Cii::get($_POST, 'ForgotForm', false)) |
|
| 219 | + { |
|
| 220 | + $model->attributes = $_POST['ForgotForm']; |
|
| 221 | + |
|
| 222 | + if ($model->initPasswordResetProcess()) |
|
| 223 | + { |
|
| 224 | + Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'A password reset link has been sent to your email address')); |
|
| 225 | + $this->redirect($this->createUrl('site/login')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $this->render('forgot', array( |
|
| 230 | + 'model' => $model |
|
| 231 | + )); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Alows a user to reset their password if they initiated a forgot password request |
|
| 236 | + * @param string $id |
|
| 237 | + */ |
|
| 238 | + public function actionResetPassword($id=NULL) |
|
| 239 | + { |
|
| 240 | + $this->layout = '//layouts/main'; |
|
| 241 | + |
|
| 242 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 243 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 244 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Reset Your password') |
|
| 245 | + ))); |
|
| 246 | + |
|
| 247 | + $model = new PasswordResetForm; |
|
| 248 | + $model->reset_key = $id; |
|
| 249 | + |
|
| 250 | + if (!$model->validateResetKey()) |
|
| 251 | + throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid')); |
|
| 252 | + |
|
| 253 | + if (Cii::get($_POST, 'PasswordResetForm', false)) |
|
| 254 | + { |
|
| 255 | + $model->attributes = $_POST['PasswordResetForm']; |
|
| 256 | + |
|
| 257 | + if ($model->save()) |
|
| 258 | + { |
|
| 259 | + Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your password has been reset, and you may now login with your new password')); |
|
| 260 | + $this->redirect($this->createUrl('site/login')); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $this->render('resetpassword', array( |
|
| 265 | + 'model' => $model |
|
| 266 | + )); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Allows the user to securely change their email address |
|
| 271 | + * @param string $key the user's secure key |
|
| 272 | + */ |
|
| 273 | + public function actionEmailChange($key=null) |
|
| 274 | + { |
|
| 275 | + $this->layout = '//layouts/main'; |
|
| 276 | + |
|
| 277 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 278 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 279 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Change Your Email Address') |
|
| 280 | + ))); |
|
| 281 | + |
|
| 282 | + $model = new EmailChangeForm; |
|
| 283 | + $model->setUser(Users::model()->findByPk(Yii::app()->user->id)); |
|
| 284 | + $model->verificationKey = $key; |
|
| 285 | + |
|
| 286 | + if (!$model->validateVerificationKey()) |
|
| 287 | + throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.')); |
|
| 288 | + |
|
| 289 | + if (Cii::get($_POST, 'EmailChangeForm', false)) |
|
| 290 | + { |
|
| 291 | + $model->attributes = $_POST['EmailChangeForm']; |
|
| 292 | + |
|
| 293 | + if ($model->save()) |
|
| 294 | + { |
|
| 295 | + Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your new email address has been verified.')); |
|
| 296 | + |
|
| 297 | + $loginForm = new LoginForm; |
|
| 298 | + $loginForm->attributes = array( |
|
| 299 | + 'username' => Users::model()->findByPk(Yii::app()->user->id)->email, |
|
| 300 | + 'password' => $model->password, |
|
| 301 | + ); |
|
| 302 | + |
|
| 303 | + if ($loginForm->login()) |
|
| 304 | + return $this->redirect(Yii::app()->homeUrl); |
|
| 305 | + |
|
| 306 | + throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'Unable to re-authenticated user.')); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $this->render('emailchange', array( |
|
| 311 | + 'model' => $model |
|
| 312 | + )); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Activates a new user's account |
|
| 317 | + * @param mixed $id The activation key |
|
| 318 | + */ |
|
| 319 | + public function actionActivation($id=NULL) |
|
| 320 | + { |
|
| 321 | + $this->layout = '//layouts/main'; |
|
| 322 | + |
|
| 323 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 324 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 325 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Activate Your Account') |
|
| 326 | + ))); |
|
| 327 | + |
|
| 328 | + $model = new ActivationForm; |
|
| 329 | + $model->activationKey = $id; |
|
| 330 | + |
|
| 331 | + if (!$model->validateKey()) |
|
| 332 | + throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
| 333 | + |
|
| 334 | + if (Cii::get($_POST, 'ActivationForm', false)) |
|
| 335 | + { |
|
| 336 | + $model->attributes = $_POST['ActivationForm']; |
|
| 337 | + |
|
| 338 | + if ($model->save()) |
|
| 339 | + { |
|
| 340 | + Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your account has successfully been activated. You may now login')); |
|
| 341 | + $this->redirect($this->createUrl('site/login')); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + $this->render('activation', array( |
|
| 346 | + 'model' => $model |
|
| 347 | + )); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Handles the registration of new users on the site |
|
| 352 | + */ |
|
| 353 | + public function actionRegister() |
|
| 354 | + { |
|
| 355 | + $this->layout = '//layouts/main'; |
|
| 356 | + |
|
| 357 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 358 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 359 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Sign Up') |
|
| 360 | + ))); |
|
| 361 | + |
|
| 362 | + $model = new RegisterForm; |
|
| 363 | + |
|
| 364 | + if (Cii::get($_POST, 'RegisterForm', false)) |
|
| 365 | + { |
|
| 366 | + $model->attributes = $_POST['RegisterForm']; |
|
| 367 | + |
|
| 368 | + // Save the user's information |
|
| 369 | + if ($model->save()) |
|
| 370 | + { |
|
| 371 | + // Set a flash message |
|
| 372 | + Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'You have successfully registered an account. Before you can login, please check your email for activation instructions')); |
|
| 373 | + $this->redirect($this->createUrl('site/login')); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $this->render('register', array( |
|
| 378 | + 'model'=>$model |
|
| 379 | + )); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Enables users who have recieved an invitation to setup a new account |
|
| 384 | + * @param string $id The activation id the of the user that we want to activate |
|
| 385 | + */ |
|
| 386 | + public function actionAcceptInvite($id=NULL) |
|
| 387 | + { |
|
| 388 | + $this->layout = '//layouts/main'; |
|
| 389 | + |
|
| 390 | + $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 391 | + '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 392 | + '{{label}}' => Yii::t('ciims.controllers.Site', 'Accept Invitation') |
|
| 393 | + ))); |
|
| 394 | + |
|
| 395 | + if ($id === NULL) |
|
| 396 | + throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 397 | + |
|
| 398 | + // Make sure we have a user first |
|
| 399 | + $meta = UserMetadata::model()->findByAttributes(array('key' => 'invitationKey', 'value' => $id)); |
|
| 400 | + if ($meta === NULL) |
|
| 401 | + throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 402 | + |
|
| 403 | + $model = new InviteForm; |
|
| 404 | + $model->email = Users::model()->findByPk($meta->user_id)->email; |
|
| 405 | + |
|
| 406 | + if (Cii::get($_POST, 'InviteForm', NULL) !== NULL) |
|
| 407 | + { |
|
| 408 | + $model->attributes = Cii::get($_POST, 'InviteForm', NULL); |
|
| 409 | + $model->id = $meta->user_id; |
|
| 410 | + |
|
| 411 | + if ($model->acceptInvite()) |
|
| 412 | + { |
|
| 413 | + $meta->delete(); |
|
| 414 | + return $this->render('invitesuccess'); |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + $this->render('acceptinvite', array( |
|
| 419 | + 'model' => $model |
|
| 420 | + )); |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - /** |
|
| 424 | - * Returns a sanitized $_GET['next'] URL if it is set. |
|
| 425 | - * @return mixed |
|
| 426 | - */ |
|
| 427 | - private function _getNext() |
|
| 428 | - { |
|
| 429 | - return str_replace('ftp://', '', str_replace('http://', '', str_replace('https://', '', Yii::app()->request->getParam('next', false)))); |
|
| 430 | - } |
|
| 423 | + /** |
|
| 424 | + * Returns a sanitized $_GET['next'] URL if it is set. |
|
| 425 | + * @return mixed |
|
| 426 | + */ |
|
| 427 | + private function _getNext() |
|
| 428 | + { |
|
| 429 | + return str_replace('ftp://', '', str_replace('http://', '', str_replace('https://', '', Yii::app()->request->getParam('next', false)))); |
|
| 430 | + } |
|
| 431 | 431 | } |
@@ -2,18 +2,18 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class SiteController extends CiiController |
| 4 | 4 | { |
| 5 | - public function filters() |
|
| 5 | + public function filters () |
|
| 6 | 6 | { |
| 7 | - return CMap::mergeArray(parent::filters(), array('accessControl')); |
|
| 7 | + return CMap::mergeArray (parent::filters (), array('accessControl')); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Setup access controls to prevent guests from changing their emaila ddress |
| 12 | 12 | */ |
| 13 | - public function accessRules() |
|
| 13 | + public function accessRules () |
|
| 14 | 14 | { |
| 15 | 15 | return array( |
| 16 | - array('deny', // The user mut be authenticated to approve an email address change |
|
| 16 | + array('deny', // The user mut be authenticated to approve an email address change |
|
| 17 | 17 | 'users'=>array('*'), |
| 18 | 18 | 'expression'=>'Yii::app()->user->isGuest==true', |
| 19 | 19 | 'actions' => array('emailchange') |
@@ -26,127 +26,127 @@ discard block |
||
| 26 | 26 | * @param $action, the action being called |
| 27 | 27 | * @see http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail |
| 28 | 28 | */ |
| 29 | - public function beforeAction($action) |
|
| 29 | + public function beforeAction ($action) |
|
| 30 | 30 | { |
| 31 | - if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) |
|
| 32 | - $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); |
|
| 31 | + if (!Yii::app ()->getRequest ()->isSecureConnection && Cii::getConfig ('forceSecureSSL', false)) |
|
| 32 | + $this->redirect ('https://'.Yii::app ()->getRequest ()->serverName.Yii::app ()->getRequest ()->requestUri); |
|
| 33 | 33 | |
| 34 | - return parent::beforeAction($action); |
|
| 34 | + return parent::beforeAction ($action); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * This is the action to handle external exceptions. |
| 39 | 39 | */ |
| 40 | - public function actionError($code=NULL) |
|
| 40 | + public function actionError ($code = NULL) |
|
| 41 | 41 | { |
| 42 | 42 | $this->layout = '//layouts/main'; |
| 43 | 43 | |
| 44 | - if($error=Yii::app()->errorHandler->error) |
|
| 44 | + if ($error = Yii::app ()->errorHandler->error) |
|
| 45 | 45 | { |
| 46 | - if(Yii::app()->request->isAjaxRequest) |
|
| 46 | + if (Yii::app ()->request->isAjaxRequest) |
|
| 47 | 47 | echo $error['message']; |
| 48 | 48 | else |
| 49 | 49 | { |
| 50 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array( |
|
| 51 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 52 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Error'), |
|
| 50 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array( |
|
| 51 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 52 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Error'), |
|
| 53 | 53 | '{{code}}' => $error['code'] |
| 54 | 54 | ))); |
| 55 | 55 | |
| 56 | - $this->render('error', array( |
|
| 56 | + $this->render ('error', array( |
|
| 57 | 57 | 'error' => $error |
| 58 | 58 | )); |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | else |
| 62 | 62 | { |
| 63 | - $message = Yii::app()->user->getFlash('error_code'); |
|
| 64 | - Yii::app()->user->setFlash('error_code', $message); |
|
| 65 | - throw new CHttpException($code, $message); |
|
| 63 | + $message = Yii::app ()->user->getFlash ('error_code'); |
|
| 64 | + Yii::app ()->user->setFlash ('error_code', $message); |
|
| 65 | + throw new CHttpException ($code, $message); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Provides basic sitemap functionality via XML |
| 71 | 71 | */ |
| 72 | - public function actionSitemap() |
|
| 72 | + public function actionSitemap () |
|
| 73 | 73 | { |
| 74 | - ob_end_clean(); |
|
| 75 | - Yii::app()->log->routes[0]->enabled = false; |
|
| 76 | - header('Content-type: text/xml; charset=utf-8'); |
|
| 77 | - $url = Yii::app()->getBaseUrl(true); |
|
| 78 | - $this->setLayout(null); |
|
| 79 | - $content = Yii::app()->db |
|
| 80 | - ->createCommand('SELECT slug, password, type_id, updated FROM content AS t WHERE vid=(SELECT MAX(vid) FROM content WHERE id=t.id) AND status = 1 AND published <= UTC_TIMESTAMP();') |
|
| 81 | - ->queryAll(); |
|
| 82 | - |
|
| 83 | - $categories = Yii::app()->db |
|
| 84 | - ->createCommand('SELECT slug, updated FROM categories;') |
|
| 85 | - ->queryAll(); |
|
| 86 | - |
|
| 87 | - $this->renderPartial('sitemap', array( |
|
| 74 | + ob_end_clean (); |
|
| 75 | + Yii::app ()->log->routes[0]->enabled = false; |
|
| 76 | + header ('Content-type: text/xml; charset=utf-8'); |
|
| 77 | + $url = Yii::app ()->getBaseUrl (true); |
|
| 78 | + $this->setLayout (null); |
|
| 79 | + $content = Yii::app ()->db |
|
| 80 | + ->createCommand ('SELECT slug, password, type_id, updated FROM content AS t WHERE vid=(SELECT MAX(vid) FROM content WHERE id=t.id) AND status = 1 AND published <= UTC_TIMESTAMP();') |
|
| 81 | + ->queryAll (); |
|
| 82 | + |
|
| 83 | + $categories = Yii::app ()->db |
|
| 84 | + ->createCommand ('SELECT slug, updated FROM categories;') |
|
| 85 | + ->queryAll (); |
|
| 86 | + |
|
| 87 | + $this->renderPartial ('sitemap', array( |
|
| 88 | 88 | 'content' => $content, |
| 89 | 89 | 'categories' => $categories, |
| 90 | 90 | 'url' => $url |
| 91 | 91 | )); |
| 92 | 92 | |
| 93 | - Yii::app()->end(); |
|
| 93 | + Yii::app ()->end (); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Provides basic searching functionality |
| 98 | 98 | * @param int $id The search pagination id |
| 99 | 99 | */ |
| 100 | - public function actionSearch($id=1) |
|
| 100 | + public function actionSearch ($id = 1) |
|
| 101 | 101 | { |
| 102 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 103 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 104 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Search') |
|
| 102 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 103 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 104 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Search') |
|
| 105 | 105 | ))); |
| 106 | 106 | |
| 107 | 107 | $this->layout = '//layouts/default'; |
| 108 | 108 | $data = array(); |
| 109 | 109 | $pages = array(); |
| 110 | 110 | $itemCount = 0; |
| 111 | - $pageSize = Cii::getConfig('searchPaginationSize', 10); |
|
| 111 | + $pageSize = Cii::getConfig ('searchPaginationSize', 10); |
|
| 112 | 112 | |
| 113 | - if (Cii::get($_GET, 'q', false)) |
|
| 113 | + if (Cii::get ($_GET, 'q', false)) |
|
| 114 | 114 | { |
| 115 | 115 | $criteria = new CDbCriteria; |
| 116 | - $criteria->addCondition('status = 1') |
|
| 117 | - ->addCondition('published <= UTC_TIMESTAMP()'); |
|
| 116 | + $criteria->addCondition ('status = 1') |
|
| 117 | + ->addCondition ('published <= UTC_TIMESTAMP()'); |
|
| 118 | 118 | |
| 119 | - if (strpos($_GET['q'], 'user_id') !== false) |
|
| 119 | + if (strpos ($_GET['q'], 'user_id') !== false) |
|
| 120 | 120 | { |
| 121 | - $criteria->addCondition('author_id = :author_id') |
|
| 122 | - ->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id)"); |
|
| 121 | + $criteria->addCondition ('author_id = :author_id') |
|
| 122 | + ->addCondition ("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id)"); |
|
| 123 | 123 | $criteria->params = array( |
| 124 | - ':author_id' => str_replace('user_id:', '', Cii::get($_GET, 'q', 0)) |
|
| 124 | + ':author_id' => str_replace ('user_id:', '', Cii::get ($_GET, 'q', 0)) |
|
| 125 | 125 | ); |
| 126 | 126 | } |
| 127 | 127 | else |
| 128 | 128 | { |
| 129 | - $param = Cii::get($_GET, 'q', 0); |
|
| 130 | - $criteria->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))"); |
|
| 129 | + $param = Cii::get ($_GET, 'q', 0); |
|
| 130 | + $criteria->addCondition ("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))"); |
|
| 131 | 131 | $criteria->params = array( |
| 132 | - ':param' => '%' . $param . '%', |
|
| 133 | - ':param2' => '%' . $param . '%' |
|
| 132 | + ':param' => '%'.$param.'%', |
|
| 133 | + ':param2' => '%'.$param.'%' |
|
| 134 | 134 | ); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $criteria->addCondition('password = ""'); |
|
| 137 | + $criteria->addCondition ('password = ""'); |
|
| 138 | 138 | $criteria->limit = $pageSize; |
| 139 | 139 | $criteria->order = 'id DESC'; |
| 140 | - $itemCount = Content::model()->count($criteria); |
|
| 141 | - $pages = new CPagination($itemCount); |
|
| 142 | - $pages->pageSize=$pageSize; |
|
| 140 | + $itemCount = Content::model ()->count ($criteria); |
|
| 141 | + $pages = new CPagination ($itemCount); |
|
| 142 | + $pages->pageSize = $pageSize; |
|
| 143 | 143 | |
| 144 | - $criteria->offset = $criteria->limit*($pages->getCurrentPage()); |
|
| 145 | - $data = Content::model()->findAll($criteria); |
|
| 146 | - $pages->applyLimit($criteria); |
|
| 144 | + $criteria->offset = $criteria->limit * ($pages->getCurrentPage ()); |
|
| 145 | + $data = Content::model ()->findAll ($criteria); |
|
| 146 | + $pages->applyLimit ($criteria); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $this->render('search', array( |
|
| 149 | + $this->render ('search', array( |
|
| 150 | 150 | 'url' => 'search', |
| 151 | 151 | 'id' => $id, |
| 152 | 152 | 'data' => $data, |
@@ -158,24 +158,24 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * Provides functionality to log a user into the system |
| 160 | 160 | */ |
| 161 | - public function actionLogin() |
|
| 161 | + public function actionLogin () |
|
| 162 | 162 | { |
| 163 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 164 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 165 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Login to your account') |
|
| 163 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 164 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 165 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Login to your account') |
|
| 166 | 166 | ))); |
| 167 | 167 | |
| 168 | 168 | $this->layout = '//layouts/main'; |
| 169 | 169 | $model = new LoginForm; |
| 170 | 170 | |
| 171 | - if (Cii::get($_POST, 'LoginForm', false)) |
|
| 171 | + if (Cii::get ($_POST, 'LoginForm', false)) |
|
| 172 | 172 | { |
| 173 | - $model->attributes = Cii::get($_POST, 'LoginForm', array()); |
|
| 174 | - if ($model->login()) |
|
| 175 | - $this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl); |
|
| 173 | + $model->attributes = Cii::get ($_POST, 'LoginForm', array()); |
|
| 174 | + if ($model->login ()) |
|
| 175 | + $this->redirect ($this->_getNext () ? : Yii::app ()->user->returnUrl); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $this->render('login', array( |
|
| 178 | + $this->render ('login', array( |
|
| 179 | 179 | 'model' => $model |
| 180 | 180 | )); |
| 181 | 181 | } |
@@ -183,50 +183,50 @@ discard block |
||
| 183 | 183 | /** |
| 184 | 184 | * Provides functionality to log a user out |
| 185 | 185 | */ |
| 186 | - public function actionLogout() |
|
| 186 | + public function actionLogout () |
|
| 187 | 187 | { |
| 188 | - if (Yii::app()->request->getParam('next', false)) |
|
| 189 | - $redirect = $this->createUrl('site/login', array('next' => $this->_getNext())); |
|
| 188 | + if (Yii::app ()->request->getParam ('next', false)) |
|
| 189 | + $redirect = $this->createUrl ('site/login', array('next' => $this->_getNext ())); |
|
| 190 | 190 | else |
| 191 | - $redirect = Yii::app()->user->returnUrl; |
|
| 191 | + $redirect = Yii::app ()->user->returnUrl; |
|
| 192 | 192 | |
| 193 | 193 | // Purge the active sessions API Key |
| 194 | - $apiKey = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'api_key')); |
|
| 194 | + $apiKey = UserMetadata::model ()->findByAttributes (array('user_id' => Yii::app ()->user->id, 'key' => 'api_key')); |
|
| 195 | 195 | |
| 196 | 196 | if ($apiKey != NULL) |
| 197 | - $apiKey->delete(); |
|
| 197 | + $apiKey->delete (); |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - Yii::app()->user->logout(); |
|
| 201 | - $this->redirect($redirect); |
|
| 200 | + Yii::app ()->user->logout (); |
|
| 201 | + $this->redirect ($redirect); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Handles resetting a users password should they forgot it |
| 206 | 206 | */ |
| 207 | - public function actionForgot() |
|
| 207 | + public function actionForgot () |
|
| 208 | 208 | { |
| 209 | 209 | $this->layout = '//layouts/main'; |
| 210 | 210 | |
| 211 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 212 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 213 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Forgot Your Password?') |
|
| 211 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 212 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 213 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Forgot Your Password?') |
|
| 214 | 214 | ))); |
| 215 | 215 | |
| 216 | 216 | $model = new ForgotForm; |
| 217 | 217 | |
| 218 | - if (Cii::get($_POST, 'ForgotForm', false)) |
|
| 218 | + if (Cii::get ($_POST, 'ForgotForm', false)) |
|
| 219 | 219 | { |
| 220 | 220 | $model->attributes = $_POST['ForgotForm']; |
| 221 | 221 | |
| 222 | - if ($model->initPasswordResetProcess()) |
|
| 222 | + if ($model->initPasswordResetProcess ()) |
|
| 223 | 223 | { |
| 224 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'A password reset link has been sent to your email address')); |
|
| 225 | - $this->redirect($this->createUrl('site/login')); |
|
| 224 | + Yii::app ()->user->setFlash ('success', Yii::t ('ciims.controllers.Site', 'A password reset link has been sent to your email address')); |
|
| 225 | + $this->redirect ($this->createUrl ('site/login')); |
|
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $this->render('forgot', array( |
|
| 229 | + $this->render ('forgot', array( |
|
| 230 | 230 | 'model' => $model |
| 231 | 231 | )); |
| 232 | 232 | } |
@@ -235,33 +235,33 @@ discard block |
||
| 235 | 235 | * Alows a user to reset their password if they initiated a forgot password request |
| 236 | 236 | * @param string $id |
| 237 | 237 | */ |
| 238 | - public function actionResetPassword($id=NULL) |
|
| 238 | + public function actionResetPassword ($id = NULL) |
|
| 239 | 239 | { |
| 240 | 240 | $this->layout = '//layouts/main'; |
| 241 | 241 | |
| 242 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 243 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 244 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Reset Your password') |
|
| 242 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 243 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 244 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Reset Your password') |
|
| 245 | 245 | ))); |
| 246 | 246 | |
| 247 | 247 | $model = new PasswordResetForm; |
| 248 | 248 | $model->reset_key = $id; |
| 249 | 249 | |
| 250 | - if (!$model->validateResetKey()) |
|
| 251 | - throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid')); |
|
| 250 | + if (!$model->validateResetKey ()) |
|
| 251 | + throw new CHttpException (403, Yii::t ('ciims.controllers.Site', 'The password reset key provided is invalid')); |
|
| 252 | 252 | |
| 253 | - if (Cii::get($_POST, 'PasswordResetForm', false)) |
|
| 253 | + if (Cii::get ($_POST, 'PasswordResetForm', false)) |
|
| 254 | 254 | { |
| 255 | 255 | $model->attributes = $_POST['PasswordResetForm']; |
| 256 | 256 | |
| 257 | - if ($model->save()) |
|
| 257 | + if ($model->save ()) |
|
| 258 | 258 | { |
| 259 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your password has been reset, and you may now login with your new password')); |
|
| 260 | - $this->redirect($this->createUrl('site/login')); |
|
| 259 | + Yii::app ()->user->setFlash ('success', Yii::t ('ciims.controllers.Site', 'Your password has been reset, and you may now login with your new password')); |
|
| 260 | + $this->redirect ($this->createUrl ('site/login')); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $this->render('resetpassword', array( |
|
| 264 | + $this->render ('resetpassword', array( |
|
| 265 | 265 | 'model' => $model |
| 266 | 266 | )); |
| 267 | 267 | } |
@@ -270,44 +270,44 @@ discard block |
||
| 270 | 270 | * Allows the user to securely change their email address |
| 271 | 271 | * @param string $key the user's secure key |
| 272 | 272 | */ |
| 273 | - public function actionEmailChange($key=null) |
|
| 273 | + public function actionEmailChange ($key = null) |
|
| 274 | 274 | { |
| 275 | 275 | $this->layout = '//layouts/main'; |
| 276 | 276 | |
| 277 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 278 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 279 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Change Your Email Address') |
|
| 277 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 278 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 279 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Change Your Email Address') |
|
| 280 | 280 | ))); |
| 281 | 281 | |
| 282 | 282 | $model = new EmailChangeForm; |
| 283 | - $model->setUser(Users::model()->findByPk(Yii::app()->user->id)); |
|
| 283 | + $model->setUser (Users::model ()->findByPk (Yii::app ()->user->id)); |
|
| 284 | 284 | $model->verificationKey = $key; |
| 285 | 285 | |
| 286 | - if (!$model->validateVerificationKey()) |
|
| 287 | - throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.')); |
|
| 286 | + if (!$model->validateVerificationKey ()) |
|
| 287 | + throw new CHttpException (403, Yii::t ('ciims.controllers.Site', 'The verification key provided is invalid.')); |
|
| 288 | 288 | |
| 289 | - if (Cii::get($_POST, 'EmailChangeForm', false)) |
|
| 289 | + if (Cii::get ($_POST, 'EmailChangeForm', false)) |
|
| 290 | 290 | { |
| 291 | 291 | $model->attributes = $_POST['EmailChangeForm']; |
| 292 | 292 | |
| 293 | - if ($model->save()) |
|
| 293 | + if ($model->save ()) |
|
| 294 | 294 | { |
| 295 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your new email address has been verified.')); |
|
| 295 | + Yii::app ()->user->setFlash ('success', Yii::t ('ciims.controllers.Site', 'Your new email address has been verified.')); |
|
| 296 | 296 | |
| 297 | 297 | $loginForm = new LoginForm; |
| 298 | 298 | $loginForm->attributes = array( |
| 299 | - 'username' => Users::model()->findByPk(Yii::app()->user->id)->email, |
|
| 299 | + 'username' => Users::model ()->findByPk (Yii::app ()->user->id)->email, |
|
| 300 | 300 | 'password' => $model->password, |
| 301 | 301 | ); |
| 302 | 302 | |
| 303 | - if ($loginForm->login()) |
|
| 304 | - return $this->redirect(Yii::app()->homeUrl); |
|
| 303 | + if ($loginForm->login ()) |
|
| 304 | + return $this->redirect (Yii::app ()->homeUrl); |
|
| 305 | 305 | |
| 306 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'Unable to re-authenticated user.')); |
|
| 306 | + throw new CHttpException (400, Yii::t ('ciims.controllers.Site', 'Unable to re-authenticated user.')); |
|
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $this->render('emailchange', array( |
|
| 310 | + $this->render ('emailchange', array( |
|
| 311 | 311 | 'model' => $model |
| 312 | 312 | )); |
| 313 | 313 | } |
@@ -316,33 +316,33 @@ discard block |
||
| 316 | 316 | * Activates a new user's account |
| 317 | 317 | * @param mixed $id The activation key |
| 318 | 318 | */ |
| 319 | - public function actionActivation($id=NULL) |
|
| 319 | + public function actionActivation ($id = NULL) |
|
| 320 | 320 | { |
| 321 | 321 | $this->layout = '//layouts/main'; |
| 322 | 322 | |
| 323 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 324 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 325 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Activate Your Account') |
|
| 323 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 324 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 325 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Activate Your Account') |
|
| 326 | 326 | ))); |
| 327 | 327 | |
| 328 | 328 | $model = new ActivationForm; |
| 329 | 329 | $model->activationKey = $id; |
| 330 | 330 | |
| 331 | - if (!$model->validateKey()) |
|
| 332 | - throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
| 331 | + if (!$model->validateKey ()) |
|
| 332 | + throw new CHttpException (403, Yii::t ('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
| 333 | 333 | |
| 334 | - if (Cii::get($_POST, 'ActivationForm', false)) |
|
| 334 | + if (Cii::get ($_POST, 'ActivationForm', false)) |
|
| 335 | 335 | { |
| 336 | 336 | $model->attributes = $_POST['ActivationForm']; |
| 337 | 337 | |
| 338 | - if ($model->save()) |
|
| 338 | + if ($model->save ()) |
|
| 339 | 339 | { |
| 340 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your account has successfully been activated. You may now login')); |
|
| 341 | - $this->redirect($this->createUrl('site/login')); |
|
| 340 | + Yii::app ()->user->setFlash ('success', Yii::t ('ciims.controllers.Site', 'Your account has successfully been activated. You may now login')); |
|
| 341 | + $this->redirect ($this->createUrl ('site/login')); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - $this->render('activation', array( |
|
| 345 | + $this->render ('activation', array( |
|
| 346 | 346 | 'model' => $model |
| 347 | 347 | )); |
| 348 | 348 | } |
@@ -350,31 +350,31 @@ discard block |
||
| 350 | 350 | /** |
| 351 | 351 | * Handles the registration of new users on the site |
| 352 | 352 | */ |
| 353 | - public function actionRegister() |
|
| 353 | + public function actionRegister () |
|
| 354 | 354 | { |
| 355 | 355 | $this->layout = '//layouts/main'; |
| 356 | 356 | |
| 357 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 358 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 359 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Sign Up') |
|
| 357 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 358 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 359 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Sign Up') |
|
| 360 | 360 | ))); |
| 361 | 361 | |
| 362 | 362 | $model = new RegisterForm; |
| 363 | 363 | |
| 364 | - if (Cii::get($_POST, 'RegisterForm', false)) |
|
| 364 | + if (Cii::get ($_POST, 'RegisterForm', false)) |
|
| 365 | 365 | { |
| 366 | 366 | $model->attributes = $_POST['RegisterForm']; |
| 367 | 367 | |
| 368 | 368 | // Save the user's information |
| 369 | - if ($model->save()) |
|
| 369 | + if ($model->save ()) |
|
| 370 | 370 | { |
| 371 | 371 | // Set a flash message |
| 372 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'You have successfully registered an account. Before you can login, please check your email for activation instructions')); |
|
| 373 | - $this->redirect($this->createUrl('site/login')); |
|
| 372 | + Yii::app ()->user->setFlash ('success', Yii::t ('ciims.controllers.Site', 'You have successfully registered an account. Before you can login, please check your email for activation instructions')); |
|
| 373 | + $this->redirect ($this->createUrl ('site/login')); |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - $this->render('register', array( |
|
| 377 | + $this->render ('register', array( |
|
| 378 | 378 | 'model'=>$model |
| 379 | 379 | )); |
| 380 | 380 | } |
@@ -383,39 +383,39 @@ discard block |
||
| 383 | 383 | * Enables users who have recieved an invitation to setup a new account |
| 384 | 384 | * @param string $id The activation id the of the user that we want to activate |
| 385 | 385 | */ |
| 386 | - public function actionAcceptInvite($id=NULL) |
|
| 386 | + public function actionAcceptInvite ($id = NULL) |
|
| 387 | 387 | { |
| 388 | 388 | $this->layout = '//layouts/main'; |
| 389 | 389 | |
| 390 | - $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 391 | - '{{app_name}}' => Cii::getConfig('name', Yii::app()->name), |
|
| 392 | - '{{label}}' => Yii::t('ciims.controllers.Site', 'Accept Invitation') |
|
| 390 | + $this->setPageTitle (Yii::t ('ciims.controllers.Site', '{{app_name}} | {{label}}', array( |
|
| 391 | + '{{app_name}}' => Cii::getConfig ('name', Yii::app ()->name), |
|
| 392 | + '{{label}}' => Yii::t ('ciims.controllers.Site', 'Accept Invitation') |
|
| 393 | 393 | ))); |
| 394 | 394 | |
| 395 | 395 | if ($id === NULL) |
| 396 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 396 | + throw new CHttpException (400, Yii::t ('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 397 | 397 | |
| 398 | 398 | // Make sure we have a user first |
| 399 | - $meta = UserMetadata::model()->findByAttributes(array('key' => 'invitationKey', 'value' => $id)); |
|
| 399 | + $meta = UserMetadata::model ()->findByAttributes (array('key' => 'invitationKey', 'value' => $id)); |
|
| 400 | 400 | if ($meta === NULL) |
| 401 | - throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 401 | + throw new CHttpException (400, Yii::t ('ciims.controllers.Site', 'There was an error fulfilling your request.')); |
|
| 402 | 402 | |
| 403 | 403 | $model = new InviteForm; |
| 404 | - $model->email = Users::model()->findByPk($meta->user_id)->email; |
|
| 404 | + $model->email = Users::model ()->findByPk ($meta->user_id)->email; |
|
| 405 | 405 | |
| 406 | - if (Cii::get($_POST, 'InviteForm', NULL) !== NULL) |
|
| 406 | + if (Cii::get ($_POST, 'InviteForm', NULL) !== NULL) |
|
| 407 | 407 | { |
| 408 | - $model->attributes = Cii::get($_POST, 'InviteForm', NULL); |
|
| 408 | + $model->attributes = Cii::get ($_POST, 'InviteForm', NULL); |
|
| 409 | 409 | $model->id = $meta->user_id; |
| 410 | 410 | |
| 411 | - if ($model->acceptInvite()) |
|
| 411 | + if ($model->acceptInvite ()) |
|
| 412 | 412 | { |
| 413 | - $meta->delete(); |
|
| 414 | - return $this->render('invitesuccess'); |
|
| 413 | + $meta->delete (); |
|
| 414 | + return $this->render ('invitesuccess'); |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - $this->render('acceptinvite', array( |
|
| 418 | + $this->render ('acceptinvite', array( |
|
| 419 | 419 | 'model' => $model |
| 420 | 420 | )); |
| 421 | 421 | } |
@@ -424,8 +424,8 @@ discard block |
||
| 424 | 424 | * Returns a sanitized $_GET['next'] URL if it is set. |
| 425 | 425 | * @return mixed |
| 426 | 426 | */ |
| 427 | - private function _getNext() |
|
| 427 | + private function _getNext () |
|
| 428 | 428 | { |
| 429 | - return str_replace('ftp://', '', str_replace('http://', '', str_replace('https://', '', Yii::app()->request->getParam('next', false)))); |
|
| 429 | + return str_replace ('ftp://', '', str_replace ('http://', '', str_replace ('https://', '', Yii::app ()->request->getParam ('next', false)))); |
|
| 430 | 430 | } |
| 431 | 431 | } |
@@ -16,7 +16,7 @@ |
||
| 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.' => '', |
@@ -17,14 +17,14 @@ |
||
| 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 | ); |
@@ -3,286 +3,286 @@ |
||
| 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 |
@@ -9,16 +9,16 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -17,11 +17,11 @@ |
||
| 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. |
@@ -19,319 +19,319 @@ |
||
| 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 | } |
@@ -17,8 +17,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -30,15 +30,15 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -16,83 +16,83 @@ |
||
| 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 | } |
@@ -21,15 +21,15 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -14,31 +14,31 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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);
|
@@ -19,155 +19,155 @@ |
||
| 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 | } |
@@ -36,15 +36,15 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -17,8 +17,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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); |
@@ -11,122 +11,122 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Configuration extends CiiModel |
| 13 | 13 | {
|
| 14 | - /** |
|
| 15 | - * Returns the static model of the specified AR class. |
|
| 16 | - * @param string $className active record class name. |
|
| 17 | - * @return Configuration the static model class |
|
| 18 | - */ |
|
| 19 | - public static function model($className=__CLASS__) |
|
| 20 | - {
|
|
| 21 | - return parent::model($className); |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * Returns the static model of the specified AR class. |
|
| 16 | + * @param string $className active record class name. |
|
| 17 | + * @return Configuration the static model class |
|
| 18 | + */ |
|
| 19 | + public static function model($className=__CLASS__) |
|
| 20 | + {
|
|
| 21 | + return parent::model($className); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @return string the associated database table name |
|
| 26 | - */ |
|
| 27 | - public function tableName() |
|
| 28 | - {
|
|
| 29 | - return 'configuration'; |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * @return string the associated database table name |
|
| 26 | + */ |
|
| 27 | + public function tableName() |
|
| 28 | + {
|
|
| 29 | + return 'configuration'; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return array validation rules for model attributes. |
|
| 34 | - */ |
|
| 35 | - public function rules() |
|
| 36 | - {
|
|
| 37 | - // NOTE: you should only define rules for those attributes that |
|
| 38 | - // will receive user inputs. |
|
| 39 | - return array( |
|
| 40 | - array('key, value', 'required'),
|
|
| 41 | - array('key', 'length', 'max'=>64),
|
|
| 42 | - // The following rule is used by search(). |
|
| 43 | - array('key, value, created, updated', 'safe', 'on'=>'search'),
|
|
| 44 | - ); |
|
| 45 | - } |
|
| 32 | + /** |
|
| 33 | + * @return array validation rules for model attributes. |
|
| 34 | + */ |
|
| 35 | + public function rules() |
|
| 36 | + {
|
|
| 37 | + // NOTE: you should only define rules for those attributes that |
|
| 38 | + // will receive user inputs. |
|
| 39 | + return array( |
|
| 40 | + array('key, value', 'required'),
|
|
| 41 | + array('key', 'length', 'max'=>64),
|
|
| 42 | + // The following rule is used by search(). |
|
| 43 | + array('key, value, created, updated', 'safe', 'on'=>'search'),
|
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return array relational rules. |
|
| 49 | - */ |
|
| 50 | - public function relations() |
|
| 51 | - {
|
|
| 52 | - // NOTE: you may need to adjust the relation name and the related |
|
| 53 | - // class name for the relations automatically generated below. |
|
| 54 | - return array(); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * @return array relational rules. |
|
| 49 | + */ |
|
| 50 | + public function relations() |
|
| 51 | + {
|
|
| 52 | + // NOTE: you may need to adjust the relation name and the related |
|
| 53 | + // class name for the relations automatically generated below. |
|
| 54 | + return array(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return array customized attribute labels (name=>label) |
|
| 59 | - */ |
|
| 60 | - public function attributeLabels() |
|
| 61 | - {
|
|
| 62 | - return array( |
|
| 63 | - 'key' => Yii::t('ciims.models.Configuration', 'Key'),
|
|
| 64 | - 'value' => Yii::t('ciims.models.Configuration', 'Value'),
|
|
| 65 | - 'created' => Yii::t('ciims.models.Configuration', 'Created'),
|
|
| 66 | - 'updated' => Yii::t('ciims.models.Configuration', 'Updated'),
|
|
| 67 | - ); |
|
| 68 | - } |
|
| 57 | + /** |
|
| 58 | + * @return array customized attribute labels (name=>label) |
|
| 59 | + */ |
|
| 60 | + public function attributeLabels() |
|
| 61 | + {
|
|
| 62 | + return array( |
|
| 63 | + 'key' => Yii::t('ciims.models.Configuration', 'Key'),
|
|
| 64 | + 'value' => Yii::t('ciims.models.Configuration', 'Value'),
|
|
| 65 | + 'created' => Yii::t('ciims.models.Configuration', 'Created'),
|
|
| 66 | + 'updated' => Yii::t('ciims.models.Configuration', 'Updated'),
|
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Retrieves a list of models based on the current search/filter conditions. |
|
| 72 | - * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
| 73 | - */ |
|
| 74 | - public function search() |
|
| 75 | - {
|
|
| 76 | - $criteria=new CDbCriteria; |
|
| 70 | + /** |
|
| 71 | + * Retrieves a list of models based on the current search/filter conditions. |
|
| 72 | + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
| 73 | + */ |
|
| 74 | + public function search() |
|
| 75 | + {
|
|
| 76 | + $criteria=new CDbCriteria; |
|
| 77 | 77 | |
| 78 | - $criteria->compare('t.key',$this->key,true);
|
|
| 79 | - $criteria->compare('value',$this->value,true);
|
|
| 80 | - $criteria->compare('created',$this->created,true);
|
|
| 81 | - $criteria->compare('updated',$this->updated,true);
|
|
| 82 | - $criteria->order = "created DESC"; |
|
| 78 | + $criteria->compare('t.key',$this->key,true);
|
|
| 79 | + $criteria->compare('value',$this->value,true);
|
|
| 80 | + $criteria->compare('created',$this->created,true);
|
|
| 81 | + $criteria->compare('updated',$this->updated,true);
|
|
| 82 | + $criteria->order = "created DESC"; |
|
| 83 | 83 | |
| 84 | - return new CActiveDataProvider($this, array( |
|
| 85 | - 'criteria'=>$criteria, |
|
| 86 | - )); |
|
| 87 | - } |
|
| 84 | + return new CActiveDataProvider($this, array( |
|
| 85 | + 'criteria'=>$criteria, |
|
| 86 | + )); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Generates a unique id |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public function generateUniqueId() |
|
| 94 | - {
|
|
| 95 | - $rnd_id = crypt(uniqid(mt_rand(),1)); |
|
| 96 | - $rnd_id = strip_tags(stripslashes($rnd_id)); |
|
| 97 | - $rnd_id = str_replace(".","",$rnd_id);
|
|
| 98 | - $rnd_id = strrev(str_replace("/","",$rnd_id));
|
|
| 99 | - $rnd_id = str_replace("$", '', substr($rnd_id,0,20));
|
|
| 89 | + /** |
|
| 90 | + * Generates a unique id |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public function generateUniqueId() |
|
| 94 | + {
|
|
| 95 | + $rnd_id = crypt(uniqid(mt_rand(),1)); |
|
| 96 | + $rnd_id = strip_tags(stripslashes($rnd_id)); |
|
| 97 | + $rnd_id = str_replace(".","",$rnd_id);
|
|
| 98 | + $rnd_id = strrev(str_replace("/","",$rnd_id));
|
|
| 99 | + $rnd_id = str_replace("$", '', substr($rnd_id,0,20));
|
|
| 100 | 100 | |
| 101 | - return $rnd_id; |
|
| 102 | - } |
|
| 101 | + return $rnd_id; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * This will do a full recursive deletion of a card from bothe the filesystem and from |
|
| 106 | - * @param string $name The folder name in runtiome |
|
| 107 | - * @return boolean If the recursive delete was successful or not |
|
| 108 | - */ |
|
| 109 | - public function fullDelete($name, $type='card') |
|
| 110 | - {
|
|
| 111 | - if ($type == 'card') |
|
| 112 | - $path = Yii::getPathOfAlias('application.runtime.cards.' . $name);
|
|
| 113 | - else |
|
| 114 | - $path = $name; |
|
| 104 | + /** |
|
| 105 | + * This will do a full recursive deletion of a card from bothe the filesystem and from |
|
| 106 | + * @param string $name The folder name in runtiome |
|
| 107 | + * @return boolean If the recursive delete was successful or not |
|
| 108 | + */ |
|
| 109 | + public function fullDelete($name, $type='card') |
|
| 110 | + {
|
|
| 111 | + if ($type == 'card') |
|
| 112 | + $path = Yii::getPathOfAlias('application.runtime.cards.' . $name);
|
|
| 113 | + else |
|
| 114 | + $path = $name; |
|
| 115 | 115 | |
| 116 | - try |
|
| 117 | - {
|
|
| 118 | - // Delete the directory path |
|
| 119 | - CiiFileDeleter::removeDirectory($path); |
|
| 116 | + try |
|
| 117 | + {
|
|
| 118 | + // Delete the directory path |
|
| 119 | + CiiFileDeleter::removeDirectory($path); |
|
| 120 | 120 | |
| 121 | - // Delete the cache |
|
| 122 | - Yii::app()->cache->delete('dashboard_cards_available');
|
|
| 123 | - Yii::app()->cache->delete('cards_in_category');
|
|
| 121 | + // Delete the cache |
|
| 122 | + Yii::app()->cache->delete('dashboard_cards_available');
|
|
| 123 | + Yii::app()->cache->delete('cards_in_category');
|
|
| 124 | 124 | |
| 125 | - // Delete the record |
|
| 126 | - return $this->delete(); |
|
| 127 | - } |
|
| 128 | - catch (Exception $e) {
|
|
| 129 | - return false; |
|
| 130 | - } |
|
| 131 | - } |
|
| 125 | + // Delete the record |
|
| 126 | + return $this->delete(); |
|
| 127 | + } |
|
| 128 | + catch (Exception $e) {
|
|
| 129 | + return false; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -9,31 +9,31 @@ discard block |
||
| 9 | 9 | * @property string $created |
| 10 | 10 | * @property string $updated |
| 11 | 11 | */ |
| 12 | -class Configuration extends CiiModel |
|
| 13 | -{
|
|
| 12 | +class Configuration extends CiiModel |
|
| 13 | +{ |
|
| 14 | 14 | /** |
| 15 | 15 | * Returns the static model of the specified AR class. |
| 16 | 16 | * @param string $className active record class name. |
| 17 | 17 | * @return Configuration the static model class |
| 18 | 18 | */ |
| 19 | - public static function model($className=__CLASS__) |
|
| 20 | - {
|
|
| 19 | + public static function model($className=__CLASS__) |
|
| 20 | + { |
|
| 21 | 21 | return parent::model($className); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * @return string the associated database table name |
| 26 | 26 | */ |
| 27 | - public function tableName() |
|
| 28 | - {
|
|
| 27 | + public function tableName() |
|
| 28 | + { |
|
| 29 | 29 | return 'configuration'; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * @return array validation rules for model attributes. |
| 34 | 34 | */ |
| 35 | - public function rules() |
|
| 36 | - {
|
|
| 35 | + public function rules() |
|
| 36 | + { |
|
| 37 | 37 | // NOTE: you should only define rules for those attributes that |
| 38 | 38 | // will receive user inputs. |
| 39 | 39 | return array( |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return array relational rules. |
| 49 | 49 | */ |
| 50 | - public function relations() |
|
| 51 | - {
|
|
| 50 | + public function relations() |
|
| 51 | + { |
|
| 52 | 52 | // NOTE: you may need to adjust the relation name and the related |
| 53 | 53 | // class name for the relations automatically generated below. |
| 54 | 54 | return array(); |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @return array customized attribute labels (name=>label) |
| 59 | 59 | */ |
| 60 | - public function attributeLabels() |
|
| 61 | - {
|
|
| 60 | + public function attributeLabels() |
|
| 61 | + { |
|
| 62 | 62 | return array( |
| 63 | 63 | 'key' => Yii::t('ciims.models.Configuration', 'Key'),
|
| 64 | 64 | 'value' => Yii::t('ciims.models.Configuration', 'Value'),
|
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * Retrieves a list of models based on the current search/filter conditions. |
| 72 | 72 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
| 73 | 73 | */ |
| 74 | - public function search() |
|
| 75 | - {
|
|
| 74 | + public function search() |
|
| 75 | + { |
|
| 76 | 76 | $criteria=new CDbCriteria; |
| 77 | 77 | |
| 78 | 78 | $criteria->compare('t.key',$this->key,true);
|
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | * Generates a unique id |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function generateUniqueId() |
|
| 94 | - {
|
|
| 93 | + public function generateUniqueId() |
|
| 94 | + { |
|
| 95 | 95 | $rnd_id = crypt(uniqid(mt_rand(),1)); |
| 96 | 96 | $rnd_id = strip_tags(stripslashes($rnd_id)); |
| 97 | 97 | $rnd_id = str_replace(".","",$rnd_id);
|
@@ -106,12 +106,13 @@ discard block |
||
| 106 | 106 | * @param string $name The folder name in runtiome |
| 107 | 107 | * @return boolean If the recursive delete was successful or not |
| 108 | 108 | */ |
| 109 | - public function fullDelete($name, $type='card') |
|
| 110 | - {
|
|
| 111 | - if ($type == 'card') |
|
| 112 | - $path = Yii::getPathOfAlias('application.runtime.cards.' . $name);
|
|
| 113 | - else |
|
| 114 | - $path = $name; |
|
| 109 | + public function fullDelete($name, $type='card') |
|
| 110 | + { |
|
| 111 | + if ($type == 'card') { |
|
| 112 | + $path = Yii::getPathOfAlias('application.runtime.cards.' . $name); |
|
| 113 | + } else { |
|
| 114 | + $path = $name; |
|
| 115 | + } |
|
| 115 | 116 | |
| 116 | 117 | try |
| 117 | 118 | {
|
@@ -124,8 +125,7 @@ discard block |
||
| 124 | 125 | |
| 125 | 126 | // Delete the record |
| 126 | 127 | return $this->delete(); |
| 127 | - } |
|
| 128 | - catch (Exception $e) {
|
|
| 128 | + } catch (Exception $e) {
|
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -16,15 +16,15 @@ discard block |
||
| 16 | 16 | * @param string $className active record class name. |
| 17 | 17 | * @return Configuration the static model class |
| 18 | 18 | */ |
| 19 | - public static function model($className=__CLASS__) |
|
| 19 | + public static function model ($className = __CLASS__) |
|
| 20 | 20 | {
|
| 21 | - return parent::model($className); |
|
| 21 | + return parent::model ($className); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * @return string the associated database table name |
| 26 | 26 | */ |
| 27 | - public function tableName() |
|
| 27 | + public function tableName () |
|
| 28 | 28 | {
|
| 29 | 29 | return 'configuration'; |
| 30 | 30 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * @return array validation rules for model attributes. |
| 34 | 34 | */ |
| 35 | - public function rules() |
|
| 35 | + public function rules () |
|
| 36 | 36 | {
|
| 37 | 37 | // NOTE: you should only define rules for those attributes that |
| 38 | 38 | // will receive user inputs. |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return array relational rules. |
| 49 | 49 | */ |
| 50 | - public function relations() |
|
| 50 | + public function relations () |
|
| 51 | 51 | {
|
| 52 | 52 | // NOTE: you may need to adjust the relation name and the related |
| 53 | 53 | // class name for the relations automatically generated below. |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @return array customized attribute labels (name=>label) |
| 59 | 59 | */ |
| 60 | - public function attributeLabels() |
|
| 60 | + public function attributeLabels () |
|
| 61 | 61 | {
|
| 62 | 62 | return array( |
| 63 | - 'key' => Yii::t('ciims.models.Configuration', 'Key'),
|
|
| 64 | - 'value' => Yii::t('ciims.models.Configuration', 'Value'),
|
|
| 65 | - 'created' => Yii::t('ciims.models.Configuration', 'Created'),
|
|
| 66 | - 'updated' => Yii::t('ciims.models.Configuration', 'Updated'),
|
|
| 63 | + 'key' => Yii::t ('ciims.models.Configuration', 'Key'),
|
|
| 64 | + 'value' => Yii::t ('ciims.models.Configuration', 'Value'),
|
|
| 65 | + 'created' => Yii::t ('ciims.models.Configuration', 'Created'),
|
|
| 66 | + 'updated' => Yii::t ('ciims.models.Configuration', 'Updated'),
|
|
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * Retrieves a list of models based on the current search/filter conditions. |
| 72 | 72 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
| 73 | 73 | */ |
| 74 | - public function search() |
|
| 74 | + public function search () |
|
| 75 | 75 | {
|
| 76 | - $criteria=new CDbCriteria; |
|
| 76 | + $criteria = new CDbCriteria; |
|
| 77 | 77 | |
| 78 | - $criteria->compare('t.key',$this->key,true);
|
|
| 79 | - $criteria->compare('value',$this->value,true);
|
|
| 80 | - $criteria->compare('created',$this->created,true);
|
|
| 81 | - $criteria->compare('updated',$this->updated,true);
|
|
| 78 | + $criteria->compare ('t.key', $this->key, true);
|
|
| 79 | + $criteria->compare ('value', $this->value, true);
|
|
| 80 | + $criteria->compare ('created', $this->created, true);
|
|
| 81 | + $criteria->compare ('updated', $this->updated, true);
|
|
| 82 | 82 | $criteria->order = "created DESC"; |
| 83 | 83 | |
| 84 | - return new CActiveDataProvider($this, array( |
|
| 84 | + return new CActiveDataProvider ($this, array( |
|
| 85 | 85 | 'criteria'=>$criteria, |
| 86 | 86 | )); |
| 87 | 87 | } |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | * Generates a unique id |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function generateUniqueId() |
|
| 93 | + public function generateUniqueId () |
|
| 94 | 94 | {
|
| 95 | - $rnd_id = crypt(uniqid(mt_rand(),1)); |
|
| 96 | - $rnd_id = strip_tags(stripslashes($rnd_id)); |
|
| 97 | - $rnd_id = str_replace(".","",$rnd_id);
|
|
| 98 | - $rnd_id = strrev(str_replace("/","",$rnd_id));
|
|
| 99 | - $rnd_id = str_replace("$", '', substr($rnd_id,0,20));
|
|
| 95 | + $rnd_id = crypt (uniqid (mt_rand (), 1)); |
|
| 96 | + $rnd_id = strip_tags (stripslashes ($rnd_id)); |
|
| 97 | + $rnd_id = str_replace (".", "", $rnd_id);
|
|
| 98 | + $rnd_id = strrev (str_replace ("/", "", $rnd_id));
|
|
| 99 | + $rnd_id = str_replace ("$", '', substr ($rnd_id, 0, 20));
|
|
| 100 | 100 | |
| 101 | 101 | return $rnd_id; |
| 102 | 102 | } |
@@ -106,24 +106,24 @@ discard block |
||
| 106 | 106 | * @param string $name The folder name in runtiome |
| 107 | 107 | * @return boolean If the recursive delete was successful or not |
| 108 | 108 | */ |
| 109 | - public function fullDelete($name, $type='card') |
|
| 109 | + public function fullDelete ($name, $type = 'card') |
|
| 110 | 110 | {
|
| 111 | 111 | if ($type == 'card') |
| 112 | - $path = Yii::getPathOfAlias('application.runtime.cards.' . $name);
|
|
| 112 | + $path = Yii::getPathOfAlias ('application.runtime.cards.'.$name);
|
|
| 113 | 113 | else |
| 114 | 114 | $path = $name; |
| 115 | 115 | |
| 116 | 116 | try |
| 117 | 117 | {
|
| 118 | 118 | // Delete the directory path |
| 119 | - CiiFileDeleter::removeDirectory($path); |
|
| 119 | + CiiFileDeleter::removeDirectory ($path); |
|
| 120 | 120 | |
| 121 | 121 | // Delete the cache |
| 122 | - Yii::app()->cache->delete('dashboard_cards_available');
|
|
| 123 | - Yii::app()->cache->delete('cards_in_category');
|
|
| 122 | + Yii::app ()->cache->delete ('dashboard_cards_available');
|
|
| 123 | + Yii::app ()->cache->delete ('cards_in_category');
|
|
| 124 | 124 | |
| 125 | 125 | // Delete the record |
| 126 | - return $this->delete(); |
|
| 126 | + return $this->delete (); |
|
| 127 | 127 | } |
| 128 | 128 | catch (Exception $e) {
|
| 129 | 129 | return false; |
@@ -31,621 +31,621 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Content extends CiiModel |
| 33 | 33 | {
|
| 34 | - public $pageSize = 9; |
|
| 35 | - |
|
| 36 | - public $viewFile = 'blog'; |
|
| 37 | - |
|
| 38 | - public $layoutFile = 'blog'; |
|
| 39 | - |
|
| 40 | - public $autosavedata = false; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Returns the static model of the specified AR class. |
|
| 44 | - * @param string $className active record class name. |
|
| 45 | - * @return Content the static model class |
|
| 46 | - */ |
|
| 47 | - public static function model($className=__CLASS__) |
|
| 48 | - {
|
|
| 49 | - return parent::model($className); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return string the associated database table name |
|
| 54 | - */ |
|
| 55 | - public function tableName() |
|
| 56 | - {
|
|
| 57 | - return 'content'; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return string[] primary key of the table |
|
| 62 | - **/ |
|
| 63 | - public function primaryKey() |
|
| 64 | - {
|
|
| 65 | - return array('id');
|
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return array validation rules for model attributes. |
|
| 70 | - */ |
|
| 71 | - public function rules() |
|
| 72 | - {
|
|
| 73 | - // NOTE: you should only define rules for those attributes that |
|
| 74 | - // will receive user inputs. |
|
| 75 | - return array( |
|
| 76 | - array('vid, author_id, title, content, status, commentable, category_id', 'required'),
|
|
| 77 | - array('vid, author_id, status, commentable, category_id, type_id, like_count', 'numerical', 'integerOnly'=>true),
|
|
| 78 | - array('title, password, slug', 'length', 'max'=>150),
|
|
| 79 | - // The following rule is used by search(). |
|
| 80 | - array('id, vid, author_id, title, content, excerpt, status, commentable, category_id, type_id, password, like_count, slug, published, created, updated', 'safe', 'on'=>'search'),
|
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return array relational rules. |
|
| 86 | - */ |
|
| 87 | - public function relations() |
|
| 88 | - {
|
|
| 89 | - // NOTE: you may need to adjust the relation name and the related |
|
| 90 | - // class name for the relations automatically generated below. |
|
| 91 | - return array( |
|
| 92 | - 'comments' => array(self::HAS_MANY, 'Comments', 'content_id'), |
|
| 93 | - 'author' => array(self::BELONGS_TO, 'Users', 'author_id'), |
|
| 94 | - 'category' => array(self::BELONGS_TO, 'Categories', 'category_id'), |
|
| 95 | - 'metadata' => array(self::HAS_MANY, 'ContentMetadata', 'content_id'), |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return array customized attribute labels (name=>label) |
|
| 101 | - */ |
|
| 102 | - public function attributeLabels() |
|
| 103 | - {
|
|
| 104 | - return array( |
|
| 105 | - 'id' => Yii::t('ciims.models.Content', 'ID'),
|
|
| 106 | - 'vid' => Yii::t('ciims.models.Content', 'Version'),
|
|
| 107 | - 'author_id' => Yii::t('ciims.models.Content', 'Author'),
|
|
| 108 | - 'title' => Yii::t('ciims.models.Content', 'Title'),
|
|
| 109 | - 'content' => Yii::t('ciims.models.Content', 'Content'),
|
|
| 110 | - 'excerpt' => Yii::t('ciims.models.Content', 'excerpt'),
|
|
| 111 | - 'status' => Yii::t('ciims.models.Content', 'Status'),
|
|
| 112 | - 'commentable' => Yii::t('ciims.models.Content', 'Commentable'),
|
|
| 113 | - 'category_id' => Yii::t('ciims.models.Content', 'Category'),
|
|
| 114 | - 'type_id' => Yii::t('ciims.models.Content', 'Type'),
|
|
| 115 | - 'password' => Yii::t('ciims.models.Content', 'Password'),
|
|
| 116 | - 'like_count' => Yii::t('ciims.models.Content', 'Likes'),
|
|
| 117 | - 'tags' => Yii::t('ciims.models.Content', 'Tags'),
|
|
| 118 | - 'slug' => Yii::t('ciims.models.Content', 'Slug'),
|
|
| 119 | - 'published' => Yii::t('ciims.models.Content', 'Published'),
|
|
| 120 | - 'created' => Yii::t('ciims.models.Content', 'Created'),
|
|
| 121 | - 'updated' => Yii::t('ciims.models.Content', 'Updated'),
|
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Returns a safe output to the theme |
|
| 127 | - * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function getSafeOutput() |
|
| 131 | - {
|
|
| 132 | - $md = new CMarkdownParser; |
|
| 133 | - $dom = new DOMDocument(); |
|
| 134 | - $dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
|
|
| 135 | - $x = new DOMXPath($dom); |
|
| 136 | - |
|
| 137 | - foreach ($x->query('//a') as $node)
|
|
| 138 | - {
|
|
| 139 | - $element = $node->getAttribute('href');
|
|
| 140 | - if (isset($element[0]) && $element[0] !== "/") |
|
| 141 | - {
|
|
| 142 | - $node->setAttribute('rel', 'nofollow');
|
|
| 143 | - $node->setAttribute('target', '_blank');
|
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $md->safeTransform($dom->saveHtml()); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function getExtract() |
|
| 151 | - {
|
|
| 152 | - Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
|
|
| 153 | - return $this->excerpt; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Correctly retrieves the number of likes for a particular post. |
|
| 158 | - * |
|
| 159 | - * This was added to address an issue with the like count changing if an article was updated |
|
| 160 | - * @return int The number of likes for this post |
|
| 161 | - */ |
|
| 162 | - |
|
| 163 | - public function getLikeCount() |
|
| 164 | - {
|
|
| 165 | - $meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
|
|
| 166 | - if ($meta === NULL) |
|
| 167 | - return 0; |
|
| 168 | - |
|
| 169 | - return $meta->value; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Gets keyword tags for this entry |
|
| 174 | - * @return array |
|
| 175 | - */ |
|
| 176 | - public function getTags() |
|
| 177 | - {
|
|
| 178 | - $tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 179 | - return $tags === NULL ? array() : json_decode($tags->value, true); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Adds a tag to the model |
|
| 184 | - * @param string $tag The tag to add |
|
| 185 | - * @return bool If the insert was successful or not |
|
| 186 | - */ |
|
| 187 | - public function addTag($tag) |
|
| 188 | - {
|
|
| 189 | - $tags = $this->tags; |
|
| 190 | - if (in_array($tag, $tags) || $tag == "") |
|
| 191 | - return false; |
|
| 192 | - |
|
| 193 | - $tags[] = $tag; |
|
| 194 | - $tags = json_encode($tags); |
|
| 195 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 196 | - |
|
| 197 | - $meta->value = $tags; |
|
| 198 | - return $meta->save(); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Removes a tag from the model |
|
| 203 | - * @param string $tag The tag to remove |
|
| 204 | - * @return bool If the removal was successful |
|
| 205 | - */ |
|
| 206 | - public function removeTag($tag) |
|
| 207 | - {
|
|
| 208 | - $tags = $this->tags; |
|
| 209 | - if (!in_array($tag, $tags) || $tag == "") |
|
| 210 | - return false; |
|
| 211 | - |
|
| 212 | - $key = array_search($tag, $tags); |
|
| 213 | - unset($tags[$key]); |
|
| 214 | - $tags = json_encode($tags); |
|
| 215 | - |
|
| 216 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 217 | - $meta->value = $tags; |
|
| 218 | - return $meta->save(); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Provides a base criteria for status, uniqueness, and published states |
|
| 223 | - * @return CDBCriteria |
|
| 224 | - */ |
|
| 225 | - public function getBaseCriteria() |
|
| 226 | - {
|
|
| 227 | - $criteria = new CDbCriteria(); |
|
| 228 | - return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
|
|
| 229 | - ->addCondition('status = 1')
|
|
| 230 | - ->addCondition('UNIX_TIMESTAMP() >= published');
|
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Returns the appropriate status' depending up the user's role |
|
| 235 | - * @return string[] |
|
| 236 | - */ |
|
| 237 | - public function getStatuses() |
|
| 238 | - {
|
|
| 239 | - |
|
| 240 | - if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7) |
|
| 241 | - return array(0 => Yii::t('ciims.models.Content', 'Draft'));
|
|
| 242 | - |
|
| 243 | - return array( |
|
| 244 | - 1 => Yii::t('ciims.models.Content', 'Published'),
|
|
| 245 | - 2 => Yii::t('ciims.models.Content', 'Ready for Review'),
|
|
| 246 | - 0 => Yii::t('ciims.models.Content', 'Draft')
|
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Determines if an article is published or not |
|
| 252 | - * @return boolean |
|
| 253 | - */ |
|
| 254 | - public function isPublished() |
|
| 255 | - {
|
|
| 256 | - return ($this->status == 1 && ($this->published <= time())) ? true : false; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Determines if a given articled is scheduled or not |
|
| 261 | - * @return boolean |
|
| 262 | - */ |
|
| 263 | - public function isScheduled() |
|
| 264 | - {
|
|
| 265 | - return ($this->status == 1 && ($this->published > time())) ? true : false; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Gets a flattened list of keyword tags for jQuery.tag.js |
|
| 270 | - * @return string |
|
| 271 | - */ |
|
| 272 | - public function getTagsFlat() |
|
| 273 | - {
|
|
| 274 | - return implode(',', $this->tags);
|
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Retrieves the layout used from Metadata |
|
| 279 | - * We cache this to speed up the viewfile |
|
| 280 | - */ |
|
| 281 | - public function getLayout() |
|
| 282 | - {
|
|
| 283 | - $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 284 | - return $model === NULL ? 'blog' : $model->value; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Sets the layout |
|
| 289 | - * @param string $data the layout file |
|
| 290 | - * @return boolean |
|
| 291 | - */ |
|
| 292 | - public function setLayout($data) |
|
| 293 | - {
|
|
| 294 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 295 | - $meta->value = $data; |
|
| 296 | - return $meta->save(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Sets the view |
|
| 301 | - * @param string $data The view file |
|
| 302 | - * @return boolean |
|
| 303 | - */ |
|
| 304 | - public function setView($data) |
|
| 305 | - {
|
|
| 306 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
|
|
| 307 | - $meta->value = $data; |
|
| 308 | - return $meta->save(); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Retrieves the viewfile used from Metadata |
|
| 313 | - * We cache this to speed up the viewfile |
|
| 314 | - */ |
|
| 315 | - public function getView() |
|
| 316 | - {
|
|
| 317 | - $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
|
|
| 318 | - return $model === NULL ? 'blog' : $model->value; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Updates the like_count after finding new data |
|
| 323 | - */ |
|
| 324 | - protected function afterFind() |
|
| 325 | - {
|
|
| 326 | - parent::afterFind(); |
|
| 327 | - $this->like_count = $this->getLikeCount(); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Retrieves a list of models based on the current search/filter conditions. |
|
| 332 | - * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
| 333 | - */ |
|
| 334 | - public function search() |
|
| 335 | - {
|
|
| 336 | - $criteria=new CDbCriteria; |
|
| 337 | - |
|
| 338 | - $criteria->compare('id',$this->id);
|
|
| 339 | - $criteria->compare('title',$this->title,true);
|
|
| 340 | - $criteria->compare('slug',$this->slug,true);
|
|
| 341 | - $criteria->compare('author_id',$this->author_id,true);
|
|
| 342 | - $criteria->compare('category_id',$this->category_id,true);
|
|
| 343 | - $criteria->compare('content',$this->content,true);
|
|
| 344 | - $criteria->compare('password', $this->password, true);
|
|
| 345 | - $criteria->compare('created',$this->created,true);
|
|
| 346 | - $criteria->compare('updated',$this->updated,true);
|
|
| 347 | - $criteria->compare('status', $this->status, true);
|
|
| 348 | - |
|
| 349 | - // Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare |
|
| 350 | - if (is_bool($this->published)) |
|
| 351 | - {
|
|
| 352 | - if ($this->published) |
|
| 353 | - $criteria->addCondition('published <= UNIX_TIMESTAMP()');
|
|
| 354 | - else |
|
| 355 | - $criteria->addCondition('published > UNIX_TIMESTAMP()');
|
|
| 356 | - } |
|
| 357 | - else |
|
| 358 | - $criteria->compare('published', $this->published,true);
|
|
| 359 | - $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
|
|
| 360 | - |
|
| 361 | - // TODO: Figure out how to restore CActiveDataProvidor by getCommentCount |
|
| 362 | - return new CActiveDataProvider($this, array( |
|
| 363 | - 'criteria' => $criteria, |
|
| 364 | - 'sort' => array( |
|
| 365 | - 'defaultOrder' => 'published DESC' |
|
| 366 | - ), |
|
| 367 | - 'pagination' => array( |
|
| 368 | - 'pageSize' => $this->pageSize |
|
| 369 | - ) |
|
| 370 | - )); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Finds all active records with the specified primary keys. |
|
| 375 | - * Overloaded to support composite primary keys. For our content, we want to find the latest version of that primary key, defined as MAX(vid) WHERE id = pk |
|
| 376 | - * See {@link find()} for detailed explanation about $condition and $params.
|
|
| 377 | - * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). |
|
| 378 | - * @param mixed $condition query condition or criteria. |
|
| 379 | - * @param array $params parameters to be bound to an SQL statement. |
|
| 380 | - * @return array the records found. An empty array is returned if none is found. |
|
| 381 | - */ |
|
| 382 | - public function findByPk($pk, $condition='', $params=array()) |
|
| 383 | - {
|
|
| 384 | - // If we do not supply a condition or parameters, use our overwritten method |
|
| 385 | - if ($condition == '' && empty($params) && $pk != null) |
|
| 386 | - {
|
|
| 387 | - if (!is_numeric($pk)) |
|
| 388 | - throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 34 | + public $pageSize = 9; |
|
| 35 | + |
|
| 36 | + public $viewFile = 'blog'; |
|
| 37 | + |
|
| 38 | + public $layoutFile = 'blog'; |
|
| 39 | + |
|
| 40 | + public $autosavedata = false; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Returns the static model of the specified AR class. |
|
| 44 | + * @param string $className active record class name. |
|
| 45 | + * @return Content the static model class |
|
| 46 | + */ |
|
| 47 | + public static function model($className=__CLASS__) |
|
| 48 | + {
|
|
| 49 | + return parent::model($className); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return string the associated database table name |
|
| 54 | + */ |
|
| 55 | + public function tableName() |
|
| 56 | + {
|
|
| 57 | + return 'content'; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return string[] primary key of the table |
|
| 62 | + **/ |
|
| 63 | + public function primaryKey() |
|
| 64 | + {
|
|
| 65 | + return array('id');
|
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return array validation rules for model attributes. |
|
| 70 | + */ |
|
| 71 | + public function rules() |
|
| 72 | + {
|
|
| 73 | + // NOTE: you should only define rules for those attributes that |
|
| 74 | + // will receive user inputs. |
|
| 75 | + return array( |
|
| 76 | + array('vid, author_id, title, content, status, commentable, category_id', 'required'),
|
|
| 77 | + array('vid, author_id, status, commentable, category_id, type_id, like_count', 'numerical', 'integerOnly'=>true),
|
|
| 78 | + array('title, password, slug', 'length', 'max'=>150),
|
|
| 79 | + // The following rule is used by search(). |
|
| 80 | + array('id, vid, author_id, title, content, excerpt, status, commentable, category_id, type_id, password, like_count, slug, published, created, updated', 'safe', 'on'=>'search'),
|
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return array relational rules. |
|
| 86 | + */ |
|
| 87 | + public function relations() |
|
| 88 | + {
|
|
| 89 | + // NOTE: you may need to adjust the relation name and the related |
|
| 90 | + // class name for the relations automatically generated below. |
|
| 91 | + return array( |
|
| 92 | + 'comments' => array(self::HAS_MANY, 'Comments', 'content_id'), |
|
| 93 | + 'author' => array(self::BELONGS_TO, 'Users', 'author_id'), |
|
| 94 | + 'category' => array(self::BELONGS_TO, 'Categories', 'category_id'), |
|
| 95 | + 'metadata' => array(self::HAS_MANY, 'ContentMetadata', 'content_id'), |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return array customized attribute labels (name=>label) |
|
| 101 | + */ |
|
| 102 | + public function attributeLabels() |
|
| 103 | + {
|
|
| 104 | + return array( |
|
| 105 | + 'id' => Yii::t('ciims.models.Content', 'ID'),
|
|
| 106 | + 'vid' => Yii::t('ciims.models.Content', 'Version'),
|
|
| 107 | + 'author_id' => Yii::t('ciims.models.Content', 'Author'),
|
|
| 108 | + 'title' => Yii::t('ciims.models.Content', 'Title'),
|
|
| 109 | + 'content' => Yii::t('ciims.models.Content', 'Content'),
|
|
| 110 | + 'excerpt' => Yii::t('ciims.models.Content', 'excerpt'),
|
|
| 111 | + 'status' => Yii::t('ciims.models.Content', 'Status'),
|
|
| 112 | + 'commentable' => Yii::t('ciims.models.Content', 'Commentable'),
|
|
| 113 | + 'category_id' => Yii::t('ciims.models.Content', 'Category'),
|
|
| 114 | + 'type_id' => Yii::t('ciims.models.Content', 'Type'),
|
|
| 115 | + 'password' => Yii::t('ciims.models.Content', 'Password'),
|
|
| 116 | + 'like_count' => Yii::t('ciims.models.Content', 'Likes'),
|
|
| 117 | + 'tags' => Yii::t('ciims.models.Content', 'Tags'),
|
|
| 118 | + 'slug' => Yii::t('ciims.models.Content', 'Slug'),
|
|
| 119 | + 'published' => Yii::t('ciims.models.Content', 'Published'),
|
|
| 120 | + 'created' => Yii::t('ciims.models.Content', 'Created'),
|
|
| 121 | + 'updated' => Yii::t('ciims.models.Content', 'Updated'),
|
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Returns a safe output to the theme |
|
| 127 | + * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function getSafeOutput() |
|
| 131 | + {
|
|
| 132 | + $md = new CMarkdownParser; |
|
| 133 | + $dom = new DOMDocument(); |
|
| 134 | + $dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
|
|
| 135 | + $x = new DOMXPath($dom); |
|
| 136 | + |
|
| 137 | + foreach ($x->query('//a') as $node)
|
|
| 138 | + {
|
|
| 139 | + $element = $node->getAttribute('href');
|
|
| 140 | + if (isset($element[0]) && $element[0] !== "/") |
|
| 141 | + {
|
|
| 142 | + $node->setAttribute('rel', 'nofollow');
|
|
| 143 | + $node->setAttribute('target', '_blank');
|
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $md->safeTransform($dom->saveHtml()); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function getExtract() |
|
| 151 | + {
|
|
| 152 | + Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
|
|
| 153 | + return $this->excerpt; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Correctly retrieves the number of likes for a particular post. |
|
| 158 | + * |
|
| 159 | + * This was added to address an issue with the like count changing if an article was updated |
|
| 160 | + * @return int The number of likes for this post |
|
| 161 | + */ |
|
| 162 | + |
|
| 163 | + public function getLikeCount() |
|
| 164 | + {
|
|
| 165 | + $meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
|
|
| 166 | + if ($meta === NULL) |
|
| 167 | + return 0; |
|
| 168 | + |
|
| 169 | + return $meta->value; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Gets keyword tags for this entry |
|
| 174 | + * @return array |
|
| 175 | + */ |
|
| 176 | + public function getTags() |
|
| 177 | + {
|
|
| 178 | + $tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 179 | + return $tags === NULL ? array() : json_decode($tags->value, true); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Adds a tag to the model |
|
| 184 | + * @param string $tag The tag to add |
|
| 185 | + * @return bool If the insert was successful or not |
|
| 186 | + */ |
|
| 187 | + public function addTag($tag) |
|
| 188 | + {
|
|
| 189 | + $tags = $this->tags; |
|
| 190 | + if (in_array($tag, $tags) || $tag == "") |
|
| 191 | + return false; |
|
| 192 | + |
|
| 193 | + $tags[] = $tag; |
|
| 194 | + $tags = json_encode($tags); |
|
| 195 | + $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 196 | + |
|
| 197 | + $meta->value = $tags; |
|
| 198 | + return $meta->save(); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Removes a tag from the model |
|
| 203 | + * @param string $tag The tag to remove |
|
| 204 | + * @return bool If the removal was successful |
|
| 205 | + */ |
|
| 206 | + public function removeTag($tag) |
|
| 207 | + {
|
|
| 208 | + $tags = $this->tags; |
|
| 209 | + if (!in_array($tag, $tags) || $tag == "") |
|
| 210 | + return false; |
|
| 211 | + |
|
| 212 | + $key = array_search($tag, $tags); |
|
| 213 | + unset($tags[$key]); |
|
| 214 | + $tags = json_encode($tags); |
|
| 215 | + |
|
| 216 | + $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 217 | + $meta->value = $tags; |
|
| 218 | + return $meta->save(); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Provides a base criteria for status, uniqueness, and published states |
|
| 223 | + * @return CDBCriteria |
|
| 224 | + */ |
|
| 225 | + public function getBaseCriteria() |
|
| 226 | + {
|
|
| 227 | + $criteria = new CDbCriteria(); |
|
| 228 | + return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
|
|
| 229 | + ->addCondition('status = 1')
|
|
| 230 | + ->addCondition('UNIX_TIMESTAMP() >= published');
|
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Returns the appropriate status' depending up the user's role |
|
| 235 | + * @return string[] |
|
| 236 | + */ |
|
| 237 | + public function getStatuses() |
|
| 238 | + {
|
|
| 239 | + |
|
| 240 | + if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7) |
|
| 241 | + return array(0 => Yii::t('ciims.models.Content', 'Draft'));
|
|
| 242 | + |
|
| 243 | + return array( |
|
| 244 | + 1 => Yii::t('ciims.models.Content', 'Published'),
|
|
| 245 | + 2 => Yii::t('ciims.models.Content', 'Ready for Review'),
|
|
| 246 | + 0 => Yii::t('ciims.models.Content', 'Draft')
|
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Determines if an article is published or not |
|
| 252 | + * @return boolean |
|
| 253 | + */ |
|
| 254 | + public function isPublished() |
|
| 255 | + {
|
|
| 256 | + return ($this->status == 1 && ($this->published <= time())) ? true : false; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Determines if a given articled is scheduled or not |
|
| 261 | + * @return boolean |
|
| 262 | + */ |
|
| 263 | + public function isScheduled() |
|
| 264 | + {
|
|
| 265 | + return ($this->status == 1 && ($this->published > time())) ? true : false; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Gets a flattened list of keyword tags for jQuery.tag.js |
|
| 270 | + * @return string |
|
| 271 | + */ |
|
| 272 | + public function getTagsFlat() |
|
| 273 | + {
|
|
| 274 | + return implode(',', $this->tags);
|
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Retrieves the layout used from Metadata |
|
| 279 | + * We cache this to speed up the viewfile |
|
| 280 | + */ |
|
| 281 | + public function getLayout() |
|
| 282 | + {
|
|
| 283 | + $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 284 | + return $model === NULL ? 'blog' : $model->value; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Sets the layout |
|
| 289 | + * @param string $data the layout file |
|
| 290 | + * @return boolean |
|
| 291 | + */ |
|
| 292 | + public function setLayout($data) |
|
| 293 | + {
|
|
| 294 | + $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 295 | + $meta->value = $data; |
|
| 296 | + return $meta->save(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Sets the view |
|
| 301 | + * @param string $data The view file |
|
| 302 | + * @return boolean |
|
| 303 | + */ |
|
| 304 | + public function setView($data) |
|
| 305 | + {
|
|
| 306 | + $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
|
|
| 307 | + $meta->value = $data; |
|
| 308 | + return $meta->save(); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Retrieves the viewfile used from Metadata |
|
| 313 | + * We cache this to speed up the viewfile |
|
| 314 | + */ |
|
| 315 | + public function getView() |
|
| 316 | + {
|
|
| 317 | + $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
|
|
| 318 | + return $model === NULL ? 'blog' : $model->value; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Updates the like_count after finding new data |
|
| 323 | + */ |
|
| 324 | + protected function afterFind() |
|
| 325 | + {
|
|
| 326 | + parent::afterFind(); |
|
| 327 | + $this->like_count = $this->getLikeCount(); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Retrieves a list of models based on the current search/filter conditions. |
|
| 332 | + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
| 333 | + */ |
|
| 334 | + public function search() |
|
| 335 | + {
|
|
| 336 | + $criteria=new CDbCriteria; |
|
| 337 | + |
|
| 338 | + $criteria->compare('id',$this->id);
|
|
| 339 | + $criteria->compare('title',$this->title,true);
|
|
| 340 | + $criteria->compare('slug',$this->slug,true);
|
|
| 341 | + $criteria->compare('author_id',$this->author_id,true);
|
|
| 342 | + $criteria->compare('category_id',$this->category_id,true);
|
|
| 343 | + $criteria->compare('content',$this->content,true);
|
|
| 344 | + $criteria->compare('password', $this->password, true);
|
|
| 345 | + $criteria->compare('created',$this->created,true);
|
|
| 346 | + $criteria->compare('updated',$this->updated,true);
|
|
| 347 | + $criteria->compare('status', $this->status, true);
|
|
| 348 | + |
|
| 349 | + // Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare |
|
| 350 | + if (is_bool($this->published)) |
|
| 351 | + {
|
|
| 352 | + if ($this->published) |
|
| 353 | + $criteria->addCondition('published <= UNIX_TIMESTAMP()');
|
|
| 354 | + else |
|
| 355 | + $criteria->addCondition('published > UNIX_TIMESTAMP()');
|
|
| 356 | + } |
|
| 357 | + else |
|
| 358 | + $criteria->compare('published', $this->published,true);
|
|
| 359 | + $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
|
|
| 360 | + |
|
| 361 | + // TODO: Figure out how to restore CActiveDataProvidor by getCommentCount |
|
| 362 | + return new CActiveDataProvider($this, array( |
|
| 363 | + 'criteria' => $criteria, |
|
| 364 | + 'sort' => array( |
|
| 365 | + 'defaultOrder' => 'published DESC' |
|
| 366 | + ), |
|
| 367 | + 'pagination' => array( |
|
| 368 | + 'pageSize' => $this->pageSize |
|
| 369 | + ) |
|
| 370 | + )); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Finds all active records with the specified primary keys. |
|
| 375 | + * Overloaded to support composite primary keys. For our content, we want to find the latest version of that primary key, defined as MAX(vid) WHERE id = pk |
|
| 376 | + * See {@link find()} for detailed explanation about $condition and $params.
|
|
| 377 | + * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). |
|
| 378 | + * @param mixed $condition query condition or criteria. |
|
| 379 | + * @param array $params parameters to be bound to an SQL statement. |
|
| 380 | + * @return array the records found. An empty array is returned if none is found. |
|
| 381 | + */ |
|
| 382 | + public function findByPk($pk, $condition='', $params=array()) |
|
| 383 | + {
|
|
| 384 | + // If we do not supply a condition or parameters, use our overwritten method |
|
| 385 | + if ($condition == '' && empty($params) && $pk != null) |
|
| 386 | + {
|
|
| 387 | + if (!is_numeric($pk)) |
|
| 388 | + throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 389 | 389 | |
| 390 | - $criteria = new CDbCriteria; |
|
| 391 | - $criteria->addCondition("t.id=:pk");
|
|
| 392 | - $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
|
|
| 393 | - $criteria->params = array( |
|
| 394 | - ':pk' => $pk |
|
| 395 | - ); |
|
| 396 | - return $this->query($criteria); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return parent::findByPk($pk, $condition, $params); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Lists all revisions in the database for a givenid |
|
| 404 | - * @param int $id [description] |
|
| 405 | - * @return array |
|
| 406 | - */ |
|
| 407 | - public function findRevisions($id) |
|
| 408 | - {
|
|
| 409 | - if (!is_numeric($id)) |
|
| 410 | - throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 390 | + $criteria = new CDbCriteria; |
|
| 391 | + $criteria->addCondition("t.id=:pk");
|
|
| 392 | + $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
|
|
| 393 | + $criteria->params = array( |
|
| 394 | + ':pk' => $pk |
|
| 395 | + ); |
|
| 396 | + return $this->query($criteria); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return parent::findByPk($pk, $condition, $params); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Lists all revisions in the database for a givenid |
|
| 404 | + * @param int $id [description] |
|
| 405 | + * @return array |
|
| 406 | + */ |
|
| 407 | + public function findRevisions($id) |
|
| 408 | + {
|
|
| 409 | + if (!is_numeric($id)) |
|
| 410 | + throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 411 | 411 | |
| 412 | - $criteria = new CDbCriteria; |
|
| 413 | - $criteria->addCondition("id=:id");
|
|
| 414 | - $criteria->params = array( |
|
| 415 | - ':id' => $id |
|
| 416 | - ); |
|
| 417 | - $criteria->order = 'vid DESC'; |
|
| 418 | - |
|
| 419 | - return $this->query($criteria, true); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * BeforeValidate |
|
| 424 | - * @see CActiveRecord::beforeValidate |
|
| 425 | - */ |
|
| 426 | - public function beforeValidate() |
|
| 427 | - {
|
|
| 428 | - // Allow publication times to be set automatically |
|
| 429 | - if (empty($this->published)) |
|
| 430 | - $this->published = time(); |
|
| 431 | - |
|
| 432 | - if (strlen($this->excerpt) == 0) |
|
| 433 | - $this->excerpt = $this->myTruncate($this->content, 250, '.', ''); |
|
| 434 | - |
|
| 435 | - return parent::beforeValidate(); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Saves a prototype copy of the model so that we can get an id back to work with |
|
| 440 | - * @return boolean $model->save(false) without any validation rules |
|
| 441 | - */ |
|
| 442 | - public function savePrototype($author_id) |
|
| 443 | - {
|
|
| 444 | - $this->title = ''; |
|
| 445 | - $this->content = ''; |
|
| 446 | - $this->excerpt = ''; |
|
| 447 | - $this->commentable = 1; |
|
| 448 | - $this->status = 0; |
|
| 449 | - $this->category_id = 1; |
|
| 450 | - $this->type_id = 2; |
|
| 451 | - $this->password = null; |
|
| 452 | - $this->created = time(); |
|
| 453 | - $this->updated = time(); |
|
| 454 | - $this->published = time(); |
|
| 455 | - $this->vid = 1; |
|
| 456 | - $this->slug = ""; |
|
| 457 | - $this->author_id = $author_id; |
|
| 458 | - |
|
| 459 | - // TODO: Why doesn't Yii return the PK id field? But it does return VID? AutoIncriment bug? |
|
| 460 | - if ($this->save(false)) |
|
| 461 | - {
|
|
| 462 | - $data = Content::model()->findByAttributes(array('created' => $this->created));
|
|
| 463 | - $this->id = $data->id; |
|
| 464 | - return true; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - return false; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * BeforeSave |
|
| 472 | - * Clears caches for rebuilding, creates the end slug that we are going to use |
|
| 473 | - * @see CActiveRecord::beforeSave(); |
|
| 474 | - */ |
|
| 475 | - public function beforeSave() |
|
| 476 | - {
|
|
| 477 | - $this->slug = $this->verifySlug($this->slug, $this->title); |
|
| 478 | - Yii::app()->cache->delete('CiiMS::Content::list');
|
|
| 479 | - Yii::app()->cache->delete('CiiMS::Routes');
|
|
| 480 | - |
|
| 481 | - Yii::app()->cache->set('content-' . $this->id . '-layout', $this->layoutFile);
|
|
| 482 | - Yii::app()->cache->set('content-' . $this->id . '-view', $this->viewFile);
|
|
| 483 | - |
|
| 484 | - return parent::beforeSave(); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * AfterSave |
|
| 489 | - * Updates the layout and view if necessary |
|
| 490 | - * @see CActiveRecord::afterSave() |
|
| 491 | - */ |
|
| 492 | - public function afterSave() |
|
| 493 | - {
|
|
| 494 | - // Delete the AutoSave document on update |
|
| 495 | - if ($this->isPublished()) |
|
| 496 | - {
|
|
| 497 | - $autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
|
|
| 498 | - if ($autosaveModel != NULL) |
|
| 499 | - $autosaveModel->delete(); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - return parent::afterSave(); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * BeforeDelete |
|
| 507 | - * Clears caches for rebuilding |
|
| 508 | - * @see CActiveRecord::beforeDelete |
|
| 509 | - */ |
|
| 510 | - public function beforeDelete() |
|
| 511 | - {
|
|
| 512 | - Yii::app()->cache->delete('CiiMS::Content::list');
|
|
| 513 | - Yii::app()->cache->delete('CiiMS::Routes');
|
|
| 514 | - Yii::app()->cache->delete('content-' . $this->id . '-layout');
|
|
| 515 | - Yii::app()->cache->delete('content-' . $this->id . '-view');
|
|
| 516 | - |
|
| 517 | - return parent::beforeDelete(); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Retrieves the available view files under the current theme |
|
| 523 | - * @return array A list of files by name |
|
| 524 | - */ |
|
| 525 | - public function getViewFiles($theme=null) |
|
| 526 | - {
|
|
| 527 | - return $this->getFiles($theme, 'views.content'); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Retrieves the available layouts under the current theme |
|
| 532 | - * @return array A list of files by name |
|
| 533 | - */ |
|
| 534 | - public function getLayoutFiles($theme=null) |
|
| 535 | - {
|
|
| 536 | - return $this->getFiles($theme, 'views.layouts'); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Retrieves view files for a particular path |
|
| 541 | - * @param string $theme The theme to reference |
|
| 542 | - * @param string $type The view type to lookup |
|
| 543 | - * @return array $files An array of files |
|
| 544 | - */ |
|
| 545 | - private function getFiles($theme=null, $type='views') |
|
| 546 | - {
|
|
| 547 | - if ($theme === null) |
|
| 548 | - $theme = Cii::getConfig('theme', 'default');
|
|
| 549 | - |
|
| 550 | - $folder = $type; |
|
| 551 | - |
|
| 552 | - if ($type == 'view') |
|
| 553 | - $folder = 'content'; |
|
| 554 | - |
|
| 555 | - $returnFiles = array(); |
|
| 556 | - |
|
| 557 | - if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
|
|
| 558 | - $theme = 'default'; |
|
| 559 | - |
|
| 560 | - $files = Yii::app()->cache->get($theme.'-available-' . $type); |
|
| 561 | - |
|
| 562 | - if ($files === false) |
|
| 563 | - {
|
|
| 564 | - $fileHelper = new CFileHelper; |
|
| 565 | - $files = $fileHelper->findFiles(Yii::getPathOfAlias('base.themes.' . $theme .'.' . $folder), array('fileTypes'=>array('php'), 'level'=>0));
|
|
| 566 | - Yii::app()->cache->set($theme.'-available-' . $type, $files); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - foreach ($files as $file) |
|
| 570 | - {
|
|
| 571 | - $f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
|
|
| 572 | - |
|
| 573 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 574 | - $f = trim(substr($f, strrpos($f, '\\') + 1)); |
|
| 575 | - |
|
| 576 | - if (!in_array($f, array('all', 'password', '_post')))
|
|
| 577 | - $returnFiles[$f] = $f; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - return $returnFiles; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Fancy truncate function to help clean up our strings for the excerpt |
|
| 585 | - * @param string $string The string we want to apply the text to |
|
| 586 | - * @param int $limit How many characters we want to break into |
|
| 587 | - * @param string $break Characters we want to break on if possible |
|
| 588 | - * @param string $pad The padding we want to apply |
|
| 589 | - * @return string Truncated string |
|
| 590 | - */ |
|
| 591 | - private function myTruncate($string, $limit, $break=".", $pad="...") |
|
| 592 | - {
|
|
| 593 | - // return with no change if string is shorter than $limit |
|
| 594 | - if(strlen($string) <= $limit) |
|
| 595 | - return $string; |
|
| 596 | - |
|
| 597 | - // is $break present between $limit and the end of the string? |
|
| 598 | - if(false !== ($breakpoint = strpos($string, $break, $limit))) |
|
| 599 | - {
|
|
| 600 | - if($breakpoint < strlen($string) - 1) |
|
| 601 | - {
|
|
| 602 | - $string = substr($string, 0, $breakpoint) . $pad; |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - return $string; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * checkSlug - Recursive method to verify that the slug can be used |
|
| 611 | - * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk |
|
| 612 | - * @param string $slug - the slug to be checked |
|
| 613 | - * @param int $id - the numeric id to be appended to the slug if a conflict exists |
|
| 614 | - * @return string $slug - the final slug to be used |
|
| 615 | - */ |
|
| 616 | - public function checkSlug($slug, $id=NULL) |
|
| 617 | - {
|
|
| 618 | - $category = false; |
|
| 619 | - |
|
| 620 | - // Find the number of items that have the same slug as this one |
|
| 621 | - $count = $this->countByAttributes(array('slug'=>$slug . $id));
|
|
| 622 | - |
|
| 623 | - // Make sure we don't have a collision with a Category |
|
| 624 | - if ($count == 0) |
|
| 625 | - {
|
|
| 626 | - $category = true; |
|
| 627 | - $count = Categories::model()->countByAttributes(array('slug'=>$slug . $id));
|
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // If we found an item that matched, it's possible that it is the current item (or a previous version of it) |
|
| 631 | - // in which case we don't need to alter the slug |
|
| 632 | - if ($count) |
|
| 633 | - {
|
|
| 634 | - // Ensures we don't have a collision on category |
|
| 635 | - if ($category) |
|
| 636 | - return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 637 | - |
|
| 638 | - // Pull the data that matches |
|
| 639 | - $data = $this->findByPk($this->id); |
|
| 640 | - |
|
| 641 | - // Check the pulled data id to the current item |
|
| 642 | - if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug) |
|
| 643 | - return $slug; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) |
|
| 647 | - return $slug . $id; |
|
| 648 | - else |
|
| 649 | - return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 650 | - } |
|
| 412 | + $criteria = new CDbCriteria; |
|
| 413 | + $criteria->addCondition("id=:id");
|
|
| 414 | + $criteria->params = array( |
|
| 415 | + ':id' => $id |
|
| 416 | + ); |
|
| 417 | + $criteria->order = 'vid DESC'; |
|
| 418 | + |
|
| 419 | + return $this->query($criteria, true); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * BeforeValidate |
|
| 424 | + * @see CActiveRecord::beforeValidate |
|
| 425 | + */ |
|
| 426 | + public function beforeValidate() |
|
| 427 | + {
|
|
| 428 | + // Allow publication times to be set automatically |
|
| 429 | + if (empty($this->published)) |
|
| 430 | + $this->published = time(); |
|
| 431 | + |
|
| 432 | + if (strlen($this->excerpt) == 0) |
|
| 433 | + $this->excerpt = $this->myTruncate($this->content, 250, '.', ''); |
|
| 434 | + |
|
| 435 | + return parent::beforeValidate(); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Saves a prototype copy of the model so that we can get an id back to work with |
|
| 440 | + * @return boolean $model->save(false) without any validation rules |
|
| 441 | + */ |
|
| 442 | + public function savePrototype($author_id) |
|
| 443 | + {
|
|
| 444 | + $this->title = ''; |
|
| 445 | + $this->content = ''; |
|
| 446 | + $this->excerpt = ''; |
|
| 447 | + $this->commentable = 1; |
|
| 448 | + $this->status = 0; |
|
| 449 | + $this->category_id = 1; |
|
| 450 | + $this->type_id = 2; |
|
| 451 | + $this->password = null; |
|
| 452 | + $this->created = time(); |
|
| 453 | + $this->updated = time(); |
|
| 454 | + $this->published = time(); |
|
| 455 | + $this->vid = 1; |
|
| 456 | + $this->slug = ""; |
|
| 457 | + $this->author_id = $author_id; |
|
| 458 | + |
|
| 459 | + // TODO: Why doesn't Yii return the PK id field? But it does return VID? AutoIncriment bug? |
|
| 460 | + if ($this->save(false)) |
|
| 461 | + {
|
|
| 462 | + $data = Content::model()->findByAttributes(array('created' => $this->created));
|
|
| 463 | + $this->id = $data->id; |
|
| 464 | + return true; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + return false; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * BeforeSave |
|
| 472 | + * Clears caches for rebuilding, creates the end slug that we are going to use |
|
| 473 | + * @see CActiveRecord::beforeSave(); |
|
| 474 | + */ |
|
| 475 | + public function beforeSave() |
|
| 476 | + {
|
|
| 477 | + $this->slug = $this->verifySlug($this->slug, $this->title); |
|
| 478 | + Yii::app()->cache->delete('CiiMS::Content::list');
|
|
| 479 | + Yii::app()->cache->delete('CiiMS::Routes');
|
|
| 480 | + |
|
| 481 | + Yii::app()->cache->set('content-' . $this->id . '-layout', $this->layoutFile);
|
|
| 482 | + Yii::app()->cache->set('content-' . $this->id . '-view', $this->viewFile);
|
|
| 483 | + |
|
| 484 | + return parent::beforeSave(); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * AfterSave |
|
| 489 | + * Updates the layout and view if necessary |
|
| 490 | + * @see CActiveRecord::afterSave() |
|
| 491 | + */ |
|
| 492 | + public function afterSave() |
|
| 493 | + {
|
|
| 494 | + // Delete the AutoSave document on update |
|
| 495 | + if ($this->isPublished()) |
|
| 496 | + {
|
|
| 497 | + $autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
|
|
| 498 | + if ($autosaveModel != NULL) |
|
| 499 | + $autosaveModel->delete(); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + return parent::afterSave(); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * BeforeDelete |
|
| 507 | + * Clears caches for rebuilding |
|
| 508 | + * @see CActiveRecord::beforeDelete |
|
| 509 | + */ |
|
| 510 | + public function beforeDelete() |
|
| 511 | + {
|
|
| 512 | + Yii::app()->cache->delete('CiiMS::Content::list');
|
|
| 513 | + Yii::app()->cache->delete('CiiMS::Routes');
|
|
| 514 | + Yii::app()->cache->delete('content-' . $this->id . '-layout');
|
|
| 515 | + Yii::app()->cache->delete('content-' . $this->id . '-view');
|
|
| 516 | + |
|
| 517 | + return parent::beforeDelete(); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Retrieves the available view files under the current theme |
|
| 523 | + * @return array A list of files by name |
|
| 524 | + */ |
|
| 525 | + public function getViewFiles($theme=null) |
|
| 526 | + {
|
|
| 527 | + return $this->getFiles($theme, 'views.content'); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Retrieves the available layouts under the current theme |
|
| 532 | + * @return array A list of files by name |
|
| 533 | + */ |
|
| 534 | + public function getLayoutFiles($theme=null) |
|
| 535 | + {
|
|
| 536 | + return $this->getFiles($theme, 'views.layouts'); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Retrieves view files for a particular path |
|
| 541 | + * @param string $theme The theme to reference |
|
| 542 | + * @param string $type The view type to lookup |
|
| 543 | + * @return array $files An array of files |
|
| 544 | + */ |
|
| 545 | + private function getFiles($theme=null, $type='views') |
|
| 546 | + {
|
|
| 547 | + if ($theme === null) |
|
| 548 | + $theme = Cii::getConfig('theme', 'default');
|
|
| 549 | + |
|
| 550 | + $folder = $type; |
|
| 551 | + |
|
| 552 | + if ($type == 'view') |
|
| 553 | + $folder = 'content'; |
|
| 554 | + |
|
| 555 | + $returnFiles = array(); |
|
| 556 | + |
|
| 557 | + if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
|
|
| 558 | + $theme = 'default'; |
|
| 559 | + |
|
| 560 | + $files = Yii::app()->cache->get($theme.'-available-' . $type); |
|
| 561 | + |
|
| 562 | + if ($files === false) |
|
| 563 | + {
|
|
| 564 | + $fileHelper = new CFileHelper; |
|
| 565 | + $files = $fileHelper->findFiles(Yii::getPathOfAlias('base.themes.' . $theme .'.' . $folder), array('fileTypes'=>array('php'), 'level'=>0));
|
|
| 566 | + Yii::app()->cache->set($theme.'-available-' . $type, $files); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + foreach ($files as $file) |
|
| 570 | + {
|
|
| 571 | + $f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
|
|
| 572 | + |
|
| 573 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 574 | + $f = trim(substr($f, strrpos($f, '\\') + 1)); |
|
| 575 | + |
|
| 576 | + if (!in_array($f, array('all', 'password', '_post')))
|
|
| 577 | + $returnFiles[$f] = $f; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + return $returnFiles; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Fancy truncate function to help clean up our strings for the excerpt |
|
| 585 | + * @param string $string The string we want to apply the text to |
|
| 586 | + * @param int $limit How many characters we want to break into |
|
| 587 | + * @param string $break Characters we want to break on if possible |
|
| 588 | + * @param string $pad The padding we want to apply |
|
| 589 | + * @return string Truncated string |
|
| 590 | + */ |
|
| 591 | + private function myTruncate($string, $limit, $break=".", $pad="...") |
|
| 592 | + {
|
|
| 593 | + // return with no change if string is shorter than $limit |
|
| 594 | + if(strlen($string) <= $limit) |
|
| 595 | + return $string; |
|
| 596 | + |
|
| 597 | + // is $break present between $limit and the end of the string? |
|
| 598 | + if(false !== ($breakpoint = strpos($string, $break, $limit))) |
|
| 599 | + {
|
|
| 600 | + if($breakpoint < strlen($string) - 1) |
|
| 601 | + {
|
|
| 602 | + $string = substr($string, 0, $breakpoint) . $pad; |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + return $string; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * checkSlug - Recursive method to verify that the slug can be used |
|
| 611 | + * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk |
|
| 612 | + * @param string $slug - the slug to be checked |
|
| 613 | + * @param int $id - the numeric id to be appended to the slug if a conflict exists |
|
| 614 | + * @return string $slug - the final slug to be used |
|
| 615 | + */ |
|
| 616 | + public function checkSlug($slug, $id=NULL) |
|
| 617 | + {
|
|
| 618 | + $category = false; |
|
| 619 | + |
|
| 620 | + // Find the number of items that have the same slug as this one |
|
| 621 | + $count = $this->countByAttributes(array('slug'=>$slug . $id));
|
|
| 622 | + |
|
| 623 | + // Make sure we don't have a collision with a Category |
|
| 624 | + if ($count == 0) |
|
| 625 | + {
|
|
| 626 | + $category = true; |
|
| 627 | + $count = Categories::model()->countByAttributes(array('slug'=>$slug . $id));
|
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // If we found an item that matched, it's possible that it is the current item (or a previous version of it) |
|
| 631 | + // in which case we don't need to alter the slug |
|
| 632 | + if ($count) |
|
| 633 | + {
|
|
| 634 | + // Ensures we don't have a collision on category |
|
| 635 | + if ($category) |
|
| 636 | + return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 637 | + |
|
| 638 | + // Pull the data that matches |
|
| 639 | + $data = $this->findByPk($this->id); |
|
| 640 | + |
|
| 641 | + // Check the pulled data id to the current item |
|
| 642 | + if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug) |
|
| 643 | + return $slug; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) |
|
| 647 | + return $slug . $id; |
|
| 648 | + else |
|
| 649 | + return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 650 | + } |
|
| 651 | 651 | } |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | * @property Categories $category |
| 30 | 30 | * @property ContentMetadata[] $contentMetadatas |
| 31 | 31 | */ |
| 32 | -class Content extends CiiModel |
|
| 33 | -{
|
|
| 32 | +class Content extends CiiModel |
|
| 33 | +{ |
|
| 34 | 34 | public $pageSize = 9; |
| 35 | 35 | |
| 36 | 36 | public $viewFile = 'blog'; |
@@ -44,32 +44,32 @@ discard block |
||
| 44 | 44 | * @param string $className active record class name. |
| 45 | 45 | * @return Content the static model class |
| 46 | 46 | */ |
| 47 | - public static function model($className=__CLASS__) |
|
| 48 | - {
|
|
| 47 | + public static function model($className=__CLASS__) |
|
| 48 | + { |
|
| 49 | 49 | return parent::model($className); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @return string the associated database table name |
| 54 | 54 | */ |
| 55 | - public function tableName() |
|
| 56 | - {
|
|
| 55 | + public function tableName() |
|
| 56 | + { |
|
| 57 | 57 | return 'content'; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @return string[] primary key of the table |
| 62 | 62 | **/ |
| 63 | - public function primaryKey() |
|
| 64 | - {
|
|
| 63 | + public function primaryKey() |
|
| 64 | + { |
|
| 65 | 65 | return array('id');
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return array validation rules for model attributes. |
| 70 | 70 | */ |
| 71 | - public function rules() |
|
| 72 | - {
|
|
| 71 | + public function rules() |
|
| 72 | + { |
|
| 73 | 73 | // NOTE: you should only define rules for those attributes that |
| 74 | 74 | // will receive user inputs. |
| 75 | 75 | return array( |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * @return array relational rules. |
| 86 | 86 | */ |
| 87 | - public function relations() |
|
| 88 | - {
|
|
| 87 | + public function relations() |
|
| 88 | + { |
|
| 89 | 89 | // NOTE: you may need to adjust the relation name and the related |
| 90 | 90 | // class name for the relations automatically generated below. |
| 91 | 91 | return array( |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | /** |
| 100 | 100 | * @return array customized attribute labels (name=>label) |
| 101 | 101 | */ |
| 102 | - public function attributeLabels() |
|
| 103 | - {
|
|
| 102 | + public function attributeLabels() |
|
| 103 | + { |
|
| 104 | 104 | return array( |
| 105 | 105 | 'id' => Yii::t('ciims.models.Content', 'ID'),
|
| 106 | 106 | 'vid' => Yii::t('ciims.models.Content', 'Version'),
|
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text |
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | - public function getSafeOutput() |
|
| 131 | - {
|
|
| 130 | + public function getSafeOutput() |
|
| 131 | + { |
|
| 132 | 132 | $md = new CMarkdownParser; |
| 133 | 133 | $dom = new DOMDocument(); |
| 134 | 134 | $dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
|
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | return $md->safeTransform($dom->saveHtml()); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public function getExtract() |
|
| 151 | - {
|
|
| 150 | + public function getExtract() |
|
| 151 | + { |
|
| 152 | 152 | Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
|
| 153 | 153 | return $this->excerpt; |
| 154 | 154 | } |
@@ -160,11 +160,12 @@ discard block |
||
| 160 | 160 | * @return int The number of likes for this post |
| 161 | 161 | */ |
| 162 | 162 | |
| 163 | - public function getLikeCount() |
|
| 164 | - {
|
|
| 163 | + public function getLikeCount() |
|
| 164 | + { |
|
| 165 | 165 | $meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
|
| 166 | - if ($meta === NULL) |
|
| 167 | - return 0; |
|
| 166 | + if ($meta === NULL) { |
|
| 167 | + return 0; |
|
| 168 | + } |
|
| 168 | 169 | |
| 169 | 170 | return $meta->value; |
| 170 | 171 | } |
@@ -173,8 +174,8 @@ discard block |
||
| 173 | 174 | * Gets keyword tags for this entry |
| 174 | 175 | * @return array |
| 175 | 176 | */ |
| 176 | - public function getTags() |
|
| 177 | - {
|
|
| 177 | + public function getTags() |
|
| 178 | + { |
|
| 178 | 179 | $tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
|
| 179 | 180 | return $tags === NULL ? array() : json_decode($tags->value, true); |
| 180 | 181 | } |
@@ -184,11 +185,12 @@ discard block |
||
| 184 | 185 | * @param string $tag The tag to add |
| 185 | 186 | * @return bool If the insert was successful or not |
| 186 | 187 | */ |
| 187 | - public function addTag($tag) |
|
| 188 | - {
|
|
| 188 | + public function addTag($tag) |
|
| 189 | + { |
|
| 189 | 190 | $tags = $this->tags; |
| 190 | - if (in_array($tag, $tags) || $tag == "") |
|
| 191 | - return false; |
|
| 191 | + if (in_array($tag, $tags) || $tag == "") { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 192 | 194 | |
| 193 | 195 | $tags[] = $tag; |
| 194 | 196 | $tags = json_encode($tags); |
@@ -203,11 +205,12 @@ discard block |
||
| 203 | 205 | * @param string $tag The tag to remove |
| 204 | 206 | * @return bool If the removal was successful |
| 205 | 207 | */ |
| 206 | - public function removeTag($tag) |
|
| 207 | - {
|
|
| 208 | + public function removeTag($tag) |
|
| 209 | + { |
|
| 208 | 210 | $tags = $this->tags; |
| 209 | - if (!in_array($tag, $tags) || $tag == "") |
|
| 210 | - return false; |
|
| 211 | + if (!in_array($tag, $tags) || $tag == "") { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 211 | 214 | |
| 212 | 215 | $key = array_search($tag, $tags); |
| 213 | 216 | unset($tags[$key]); |
@@ -222,8 +225,8 @@ discard block |
||
| 222 | 225 | * Provides a base criteria for status, uniqueness, and published states |
| 223 | 226 | * @return CDBCriteria |
| 224 | 227 | */ |
| 225 | - public function getBaseCriteria() |
|
| 226 | - {
|
|
| 228 | + public function getBaseCriteria() |
|
| 229 | + { |
|
| 227 | 230 | $criteria = new CDbCriteria(); |
| 228 | 231 | return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
|
| 229 | 232 | ->addCondition('status = 1')
|
@@ -234,11 +237,12 @@ discard block |
||
| 234 | 237 | * Returns the appropriate status' depending up the user's role |
| 235 | 238 | * @return string[] |
| 236 | 239 | */ |
| 237 | - public function getStatuses() |
|
| 238 | - {
|
|
| 240 | + public function getStatuses() |
|
| 241 | + { |
|
| 239 | 242 | |
| 240 | - if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7) |
|
| 241 | - return array(0 => Yii::t('ciims.models.Content', 'Draft'));
|
|
| 243 | + if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7) { |
|
| 244 | + return array(0 => Yii::t('ciims.models.Content', 'Draft')); |
|
| 245 | + } |
|
| 242 | 246 | |
| 243 | 247 | return array( |
| 244 | 248 | 1 => Yii::t('ciims.models.Content', 'Published'),
|
@@ -251,8 +255,8 @@ discard block |
||
| 251 | 255 | * Determines if an article is published or not |
| 252 | 256 | * @return boolean |
| 253 | 257 | */ |
| 254 | - public function isPublished() |
|
| 255 | - {
|
|
| 258 | + public function isPublished() |
|
| 259 | + { |
|
| 256 | 260 | return ($this->status == 1 && ($this->published <= time())) ? true : false; |
| 257 | 261 | } |
| 258 | 262 | |
@@ -260,8 +264,8 @@ discard block |
||
| 260 | 264 | * Determines if a given articled is scheduled or not |
| 261 | 265 | * @return boolean |
| 262 | 266 | */ |
| 263 | - public function isScheduled() |
|
| 264 | - {
|
|
| 267 | + public function isScheduled() |
|
| 268 | + { |
|
| 265 | 269 | return ($this->status == 1 && ($this->published > time())) ? true : false; |
| 266 | 270 | } |
| 267 | 271 | |
@@ -269,8 +273,8 @@ discard block |
||
| 269 | 273 | * Gets a flattened list of keyword tags for jQuery.tag.js |
| 270 | 274 | * @return string |
| 271 | 275 | */ |
| 272 | - public function getTagsFlat() |
|
| 273 | - {
|
|
| 276 | + public function getTagsFlat() |
|
| 277 | + { |
|
| 274 | 278 | return implode(',', $this->tags);
|
| 275 | 279 | } |
| 276 | 280 | |
@@ -278,8 +282,8 @@ discard block |
||
| 278 | 282 | * Retrieves the layout used from Metadata |
| 279 | 283 | * We cache this to speed up the viewfile |
| 280 | 284 | */ |
| 281 | - public function getLayout() |
|
| 282 | - {
|
|
| 285 | + public function getLayout() |
|
| 286 | + { |
|
| 283 | 287 | $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
|
| 284 | 288 | return $model === NULL ? 'blog' : $model->value; |
| 285 | 289 | } |
@@ -289,8 +293,8 @@ discard block |
||
| 289 | 293 | * @param string $data the layout file |
| 290 | 294 | * @return boolean |
| 291 | 295 | */ |
| 292 | - public function setLayout($data) |
|
| 293 | - {
|
|
| 296 | + public function setLayout($data) |
|
| 297 | + { |
|
| 294 | 298 | $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
|
| 295 | 299 | $meta->value = $data; |
| 296 | 300 | return $meta->save(); |
@@ -301,8 +305,8 @@ discard block |
||
| 301 | 305 | * @param string $data The view file |
| 302 | 306 | * @return boolean |
| 303 | 307 | */ |
| 304 | - public function setView($data) |
|
| 305 | - {
|
|
| 308 | + public function setView($data) |
|
| 309 | + { |
|
| 306 | 310 | $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
|
| 307 | 311 | $meta->value = $data; |
| 308 | 312 | return $meta->save(); |
@@ -312,8 +316,8 @@ discard block |
||
| 312 | 316 | * Retrieves the viewfile used from Metadata |
| 313 | 317 | * We cache this to speed up the viewfile |
| 314 | 318 | */ |
| 315 | - public function getView() |
|
| 316 | - {
|
|
| 319 | + public function getView() |
|
| 320 | + { |
|
| 317 | 321 | $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
|
| 318 | 322 | return $model === NULL ? 'blog' : $model->value; |
| 319 | 323 | } |
@@ -321,8 +325,8 @@ discard block |
||
| 321 | 325 | /** |
| 322 | 326 | * Updates the like_count after finding new data |
| 323 | 327 | */ |
| 324 | - protected function afterFind() |
|
| 325 | - {
|
|
| 328 | + protected function afterFind() |
|
| 329 | + { |
|
| 326 | 330 | parent::afterFind(); |
| 327 | 331 | $this->like_count = $this->getLikeCount(); |
| 328 | 332 | } |
@@ -331,8 +335,8 @@ discard block |
||
| 331 | 335 | * Retrieves a list of models based on the current search/filter conditions. |
| 332 | 336 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
| 333 | 337 | */ |
| 334 | - public function search() |
|
| 335 | - {
|
|
| 338 | + public function search() |
|
| 339 | + { |
|
| 336 | 340 | $criteria=new CDbCriteria; |
| 337 | 341 | |
| 338 | 342 | $criteria->compare('id',$this->id);
|
@@ -349,13 +353,14 @@ discard block |
||
| 349 | 353 | // Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare |
| 350 | 354 | if (is_bool($this->published)) |
| 351 | 355 | {
|
| 352 | - if ($this->published) |
|
| 353 | - $criteria->addCondition('published <= UNIX_TIMESTAMP()');
|
|
| 354 | - else |
|
| 355 | - $criteria->addCondition('published > UNIX_TIMESTAMP()');
|
|
| 356 | - } |
|
| 357 | - else |
|
| 358 | - $criteria->compare('published', $this->published,true);
|
|
| 356 | + if ($this->published) { |
|
| 357 | + $criteria->addCondition('published <= UNIX_TIMESTAMP()'); |
|
| 358 | + } else { |
|
| 359 | + $criteria->addCondition('published > UNIX_TIMESTAMP()'); |
|
| 360 | + } |
|
| 361 | + } else { |
|
| 362 | + $criteria->compare('published', $this->published,true); |
|
| 363 | + } |
|
| 359 | 364 | $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
|
| 360 | 365 | |
| 361 | 366 | // TODO: Figure out how to restore CActiveDataProvidor by getCommentCount |
@@ -379,13 +384,14 @@ discard block |
||
| 379 | 384 | * @param array $params parameters to be bound to an SQL statement. |
| 380 | 385 | * @return array the records found. An empty array is returned if none is found. |
| 381 | 386 | */ |
| 382 | - public function findByPk($pk, $condition='', $params=array()) |
|
| 383 | - {
|
|
| 387 | + public function findByPk($pk, $condition='', $params=array()) |
|
| 388 | + { |
|
| 384 | 389 | // If we do not supply a condition or parameters, use our overwritten method |
| 385 | 390 | if ($condition == '' && empty($params) && $pk != null) |
| 386 | 391 | {
|
| 387 | - if (!is_numeric($pk)) |
|
| 388 | - throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 392 | + if (!is_numeric($pk)) { |
|
| 393 | + throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.')); |
|
| 394 | + } |
|
| 389 | 395 | |
| 390 | 396 | $criteria = new CDbCriteria; |
| 391 | 397 | $criteria->addCondition("t.id=:pk");
|
@@ -404,10 +410,11 @@ discard block |
||
| 404 | 410 | * @param int $id [description] |
| 405 | 411 | * @return array |
| 406 | 412 | */ |
| 407 | - public function findRevisions($id) |
|
| 408 | - {
|
|
| 409 | - if (!is_numeric($id)) |
|
| 410 | - throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 413 | + public function findRevisions($id) |
|
| 414 | + { |
|
| 415 | + if (!is_numeric($id)) { |
|
| 416 | + throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.')); |
|
| 417 | + } |
|
| 411 | 418 | |
| 412 | 419 | $criteria = new CDbCriteria; |
| 413 | 420 | $criteria->addCondition("id=:id");
|
@@ -423,14 +430,16 @@ discard block |
||
| 423 | 430 | * BeforeValidate |
| 424 | 431 | * @see CActiveRecord::beforeValidate |
| 425 | 432 | */ |
| 426 | - public function beforeValidate() |
|
| 427 | - {
|
|
| 433 | + public function beforeValidate() |
|
| 434 | + { |
|
| 428 | 435 | // Allow publication times to be set automatically |
| 429 | - if (empty($this->published)) |
|
| 430 | - $this->published = time(); |
|
| 436 | + if (empty($this->published)) { |
|
| 437 | + $this->published = time(); |
|
| 438 | + } |
|
| 431 | 439 | |
| 432 | - if (strlen($this->excerpt) == 0) |
|
| 433 | - $this->excerpt = $this->myTruncate($this->content, 250, '.', ''); |
|
| 440 | + if (strlen($this->excerpt) == 0) { |
|
| 441 | + $this->excerpt = $this->myTruncate($this->content, 250, '.', ''); |
|
| 442 | + } |
|
| 434 | 443 | |
| 435 | 444 | return parent::beforeValidate(); |
| 436 | 445 | } |
@@ -439,8 +448,8 @@ discard block |
||
| 439 | 448 | * Saves a prototype copy of the model so that we can get an id back to work with |
| 440 | 449 | * @return boolean $model->save(false) without any validation rules |
| 441 | 450 | */ |
| 442 | - public function savePrototype($author_id) |
|
| 443 | - {
|
|
| 451 | + public function savePrototype($author_id) |
|
| 452 | + { |
|
| 444 | 453 | $this->title = ''; |
| 445 | 454 | $this->content = ''; |
| 446 | 455 | $this->excerpt = ''; |
@@ -472,8 +481,8 @@ discard block |
||
| 472 | 481 | * Clears caches for rebuilding, creates the end slug that we are going to use |
| 473 | 482 | * @see CActiveRecord::beforeSave(); |
| 474 | 483 | */ |
| 475 | - public function beforeSave() |
|
| 476 | - {
|
|
| 484 | + public function beforeSave() |
|
| 485 | + { |
|
| 477 | 486 | $this->slug = $this->verifySlug($this->slug, $this->title); |
| 478 | 487 | Yii::app()->cache->delete('CiiMS::Content::list');
|
| 479 | 488 | Yii::app()->cache->delete('CiiMS::Routes');
|
@@ -489,14 +498,15 @@ discard block |
||
| 489 | 498 | * Updates the layout and view if necessary |
| 490 | 499 | * @see CActiveRecord::afterSave() |
| 491 | 500 | */ |
| 492 | - public function afterSave() |
|
| 493 | - {
|
|
| 501 | + public function afterSave() |
|
| 502 | + { |
|
| 494 | 503 | // Delete the AutoSave document on update |
| 495 | 504 | if ($this->isPublished()) |
| 496 | 505 | {
|
| 497 | 506 | $autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
|
| 498 | - if ($autosaveModel != NULL) |
|
| 499 | - $autosaveModel->delete(); |
|
| 507 | + if ($autosaveModel != NULL) { |
|
| 508 | + $autosaveModel->delete(); |
|
| 509 | + } |
|
| 500 | 510 | } |
| 501 | 511 | |
| 502 | 512 | return parent::afterSave(); |
@@ -507,8 +517,8 @@ discard block |
||
| 507 | 517 | * Clears caches for rebuilding |
| 508 | 518 | * @see CActiveRecord::beforeDelete |
| 509 | 519 | */ |
| 510 | - public function beforeDelete() |
|
| 511 | - {
|
|
| 520 | + public function beforeDelete() |
|
| 521 | + { |
|
| 512 | 522 | Yii::app()->cache->delete('CiiMS::Content::list');
|
| 513 | 523 | Yii::app()->cache->delete('CiiMS::Routes');
|
| 514 | 524 | Yii::app()->cache->delete('content-' . $this->id . '-layout');
|
@@ -522,8 +532,8 @@ discard block |
||
| 522 | 532 | * Retrieves the available view files under the current theme |
| 523 | 533 | * @return array A list of files by name |
| 524 | 534 | */ |
| 525 | - public function getViewFiles($theme=null) |
|
| 526 | - {
|
|
| 535 | + public function getViewFiles($theme=null) |
|
| 536 | + { |
|
| 527 | 537 | return $this->getFiles($theme, 'views.content'); |
| 528 | 538 | } |
| 529 | 539 | |
@@ -531,8 +541,8 @@ discard block |
||
| 531 | 541 | * Retrieves the available layouts under the current theme |
| 532 | 542 | * @return array A list of files by name |
| 533 | 543 | */ |
| 534 | - public function getLayoutFiles($theme=null) |
|
| 535 | - {
|
|
| 544 | + public function getLayoutFiles($theme=null) |
|
| 545 | + { |
|
| 536 | 546 | return $this->getFiles($theme, 'views.layouts'); |
| 537 | 547 | } |
| 538 | 548 | |
@@ -542,20 +552,23 @@ discard block |
||
| 542 | 552 | * @param string $type The view type to lookup |
| 543 | 553 | * @return array $files An array of files |
| 544 | 554 | */ |
| 545 | - private function getFiles($theme=null, $type='views') |
|
| 546 | - {
|
|
| 547 | - if ($theme === null) |
|
| 548 | - $theme = Cii::getConfig('theme', 'default');
|
|
| 555 | + private function getFiles($theme=null, $type='views') |
|
| 556 | + { |
|
| 557 | + if ($theme === null) { |
|
| 558 | + $theme = Cii::getConfig('theme', 'default'); |
|
| 559 | + } |
|
| 549 | 560 | |
| 550 | 561 | $folder = $type; |
| 551 | 562 | |
| 552 | - if ($type == 'view') |
|
| 553 | - $folder = 'content'; |
|
| 563 | + if ($type == 'view') { |
|
| 564 | + $folder = 'content'; |
|
| 565 | + } |
|
| 554 | 566 | |
| 555 | 567 | $returnFiles = array(); |
| 556 | 568 | |
| 557 | - if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
|
|
| 558 | - $theme = 'default'; |
|
| 569 | + if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme))) { |
|
| 570 | + $theme = 'default'; |
|
| 571 | + } |
|
| 559 | 572 | |
| 560 | 573 | $files = Yii::app()->cache->get($theme.'-available-' . $type); |
| 561 | 574 | |
@@ -570,11 +583,13 @@ discard block |
||
| 570 | 583 | {
|
| 571 | 584 | $f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
|
| 572 | 585 | |
| 573 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 574 | - $f = trim(substr($f, strrpos($f, '\\') + 1)); |
|
| 586 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
| 587 | + $f = trim(substr($f, strrpos($f, '\\') + 1)); |
|
| 588 | + } |
|
| 575 | 589 | |
| 576 | - if (!in_array($f, array('all', 'password', '_post')))
|
|
| 577 | - $returnFiles[$f] = $f; |
|
| 590 | + if (!in_array($f, array('all', 'password', '_post'))) { |
|
| 591 | + $returnFiles[$f] = $f; |
|
| 592 | + } |
|
| 578 | 593 | } |
| 579 | 594 | |
| 580 | 595 | return $returnFiles; |
@@ -588,11 +603,12 @@ discard block |
||
| 588 | 603 | * @param string $pad The padding we want to apply |
| 589 | 604 | * @return string Truncated string |
| 590 | 605 | */ |
| 591 | - private function myTruncate($string, $limit, $break=".", $pad="...") |
|
| 592 | - {
|
|
| 606 | + private function myTruncate($string, $limit, $break=".", $pad="...") |
|
| 607 | + { |
|
| 593 | 608 | // return with no change if string is shorter than $limit |
| 594 | - if(strlen($string) <= $limit) |
|
| 595 | - return $string; |
|
| 609 | + if(strlen($string) <= $limit) { |
|
| 610 | + return $string; |
|
| 611 | + } |
|
| 596 | 612 | |
| 597 | 613 | // is $break present between $limit and the end of the string? |
| 598 | 614 | if(false !== ($breakpoint = strpos($string, $break, $limit))) |
@@ -613,8 +629,8 @@ discard block |
||
| 613 | 629 | * @param int $id - the numeric id to be appended to the slug if a conflict exists |
| 614 | 630 | * @return string $slug - the final slug to be used |
| 615 | 631 | */ |
| 616 | - public function checkSlug($slug, $id=NULL) |
|
| 617 | - {
|
|
| 632 | + public function checkSlug($slug, $id=NULL) |
|
| 633 | + { |
|
| 618 | 634 | $category = false; |
| 619 | 635 | |
| 620 | 636 | // Find the number of items that have the same slug as this one |
@@ -632,20 +648,23 @@ discard block |
||
| 632 | 648 | if ($count) |
| 633 | 649 | {
|
| 634 | 650 | // Ensures we don't have a collision on category |
| 635 | - if ($category) |
|
| 636 | - return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 651 | + if ($category) { |
|
| 652 | + return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 653 | + } |
|
| 637 | 654 | |
| 638 | 655 | // Pull the data that matches |
| 639 | 656 | $data = $this->findByPk($this->id); |
| 640 | 657 | |
| 641 | 658 | // Check the pulled data id to the current item |
| 642 | - if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug) |
|
| 643 | - return $slug; |
|
| 659 | + if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug) { |
|
| 660 | + return $slug; |
|
| 661 | + } |
|
| 644 | 662 | } |
| 645 | 663 | |
| 646 | - if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) |
|
| 647 | - return $slug . $id; |
|
| 648 | - else |
|
| 649 | - return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 664 | + if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) { |
|
| 665 | + return $slug . $id; |
|
| 666 | + } else { |
|
| 667 | + return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 668 | + } |
|
| 650 | 669 | } |
| 651 | 670 | } |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | * @param string $className active record class name. |
| 45 | 45 | * @return Content the static model class |
| 46 | 46 | */ |
| 47 | - public static function model($className=__CLASS__) |
|
| 47 | + public static function model ($className = __CLASS__) |
|
| 48 | 48 | {
|
| 49 | - return parent::model($className); |
|
| 49 | + return parent::model ($className); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @return string the associated database table name |
| 54 | 54 | */ |
| 55 | - public function tableName() |
|
| 55 | + public function tableName () |
|
| 56 | 56 | {
|
| 57 | 57 | return 'content'; |
| 58 | 58 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * @return string[] primary key of the table |
| 62 | 62 | **/ |
| 63 | - public function primaryKey() |
|
| 63 | + public function primaryKey () |
|
| 64 | 64 | {
|
| 65 | 65 | return array('id');
|
| 66 | 66 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * @return array validation rules for model attributes. |
| 70 | 70 | */ |
| 71 | - public function rules() |
|
| 71 | + public function rules () |
|
| 72 | 72 | {
|
| 73 | 73 | // NOTE: you should only define rules for those attributes that |
| 74 | 74 | // will receive user inputs. |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * @return array relational rules. |
| 86 | 86 | */ |
| 87 | - public function relations() |
|
| 87 | + public function relations () |
|
| 88 | 88 | {
|
| 89 | 89 | // NOTE: you may need to adjust the relation name and the related |
| 90 | 90 | // class name for the relations automatically generated below. |
@@ -99,26 +99,26 @@ discard block |
||
| 99 | 99 | /** |
| 100 | 100 | * @return array customized attribute labels (name=>label) |
| 101 | 101 | */ |
| 102 | - public function attributeLabels() |
|
| 102 | + public function attributeLabels () |
|
| 103 | 103 | {
|
| 104 | 104 | return array( |
| 105 | - 'id' => Yii::t('ciims.models.Content', 'ID'),
|
|
| 106 | - 'vid' => Yii::t('ciims.models.Content', 'Version'),
|
|
| 107 | - 'author_id' => Yii::t('ciims.models.Content', 'Author'),
|
|
| 108 | - 'title' => Yii::t('ciims.models.Content', 'Title'),
|
|
| 109 | - 'content' => Yii::t('ciims.models.Content', 'Content'),
|
|
| 110 | - 'excerpt' => Yii::t('ciims.models.Content', 'excerpt'),
|
|
| 111 | - 'status' => Yii::t('ciims.models.Content', 'Status'),
|
|
| 112 | - 'commentable' => Yii::t('ciims.models.Content', 'Commentable'),
|
|
| 113 | - 'category_id' => Yii::t('ciims.models.Content', 'Category'),
|
|
| 114 | - 'type_id' => Yii::t('ciims.models.Content', 'Type'),
|
|
| 115 | - 'password' => Yii::t('ciims.models.Content', 'Password'),
|
|
| 116 | - 'like_count' => Yii::t('ciims.models.Content', 'Likes'),
|
|
| 117 | - 'tags' => Yii::t('ciims.models.Content', 'Tags'),
|
|
| 118 | - 'slug' => Yii::t('ciims.models.Content', 'Slug'),
|
|
| 119 | - 'published' => Yii::t('ciims.models.Content', 'Published'),
|
|
| 120 | - 'created' => Yii::t('ciims.models.Content', 'Created'),
|
|
| 121 | - 'updated' => Yii::t('ciims.models.Content', 'Updated'),
|
|
| 105 | + 'id' => Yii::t ('ciims.models.Content', 'ID'),
|
|
| 106 | + 'vid' => Yii::t ('ciims.models.Content', 'Version'),
|
|
| 107 | + 'author_id' => Yii::t ('ciims.models.Content', 'Author'),
|
|
| 108 | + 'title' => Yii::t ('ciims.models.Content', 'Title'),
|
|
| 109 | + 'content' => Yii::t ('ciims.models.Content', 'Content'),
|
|
| 110 | + 'excerpt' => Yii::t ('ciims.models.Content', 'excerpt'),
|
|
| 111 | + 'status' => Yii::t ('ciims.models.Content', 'Status'),
|
|
| 112 | + 'commentable' => Yii::t ('ciims.models.Content', 'Commentable'),
|
|
| 113 | + 'category_id' => Yii::t ('ciims.models.Content', 'Category'),
|
|
| 114 | + 'type_id' => Yii::t ('ciims.models.Content', 'Type'),
|
|
| 115 | + 'password' => Yii::t ('ciims.models.Content', 'Password'),
|
|
| 116 | + 'like_count' => Yii::t ('ciims.models.Content', 'Likes'),
|
|
| 117 | + 'tags' => Yii::t ('ciims.models.Content', 'Tags'),
|
|
| 118 | + 'slug' => Yii::t ('ciims.models.Content', 'Slug'),
|
|
| 119 | + 'published' => Yii::t ('ciims.models.Content', 'Published'),
|
|
| 120 | + 'created' => Yii::t ('ciims.models.Content', 'Created'),
|
|
| 121 | + 'updated' => Yii::t ('ciims.models.Content', 'Updated'),
|
|
| 122 | 122 | ); |
| 123 | 123 | } |
| 124 | 124 | |
@@ -127,29 +127,29 @@ discard block |
||
| 127 | 127 | * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text |
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | - public function getSafeOutput() |
|
| 130 | + public function getSafeOutput () |
|
| 131 | 131 | {
|
| 132 | 132 | $md = new CMarkdownParser; |
| 133 | - $dom = new DOMDocument(); |
|
| 134 | - $dom->loadHtml('<?xml encoding="UTF-8">'.$md->safeTransform($this->content));
|
|
| 135 | - $x = new DOMXPath($dom); |
|
| 133 | + $dom = new DOMDocument (); |
|
| 134 | + $dom->loadHtml ('<?xml encoding="UTF-8">'.$md->safeTransform ($this->content));
|
|
| 135 | + $x = new DOMXPath ($dom); |
|
| 136 | 136 | |
| 137 | - foreach ($x->query('//a') as $node)
|
|
| 137 | + foreach ($x->query ('//a') as $node)
|
|
| 138 | 138 | {
|
| 139 | - $element = $node->getAttribute('href');
|
|
| 139 | + $element = $node->getAttribute ('href');
|
|
| 140 | 140 | if (isset($element[0]) && $element[0] !== "/") |
| 141 | 141 | {
|
| 142 | - $node->setAttribute('rel', 'nofollow');
|
|
| 143 | - $node->setAttribute('target', '_blank');
|
|
| 142 | + $node->setAttribute ('rel', 'nofollow');
|
|
| 143 | + $node->setAttribute ('target', '_blank');
|
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return $md->safeTransform($dom->saveHtml()); |
|
| 147 | + return $md->safeTransform ($dom->saveHtml ()); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public function getExtract() |
|
| 150 | + public function getExtract () |
|
| 151 | 151 | {
|
| 152 | - Yii::log(Yii::t('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
|
|
| 152 | + Yii::log (Yii::t ('ciims.models.Content', 'Use of property "extract" is deprecated in favor of "excerpt"'), 'system.db.ar.CActiveRecord', 'info');
|
|
| 153 | 153 | return $this->excerpt; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | * @return int The number of likes for this post |
| 161 | 161 | */ |
| 162 | 162 | |
| 163 | - public function getLikeCount() |
|
| 163 | + public function getLikeCount () |
|
| 164 | 164 | {
|
| 165 | - $meta = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'likes'));
|
|
| 165 | + $meta = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'likes'));
|
|
| 166 | 166 | if ($meta === NULL) |
| 167 | 167 | return 0; |
| 168 | 168 | |
@@ -173,10 +173,10 @@ discard block |
||
| 173 | 173 | * Gets keyword tags for this entry |
| 174 | 174 | * @return array |
| 175 | 175 | */ |
| 176 | - public function getTags() |
|
| 176 | + public function getTags () |
|
| 177 | 177 | {
|
| 178 | - $tags = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 179 | - return $tags === NULL ? array() : json_decode($tags->value, true); |
|
| 178 | + $tags = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 179 | + return $tags === NULL ? array() : json_decode ($tags->value, true); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -184,18 +184,18 @@ discard block |
||
| 184 | 184 | * @param string $tag The tag to add |
| 185 | 185 | * @return bool If the insert was successful or not |
| 186 | 186 | */ |
| 187 | - public function addTag($tag) |
|
| 187 | + public function addTag ($tag) |
|
| 188 | 188 | {
|
| 189 | 189 | $tags = $this->tags; |
| 190 | - if (in_array($tag, $tags) || $tag == "") |
|
| 190 | + if (in_array ($tag, $tags) || $tag == "") |
|
| 191 | 191 | return false; |
| 192 | 192 | |
| 193 | 193 | $tags[] = $tag; |
| 194 | - $tags = json_encode($tags); |
|
| 195 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 194 | + $tags = json_encode ($tags); |
|
| 195 | + $meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 196 | 196 | |
| 197 | 197 | $meta->value = $tags; |
| 198 | - return $meta->save(); |
|
| 198 | + return $meta->save (); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -203,47 +203,47 @@ discard block |
||
| 203 | 203 | * @param string $tag The tag to remove |
| 204 | 204 | * @return bool If the removal was successful |
| 205 | 205 | */ |
| 206 | - public function removeTag($tag) |
|
| 206 | + public function removeTag ($tag) |
|
| 207 | 207 | {
|
| 208 | 208 | $tags = $this->tags; |
| 209 | - if (!in_array($tag, $tags) || $tag == "") |
|
| 209 | + if (!in_array ($tag, $tags) || $tag == "") |
|
| 210 | 210 | return false; |
| 211 | 211 | |
| 212 | - $key = array_search($tag, $tags); |
|
| 212 | + $key = array_search ($tag, $tags); |
|
| 213 | 213 | unset($tags[$key]); |
| 214 | - $tags = json_encode($tags); |
|
| 214 | + $tags = json_encode ($tags); |
|
| 215 | 215 | |
| 216 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 216 | + $meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'keywords'));
|
|
| 217 | 217 | $meta->value = $tags; |
| 218 | - return $meta->save(); |
|
| 218 | + return $meta->save (); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * Provides a base criteria for status, uniqueness, and published states |
| 223 | 223 | * @return CDBCriteria |
| 224 | 224 | */ |
| 225 | - public function getBaseCriteria() |
|
| 225 | + public function getBaseCriteria () |
|
| 226 | 226 | {
|
| 227 | - $criteria = new CDbCriteria(); |
|
| 228 | - return $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
|
|
| 229 | - ->addCondition('status = 1')
|
|
| 230 | - ->addCondition('UNIX_TIMESTAMP() >= published');
|
|
| 227 | + $criteria = new CDbCriteria (); |
|
| 228 | + return $criteria->addCondition ("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")
|
|
| 229 | + ->addCondition ('status = 1')
|
|
| 230 | + ->addCondition ('UNIX_TIMESTAMP() >= published');
|
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * Returns the appropriate status' depending up the user's role |
| 235 | 235 | * @return string[] |
| 236 | 236 | */ |
| 237 | - public function getStatuses() |
|
| 237 | + public function getStatuses () |
|
| 238 | 238 | {
|
| 239 | 239 | |
| 240 | - if (Yii::app()->user->role == 5 || Yii::app()->user->role == 7) |
|
| 241 | - return array(0 => Yii::t('ciims.models.Content', 'Draft'));
|
|
| 240 | + if (Yii::app ()->user->role == 5 || Yii::app ()->user->role == 7) |
|
| 241 | + return array(0 => Yii::t ('ciims.models.Content', 'Draft'));
|
|
| 242 | 242 | |
| 243 | 243 | return array( |
| 244 | - 1 => Yii::t('ciims.models.Content', 'Published'),
|
|
| 245 | - 2 => Yii::t('ciims.models.Content', 'Ready for Review'),
|
|
| 246 | - 0 => Yii::t('ciims.models.Content', 'Draft')
|
|
| 244 | + 1 => Yii::t ('ciims.models.Content', 'Published'),
|
|
| 245 | + 2 => Yii::t ('ciims.models.Content', 'Ready for Review'),
|
|
| 246 | + 0 => Yii::t ('ciims.models.Content', 'Draft')
|
|
| 247 | 247 | ); |
| 248 | 248 | } |
| 249 | 249 | |
@@ -251,36 +251,36 @@ discard block |
||
| 251 | 251 | * Determines if an article is published or not |
| 252 | 252 | * @return boolean |
| 253 | 253 | */ |
| 254 | - public function isPublished() |
|
| 254 | + public function isPublished () |
|
| 255 | 255 | {
|
| 256 | - return ($this->status == 1 && ($this->published <= time())) ? true : false; |
|
| 256 | + return ($this->status == 1 && ($this->published <= time ())) ? true : false; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Determines if a given articled is scheduled or not |
| 261 | 261 | * @return boolean |
| 262 | 262 | */ |
| 263 | - public function isScheduled() |
|
| 263 | + public function isScheduled () |
|
| 264 | 264 | {
|
| 265 | - return ($this->status == 1 && ($this->published > time())) ? true : false; |
|
| 265 | + return ($this->status == 1 && ($this->published > time ())) ? true : false; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
| 269 | 269 | * Gets a flattened list of keyword tags for jQuery.tag.js |
| 270 | 270 | * @return string |
| 271 | 271 | */ |
| 272 | - public function getTagsFlat() |
|
| 272 | + public function getTagsFlat () |
|
| 273 | 273 | {
|
| 274 | - return implode(',', $this->tags);
|
|
| 274 | + return implode (',', $this->tags);
|
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | 278 | * Retrieves the layout used from Metadata |
| 279 | 279 | * We cache this to speed up the viewfile |
| 280 | 280 | */ |
| 281 | - public function getLayout() |
|
| 281 | + public function getLayout () |
|
| 282 | 282 | {
|
| 283 | - $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 283 | + $model = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 284 | 284 | return $model === NULL ? 'blog' : $model->value; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | * @param string $data the layout file |
| 290 | 290 | * @return boolean |
| 291 | 291 | */ |
| 292 | - public function setLayout($data) |
|
| 292 | + public function setLayout ($data) |
|
| 293 | 293 | {
|
| 294 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 294 | + $meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'layout'));
|
|
| 295 | 295 | $meta->value = $data; |
| 296 | - return $meta->save(); |
|
| 296 | + return $meta->save (); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -301,65 +301,65 @@ discard block |
||
| 301 | 301 | * @param string $data The view file |
| 302 | 302 | * @return boolean |
| 303 | 303 | */ |
| 304 | - public function setView($data) |
|
| 304 | + public function setView ($data) |
|
| 305 | 305 | {
|
| 306 | - $meta = $this->getPrototype('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
|
|
| 306 | + $meta = $this->getPrototype ('ContentMetadata', array('content_id' => $this->id, 'key' => 'view'));
|
|
| 307 | 307 | $meta->value = $data; |
| 308 | - return $meta->save(); |
|
| 308 | + return $meta->save (); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
| 312 | 312 | * Retrieves the viewfile used from Metadata |
| 313 | 313 | * We cache this to speed up the viewfile |
| 314 | 314 | */ |
| 315 | - public function getView() |
|
| 315 | + public function getView () |
|
| 316 | 316 | {
|
| 317 | - $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view'));
|
|
| 317 | + $model = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'view'));
|
|
| 318 | 318 | return $model === NULL ? 'blog' : $model->value; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
| 322 | 322 | * Updates the like_count after finding new data |
| 323 | 323 | */ |
| 324 | - protected function afterFind() |
|
| 324 | + protected function afterFind () |
|
| 325 | 325 | {
|
| 326 | - parent::afterFind(); |
|
| 327 | - $this->like_count = $this->getLikeCount(); |
|
| 326 | + parent::afterFind (); |
|
| 327 | + $this->like_count = $this->getLikeCount (); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
| 331 | 331 | * Retrieves a list of models based on the current search/filter conditions. |
| 332 | 332 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
| 333 | 333 | */ |
| 334 | - public function search() |
|
| 334 | + public function search () |
|
| 335 | 335 | {
|
| 336 | - $criteria=new CDbCriteria; |
|
| 336 | + $criteria = new CDbCriteria; |
|
| 337 | 337 | |
| 338 | - $criteria->compare('id',$this->id);
|
|
| 339 | - $criteria->compare('title',$this->title,true);
|
|
| 340 | - $criteria->compare('slug',$this->slug,true);
|
|
| 341 | - $criteria->compare('author_id',$this->author_id,true);
|
|
| 342 | - $criteria->compare('category_id',$this->category_id,true);
|
|
| 343 | - $criteria->compare('content',$this->content,true);
|
|
| 344 | - $criteria->compare('password', $this->password, true);
|
|
| 345 | - $criteria->compare('created',$this->created,true);
|
|
| 346 | - $criteria->compare('updated',$this->updated,true);
|
|
| 347 | - $criteria->compare('status', $this->status, true);
|
|
| 338 | + $criteria->compare ('id', $this->id);
|
|
| 339 | + $criteria->compare ('title', $this->title, true);
|
|
| 340 | + $criteria->compare ('slug', $this->slug, true);
|
|
| 341 | + $criteria->compare ('author_id', $this->author_id, true);
|
|
| 342 | + $criteria->compare ('category_id', $this->category_id, true);
|
|
| 343 | + $criteria->compare ('content', $this->content, true);
|
|
| 344 | + $criteria->compare ('password', $this->password, true);
|
|
| 345 | + $criteria->compare ('created', $this->created, true);
|
|
| 346 | + $criteria->compare ('updated', $this->updated, true);
|
|
| 347 | + $criteria->compare ('status', $this->status, true);
|
|
| 348 | 348 | |
| 349 | 349 | // Handle publishing with a true/false value simply to do this calculation. Otherwise default to compare |
| 350 | - if (is_bool($this->published)) |
|
| 350 | + if (is_bool ($this->published)) |
|
| 351 | 351 | {
|
| 352 | 352 | if ($this->published) |
| 353 | - $criteria->addCondition('published <= UNIX_TIMESTAMP()');
|
|
| 353 | + $criteria->addCondition ('published <= UNIX_TIMESTAMP()');
|
|
| 354 | 354 | else |
| 355 | - $criteria->addCondition('published > UNIX_TIMESTAMP()');
|
|
| 355 | + $criteria->addCondition ('published > UNIX_TIMESTAMP()');
|
|
| 356 | 356 | } |
| 357 | 357 | else |
| 358 | - $criteria->compare('published', $this->published,true);
|
|
| 359 | - $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
|
|
| 358 | + $criteria->compare ('published', $this->published, true);
|
|
| 359 | + $criteria->addCondition ("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)");
|
|
| 360 | 360 | |
| 361 | 361 | // TODO: Figure out how to restore CActiveDataProvidor by getCommentCount |
| 362 | - return new CActiveDataProvider($this, array( |
|
| 362 | + return new CActiveDataProvider ($this, array( |
|
| 363 | 363 | 'criteria' => $criteria, |
| 364 | 364 | 'sort' => array( |
| 365 | 365 | 'defaultOrder' => 'published DESC' |
@@ -379,24 +379,24 @@ discard block |
||
| 379 | 379 | * @param array $params parameters to be bound to an SQL statement. |
| 380 | 380 | * @return array the records found. An empty array is returned if none is found. |
| 381 | 381 | */ |
| 382 | - public function findByPk($pk, $condition='', $params=array()) |
|
| 382 | + public function findByPk ($pk, $condition = '', $params = array()) |
|
| 383 | 383 | {
|
| 384 | 384 | // If we do not supply a condition or parameters, use our overwritten method |
| 385 | 385 | if ($condition == '' && empty($params) && $pk != null) |
| 386 | 386 | {
|
| 387 | - if (!is_numeric($pk)) |
|
| 388 | - throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 387 | + if (!is_numeric ($pk)) |
|
| 388 | + throw new CHttpException (400, Yii::t ('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 389 | 389 | |
| 390 | 390 | $criteria = new CDbCriteria; |
| 391 | - $criteria->addCondition("t.id=:pk");
|
|
| 392 | - $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
|
|
| 391 | + $criteria->addCondition ("t.id=:pk");
|
|
| 392 | + $criteria->addCondition ("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
|
|
| 393 | 393 | $criteria->params = array( |
| 394 | 394 | ':pk' => $pk |
| 395 | 395 | ); |
| 396 | - return $this->query($criteria); |
|
| 396 | + return $this->query ($criteria); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - return parent::findByPk($pk, $condition, $params); |
|
| 399 | + return parent::findByPk ($pk, $condition, $params); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -404,42 +404,42 @@ discard block |
||
| 404 | 404 | * @param int $id [description] |
| 405 | 405 | * @return array |
| 406 | 406 | */ |
| 407 | - public function findRevisions($id) |
|
| 407 | + public function findRevisions ($id) |
|
| 408 | 408 | {
|
| 409 | - if (!is_numeric($id)) |
|
| 410 | - throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 409 | + if (!is_numeric ($id)) |
|
| 410 | + throw new CHttpException (400, Yii::t ('ciims.models.Content', 'The content ID provided was invalid.'));
|
|
| 411 | 411 | |
| 412 | 412 | $criteria = new CDbCriteria; |
| 413 | - $criteria->addCondition("id=:id");
|
|
| 413 | + $criteria->addCondition ("id=:id");
|
|
| 414 | 414 | $criteria->params = array( |
| 415 | 415 | ':id' => $id |
| 416 | 416 | ); |
| 417 | 417 | $criteria->order = 'vid DESC'; |
| 418 | 418 | |
| 419 | - return $this->query($criteria, true); |
|
| 419 | + return $this->query ($criteria, true); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
| 423 | 423 | * BeforeValidate |
| 424 | 424 | * @see CActiveRecord::beforeValidate |
| 425 | 425 | */ |
| 426 | - public function beforeValidate() |
|
| 426 | + public function beforeValidate () |
|
| 427 | 427 | {
|
| 428 | 428 | // Allow publication times to be set automatically |
| 429 | 429 | if (empty($this->published)) |
| 430 | - $this->published = time(); |
|
| 430 | + $this->published = time (); |
|
| 431 | 431 | |
| 432 | - if (strlen($this->excerpt) == 0) |
|
| 433 | - $this->excerpt = $this->myTruncate($this->content, 250, '.', ''); |
|
| 432 | + if (strlen ($this->excerpt) == 0) |
|
| 433 | + $this->excerpt = $this->myTruncate ($this->content, 250, '.', ''); |
|
| 434 | 434 | |
| 435 | - return parent::beforeValidate(); |
|
| 435 | + return parent::beforeValidate (); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | 439 | * Saves a prototype copy of the model so that we can get an id back to work with |
| 440 | 440 | * @return boolean $model->save(false) without any validation rules |
| 441 | 441 | */ |
| 442 | - public function savePrototype($author_id) |
|
| 442 | + public function savePrototype ($author_id) |
|
| 443 | 443 | {
|
| 444 | 444 | $this->title = ''; |
| 445 | 445 | $this->content = ''; |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | $this->category_id = 1; |
| 450 | 450 | $this->type_id = 2; |
| 451 | 451 | $this->password = null; |
| 452 | - $this->created = time(); |
|
| 453 | - $this->updated = time(); |
|
| 454 | - $this->published = time(); |
|
| 452 | + $this->created = time (); |
|
| 453 | + $this->updated = time (); |
|
| 454 | + $this->published = time (); |
|
| 455 | 455 | $this->vid = 1; |
| 456 | 456 | $this->slug = ""; |
| 457 | 457 | $this->author_id = $author_id; |
| 458 | 458 | |
| 459 | 459 | // TODO: Why doesn't Yii return the PK id field? But it does return VID? AutoIncriment bug? |
| 460 | - if ($this->save(false)) |
|
| 460 | + if ($this->save (false)) |
|
| 461 | 461 | {
|
| 462 | - $data = Content::model()->findByAttributes(array('created' => $this->created));
|
|
| 462 | + $data = Content::model ()->findByAttributes (array('created' => $this->created));
|
|
| 463 | 463 | $this->id = $data->id; |
| 464 | 464 | return true; |
| 465 | 465 | } |
@@ -472,16 +472,16 @@ discard block |
||
| 472 | 472 | * Clears caches for rebuilding, creates the end slug that we are going to use |
| 473 | 473 | * @see CActiveRecord::beforeSave(); |
| 474 | 474 | */ |
| 475 | - public function beforeSave() |
|
| 475 | + public function beforeSave () |
|
| 476 | 476 | {
|
| 477 | - $this->slug = $this->verifySlug($this->slug, $this->title); |
|
| 478 | - Yii::app()->cache->delete('CiiMS::Content::list');
|
|
| 479 | - Yii::app()->cache->delete('CiiMS::Routes');
|
|
| 477 | + $this->slug = $this->verifySlug ($this->slug, $this->title); |
|
| 478 | + Yii::app ()->cache->delete ('CiiMS::Content::list');
|
|
| 479 | + Yii::app ()->cache->delete ('CiiMS::Routes');
|
|
| 480 | 480 | |
| 481 | - Yii::app()->cache->set('content-' . $this->id . '-layout', $this->layoutFile);
|
|
| 482 | - Yii::app()->cache->set('content-' . $this->id . '-view', $this->viewFile);
|
|
| 481 | + Yii::app ()->cache->set ('content-'.$this->id.'-layout', $this->layoutFile);
|
|
| 482 | + Yii::app ()->cache->set ('content-'.$this->id.'-view', $this->viewFile);
|
|
| 483 | 483 | |
| 484 | - return parent::beforeSave(); |
|
| 484 | + return parent::beforeSave (); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -489,17 +489,17 @@ discard block |
||
| 489 | 489 | * Updates the layout and view if necessary |
| 490 | 490 | * @see CActiveRecord::afterSave() |
| 491 | 491 | */ |
| 492 | - public function afterSave() |
|
| 492 | + public function afterSave () |
|
| 493 | 493 | {
|
| 494 | 494 | // Delete the AutoSave document on update |
| 495 | - if ($this->isPublished()) |
|
| 495 | + if ($this->isPublished ()) |
|
| 496 | 496 | {
|
| 497 | - $autosaveModel = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'autosave'));
|
|
| 497 | + $autosaveModel = ContentMetadata::model ()->findByAttributes (array('content_id' => $this->id, 'key' => 'autosave'));
|
|
| 498 | 498 | if ($autosaveModel != NULL) |
| 499 | - $autosaveModel->delete(); |
|
| 499 | + $autosaveModel->delete (); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - return parent::afterSave(); |
|
| 502 | + return parent::afterSave (); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -507,14 +507,14 @@ discard block |
||
| 507 | 507 | * Clears caches for rebuilding |
| 508 | 508 | * @see CActiveRecord::beforeDelete |
| 509 | 509 | */ |
| 510 | - public function beforeDelete() |
|
| 510 | + public function beforeDelete () |
|
| 511 | 511 | {
|
| 512 | - Yii::app()->cache->delete('CiiMS::Content::list');
|
|
| 513 | - Yii::app()->cache->delete('CiiMS::Routes');
|
|
| 514 | - Yii::app()->cache->delete('content-' . $this->id . '-layout');
|
|
| 515 | - Yii::app()->cache->delete('content-' . $this->id . '-view');
|
|
| 512 | + Yii::app ()->cache->delete ('CiiMS::Content::list');
|
|
| 513 | + Yii::app ()->cache->delete ('CiiMS::Routes');
|
|
| 514 | + Yii::app ()->cache->delete ('content-'.$this->id.'-layout');
|
|
| 515 | + Yii::app ()->cache->delete ('content-'.$this->id.'-view');
|
|
| 516 | 516 | |
| 517 | - return parent::beforeDelete(); |
|
| 517 | + return parent::beforeDelete (); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | |
@@ -522,18 +522,18 @@ discard block |
||
| 522 | 522 | * Retrieves the available view files under the current theme |
| 523 | 523 | * @return array A list of files by name |
| 524 | 524 | */ |
| 525 | - public function getViewFiles($theme=null) |
|
| 525 | + public function getViewFiles ($theme = null) |
|
| 526 | 526 | {
|
| 527 | - return $this->getFiles($theme, 'views.content'); |
|
| 527 | + return $this->getFiles ($theme, 'views.content'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
| 531 | 531 | * Retrieves the available layouts under the current theme |
| 532 | 532 | * @return array A list of files by name |
| 533 | 533 | */ |
| 534 | - public function getLayoutFiles($theme=null) |
|
| 534 | + public function getLayoutFiles ($theme = null) |
|
| 535 | 535 | {
|
| 536 | - return $this->getFiles($theme, 'views.layouts'); |
|
| 536 | + return $this->getFiles ($theme, 'views.layouts'); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | /** |
@@ -542,10 +542,10 @@ discard block |
||
| 542 | 542 | * @param string $type The view type to lookup |
| 543 | 543 | * @return array $files An array of files |
| 544 | 544 | */ |
| 545 | - private function getFiles($theme=null, $type='views') |
|
| 545 | + private function getFiles ($theme = null, $type = 'views') |
|
| 546 | 546 | {
|
| 547 | 547 | if ($theme === null) |
| 548 | - $theme = Cii::getConfig('theme', 'default');
|
|
| 548 | + $theme = Cii::getConfig ('theme', 'default');
|
|
| 549 | 549 | |
| 550 | 550 | $folder = $type; |
| 551 | 551 | |
@@ -554,26 +554,26 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | $returnFiles = array(); |
| 556 | 556 | |
| 557 | - if (!file_exists(YiiBase::getPathOfAlias('base.themes.' . $theme)))
|
|
| 557 | + if (!file_exists (YiiBase::getPathOfAlias ('base.themes.'.$theme)))
|
|
| 558 | 558 | $theme = 'default'; |
| 559 | 559 | |
| 560 | - $files = Yii::app()->cache->get($theme.'-available-' . $type); |
|
| 560 | + $files = Yii::app ()->cache->get ($theme.'-available-'.$type); |
|
| 561 | 561 | |
| 562 | 562 | if ($files === false) |
| 563 | 563 | {
|
| 564 | 564 | $fileHelper = new CFileHelper; |
| 565 | - $files = $fileHelper->findFiles(Yii::getPathOfAlias('base.themes.' . $theme .'.' . $folder), array('fileTypes'=>array('php'), 'level'=>0));
|
|
| 566 | - Yii::app()->cache->set($theme.'-available-' . $type, $files); |
|
| 565 | + $files = $fileHelper->findFiles (Yii::getPathOfAlias ('base.themes.'.$theme.'.'.$folder), array('fileTypes'=>array('php'), 'level'=>0));
|
|
| 566 | + Yii::app ()->cache->set ($theme.'-available-'.$type, $files); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | foreach ($files as $file) |
| 570 | 570 | {
|
| 571 | - $f = str_replace('content', '', str_replace('/', '', str_replace('.php', '', substr( $file, strrpos( $file, '/' ) + 1 ))));
|
|
| 571 | + $f = str_replace ('content', '', str_replace ('/', '', str_replace ('.php', '', substr ($file, strrpos ($file, '/') + 1))));
|
|
| 572 | 572 | |
| 573 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 574 | - $f = trim(substr($f, strrpos($f, '\\') + 1)); |
|
| 573 | + if (strtoupper (substr (PHP_OS, 0, 3)) === 'WIN') |
|
| 574 | + $f = trim (substr ($f, strrpos ($f, '\\') + 1)); |
|
| 575 | 575 | |
| 576 | - if (!in_array($f, array('all', 'password', '_post')))
|
|
| 576 | + if (!in_array ($f, array('all', 'password', '_post')))
|
|
| 577 | 577 | $returnFiles[$f] = $f; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -588,18 +588,18 @@ discard block |
||
| 588 | 588 | * @param string $pad The padding we want to apply |
| 589 | 589 | * @return string Truncated string |
| 590 | 590 | */ |
| 591 | - private function myTruncate($string, $limit, $break=".", $pad="...") |
|
| 591 | + private function myTruncate ($string, $limit, $break = ".", $pad = "...") |
|
| 592 | 592 | {
|
| 593 | 593 | // return with no change if string is shorter than $limit |
| 594 | - if(strlen($string) <= $limit) |
|
| 594 | + if (strlen ($string) <= $limit) |
|
| 595 | 595 | return $string; |
| 596 | 596 | |
| 597 | 597 | // is $break present between $limit and the end of the string? |
| 598 | - if(false !== ($breakpoint = strpos($string, $break, $limit))) |
|
| 598 | + if (false !== ($breakpoint = strpos ($string, $break, $limit))) |
|
| 599 | 599 | {
|
| 600 | - if($breakpoint < strlen($string) - 1) |
|
| 600 | + if ($breakpoint < strlen ($string) - 1) |
|
| 601 | 601 | {
|
| 602 | - $string = substr($string, 0, $breakpoint) . $pad; |
|
| 602 | + $string = substr ($string, 0, $breakpoint).$pad; |
|
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | |
@@ -613,18 +613,18 @@ discard block |
||
| 613 | 613 | * @param int $id - the numeric id to be appended to the slug if a conflict exists |
| 614 | 614 | * @return string $slug - the final slug to be used |
| 615 | 615 | */ |
| 616 | - public function checkSlug($slug, $id=NULL) |
|
| 616 | + public function checkSlug ($slug, $id = NULL) |
|
| 617 | 617 | {
|
| 618 | 618 | $category = false; |
| 619 | 619 | |
| 620 | 620 | // Find the number of items that have the same slug as this one |
| 621 | - $count = $this->countByAttributes(array('slug'=>$slug . $id));
|
|
| 621 | + $count = $this->countByAttributes (array('slug'=>$slug.$id));
|
|
| 622 | 622 | |
| 623 | 623 | // Make sure we don't have a collision with a Category |
| 624 | 624 | if ($count == 0) |
| 625 | 625 | {
|
| 626 | 626 | $category = true; |
| 627 | - $count = Categories::model()->countByAttributes(array('slug'=>$slug . $id));
|
|
| 627 | + $count = Categories::model ()->countByAttributes (array('slug'=>$slug.$id));
|
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | // If we found an item that matched, it's possible that it is the current item (or a previous version of it) |
@@ -633,19 +633,19 @@ discard block |
||
| 633 | 633 | {
|
| 634 | 634 | // Ensures we don't have a collision on category |
| 635 | 635 | if ($category) |
| 636 | - return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 636 | + return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1))); |
|
| 637 | 637 | |
| 638 | 638 | // Pull the data that matches |
| 639 | - $data = $this->findByPk($this->id); |
|
| 639 | + $data = $this->findByPk ($this->id); |
|
| 640 | 640 | |
| 641 | 641 | // Check the pulled data id to the current item |
| 642 | 642 | if ($data !== NULL && $data->id == $this->id && $data->slug == $this->slug) |
| 643 | 643 | return $slug; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) |
|
| 647 | - return $slug . $id; |
|
| 646 | + if ($count == 0 && !in_array ($slug, $this->forbiddenRoutes)) |
|
| 647 | + return $slug.$id; |
|
| 648 | 648 | else |
| 649 | - return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1))); |
|
| 649 | + return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1))); |
|
| 650 | 650 | } |
| 651 | 651 | } |
@@ -16,82 +16,82 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class ContentMetadata extends CiiModel |
| 18 | 18 | {
|
| 19 | - /** |
|
| 20 | - * Returns the static model of the specified AR class. |
|
| 21 | - * @param string $className active record class name. |
|
| 22 | - * @return ContentMetadata the static model class |
|
| 23 | - */ |
|
| 24 | - public static function model($className=__CLASS__) |
|
| 25 | - {
|
|
| 26 | - return parent::model($className); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * Returns the static model of the specified AR class. |
|
| 21 | + * @param string $className active record class name. |
|
| 22 | + * @return ContentMetadata the static model class |
|
| 23 | + */ |
|
| 24 | + public static function model($className=__CLASS__) |
|
| 25 | + {
|
|
| 26 | + return parent::model($className); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return string the associated database table name |
|
| 31 | - */ |
|
| 32 | - public function tableName() |
|
| 33 | - {
|
|
| 34 | - return 'content_metadata'; |
|
| 35 | - } |
|
| 29 | + /** |
|
| 30 | + * @return string the associated database table name |
|
| 31 | + */ |
|
| 32 | + public function tableName() |
|
| 33 | + {
|
|
| 34 | + return 'content_metadata'; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return array validation rules for model attributes. |
|
| 39 | - */ |
|
| 40 | - public function rules() |
|
| 41 | - {
|
|
| 42 | - // NOTE: you should only define rules for those attributes that |
|
| 43 | - // will receive user inputs. |
|
| 44 | - return array( |
|
| 45 | - array('content_id, key, value', 'required'),
|
|
| 46 | - array('content_id', 'numerical', 'integerOnly'=>true),
|
|
| 47 | - array('key', 'length', 'max'=>50),
|
|
| 48 | - // The following rule is used by search(). |
|
| 49 | - array('id, content_id, key, value, created, updated', 'safe', 'on'=>'search'),
|
|
| 50 | - ); |
|
| 51 | - } |
|
| 37 | + /** |
|
| 38 | + * @return array validation rules for model attributes. |
|
| 39 | + */ |
|
| 40 | + public function rules() |
|
| 41 | + {
|
|
| 42 | + // NOTE: you should only define rules for those attributes that |
|
| 43 | + // will receive user inputs. |
|
| 44 | + return array( |
|
| 45 | + array('content_id, key, value', 'required'),
|
|
| 46 | + array('content_id', 'numerical', 'integerOnly'=>true),
|
|
| 47 | + array('key', 'length', 'max'=>50),
|
|
| 48 | + // The following rule is used by search(). |
|
| 49 | + array('id, content_id, key, value, created, updated', 'safe', 'on'=>'search'),
|
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return array relational rules. |
|
| 55 | - */ |
|
| 56 | - public function relations() |
|
| 57 | - {
|
|
| 58 | - // NOTE: you may need to adjust the relation name and the related |
|
| 59 | - // class name for the relations automatically generated below. |
|
| 60 | - return array( |
|
| 61 | - 'content' => array(self::BELONGS_TO, 'Content', 'content_id'), |
|
| 62 | - ); |
|
| 63 | - } |
|
| 53 | + /** |
|
| 54 | + * @return array relational rules. |
|
| 55 | + */ |
|
| 56 | + public function relations() |
|
| 57 | + {
|
|
| 58 | + // NOTE: you may need to adjust the relation name and the related |
|
| 59 | + // class name for the relations automatically generated below. |
|
| 60 | + return array( |
|
| 61 | + 'content' => array(self::BELONGS_TO, 'Content', 'content_id'), |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return array customized attribute labels (name=>label) |
|
| 67 | - */ |
|
| 68 | - public function attributeLabels() |
|
| 69 | - {
|
|
| 70 | - return array( |
|
| 71 | - 'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
|
|
| 72 | - 'key' => Yii::t('ciims.models.ContentMetadata', 'Key'),
|
|
| 73 | - 'value' => Yii::t('ciims.models.ContentMetadata', 'Value'),
|
|
| 74 | - 'created' => Yii::t('ciims.models.ContentMetadata', 'Created'),
|
|
| 75 | - 'updated' => Yii::t('ciims.models.ContentMetadata', 'Updated')
|
|
| 76 | - ); |
|
| 77 | - } |
|
| 65 | + /** |
|
| 66 | + * @return array customized attribute labels (name=>label) |
|
| 67 | + */ |
|
| 68 | + public function attributeLabels() |
|
| 69 | + {
|
|
| 70 | + return array( |
|
| 71 | + 'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
|
|
| 72 | + 'key' => Yii::t('ciims.models.ContentMetadata', 'Key'),
|
|
| 73 | + 'value' => Yii::t('ciims.models.ContentMetadata', 'Value'),
|
|
| 74 | + 'created' => Yii::t('ciims.models.ContentMetadata', 'Created'),
|
|
| 75 | + 'updated' => Yii::t('ciims.models.ContentMetadata', 'Updated')
|
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Retrieves a list of models based on the current search/filter conditions. |
|
| 81 | - * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
| 82 | - */ |
|
| 83 | - public function search() |
|
| 84 | - {
|
|
| 85 | - $criteria=new CDbCriteria; |
|
| 79 | + /** |
|
| 80 | + * Retrieves a list of models based on the current search/filter conditions. |
|
| 81 | + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
| 82 | + */ |
|
| 83 | + public function search() |
|
| 84 | + {
|
|
| 85 | + $criteria=new CDbCriteria; |
|
| 86 | 86 | |
| 87 | - $criteria->compare('content_id',$this->content_id);
|
|
| 88 | - $criteria->compare('t.key',$this->key,true);
|
|
| 89 | - $criteria->compare('value',$this->value,true);
|
|
| 90 | - $criteria->compare('created',$this->created,true);
|
|
| 91 | - $criteria->compare('updated',$this->updated,true);
|
|
| 87 | + $criteria->compare('content_id',$this->content_id);
|
|
| 88 | + $criteria->compare('t.key',$this->key,true);
|
|
| 89 | + $criteria->compare('value',$this->value,true);
|
|
| 90 | + $criteria->compare('created',$this->created,true);
|
|
| 91 | + $criteria->compare('updated',$this->updated,true);
|
|
| 92 | 92 | |
| 93 | - return new CActiveDataProvider($this, array( |
|
| 94 | - 'criteria'=>$criteria, |
|
| 95 | - )); |
|
| 96 | - } |
|
| 93 | + return new CActiveDataProvider($this, array( |
|
| 94 | + 'criteria'=>$criteria, |
|
| 95 | + )); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | * @param string $className active record class name. |
| 22 | 22 | * @return ContentMetadata the static model class |
| 23 | 23 | */ |
| 24 | - public static function model($className=__CLASS__) |
|
| 24 | + public static function model ($className = __CLASS__) |
|
| 25 | 25 | {
|
| 26 | - return parent::model($className); |
|
| 26 | + return parent::model ($className); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @return string the associated database table name |
| 31 | 31 | */ |
| 32 | - public function tableName() |
|
| 32 | + public function tableName () |
|
| 33 | 33 | {
|
| 34 | 34 | return 'content_metadata'; |
| 35 | 35 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @return array validation rules for model attributes. |
| 39 | 39 | */ |
| 40 | - public function rules() |
|
| 40 | + public function rules () |
|
| 41 | 41 | {
|
| 42 | 42 | // NOTE: you should only define rules for those attributes that |
| 43 | 43 | // will receive user inputs. |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * @return array relational rules. |
| 55 | 55 | */ |
| 56 | - public function relations() |
|
| 56 | + public function relations () |
|
| 57 | 57 | {
|
| 58 | 58 | // NOTE: you may need to adjust the relation name and the related |
| 59 | 59 | // class name for the relations automatically generated below. |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @return array customized attribute labels (name=>label) |
| 67 | 67 | */ |
| 68 | - public function attributeLabels() |
|
| 68 | + public function attributeLabels () |
|
| 69 | 69 | {
|
| 70 | 70 | return array( |
| 71 | - 'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
|
|
| 72 | - 'key' => Yii::t('ciims.models.ContentMetadata', 'Key'),
|
|
| 73 | - 'value' => Yii::t('ciims.models.ContentMetadata', 'Value'),
|
|
| 74 | - 'created' => Yii::t('ciims.models.ContentMetadata', 'Created'),
|
|
| 75 | - 'updated' => Yii::t('ciims.models.ContentMetadata', 'Updated')
|
|
| 71 | + 'content_id' => Yii::t ('ciims.models.ContentMetadata', 'Content ID'),
|
|
| 72 | + 'key' => Yii::t ('ciims.models.ContentMetadata', 'Key'),
|
|
| 73 | + 'value' => Yii::t ('ciims.models.ContentMetadata', 'Value'),
|
|
| 74 | + 'created' => Yii::t ('ciims.models.ContentMetadata', 'Created'),
|
|
| 75 | + 'updated' => Yii::t ('ciims.models.ContentMetadata', 'Updated')
|
|
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | * Retrieves a list of models based on the current search/filter conditions. |
| 81 | 81 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
| 82 | 82 | */ |
| 83 | - public function search() |
|
| 83 | + public function search () |
|
| 84 | 84 | {
|
| 85 | - $criteria=new CDbCriteria; |
|
| 85 | + $criteria = new CDbCriteria; |
|
| 86 | 86 | |
| 87 | - $criteria->compare('content_id',$this->content_id);
|
|
| 88 | - $criteria->compare('t.key',$this->key,true);
|
|
| 89 | - $criteria->compare('value',$this->value,true);
|
|
| 90 | - $criteria->compare('created',$this->created,true);
|
|
| 91 | - $criteria->compare('updated',$this->updated,true);
|
|
| 87 | + $criteria->compare ('content_id', $this->content_id);
|
|
| 88 | + $criteria->compare ('t.key', $this->key, true);
|
|
| 89 | + $criteria->compare ('value', $this->value, true);
|
|
| 90 | + $criteria->compare ('created', $this->created, true);
|
|
| 91 | + $criteria->compare ('updated', $this->updated, true);
|
|
| 92 | 92 | |
| 93 | - return new CActiveDataProvider($this, array( |
|
| 93 | + return new CActiveDataProvider ($this, array( |
|
| 94 | 94 | 'criteria'=>$criteria, |
| 95 | 95 | )); |
| 96 | 96 | } |
@@ -14,31 +14,31 @@ discard block |
||
| 14 | 14 | * The followings are the available model relations: |
| 15 | 15 | * @property Content $content |
| 16 | 16 | */ |
| 17 | -class ContentMetadata extends CiiModel |
|
| 18 | -{
|
|
| 17 | +class ContentMetadata extends CiiModel |
|
| 18 | +{ |
|
| 19 | 19 | /** |
| 20 | 20 | * Returns the static model of the specified AR class. |
| 21 | 21 | * @param string $className active record class name. |
| 22 | 22 | * @return ContentMetadata the static model class |
| 23 | 23 | */ |
| 24 | - public static function model($className=__CLASS__) |
|
| 25 | - {
|
|
| 24 | + public static function model($className=__CLASS__) |
|
| 25 | + { |
|
| 26 | 26 | return parent::model($className); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @return string the associated database table name |
| 31 | 31 | */ |
| 32 | - public function tableName() |
|
| 33 | - {
|
|
| 32 | + public function tableName() |
|
| 33 | + { |
|
| 34 | 34 | return 'content_metadata'; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @return array validation rules for model attributes. |
| 39 | 39 | */ |
| 40 | - public function rules() |
|
| 41 | - {
|
|
| 40 | + public function rules() |
|
| 41 | + { |
|
| 42 | 42 | // NOTE: you should only define rules for those attributes that |
| 43 | 43 | // will receive user inputs. |
| 44 | 44 | return array( |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * @return array relational rules. |
| 55 | 55 | */ |
| 56 | - public function relations() |
|
| 57 | - {
|
|
| 56 | + public function relations() |
|
| 57 | + { |
|
| 58 | 58 | // NOTE: you may need to adjust the relation name and the related |
| 59 | 59 | // class name for the relations automatically generated below. |
| 60 | 60 | return array( |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @return array customized attribute labels (name=>label) |
| 67 | 67 | */ |
| 68 | - public function attributeLabels() |
|
| 69 | - {
|
|
| 68 | + public function attributeLabels() |
|
| 69 | + { |
|
| 70 | 70 | return array( |
| 71 | 71 | 'content_id' => Yii::t('ciims.models.ContentMetadata', 'Content ID'),
|
| 72 | 72 | 'key' => Yii::t('ciims.models.ContentMetadata', 'Key'),
|
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * Retrieves a list of models based on the current search/filter conditions. |
| 81 | 81 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
| 82 | 82 | */ |
| 83 | - public function search() |
|
| 84 | - {
|
|
| 83 | + public function search() |
|
| 84 | + { |
|
| 85 | 85 | $criteria=new CDbCriteria; |
| 86 | 86 | |
| 87 | 87 | $criteria->compare('content_id',$this->content_id);
|