Ejemplo n.º 1
0
 public function actionEdit()
 {
     $data = Yii::$app->request->post('Department');
     $result = array();
     if (is_numeric($data['id']) && $data['id'] > 0) {
         $model = Department::findOne($data['id']);
         if (!$model) {
             $result['status'] = 0;
             $result['message'] = '未找到该记录';
         }
     } else {
         $model = new Department();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $result['status'] = 1;
             $result['message'] = '保存成功';
         }
     }
     $errors = $model->getFirstErrors();
     if ($errors) {
         $result['status'] = 0;
         $result['message'] = current($errors);
     }
     return $this->renderJson($result);
 }
Ejemplo n.º 2
0
 public function actionCreate()
 {
     $dept = new Department();
     if ($dept->load(Yii::$app->request->post()) && $dept->save()) {
         return $this->redirect(['index']);
     }
     return $this->render('create', ['dept' => $dept]);
 }
Ejemplo n.º 3
0
 /**
  * Creates a new Department model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Department();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->department_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function create(DepartmentRequest $request)
 {
     $this->authorize('create-department');
     $input = $request->all();
     // Convert roles into JSON
     $input['roles'] = json_encode($input['roles']);
     $department = new Department();
     $department->event_id = $input['event_id'];
     $department->save();
     $department->update($input);
     event(new EventChanged($department->event, ['type' => 'department', 'status' => 'created']));
     $request->session()->flash('success', 'Your department has been created.');
     return redirect('/event/' . $department->event->id);
 }
Ejemplo n.º 5
0
 public function cloneEvent(Request $request, Event $event)
 {
     $this->authorize('create-event');
     $this->validate($request, ['start_date' => 'required|date_format:Y-m-d']);
     // Set up event information
     $startDate = new Carbon($event->start_date);
     $endDate = new Carbon($event->end_date);
     $newStartDate = new Carbon($request->input('start_date'));
     $departments = $event->departments;
     // Find the difference of the start dates
     $difference = $startDate->diffInSeconds($newStartDate);
     // Create new event from old event data
     $newEvent = Event::create(['name' => $event->name, 'description' => $event->description, 'start_date' => $startDate->addSeconds($difference)->format('Y-m-d'), 'end_date' => $endDate->addSeconds($difference)->format('Y-m-d')]);
     // Add the image manually because it's not automatically fillable
     if ($event->image) {
         $newEvent->image = $event->image;
         $newEvent->save();
     }
     // Loop through event departments
     foreach ($departments as $department) {
         // Create new department
         $newDepartment = new Department();
         $newDepartment->event_id = $newEvent->id;
         $newDepartment->save();
         // Because the event_id isn't fillable, we have to define it first and then update
         $newDepartment->update(['name' => $department->name, 'description' => $department->description, 'roles' => $department->roles]);
         // Loop through shifts
         $shifts = $department->shifts;
         foreach ($shifts as $shift) {
             // Adjust shift dates
             $shift->start_date = new Carbon($shift->start_date);
             $shift->end_date = new Carbon($shift->end_date);
             $shift->start_date = $shift->start_date->addSeconds($difference)->format('Y-m-d');
             $shift->end_date = $shift->end_date->addSeconds($difference)->format('Y-m-d');
             // Update the department ID
             $shift->department_id = $newDepartment->id;
             $newShift = Shift::create(['department_id' => $newDepartment->id, 'name' => $shift->name, 'start_date' => $shift->start_date, 'end_date' => $shift->end_date, 'start_time' => $shift->start_time, 'end_time' => $shift->end_time, 'duration' => $shift->duration, 'roles' => $shift->roles]);
             Slot::generate($newShift);
         }
     }
     $request->session()->flash('success', 'Event has been cloned.');
     return redirect('/event/' . $newEvent->id);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $createDep = new Department();
     $createDep->id = '1';
     $createDep->name = 'Managment';
     $createDep->save();
     \DB::table('department_user')->insert(['department_id' => 1, 'user_id' => 1]);
 }
 public static function createDepartment($name, $status, $userId)
 {
     $department = new Department();
     $date = GeneralValues::getActualDate();
     $department->name = $name;
     $department->status = $status;
     $department->created_at = $date;
     $department->updated_at = $date;
     $department->fk_user_who_create = $userId;
     $department->save();
     return $department;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(App\Models\User::class, 5)->create()->each(function ($c) {
     });
     $createDep = new Department();
     $createDep->id = '2';
     $createDep->name = 'Nerds';
     $createDep->save();
     $createDep = new Department();
     $createDep->id = '3';
     $createDep->name = 'Genius';
     $createDep->save();
     $newrole = new RoleUser();
     $newrole->role_id = '1';
     $newrole->user_id = '2';
     $newrole->timestamps = false;
     $newrole->save();
     $newrole = new RoleUser();
     $newrole->role_id = '2';
     $newrole->user_id = '3';
     $newrole->timestamps = false;
     $newrole->save();
     $newrole = new RoleUser();
     $newrole->role_id = '3';
     $newrole->user_id = '4';
     $newrole->timestamps = false;
     $newrole->save();
     $newrole = new RoleUser();
     $newrole->role_id = '3';
     $newrole->user_id = '5';
     $newrole->timestamps = false;
     $newrole->save();
     $newrole = new RoleUser();
     $newrole->role_id = '3';
     $newrole->user_id = '6';
     $newrole->timestamps = false;
     $newrole->save();
     \DB::table('department_user')->insert([['department_id' => 1, 'user_id' => 2], ['department_id' => 2, 'user_id' => 3], ['department_id' => 3, 'user_id' => 4], ['department_id' => 3, 'user_id' => 5], ['department_id' => 2, 'user_id' => 6]]);
 }