/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $student = Student::find($id); if ($student == NULL) { throw new Exception('Invalid Student ID'); } $student->year = (int) substr($student->year, 2, 4); $student_category = StudentCategories::find($student->category); $student->category = $student_category->category; $student_branch = Branch::find($student->branch); $student->branch = $student_branch->branch; if ($student->rejected == 1) { unset($student->approved); unset($student->books_issued); $student->rejected = (bool) $student->rejected; return $student; } if ($student->approved == 0) { unset($student->rejected); unset($student->books_issued); $student->approved = (bool) $student->approved; return $student; } unset($student->rejected); unset($student->approved); $student_issued_books = Logs::select('book_issue_id', 'issued_at')->where('student_id', '=', $id)->orderBy('time_stamp', 'desc')->take($student->books_issued)->get(); foreach ($student_issued_books as $issued_book) { $issue = Issue::find($issued_book->book_issue_id); $book = Books::find($issue->book_id); $issued_book->name = $book->title; $issued_book->issued_at = date('d-M', $issued_book->issued_at); } $student->issued_books = $student_issued_books; return $student; }
public function store() { $data = Input::all()['data']; $bookID = $data['bookID']; $studentID = $data['studentID']; $student = Student::find($studentID); if ($student == NULL) { throw new Exception('Invalid Student ID'); } else { $approved = $student->approved; if ($approved == 0) { throw new Exception('Student still not approved by Admin Librarian'); } else { $books_issued = $student->books_issued; $category = $student->category; $max_allowed = StudentCategories::where('cat_id', '=', $category)->firstOrFail()->max_allowed; if ($books_issued >= $max_allowed) { throw new Exception('Student cannot issue any more books'); } else { $book = Issue::find($bookID); if ($book == NULL) { throw new Exception('Invalid Book Issue ID'); } else { $book_availability = $book->available_status; if ($book_availability != 1) { throw new Exception('Book not available for issue'); } else { // book is to be issued DB::transaction(function () use($bookID, $studentID) { $log = new Logs(); $log->book_issue_id = $bookID; $log->student_id = $studentID; $log->issue_by = Auth::id(); $log->issued_at = time(); $log->return_time = 0; $log->save(); // changing the availability status $book = Issue::find($bookID); $book->available_status = 0; $book->save(); // increasing number of books issed by student $student = Student::find($studentID); $student->books_issued = $student->books_issued + 1; $student->save(); }); return 'Successfully Issued'; } } } } } }
/** * 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 the ID of the model to be loaded */ public function loadModel($id) { $model = StudentCategories::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionAjax_Create() { if (isset($_POST['StudentCategories'])) { $model = new StudentCategories(); //set the submitted values $model->attributes = $_POST['StudentCategories']; //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; } } }
<tr> <td class="listbx_subhdng">Language</td> <td class="subhdng_nrmal"><?php echo $model->language; ?> </td> <td class="listbx_subhdng">Email</td> <td class="subhdng_nrmal"><?php echo $model->email; ?> </td> </tr> <tr> <td class="listbx_subhdng">Category</td> <td class="subhdng_nrmal"><?php $cat = StudentCategories::model()->findByAttributes(array('id' => $model->student_category_id)); echo $cat->name; ?> </td> <td class="listbx_subhdng">Religion</td> <td class="subhdng_nrmal"><?php echo $model->religion; ?> </td> </tr> <tr > <td colspan="4" class="listbx_subhdng">In case of emergencies,<br /> contact : <?php $posts = Guardians::model()->findByAttributes(array('id' => $model->immediate_contact_id)); if (count($posts) == 0) { echo "No Guardians are added" . ' ' . CHtml::link('Add new', array('guardians/create&id=' . $model->id));
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $issue = Issue::find($id); if ($issue == NULL) { throw new Exception('Invalid Book ID'); } $issue->added_at_timestamp = date('d-M-y h:i A', strtotime($issue->added_at_timestamp)); $book = Books::find($issue->book_id); $issue->book_name = $book->title; $issue->author = $book->author; $issue->category = Categories::find($book->category_id)->category; $issue->available_status = (bool) $issue->available_status; if ($issue->available_status == 1) { return $issue; } $conditions = array('return_time' => 0, 'book_issue_id' => $id); $book_issue_log = Logs::where($conditions)->take(1)->get(); foreach ($book_issue_log as $log) { $student_id = $log->student_id; } $student_data = Student::find($student_id); unset($student_data->email_id); unset($student_data->books_issued); unset($student_data->approved); unset($student_data->rejected); $student_branch = Branch::find($student_data->branch)->branch; $roll_num = $student_data->roll_num . '/' . $student_branch . '/' . substr($student_data->year, 2, 4); unset($student_data->roll_num); unset($student_data->branch); unset($student_data->year); $student_data->roll_num = $roll_num; $student_data->category = StudentCategories::find($student_data->category)->category; $issue->student = $student_data; return $issue; }
?> <tr> <td><?php echo $i; ?> </td> <td><?php echo $particular_1->name; ?> </td> <td> <?php if ($particular_1->student_category_id == NULL and $particular_1->admission_no == NULL) { echo 'All'; } elseif ($particular_1->student_category_id != NULL and $particular_1->admission_no == NULL) { $student_category = StudentCategories::model()->findByAttributes(array('id' => $particular_1->student_category_id)); echo 'Category: ' . $student_category->name; } elseif ($particular_1->student_category_id == NULL and $particular_1->admission_no != NULL) { echo 'Admission No: ' . $particular_1->admission_no; } else { echo '-'; } ?> </td> <td><?php echo $currency->config_value . ' ' . $particular_1->amount; ?> </td> </tr> <?php
<div class="row_checkbox" id="category" > <?php if ($model->isNewRecord) { ?> <?php echo $form->labelEx($model, 'student_category_id'); ?> <?php $data = CHtml::listData(StudentCategories::model()->findAll(), 'id', 'name'); echo '<div style="height:auto;width:450px;overflow-y:auto;line-height:0px;">'; echo '<table>'; echo $form->checkBoxList($model, 'id', $data, array('htmlOption' => 'style=clear:both', 'template' => '<tr><td>{input}</td><td>{label}</td></tr>', 'checkAll' => 'All')); echo '</table>'; echo '</div>'; ?> <?php } ?> </div> <div class="row" id="admission" style="display:none;"> <?php echo $form->labelEx($model, 'admission_no'); ?>
<td> </td> <td valign="top"> <?php echo $form->textField($model, 'religion', array('size' => 10, 'maxlength' => 255)); ?> <?php echo $form->error($model, 'religion'); ?> </td> <td> </td> <td valign="top"> <?php //echo $form->textField($model,'student_category_id'); ?> <?php echo $form->dropDownList($model, 'student_category_id', CHtml::listData(StudentCategories::model()->findAll(), 'id', 'name')); ?> <?php echo $form->error($model, 'student_category_id'); ?> </td> </tr> </table> </div> </div> <div class="formCon" > <div class="formConInner"> <h3>Contact Details</h3> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr>
public function __construct() { $this->categories_list = Categories::select()->orderBy('category')->get(); $this->branch_list = Branch::select()->orderBy('id')->get(); $this->student_categories_list = StudentCategories::select()->orderBy('cat_id')->get(); }
$page_size = Yii::app()->params['listPerPage']; ?> <ul> <li> <?php echo CHtml::link('<span>' . Yii::t('students', 'Create New Category') . '</span>', array('#'), array('id' => 'add_student-categories', 'class' => 'addbttn last')); ?> </li> </ul> <div class="clear"></div> </div><div id="success_flash" align="center" style=" color:#F00; display:none;"><h4>Selected category Deleted Successfully !</h4> </div> </div> <?php $datas = StudentCategories::model()->findAll($criteria); ?> <div id="student-categories-grid"> <div class="grid_table_con"> <table width="100%" border="0" cellspacing="0" cellpadding="0" id="example"> <tr> <th width="45%"><?php echo Yii::t('students', 'Category Name'); ?> <a href="#" class="sort_but"></a></th> <th width="16%"><?php echo Yii::t('students', 'Status'); ?> <a href="#" class="sort_but"></a></th> <th width="19%"><?php
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id)); if ($settings != NULL) { $date1 = date($settings->displaydate, strtotime($model->admission_date)); $date2 = date($settings->displaydate, strtotime($model->date_of_birth)); } $model->admission_date = $date1; $model->date_of_birth = $date2; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Students'])) { $old_model = $model->attributes; // For activity feed $model->attributes = $_POST['Students']; if ($model->admission_date) { $model->admission_date = date('Y-m-d', strtotime($model->admission_date)); } if ($model->date_of_birth) { $model->date_of_birth = date('Y-m-d', strtotime($model->date_of_birth)); } if ($file = CUploadedFile::getInstance($model, 'photo_data')) { $model->photo_file_name = $file->name; $model->photo_content_type = $file->type; $model->photo_file_size = $file->size; $model->photo_data = file_get_contents($file->tempName); } if ($model->save()) { // Saving to activity feed $results = array_diff_assoc($_POST['Students'], $old_model); // To get the fields that are modified. //print_r($old_model);echo '<br/><br/>';print_r($_POST['Students']);echo '<br/><br/>';print_r($results);echo '<br/><br/>'.count($results);echo '<br/><br/>'; foreach ($results as $key => $value) { if ($key != 'updated_at') { if ($key == 'batch_id') { $value = Batches::model()->findByAttributes(array('id' => $value)); $value = $value->name . '-' . $value->course123->course_name; $old_model_value = Batches::model()->findByAttributes(array('id' => $old_model[$key])); $old_model[$key] = $old_model_value->name . '-' . $old_model_value->course123->course_name; } elseif ($key == 'gender') { if ($value == 'F') { $value = 'Female'; } else { $value = 'Male'; } if ($old_model[$key] == 'F') { $old_model[$key] = 'Female'; } else { $old_model[$key] = 'Male'; } } elseif ($key == 'student_category_id') { $value = StudentCategories::model()->findByAttributes(array('id' => $value)); $value = $value->name; $old_model_value = StudentCategories::model()->findByAttributes(array('id' => $old_model[$key])); $old_model[$key] = $old_model_value->name; } elseif ($key == 'nationality_id' or $key == 'country_id') { $value = Countries::model()->findByAttributes(array('id' => $value)); $value = $value->name; $old_model_value = Countries::model()->findByAttributes(array('id' => $old_model[$key])); $old_model[$key] = $old_model_value->name; } //echo $key.'-'.$model->getAttributeLabel($key).'-'.$value.'-'.$old_model[$key].'<br/>'; //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, '4', $model->id, ucfirst($model->first_name) . ' ' . ucfirst($model->middle_name) . ' ' . ucfirst($model->last_name), $model->getAttributeLabel($key), $old_model[$key], $value); } } //END saving to activity feed if (defined('EMAIL_ALERT_ADDRESS')) { $name = $model->first_name . " " . $model->last_name; UserModule::sendMail(constant('EMAIL_ALERT_ADDRESS'), UserModule::t("Student details modified : {student_name}", array('{student_name}' => $name)), UserModule::t("Student details has been modified for : {student_name}", array('{student_name}' => $name))); } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
public function getCategory($data, $row) { $student_category = StudentCategories::model()->findByAttributes(array('id' => $data->student_category_id, 'is_deleted' => 0)); if (count($student_category) > 0) { return $student_category->name; } else { return '-'; } }