/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Exams(); $model_1 = new ExamGroups(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Exams'])) { //$model->attributes=$_POST['Exams']; if (isset($_REQUEST['exam_group_id'])) { $insert_id = $_REQUEST['exam_group_id']; } else { $model_1->attributes = $_POST['ExamGroups']; $model_1->batch_id = $_REQUEST['id']; $model_1->save(); $insert_id = Yii::app()->db->getLastInsertID(); } $posts = Subjects::model()->findAll("batch_id=:x AND no_exams=:y", array(':x' => $_REQUEST['id'], ':y' => 0)); $list = $_POST['Exams']; $count = count($list['subject_id']); $electivecount = count($_POST['ElectiveExams']['elective_id']); $j = 0; for ($i = 0; $i < $count; $i++) { if ($list['maximum_marks'][$i] != NULL and $list['minimum_marks'][$i] != NULL and $list['start_time'][$i] != NULL and $list['end_time'][$i] != NULL) { $model = new Exams(); $model->exam_group_id = $insert_id; $model->subject_id = $list['subject_id'][$i]; $model->maximum_marks = $list['maximum_marks'][$i]; $model->minimum_marks = $list['minimum_marks'][$i]; $model->start_time = $list['start_time'][$i]; $model->end_time = $list['end_time'][$i]; if ($model->start_time) { $date1 = date('Y-m-d H:i', strtotime($model->start_time)); $model->start_time = $date1; } if ($model->end_time) { $date2 = date('Y-m-d H:i', strtotime($model->end_time)); $model->end_time = $date2; } $model->grading_level_id = $list['grading_level_id']; $model->weightage = $list['weightage']; $model->event_id = $list['event_id']; $model->created_at = $list['created_at']; $model->updated_at = $list['updated_at']; //$model->save(); if ($model->save()) { $subject_name = Subjects::model()->findByAttributes(array('id' => $model->subject_id)); $examgroup = ExamGroups::model()->findByAttributes(array('id' => $model->exam_group_id)); $batch = Batches::model()->findByAttributes(array('id' => $examgroup->batch_id)); $exam = ucfirst($subject_name->name) . ' - ' . ucfirst($examgroup->name) . ' (' . ucfirst($batch->name) . '-' . ucfirst($batch->course123->course_name) . ')'; //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value) ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '17', $model->id, $exam, NULL, NULL, NULL); } } } $this->redirect(array('exams/create', 'id' => $_REQUEST['id'], 'exam_group_id' => $_REQUEST['exam_group_id'])); } $this->render('create', array('model' => $model, 'model_1' => $model_1)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Exams(); $model_1 = new ExamGroups(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Exams'])) { //$model->attributes=$_POST['Exams']; if (isset($_REQUEST['exam_group_id'])) { $insert_id = $_REQUEST['exam_group_id']; } else { $model_1->attributes = $_POST['ExamGroups']; $model_1->batch_id = $_REQUEST['id']; $model_1->save(); $insert_id = Yii::app()->db->getLastInsertID(); } $posts = Subjects::model()->findAll("batch_id=:x AND no_exams=:y", array(':x' => $_REQUEST['id'], ':y' => 0)); $list = $_POST['Exams']; $count = count($list['subject_id']); $j = 0; for ($i = 0; $i < $count; $i++) { if ($list['maximum_marks'][$i] != NULL and $list['minimum_marks'][$i] != NULL and $list['start_time'][$i] != NULL and $list['end_time'][$i] != NULL) { $model = new Exams(); $model->exam_group_id = $insert_id; $model->subject_id = $list['subject_id'][$i]; $model->maximum_marks = $list['maximum_marks'][$i]; $model->minimum_marks = $list['minimum_marks'][$i]; $model->start_time = $list['start_time'][$i]; $model->end_time = $list['end_time'][$i]; if ($model->start_time) { $date1 = date('Y-m-d H:i', strtotime($model->start_time)); $model->start_time = $date1; } if ($model->end_time) { $date2 = date('Y-m-d H:i', strtotime($model->end_time)); $model->end_time = $date2; } $model->grading_level_id = $list['grading_level_id']; $model->weightage = $list['weightage']; $model->event_id = $list['event_id']; $model->created_at = $list['created_at']; $model->updated_at = $list['updated_at']; $model->save(); } } $this->redirect(array('exams/create', 'id' => $_REQUEST['id'], 'exam_group_id' => $_REQUEST['exam_group_id'])); } $this->render('create', array('model' => $model, 'model_1' => $model_1)); }
public function actionAjax_Create() { if (isset($_POST['ExamGroups'])) { $model = new ExamGroups(); //set the submitted values $model->attributes = $_POST['ExamGroups']; $model->exam_date = date('Y-m-d', strtotime($model->exam_date)); //return the JSON result to provide feedback. if ($model->save(false)) { //Adding activity to feed via saveFeed($initiator_id,$activity_type,$goal_id,$goal_name,$field_name,$initial_field_value,$new_field_value) ActivityFeed::model()->saveFeed(Yii::app()->user->Id, '11', $model->id, ucfirst($model->name), NULL, NULL, NULL); // Send SMS if saved $sms_settings = SmsSettings::model()->findAll(); $to = ''; // Send SMS only if, SMS is enabled and schedule is published if ($model->is_published == '1' and $sms_settings[0]->is_enabled == '1' and $sms_settings[5]->is_enabled == '1') { $students = Students::model()->findAll("batch_id=:x and is_deleted=:y and is_active=:z", array(':x' => $model->batch_id, ':y' => 0, ':z' => 1)); //Selecting students of the batch foreach ($students as $student) { if ($student->phone1) { // Checking if phone number is provided $to = $student->phone1; } elseif ($student->phone2) { $to = $student->phone2; } if ($to != '') { // Sending SMS to each student $college = Configurations::model()->findByPk(1); $from = $college->config_value; $message = $model->name . ' is scheduled'; SmsSettings::model()->sendSms($to, $from, $message); } } } echo json_encode(array('success' => true, 'id' => $model->primaryKey)); exit; } else { echo json_encode(array('success' => false)); exit; } } }
public function actionAjax_Create() { if (isset($_POST['ExamGroups'])) { $model = new ExamGroups(); //set the submitted values $model->attributes = $_POST['ExamGroups']; if ($model->exam_date) { $model->exam_date = date('Y-m-d', strtotime($model->exam_date)); } //return the JSON result to provide feedback. if ($model->save(false)) { echo json_encode(array('success' => true, 'id' => $model->primaryKey)); exit; } else { echo json_encode(array('success' => false)); exit; } } }