コード例 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $static = ['property' => ['classroom', 'others'], 'property.status' => ['normal', 'deleted'], 'repair.type' => ['cleanup', 'maintain'], 'repair.status' => ['submitted', 'canceled', 'processing', 'finished'], 'loan.type' => ['meeting', 'course', 'speech', 'interview', 'others'], 'loan.status' => ['submitted', 'canceled', 'accepted', 'refused', 'deleted'], 'time.type' => ['semester', 'vacation']];
     foreach ($static as $category => $collections) {
         foreach ($collections as $value) {
             Category::firstOrCreate(['category' => $category, 'name' => $value]);
         }
     }
 }
コード例 #2
0
 /**
  * Display a listing of the normal classroom.
  *
  * @param Request $request
  * @return
  */
 public function indexClassroom(Request $request)
 {
     // get date
     $date = $request->input('date', date('Y-m-d', time()));
     $classroom_list = Property::with(['category', 'status', 'loanClassroom' => function ($query) use($date) {
         $query->where('date_ended_at', '>=', $date);
     }])->where('category', Category::getCategoryId('property', 'classroom'))->get();
     return response()->json($classroom_list);
 }
コード例 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $repair = Repair::where('user_id', Auth::user()->id)->find($id);
     if ($repair === null) {
         return response()->json(['status' => 2]);
     }
     $repair->status = Category::getCategoryId('repair.status', 'canceled');
     $result = $repair->save();
     return response()->json(['status' => $result === true ? 0 : 2]);
 }
コード例 #4
0
 /**
  * Update the repair list's status to finished
  * and also update the aim property to status -normal.
  *
  * @param  Request  $request
  * @return Json
  */
 public function update(Request $request)
 {
     // get repair list
     $repair_list = $request->input('repair_list');
     if (!is_array($repair_list)) {
         return response()->json(['status' => 2]);
         // paramater error.
     }
     $property_list = Repair::whereIn('id', $repair_list)->get()->pluck('property_id');
     // update repair status
     $affect_repairs = Repair::whereIn('id', $repair_list)->update(['status' => Category::getCategoryId('repair.status', 'finished')]);
     return response()->json(['status' => 0]);
 }
コード例 #5
0
 /** @test */
 public function update_repair()
 {
     $property = Property::find($this->getTestPropertyId(true));
     factory(Repair::class, 5)->make(['status' => Category::getCategories('repair.status', 'processing', true)])->each(function (Repair $repair) use($property) {
         $property->repairs()->save($repair);
     });
     $property->load(['repairs']);
     $this->call('PUT', '/', ['repair_list' => $property->getRelation('repairs')->pluck('id')]);
     $this->assertResponseOk();
     $this->seeJson();
     $this->assertSame(Category::getCategories('property.status', 'normal', true), Property::find($this->getTestPropertyId(true))->getAttribute('status'));
     foreach (Property::with(['repairs'])->find($this->getTestPropertyId(true))->getRelation('repairs') as $repair) {
         $this->assertSame(Category::getCategories('repair.status', 'finished', true), $repair->getAttribute('status'));
     }
 }
コード例 #6
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (\Entrust::hasRole('student') && $request->input('type') == Category::getCategoryId('loan.type', 'interview')) {
         $judge_column = 'stu_date_began_at';
     } else {
         $judge_column = 'date_began_at';
     }
     $timezone = Timezone::whereRaw("? BETWEEN `{$judge_column}` AND `date_ended_at`", [Carbon::now()->toDateString()])->where('date_began_at', '<=', $request->input('date_began_at'))->where('date_ended_at', '>=', $request->input('date_ended_at'))->first();
     if ($timezone != null) {
         $request->merge(['timezone' => $timezone, 'long_term_token' => bindec($request->input('long_term_token'))]);
         return $next($request);
     } else {
         return abort(403);
     }
 }
コード例 #7
0
 /**
  * check loan data conflict or not.
  *
  * @param array $date_info
  * @param array $time_info
  * @param int $LTK
  * @return bool
  */
 public static function checkConflict($p_id, $date_info, $time_info, $LTK)
 {
     $loans = new Loan();
     $conflict_num = self::getConflictQuery($p_id, $date_info, $time_info, $LTK, $loans)->where('status', '=', Category::getCategoryId('loan.status', 'accepted'))->count();
     return $conflict_num > 0;
 }
コード例 #8
0
 /**
  * 取得有效教室借用.
  *
  * @return
  */
 public function loanClassroom()
 {
     return $this->hasMany(Loan::class)->join('categories as ct', 'type', '=', 'ct.id')->whereIn('status', Category::getCategoryIds(['loan.status' => ['accepted', 'processing']]))->select('loans.*', 'ct.category', 'ct.name');
 }
コード例 #9
0
    $faker = Faker\Factory::create('zh_TW');
    return ['name' => $faker->name, 'describe' => $faker->realText(16), 'category' => Category::getCategories('property')->random()->getAttribute('id'), 'status' => Category::getCategories('property.status')->random()->getAttribute('id'), 'code' => mt_rand(10000000, 99999999)];
});
$factory->define(\App\Affair\Repair::class, function () {
    $faker = Faker\Factory::create('zh_TW');
    return ['user_id' => User::all()->random()->getAttribute('id'), 'title' => mt_rand(0, 1) ? $faker->realText(mt_rand(10, 15)) : '', 'type' => Category::getCategories('repair.type')->random()->getAttribute('id'), 'remark' => $faker->realText(32), 'status' => Category::getCategories('repair.status')->random()->getAttribute('id')];
});
$factory->define(\App\Affair\Loan::class, function () {
    $faker = Faker\Factory::create('zh_TW');
    $time = mt_rand(0, 1);
    // get randomal Timezone
    $began_date = Timezone::all()->random()->getAttribute('date_began_at');
    $day = (new Carbon($began_date))->addDays(rand(1, 10));
    // get date begin/end
    $begin = $day->toDateString();
    $end = $day->addDays(mt_rand(0, 10))->toDateString();
    return ['user_id' => User::all()->random()->getAttribute('id'), 'type' => Category::getCategories('loan.type')->random()->getAttribute('id'), 'date_began_at' => $begin, 'date_ended_at' => $end, 'time_began_at' => $time ? $day->addHours(mt_rand(0, 7))->toTimeString() : null, 'time_ended_at' => $time ? $day->addHours(mt_rand(7, 15))->toTimeString() : null, 'remark' => $faker->realText(32), 'status' => Category::getCategories('loan.status')->random()->getAttribute('id'), 'long_term_token' => $begin != $end ? mt_rand(0, 127) : 1 << date('w', strtotime($begin))];
});
$factory->define(\App\Affair\Timezone::class, function () {
    $faker = Faker\Factory::create('zh_TW');
    $day = Carbon::now()->startOfDay()->addDays(mt_rand(1, 365));
    $stu_start = clone $day;
    $lab_start = clone $day;
    if (mt_rand(0, 1) === 1) {
        $type = Category::getCategoryId('time.type', 'semester');
    } else {
        $type = Category::getCategoryId('time.type', 'vacation');
        $stu_start->subDays(7);
    }
    return ['zone_name' => $faker->realText(mt_rand(10, 15)), 'type' => $type, 'date_began_at' => $day->toDateString(), 'date_ended_at' => $day->addDays(mt_rand(30, 150))->toDateString(), 'stu_date_began_at' => $stu_start->toDateString(), 'lab_date_began_at' => $lab_start->toDateString()];
});
コード例 #10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $affect_rows = Property::where('id', '=', $id)->update(['status' => Category::getCategoryId('property.status', 'deleted')]);
     return response()->json(['status' => $affect_rows == 1 ? 0 : 2]);
 }
コード例 #11
0
 /**
  * Get random category name.
  *
  * @param string $category
  * @return string
  */
 protected function randomCategoryName($category)
 {
     return Category::getCategories($category)->random()->getAttribute('name');
 }
コード例 #12
0
 /**
  * Set classroom borrow infomation.
  *
  * @param Request $request
  * @return Json
  */
 public function setClassroomBorrowInfo(Request $request)
 {
     // parse timezone info
     $timezone_info = array_only($request->all(), ['zone_name', 'date_began_at', 'date_ended_at', 'stu_date_began_at', 'lab_date_began_at']);
     Timezone::create(array_merge($timezone_info, ['type' => Category::getCategoryId('time.type', $request->input('type'))]));
     return response()->json(['status' => 0]);
 }
コード例 #13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroyClassroomBorrow($id)
 {
     $affect_rows = Loan::where('id', '=', $id)->where('user_id', '=', Auth::user()->id)->where('loan.status', '=', Category::getCategroyId('loan.status', 'submitted'))->update(['status' => Category::getCategoryId('loan.status', 'canceled')]);
     return response()->json(['status' => $affect_rows == 1 ? 0 : 2]);
 }
コード例 #14
0
 /** @test */
 public function it_should_get_specific_category_id_if_all_parameters_are_present()
 {
     $this->assertSame(Category::where('category', 'loan.status')->where('name', 'canceled')->first()->getAttribute('id'), Category::getCategories('loan.status', 'canceled', true));
     $this->assertSame(Category::where('category', 'loan.type')->where('name', 'interview')->first()->getAttribute('id'), Category::getCategories('loan.type', 'interview', true));
     $this->assertSame(Category::where('category', 'property')->where('name', 'classroom')->first()->getAttribute('id'), Category::getCategories('property', 'classroom', true));
 }