public function run()
 {
     $params = array();
     $criteria = new CDbCriteria();
     //        $criteria->select = array('id,username,fullname,phone,address,status');
     $criteria->select = '*';
     if (isset($this->team_lear_id) and $this->team_lear_id != '') {
         $criteria->addCondition('team_lear_id=' . $this->team_lear_id);
     }
     $criteria->params = $params;
     $total = ATrainingTeam::model()->count($criteria);
     $offset = $this->limit * ($this->page - 1);
     $criteria->limit = $this->limit;
     $criteria->offset = $offset;
     $data = ATrainingTeam::model()->findAll($criteria);
     $listTrainee = array();
     if (!empty($data)) {
         foreach ($data as $item) {
             $listTrainee[] = CJSON::decode(CJSON::encode($item->pls_user));
         }
     }
     $data = $listTrainee;
     $pages = new CPagination($total);
     $pages->pageSize = $this->limit;
     $pages->applyLimit($criteria);
     $this->render($this->view, array('data' => $data, 'pages' => $pages));
 }
 public function actionAddSessionTrainee()
 {
     $dataListTrainee = $_POST['listTrainee'];
     $listTrainee = Yii::app()->session->get('listTrainee') ? json_decode(Yii::app()->session->get('listTrainee'), true) : array();
     if (!empty($dataListTrainee)) {
         foreach ($dataListTrainee as $item) {
             $listTrainee[$item['id']] = $item;
             if (!empty($item['team_leader_id'])) {
                 $model = ATrainingTeam::model()->find('trainee_id=' . $item['id'] . ' AND team_leader_id=' . $item['team_leader_id']);
                 if (empty($model)) {
                     $model = new ATrainingTeam();
                     $model->team_leader_id = $item['team_leader_id'];
                     $model->trainee_id = $item['id'];
                     //$model->status = 1;
                     if ($model->save()) {
                         $modelTeam = AUser::model()->find('id=' . $model->team_leader_id);
                         //$modelCourse->trainee_count = $modelCourse->trainee_count + 1;
                         $modelTeam->save();
                     }
                 }
             }
         }
     }
     Yii::app()->session->add('listTrainee', json_encode($listTrainee));
     echo 'true';
 }
Esempio n. 3
0
    echo Yii::t('web/home', 'Addess');
    ?>
</th>
        <th></th>
    </tr>
    </thead>
    <tbody  class="last_desgin">
        <?php 
    $index = 1;
    if (isset($_GET['page']) and !empty($_GET['page'])) {
        $index = $this->limit * ($_GET['page'] - 1) + $index;
    }
    ?>
        <?php 
    foreach ($data as $item) {
        $TrainingTeam = ATrainingTeam::model()->find('trainee_id=:trainee_id', array(':trainee_id' => $item['id']));
        //if(!isset($TrainingTeam)):
        ?>
        
    <tr>
        <td width="30" align="center" style="text-align: center !important;"><input type="checkbox" id="trainee_<?php 
        echo $item['id'];
        ?>
" <?php 
        echo (isset($listTrainee[$item['id']]) and !empty($listTrainee[$item['id']])) ? 'checked="checked"' : '';
        ?>
 data-fullname="<?php 
        echo $item['fullname'];
        ?>
" data-username="<?php 
        echo $item['username'];
 /**
  * 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 $id the ID of the model to be loaded
  * @return ATrainingTeam the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ATrainingTeam::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * 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']));
         }
     }
 }
Esempio n. 6
0
 public static function getIDTrainee()
 {
     $criteria = new CDbCriteria();
     //$criteria->condition = '';
     $rs = ATrainingTeam::model()->findAll($criteria);
     if ($rs && count($rs) > 0) {
         $arrID = array();
         foreach ($rs as $item) {
             $arrID[] = $item['trainee_id'];
         }
         return $arrID;
     } else {
         return null;
     }
 }