Example #1
0
 /**
  * Updates the settings of notifications
  * Inserts a record in "settings" table only if the user does not want to receive mail
  * @return array of models
  */
 public function actionUpdate()
 {
     $role_name = Yii::app()->user->getRole();
     if ($role_name == NULL) {
         throw new CHttpException(400, Yii::t('http_status', 400));
     }
     $models = array();
     $categories = array();
     $modelCategories = NotificationCategories::model()->findAllByAttributes(array(), 'role_name=:role_name', array(':role_name' => $role_name));
     $index = 0;
     foreach ($modelCategories as $modelCategory) {
         $category['category'] = $modelCategory->category;
         $category['type'] = $modelCategory->type;
         $category['id'] = $modelCategory->id;
         $model = $this->loadModel($category['id']);
         if ($model === null) {
             $model = new Settings();
             if ($_POST['send_mail' . $index] == "false") {
                 $model->attributes = array('username' => Yii::app()->user->id, 'notification_category_ptr' => $category['id']);
                 $model->save();
             } else {
                 $model->setAttribute('send_mail', true);
             }
             $category['model'] = $model;
         } else {
             if ($_POST['send_mail' . $index] == "true") {
                 $model->delete();
                 $model = new Settings();
                 $model->setAttribute('send_mail', true);
             }
             $category['model'] = $model;
         }
         $index++;
         $categories[] = $category;
     }
     $this->render('update', array('categories' => $categories));
 }
Example #2
0
 /**
  * Checks if there are categories of notifications associated with the role of the user logged
  * Returns true if they exist, false otherwise
  *
  */
 public function haveSettings()
 {
     if (!Yii::app()->user->isGuest) {
         $user = $this->loadUser(Yii::app()->user->id);
         $settings = NotificationCategories::model()->find('role_name=:role_name', array(':role_name' => Yii::app()->user->getRole()));
         if (empty($settings)) {
             return false;
         }
         return true;
     }
 }
Example #3
0
 /**
  * Find the category of notification.
  * @param string $category the category description
  * @param string $type the description of the operation performed
  * @return array $categories the roles that identify the recipients of this notification
  */
 public static function findCategory($category, $type)
 {
     $notification_categories = NotificationCategories::model()->findAll('category=:category AND type=:type', array(':category' => $category, ':type' => $type));
     if ($notification_categories != null) {
         $categories = array();
         foreach ($notification_categories as $nc) {
             $categories[$nc->id] = $nc->role_name;
         }
     } else {
         $this->notification_category_ptr = -1;
         Yii::log('category=' . $category . ' type=' . $type, CLogger::LEVEL_INFO, 'Notifications::findCategory()');
     }
     //Yii::log('categories='.print_r($categories, true), CLogger::LEVEL_INFO, 'Notifications::findCategory()');
     return $categories;
 }