public function run() { $faker = Faker\Factory::create(); for ($i = 0; $i < 70; $i++) { $user = User::where('roles', 'applicant')->get()->shuffle()->first(); $board = null; while (null == $board) { $day_type = array('internal' => self::INTERNAL_DAYS, 'external' => self::EXTERNAL_DAYS, 'union' => self::UNION_DAYS); $type = $faker->randomElement(['internal', 'external', 'union']); $days = $day_type[$type] - 1; $from = date_format($faker->dateTimeBetween('-3 months', '+3 months'), 'Y-m-d'); $end = date('Y-m-d', strtotime("{$from} + {$days} days")); $board = Board::where('type', '!=', 'large')->isEmpty($from, $end)->get()->shuffle()->first(); } ApplyRecord::create(array('board_id' => $board->id, 'user_id' => $user->id, 'event_name' => $faker->company(), 'event_type' => $type, 'post_from' => $from, 'post_end' => $end)); } for ($i = 0; $i < 30; $i++) { $user = User::where('roles', 'applicant')->get()->shuffle()->first(); $board = null; while (null == $board) { $type = $faker->randomElement(['internal', 'external', 'union']); $days = self::LARGE_POSTER_DAYS - 1; $from = date_format($faker->dateTimeBetween('-3 months', '+3 months'), 'Y-m-d'); $end = date('Y-m-d', strtotime("{$from} + {$days} days")); $board = Board::where('type', 'large')->isEmpty($from, $end)->get()->shuffle()->first(); } ApplyRecord::create(array('board_id' => $board->id, 'user_id' => $user->id, 'event_name' => $faker->company(), 'event_type' => $type, 'post_from' => $from, 'post_end' => $end)); } }
public function scopeIsEmpty($query, $from = '', $end = '') { if (empty($from) or empty($end)) { $from = $end = date("Y-m-d"); } $records = ApplyRecord::date($from, $end); $using_boards = array_unique($records->lists('board_id')); return $query->whereNotIn('id', $using_boards); }
public function saveMyrsc($nCoolType) { $record = new ApplyRecord(); $apply = new Apply(); $apply->setRecord(); $result = $record->saveRecord($nCoolType, $apply); if (!$result) { Log::write('RecordTask::saveApply():saveRecord() failed', 'log'); // return false; } $record->close(); $queue = new QueueTask(); $queue->push('apply', $nCoolType, json_encode($apply), 'coolshow_apply_count'); return true; }
Route::filter('perm_boards_manage', function () { if (!Auth::user()->can('boards_management')) { return Response::json(['success' => false, 'messages' => 'Permission Deny']); } }); Route::filter('perm_user_manage', function () { if (!Auth::user()->can('users_management')) { return Response::json(['success' => false, 'messages' => 'Permission Deny']); } }); Route::filter('perm_apply', function () { if (!Auth::user()->ability([], ['apply_records_management', 'apply_post'])) { return Response::json(['success' => false, 'messages' => 'Permission Deny']); } }); Route::filter('perm_apply_owner', function () { $record_id = Request::segment(3); $record = ApplyRecord::find($record_id); $user_id = $record->user_id; if (!Auth::user()->can('apply_records_management')) { if ($user_id !== Auth::id()) { return Response::json(['success' => false, 'messages' => 'Permission Deny']); } } }); Route::filter('input_date', function () { $validator = Validator::make(Input::all(), ['from' => 'date_format:Y-m-d', 'end' => 'date_format:Y-m-d']); if ($validator->fails()) { return Response::json(['success' => false, 'messages' => $validator->errors()]); } });
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { ApplyRecord::destroy($id); return Response::json(['success' => true]); }