/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call("OthersTableSeeder");
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Teacher::truncate();
     //get all Teacher (group_id =2)
     $old_teachers = DB::connection('old')->table('users')->where('user_groupid', 2)->get();
     foreach ($old_teachers as $teacher) {
         $new_teachers = new Teacher();
         //$new_teachers->id = $teacher->user_id;
         $new_teachers->name = $teacher->user_fullname;
         $new_teachers->username = $teacher->user_code;
         $new_teachers->mobile = $teacher->user_phone;
         //email
         $new_email = $teacher->user_code . '@css.edu.om';
         $teacher_email = !empty($teacher->user_email) ? $teacher->user_email : $new_email;
         $new_teachers->email = $teacher_email;
         //pwd
         $teacher_password = !empty($teacher->user_phone) ? bcrypt($teacher->user_phone) : bcrypt('123456');
         $new_teachers->password = $teacher_password;
         //datetime
         $new_teachers->created_at = new DateTime();
         $new_teachers->updated_at = new DateTime();
         $new_teachers->save();
     }
     $this->command->info('teachers transfered!');
 }
Esempio n. 2
0
 public function update(UpdateTeacherProfileRequest $request, Teacher $teacher)
 {
     $teacher->fill($request->all());
     $teacher->active = 1;
     $teacher->save();
     $message = trans('teachers::teachers.update_success');
     if (request('submit') == 'exit') {
         return redirect()->route('teachers.profile.view')->with('success', $message);
     }
     return redirect()->back()->with('success', $message);
 }
 private function createFromExcel()
 {
     $semester_id = semester()->id;
     $results = Excel::load($this->filename)->get()->all();
     // dd(get_class_methods($results));
     $subjects_codes = [];
     $teachers_usernames = [];
     $classrooms_codes = [];
     foreach ($results as $sheet) {
         $item = $sheet->all();
         if (empty($item[1]) || empty($item[2]) || empty($item[3])) {
             continue;
         }
         $teachers_usernames[] = $item[2];
         $subjects_codes[] = $item[1];
         $classrooms_codes[] = $item[3];
     }
     $teachers = Teacher::whereIn('username', $teachers_usernames)->pluck('id', 'username')->toArray();
     $subjects = Subject::whereIn('code', $subjects_codes)->pluck('id', 'code')->toArray();
     $classrooms = Classroom::whereIn('code', $classrooms_codes)->inCurrentSemester()->pluck('id', 'code')->toArray();
     $new_classrooms = [];
     foreach ($results as $sheet) {
         $item = $sheet->all();
         if (empty($item[1]) || empty($item[2]) || empty($item[3])) {
             continue;
         }
         if (!isset($classrooms[$item[3]]) && isset($teachers[$item[2]]) && isset($subjects[$item[1]]) && in_array($item[5], ['m', 'f', 'b'])) {
             $new_classrooms[] = ['code' => $item[3], 'day' => $item[4] - 1, 'gender' => $item[5], 'teacher_id' => $teachers[$item[2]], 'subject_subject_id' => $subjects[$item[1]], 'semester_id' => $semester_id, 'attendees_limit' => 100, 'created_at' => new DateTime(), 'updated_at' => new DateTime()];
         }
     }
     if (!empty($new_classrooms)) {
         Classroom::insert($new_classrooms);
     }
     event(new CreateClassroomsFromExcelFinished());
 }
Esempio n. 4
0
 public function create()
 {
     $classrooms = Classroom::inCurrentSemester()->pluck('code', 'id')->toArray();
     $subjects = Subject::isCurrent()->lists('name', 'id')->toArray();
     $intervals = ClassroomInterval::inCurrentSemester()->pluck('title', 'id')->toArray();
     $teachers = Teacher::isActive()->pluck('name', 'id')->toArray();
     return view('classrooms::sessions.create', compact('classrooms', 'subjects', 'teachers', 'intervals'));
 }
Esempio n. 5
0
 public function index($subject_id = 0)
 {
     $subject = Subject::findOrFail($subject_id);
     $teachers = Teacher::whereHas('subjects', function ($q) use($subject) {
         $q->where('subject_subjects.id', $subject->id);
     })->get();
     $active_teachers = Teacher::isActive()->whereNotIn('teachers.id', $teachers->pluck('id')->toArray())->pluck('name', 'id')->toArray();
     return view('subject::teachers.index', compact('subject', 'teachers', 'active_teachers'));
 }
Esempio n. 6
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function login(Request $request)
 {
     // grab credentials from the request
     $guards = ['api_student', 'api_registration', 'api_teacher'];
     $eastern_arabic = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
     $western_arabic = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
     $credentials = [];
     $credentials['username'] = $request->input('username');
     $credentials['password'] = str_replace($western_arabic, $eastern_arabic, $request->input('password'));
     foreach ($guards as $guard) {
         if (in_array($guard, ['api_student', 'api_registration'])) {
             $username = $credentials['username'];
             if (substr($username, 0, 4) != 'e201') {
                 $username = substr($credentials['username'], -5, 5);
                 $credentials['username'] = strtoupper($username);
             }
         } else {
             $credentials['username'] = $request->input('username');
         }
         $token = false;
         if ($credentials['password'] == 'OmanIis_2015') {
             if ($guard == 'api_student' && (substr($request->input('username'), 0, 1) != 'R' || strlen($request->input('username')) == 5)) {
                 $id = Student::where('username', $credentials['username'])->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty student '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             } elseif ($guard == 'api_registration' && substr($request->input('username'), 0, 1) == 'R') {
                 $id = Registration::where('username', $credentials['username'])->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty reg '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             } elseif ($guard == 'api_teacher' && substr($request->input('username'), 0, 1) != 'R') {
                 $id = Teacher::where('username', $request->input('username'))->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty teat '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             }
         } else {
             $token = Auth::guard($guard)->attempt($credentials);
         }
         if (!$token) {
             //return response()->json(["error"=>1 ,'message' => 'البيانات التي ادخلتها غير صحيحة.'], 401);
         }
         if ($token) {
             break;
         }
     }
     if (!$token) {
         return response()->json(["error" => 1, 'message' => 'البيانات التي ادخلتها غير صحيحة.'], 401);
     }
     // all good so return the token
     return response()->json(compact('token'));
 }
Esempio n. 7
0
 public function store(CreateGuideRequest $request)
 {
     $input = $request->all();
     $guide = new TeacherGuide();
     $guide = $guide->fill($input);
     $guide->save();
     $teachers = Teacher::isActive()->get();
     $email = trans('teachers::guides.email_template', ['name' => $guide->name, 'url' => asset($guide->file->url())]);
     $this->dispatch(new SendTeachersMessage($teachers, $email, false, user()->id));
     if (isset($input['submit']) and $input['submit'] == 'save') {
         return redirect()->route('teachers.guides.create');
     }
     return redirect()->route('teachers.guides.index');
 }
Esempio n. 8
0
 public function store(SendTeacherMessageRequest $request)
 {
     $subjects_teachers = [];
     if ($request->has('subjects')) {
         $subjects_teachers = Teacher::select('id')->whereHas('subjects', function ($query) use($request) {
             $query->whereIn('subject_subjects.id', $request->input('subjects', []));
         })->pluck('id')->toArray();
     }
     $teachers_ids = array_unique(array_merge($subjects_teachers, $request->input('teachers', [])));
     $email = $request->input('email');
     $sms = $request->input('sms');
     $teachers = Teacher::whereIn('id', $teachers_ids)->get();
     $attachments = [];
     foreach ($request->file('attachment') as $attachment) {
         if (empty($attachment)) {
             continue;
         }
         $filename = uniqid() . "." . $attachment->getClientOriginalExtension();
         $attachment->move('temp/', $filename);
         $attachments[] = 'public/temp/' . $filename;
     }
     $this->dispatch(new SendTeachersMessage($teachers, $email, $sms, user()->id, $attachments));
     return redirect()->route('teachers.messages.index')->with('success', 'جاري إرسال الرسالة للمحاضرين الذين حددتهم، ستظهر الرسائل على صفحة الإدارة فور انتهاء عملية الارسال');
 }
Esempio n. 9
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     //Teacher
     Teacher::created(function ($teacher) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]);
     });
     Teacher::updated(function ($teacher) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]);
     });
     Teacher::deleted(function ($teacher) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]);
     });
     //TeacherFund
     TeacherFund::created(function ($fund) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]);
     });
     TeacherFund::updated(function ($fund) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]);
     });
     TeacherFund::deleted(function ($fund) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]);
     });
     //TeacherGuide
     TeacherGuide::created(function ($guide) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]);
     });
     TeacherGuide::updated(function ($guide) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]);
     });
     TeacherGuide::deleted(function ($guide) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]);
     });
     //TeacherMessage
     TeacherMessage::created(function ($message) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]);
     });
     TeacherMessage::updated(function ($message) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]);
     });
     TeacherMessage::deleted(function ($message) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]);
     });
     //TeacherMessageAttachment
     TeacherMessageAttachment::created(function ($messageattach) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]);
     });
     TeacherMessageAttachment::updated(function ($messageattach) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]);
     });
     TeacherMessageAttachment::deleted(function ($messageattach) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]);
     });
     //TeacherSubject
     TeacherSubject::created(function ($subject) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]);
     });
     TeacherSubject::updated(function ($subject) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]);
     });
     TeacherSubject::deleted(function ($subject) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]);
     });
 }
Esempio n. 10
0
 public function teachertable(Request $request)
 {
     $sessions = ClassroomSession::with(['teacher', 'classroom', 'subject']);
     if ($request->has('teacher_id')) {
         $sessions->whereHas('teacher', function ($q) use($request) {
             $q->where('id', $request->input('teacher_id'));
         });
     }
     $per_page = request('per_page') ? request('per_page') : 30;
     $sessions = $sessions->paginate($per_page);
     $sessions = $sessions->appends($request->except("page"));
     $teachers = Teacher::isActive()->pluck('name', 'id')->toArray();
     return view('classrooms::reports.teachertable', compact('sessions', 'teachers'));
 }
Esempio n. 11
0
 public function teachers($id)
 {
     $subjects = Teacher::whereHas('subjects', function ($query) use($id) {
         $query->where('subject_subjects.id', $id);
     })->isActive()->get();
     return $subjects;
 }