public function actionAdmin() { $model = new Student('search'); $model->unsetAttributes(); if (isset($_GET['Student'])) { $model->setAttributes($_GET['Student']); } $this->render('admin', array('model' => $model)); }
public function actionCreate() { $model = new Student(); // $this->performAjaxValidation($model, 'product-form'); if (isset($_POST['Student'])) { $model->setAttributes($_POST['Student']); $relatedData = array('assignments' => $_POST['Student']['assignments'] === '' ? null : $_POST['Student']['assignments']); if ($model->saveWithRelated($relatedData)) { //if model was saved echo '<textarea>' . json_encode(array('success' => true, 'id' => $model->primaryKey)) . '</textarea>'; Yii::app()->end(); } else { echo '<textarea>' . json_encode(array('success' => false)) . '</textarea>'; Yii::app()->end(); } } }
public function actionRegister() { $arrayAuthRoleItems = Yii::app()->authManager->getAuthItems(2, Yii::app()->user->getId()); $arrayKeys = array_keys($arrayAuthRoleItems); $role = strtolower($arrayKeys[0]); if ($role == 'admin' || $role == 'teacher') { $this->redirect('/'); } $this->layout = 'dangkyhoc'; $model = new Student(); if (isset($_GET['cid']) && (int) $_GET['cid']) { $model->class_id = $_GET['cid']; } $db = Yii::app()->db; if (isset($_POST['Student']) && $_POST['Student']) { $model->setAttributes($_POST['Student']); $gclass = ClassGuitar::model()->findByPk($model->class_id); $sql = "SELECT * FROM {{student}} WHERE user_id =" . Yii::app()->user->id . " ORDER BY id DESC"; $cmd = $db->createCommand($sql); $student = $cmd->queryRow(); if ($student) { // var_dump($studentơclass_id); $gclass2 = ClassGuitar::model()->findByPk($student['class_id']); if ($student['status'] == 'comp') { //Hoàn thành if ($gclass->tid <= $gclass2->tid) { $training = Training::model()->findByPk($gclass2->tid); Yii::app()->user->setFlash('error', 'Bạn đã hoàn thành một lớp thuộc khóa <b>' . $training->title . '</b>. Vui lòng đăng ký khóa học cao hơn.'); } } elseif ($student['status'] == 'reg') { // Mới đăng ký Yii::app()->user->setFlash('error', 'Bạn đã đăng ký học tại lớp <b>' . $gclass2->title . '</b>. Vui lòng hủy đơn đăng ký này trước khi đăng ký tham gia lớp học khác!'); } else { $center = Center::model()->findByPk($gclass2->cid); Yii::app()->user->setFlash('error', 'Bạn đang tham gia lớp học <b>' . $gclass2->title . '</b> tại cơ sở <b>' . $center->title . '</b>!'); } } else { } if (!Yii::app()->user->hasFlash('error') && $model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { Yii::app()->user->setFlash('success', 'Bạn đã đăng ký lớp học thành công. LNT sẽ sớm liên lạc lại với bạn.'); } } } else { $oldStudent = Student::model()->find('user_id=' . Yii::app()->user->id); if ($oldStudent) { $model->name = $oldStudent->name; $model->email = $oldStudent->email; $model->tel = $oldStudent->tel; $model->birthday = $oldStudent->birthday; } } $this->render('register', array('model' => $model)); }
/** * Prepares dataproviders for models and jstree open nodes. * @return array Contains the dataproviders for the models,open nodes for the tree and the model to search for. * @since 1.0 */ private function prepare_dataproviders() { //create an array open_nodes with the ids of the nodes that we want to be initially open //when the tree is loaded.Modify this to suit your needs.Here,we open all nodes on load. $categories = Classroom::model()->findAll(array('order' => 'lft')); $identifiers = array(); foreach ($categories as $n => $category) { $identifiers[] = "'" . 'node_' . $category->id . "'"; } $open_nodes = implode(',', $identifiers); $cat_dataProvider = new CActiveDataProvider('Classroom'); $prod_criteria = new CDbCriteria(); $prod_criteria->with = array('assignments' => array('on' => 'assignments.id=:cat_id', 'together' => true, 'joinType' => 'INNER JOIN', 'params' => array(':cat_id' => $_GET['cat_id']))); //for search $model = new Student('search'); $model->unsetAttributes(); if (isset($_GET['Student'])) { //if searching $model->setAttributes($_GET['Student']); $search_criteria = $model->searchCriteria(); $prod_criteria->mergeWith($search_criteria); } $prod_dataProvider = new CActiveDataProvider('Student', array('criteria' => $prod_criteria, 'pagination' => array('pageSize' => self::PAGING_SIZE_CAT))); return array('cat_provider' => $cat_dataProvider, 'prod_provider' => $prod_dataProvider, 'open_nodes' => $open_nodes, 'model' => $model); }