public function CanView() { $user = User::model()->find('id=:id', array(':id' => Yii::app()->user->id)); $superuser = $user != null ? $user->superuser : 0; if ($superuser == 1) { return true; } else { if ($user != null && $user->profile->user_role == 10) { $countryAdministratorCheck = CountryAdministrator::model()->find('user_id=:user_id and country_id=:country_id', array(':user_id' => Yii::app()->user->id, ':country_id' => $this->country_id)); $change_to_country_id = isset($_POST['Region']['country_id']) ? $_POST['Region']['country_id'] : -1; $countryAdministratorCheck2 = CountryAdministrator::model()->find('user_id=:user_id and country_id=:country_id', array(':user_id' => Yii::app()->user->id, ':country_id' => $change_to_country_id)); if ($countryAdministratorCheck != null && $countryAdministratorCheck2 != null || $countryAdministratorCheck2 != null && $change_to_country_id != -1 || $countryAdministratorCheck != null && $change_to_country_id == -1) { return true; } } } return false; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = CountryAdministrator::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }