public function actionIndex()
 {
     $model = Teachers::model()->find();
     $flag = 0;
     $flag1 = 0;
     if (!empty($_POST['Teachers'])) {
         $image1_old = $model->attributes['image1'];
         if (!empty(CUploadedFile::getInstance($model, 'image1')->name)) {
             $image1_old = $model->attributes['image1'];
             $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image1_old);
             if (file_exists($path) && !empty($image1_old)) {
                 unlink($path);
             }
             $model->attributes = $_POST['Teachers'];
             $model->image1 = CUploadedFile::getInstance($model, 'image1');
             $image = $model->image1;
             $imageType = explode('.', $model->image1->name);
             $imageType = $imageType[count($imageType) - 1];
             $imageName = md5(uniqid()) . '.' . $imageType;
             $model->image1 = $imageName;
             $images_path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName;
             $flag = 1;
         } else {
             $model->image1 = $image1_old;
             $model->attributes = $_POST['Teachers'];
         }
         $image2_old = $model->attributes['image2'];
         if (!empty(CUploadedFile::getInstance($model, 'image2')->name)) {
             $image2_old = $model->attributes['image2'];
             $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image2_old);
             if (file_exists($path) && !empty($image2_old)) {
                 unlink($path);
             }
             $model->image2 = CUploadedFile::getInstance($model, 'image2');
             $image1 = $model->image2;
             $imageType = explode('.', $model->image2->name);
             $imageType = $imageType[count($imageType) - 1];
             $imageName = md5(uniqid()) . '.' . $imageType;
             $model->image2 = $imageName;
             $images_path1 = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName;
             $flag1 = 1;
         } else {
             $model->image2 = $image2_old;
             $model->attributes = $_POST['Teachers'];
         }
         if ($model->save()) {
             Yii::app()->user->setFlash('success', translate('Cập nhật thành công.'));
             if ($flag == 1) {
                 $image->saveAs($images_path);
             }
             if ($flag1 == 1) {
                 $image1->saveAs($images_path1);
             }
             $this->redirect(PIUrl::createUrl('/admin/teachers'));
         }
     }
     $this->render('index', array('model' => $model));
 }
Beispiel #2
0
echo $form->labelEx($model, 'amount');
?>
		<?php 
echo $form->textField($model, 'amount');
?>
		<?php 
echo $form->error($model, 'amount');
?>
	</div>
	
	<div class="row">
		<?php 
echo $form->labelEx($model, 'teacher_id');
?>
		<?php 
echo $form->dropDownList($model, 'teacher_id', CHtml::listData(Teachers::model()->findAll(), 'id', 'first_name'), array('empty' => 'Select a teacher'));
?>
		<?php 
echo $form->error($model, 'teacher_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'payed');
?>
		<?php 
echo $form->checkbox($model, 'payed');
?>
		<?php 
echo $form->error($model, 'payed');
 /**
  * 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 = Teachers::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionUpdateReplace($replace_id)
 {
     $semester = Semesters::model()->actual();
     if (!$semester) {
         throw new CHttpException(404, 'Сейчас нет семестра :-(');
     }
     /** @var GroupReplace $model */
     $model = GroupReplace::model()->findByPk($replace_id);
     if (!$model || strtotime($model->date) < strtotime(date('Y-m-d'))) {
         throw new CHttpException(404, 'Замена не найдена');
     }
     $classrooms = CHtml::listData(Classrooms::model()->byName()->findAll(), 'id', 'name');
     $subjects = CHtml::listData(Subjects::model()->byName()->findAll(), 'id', 'name');
     $teachers = CHtml::listData(Teachers::model()->byLastName()->findAll(), 'id', function ($model) {
         return join(' ', [$model->lastname, $model->firstname, $model->middlename]);
     });
     if (Yii::app()->request->isPostRequest) {
         $replace = Yii::app()->request->getParam('GroupReplace');
         $model->setAttributes($replace);
         $model->setAttributes(['group_id' => self::$group->id]);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Замена успешна обновлена');
             $this->redirect(['replaces', 'id' => self::$group->number]);
         }
     }
     $this->render('replace/form', ['semester' => $semester, 'model' => $model, 'teachers' => $teachers, 'subjects' => $subjects, 'classrooms' => $classrooms, 'numbers' => [1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5]]);
 }