예제 #1
0
파일: Register.php 프로젝트: BePsvPT/CCU
 /**
  * Create a new register instance.
  *
  * @param \App\Ccu\Member\Account $account
  */
 public function __construct(Account $account)
 {
     $this->to = $account->getAttribute('email');
     $this->account = $account;
     $this->category = Category::getCategories('verifies.account', true);
     $this->make();
 }
예제 #2
0
파일: Search.php 프로젝트: BePsvPT/CCU
 /**
  * Course dimension filter.
  */
 protected function dimensionFilter()
 {
     if (isset($this->filter['dimension'])) {
         $dimensionId = intval($this->filter['dimension']);
         // 確認所查詢的向度存在
         $dimension = Category::getCategories('courses.dimension')->search(function ($item) use($dimensionId) {
             return $item->getAttribute('id') === $dimensionId;
         });
         if (false !== $dimension) {
             $this->model = $this->model->where('dimension_id', '=', $dimensionId);
             ++$this->filterCount;
         }
     }
 }
예제 #3
0
 /**
  * 將系所分到學院中.
  *
  * @return void
  */
 protected function classifyDepartment()
 {
     $colleges = ['文學院', '理學院', '社會科學學院', '工學院', '管理學院', '法學院', '教育學院', '其他'];
     foreach (Category::where('category', 'college')->get() as $college) {
         $index = array_search($college->getAttribute('name'), $colleges, true) + 1;
         $query = Category::where('category', 'department');
         if (8 !== $index) {
             $query = $query->where('remark', 'like', "{$index}%");
         } else {
             $query = $query->whereIn('remark', ['I001', 'V000', 'F000', 'Z121']);
         }
         $college->update(['remark' => $query->orderBy('id')->get()->implode('id', ',')]);
     }
 }
예제 #4
0
 /**
  * 取得學院的系所.
  *
  * @param string $name
  * @return \Illuminate\Http\JsonResponse
  */
 public function colleges($name = '')
 {
     $college = Category::getCategories('college', $name);
     if (is_null($college)) {
         return $this->responseNotFound();
     } elseif (empty($name)) {
         return $this->setData($college)->responseOk();
     }
     $key = 'department-' . $college->getAttribute('id');
     $departments = Cache::tags('resource')->remember($key, Category::MINUTES_PER_MONTH, function () use($college) {
         return Category::whereIn('id', explode(',', $college->getAttribute('remark')))->get();
     });
     return $this->setData($departments)->responseOk();
 }
예제 #5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = User::all();
     $professors = Category::getCategories('professor');
     $dimensions = Category::getCategories('course.dimension');
     $generalDepartmentId = Category::getCategories('department', '通識中心', true);
     // 課程
     factory(Course::class, mt_rand(30, 80))->create()->each(function (Course $course) use($users, $professors, $dimensions, $generalDepartmentId) {
         // 通識課程
         if ($course->getAttribute('department_id') === $generalDepartmentId) {
             $course->dimension()->save($dimensions->random());
         }
         // 課程教授
         //$course->professors()->saveMany($professors->random(mt_rand(2, 3)));
     });
 }
예제 #6
0
 public function search(Request $request)
 {
     $key = 'search-' . sha1(implode('|', $request->only(['college', 'department_id', 'keyword'])));
     $courses = Cache::tags('course')->remember($key, Course::MINUTES_PER_MONTH, function () use($request) {
         $query = Course::with(['dimension', 'professors'])->groupBy('code')->orderBy('department_id')->orderBy('code');
         if ($request->has('department_id')) {
             $query = $query->where('department_id', $request->input('department_id'));
         } elseif ($request->has('college')) {
             $query = $query->whereIn('department_id', explode(',', Category::getCategories('college', $request->input('college'))->getAttribute('remark')));
         }
         if ($request->has('keyword')) {
             $query = $query->where(function (Builder $query) use($request) {
                 $query->where('code', 'like', '%' . $request->input('keyword') . '%')->orWhere('name', 'like', '%' . $request->input('keyword') . '%');
             });
         }
         return $query->get();
     });
     return $this->setData($courses)->responseOk();
 }
예제 #7
0
 public function semesters()
 {
     return response()->json(Category::getCategories('courses.semester'));
 }
예제 #8
0
파일: Verify.php 프로젝트: BePsvPT/CCU
 /**
  * Get token expires hours.
  *
  * @param $categoryId
  * @return bool|int
  */
 public static function getExpireHours($categoryId)
 {
     $categories = Category::getCategories();
     $category = $categories->search(function ($item) use($categoryId) {
         return $item->getAttribute('id') === $categoryId;
     });
     return false !== $category ? json_decode($categories[$category]->getAttribute('name'))->{'expireHours'} : false;
 }
예제 #9
0
 /**
  * 取得教授 collection.
  *
  * @param string $professors
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function professors($professors)
 {
     $professors = explode(' ', $professors);
     $result = Category::where('category', 'professor')->whereIn('name', $professors)->get();
     // 將尚未有資料的教授新增到資料庫中
     foreach (array_diff($professors, $result->pluck('name')->toArray()) as $name) {
         $result->push(Category::create(['category' => 'professor', 'name' => $name])->fresh());
     }
     return $result;
 }
예제 #10
0
파일: Account.php 프로젝트: BePsvPT/CCU
 /**
  * Get the account events for the account.
  *
  * @return \Illuminate\Database\Eloquent\Relations\HasMany
  */
 public function events()
 {
     return $this->hasMany(\App\Ccu\General\Event::class)->where('category_id', '=', Category::getCategories('events.account', true));
 }
예제 #11
0
 /**
  * Save courses data to database.
  *
  * @param array $data
  * @return bool
  */
 protected function savingData($data)
 {
     foreach ($data as $datum) {
         $department_id = array_search($datum['department'], $this->correspondenceTable) + 22;
         // prefix 22
         DB::beginTransaction();
         try {
             foreach ($datum['courses'] as $course) {
                 if (Course::where('code', '=', $course['code'])->where('professor', '=', $course['professor'])->exists()) {
                     continue;
                 } else {
                     if (null !== $course['dimension']) {
                         $course['dimension'] = Category::where('category', '=', 'courses.dimension')->where('name', '=', $course['dimension'])->first()->getAttribute('id');
                     }
                 }
                 Course::create(['code' => $course['code'], 'department_id' => $department_id, 'dimension_id' => $course['dimension'], 'name' => $course['name'], 'name_en' => $course['name_en'], 'professor' => $course['professor']]);
                 ++$this->count;
             }
         } catch (Exception $e) {
             DB::rollBack();
             $this->error($e->getMessage());
             return false;
         }
         DB::commit();
     }
     return true;
 }
예제 #12
0
파일: Event.php 프로젝트: BePsvPT/CCU
 /**
  * @param string $categoryName
  * @param \App\Ccu\Member\Account $account
  * @param string $action
  * @param mixed|null $detail
  * @return Event
  */
 public static function _create($categoryName, $account, $action, $detail = null)
 {
     return static::create(['category_id' => Category::getCategories($categoryName, true), 'account_id' => $account->getAttribute('id'), 'action' => $action, 'detail' => $detail]);
 }
예제 #13
0
 /**
  * @test
  */
 public function it_should_return_specific_category_id_if_all_params_are_present()
 {
     $this->assertSame($this->categories[0]->getAttribute('id'), Category::getCategories('test-case', 'case1', true));
     $this->assertSame($this->categories[1]->getAttribute('id'), Category::getCategories('test-case', 'case2', true));
     $this->assertSame($this->categories[2]->getAttribute('id'), Category::getCategories('test-case', 'case3', true));
 }
예제 #14
0
function categoryRandomElement($category)
{
    return Category::getCategories($category)->random()->getAttribute('id');
}