Пример #1
0
 /**
  * Creates a new Course model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Course();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CourseRequest $request)
 {
     $data = $request->all();
     unset($data['Id']);
     $course = new Course();
     $course->fromArray($data);
     $course->save();
     flash()->success("ADDED");
     session(['attribute' => \Lang::get('general.COURSE')]);
     return redirect($this->main_page);
 }
Пример #3
0
 /**
  * @param Request $request
  * @param Course $course
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(Request $request, Course $course)
 {
     $regex = '/^(?=.+)(?:[1-9]\\d*|0)?(?:\\.\\d+)?$/';
     $validator = Validator::make($request->all(), ['name' => 'required|string|max:255', 'course_purchase' => ['required', 'regex:' . $regex]]);
     if ($validator->fails()) {
         return redirect()->route('admin.course.create')->withErrors($validator->errors())->withInput();
     }
     $currency = new Currency();
     $currency->name = $request->name;
     $currency->save();
     $course->currency()->associate($currency);
     $course->fill($request->all());
     $course->save();
     return redirect()->route('admin.course.index');
 }
Пример #4
0
 public function actionSave()
 {
     if (!empty($_POST['course'][Course::PK])) {
         $item = Course::findByPK($_POST['course'][Course::PK]);
     } else {
         $item = new Course();
     }
     $item->fill($_POST['course']);
     $item->save();
     if ($item->wasNew() && !empty($_POST['lessonsCount'])) {
         $lessonsCount = (int) $_POST['lessonsCount'];
         for ($i = 1; $i <= $lessonsCount; $i++) {
             $lesson = new Lesson();
             $lesson->num = $i;
             $lesson->title = 'Урок ' . $i;
             $lesson->course = $item;
             $lesson->save();
         }
     }
     $this->redirect('/admin/courses');
 }
Пример #5
0
 public function addOperation()
 {
     if ($this->currency_id != '1') {
         $course = new Course();
         if (!$course->checkCourse($this->currency_id)) {
             $course->currency_id = $this->currency_id;
             $currency = Currency::findOne($this->currency_id);
             $course->course = $course->getCourse($currency->iso);
             if (!$course->save()) {
                 throw new ErrorException('Курс не обновлен' . var_dump($course));
             }
         }
     }
     $operation = new Operation();
     $operation->user_id = Yii::$app->getUser()->id;
     $operation->category_id = $this->category_id === '' ? 1 : $this->category_id;
     $operation->currency_id = $this->currency_id === '' ? 1 : $this->currency_id;
     $operation->summ = $this->operation_type == 'income' ? $this->summ * 100 : $this->summ * -100;
     $operation->description = $this->description;
     return $operation->save() ? $operation : null;
 }
Пример #6
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCourse !== null) {
             if ($this->aCourse->isModified() || $this->aCourse->isNew()) {
                 $affectedRows += $this->aCourse->save($con);
             }
             $this->setCourse($this->aCourse);
         }
         if ($this->aSchoolYear !== null) {
             if ($this->aSchoolYear->isModified() || $this->aSchoolYear->isNew()) {
                 $affectedRows += $this->aSchoolYear->save($con);
             }
             $this->setSchoolYear($this->aSchoolYear);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->adminUsersScheduledForDeletion !== null) {
             if (!$this->adminUsersScheduledForDeletion->isEmpty()) {
                 \App\Models\AdminUserQuery::create()->filterByPrimaryKeys($this->adminUsersScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->adminUsersScheduledForDeletion = null;
             }
         }
         if ($this->collAdminUsers !== null) {
             foreach ($this->collAdminUsers as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->applicationsScheduledForDeletion !== null) {
             if (!$this->applicationsScheduledForDeletion->isEmpty()) {
                 \App\Models\ApplicationQuery::create()->filterByPrimaryKeys($this->applicationsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->applicationsScheduledForDeletion = null;
             }
         }
         if ($this->collApplications !== null) {
             foreach ($this->collApplications as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Пример #7
0
 /**
  * Add a slug to the course.
  *
  * @param Course $course
  * @param $slug
  * @return Course
  */
 public function addSlug(Course $course, $slug)
 {
     \DB::transaction(function () use($course, $slug) {
         $course->slug = $slug;
         $course->save();
     });
     return $course;
 }
 /**
  * Save a model with it's relations.
  *
  * @param $data
  * @param null $id
  *
  * @return static
  */
 public static function save($data, $id = null)
 {
     if ($id) {
         $employee = Employee::findOrFail($id);
         $employee->fill($data);
     } else {
         $employee = Employee::create($data);
     }
     Address::whereEmployeeId($employee->id)->delete();
     // flush
     Course::whereEmployeeId($employee->id)->delete();
     foreach (array_get($data, 'address', []) as $key => $d) {
         if (empty($d['city']) && empty($d['street']) && empty($d['number'])) {
             continue;
         }
         $address = new Address($d);
         $address->employee_id = $employee->id;
         $address->save();
     }
     foreach (array_get($data, 'course', []) as $key => $d) {
         if (empty($d['title']) && empty($d['start']) && empty($d['end'])) {
             continue;
         }
         $course = new Course($d);
         $course->employee_id = $employee->id;
         $course->save();
     }
     $employee->save();
     return $employee;
 }
Пример #9
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCourse !== null) {
             if ($this->aCourse->isModified() || $this->aCourse->isNew()) {
                 $affectedRows += $this->aCourse->save($con);
             }
             $this->setCourse($this->aCourse);
         }
         if ($this->aProfessor !== null) {
             if ($this->aProfessor->isModified() || $this->aProfessor->isNew()) {
                 $affectedRows += $this->aProfessor->save($con);
             }
             $this->setProfessor($this->aProfessor);
         }
         if ($this->aSubject !== null) {
             if ($this->aSubject->isModified() || $this->aSubject->isNew()) {
                 $affectedRows += $this->aSubject->save($con);
             }
             $this->setSubject($this->aSubject);
         }
         if ($this->aSchoolYear !== null) {
             if ($this->aSchoolYear->isModified() || $this->aSchoolYear->isNew()) {
                 $affectedRows += $this->aSchoolYear->save($con);
             }
             $this->setSchoolYear($this->aSchoolYear);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Пример #10
0
 /**
  * Normally we try taken form data with Request Controller but in this case we are using Facade
  * Todo: Add Validator (Critical, after all core business function is implemented)
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function saveMatkul(Request $request)
 {
     $input = $request->all();
     $validator = $this->course_validator($input);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $course = new Course();
     $course->Kode_Matkul = $input['Kode_Matkul'];
     $course->Nama_Matkul = $input['Nama_Matkul'];
     $course->SKS = $input['SKS'];
     $course->prodi_id = $input['prodi_id'];
     $course->day = $input['day'];
     $course->id_ruang = $input['id_ruang'];
     $course->time = $input['time'];
     $course->Kode_Dosen = $input['Kode_Dosen'];
     $semester = Kalender::getRunningSemester();
     $course->id_semester = $semester->id;
     $course->course_start_day = $input['course_start_day'];
     $course->save();
     return $this->viewCourseByLecturer();
 }