/**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if ($_GET['group_id'] == 1) {
         //check exist course and test created by a trainer
         if (Course::model()->checkCourse($id) && Test::model()->checkTest($id)) {
             Yii::app()->user->setFlash('unsuccess', ' Can not delete a trainer.');
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
         // delete trainer
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             Yii::app()->user->setFlash('success', 'You did delete a trainer when: <br>- Not exist course created by trainer.<br>- Not exist test created by trainer.');
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     } elseif ($_GET['group_id'] == 2) {
         //Delete course trainee
         CourseTrainee::model()->deleteCourseTrainee($id);
         //Delete user test
         UserTest::model()->deleteUserTest($id);
         //Delete training log and training random question
         TrainingLog::model()->deleteTrainingLog($id);
         TrainingRandomquestion::model()->deleteTrainingRadomQuestion($id);
         //delete trainee
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         Yii::app()->user->setFlash('success', 'You did delete a trainee: <br>- Delete course trainee.<br>- Delete Training log and training random question.<br>- Delete user test and user answers.');
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     } elseif ($_GET['group_id'] == 3) {
         // delete training manager
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         Yii::app()->user->setFlash('success', 'You did delete a training manager.');
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     } elseif ($_GET['group_id'] == 4) {
         // delete team leader
         ATrainingTeam::deleteTeamleader($id);
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         Yii::app()->user->setFlash('success', 'You did delete a team leader.');
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     }
 }
 /**
  * Returns the static model of the specified AR class.
  * Please note that you should have this exact method in all your CActiveRecord descendants!
  * @param string $className active record class name.
  * @return WTrainingRandomquestion the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }