示例#1
0
 public function index()
 {
     $person = new Person();
     $report = new Report();
     $item = new Item();
     $role = session('user.role');
     $data = ['total_users' => 0, 'total_report' => 0, 'total_item' => 0];
     if ($role == 'U') {
         //get data on report and item only
     } else {
         if ($role == 'M') {
             $response = $person->getAssignedPersons(session('user.id'));
             if (!empty($response)) {
                 //get total reports or their assigned users
                 $data['total_users'] = $response['totalRecords'];
                 foreach ($response['data'] as $row) {
                     $reports = $report->getReportsByPerson($row['id']);
                     if (!empty($reports['data'])) {
                         $data['total_report'] += $reports['totalRecords'];
                         //get item of the report
                         foreach ($reports['data'] as $srow) {
                             $items = $item->getItemsByReport($srow['id']);
                             $data['total_item'] += $items['totalRecords'];
                         }
                     }
                 }
                 //get current user's report
                 $response = $report->getReportsByPerson(session('user.id'));
                 if (!empty($response['data'])) {
                     $data['total_report'] += $response['totalRecords'];
                     //get item of the report
                     foreach ($response['data'] as $row) {
                         $items = $item->getItemsByReport($row['id']);
                         $data['total_item'] += $items['totalRecords'];
                     }
                 }
             }
         } else {
             //admin
             $response = $person->all([]);
             if (!empty($response)) {
                 //get total reports or their assigned users
                 $data['total_users'] = $response['totalRecords'];
                 foreach ($response['data'] as $row) {
                     $reports = $report->getReportsByPerson($row['id']);
                     if (isset($reports['data']) && !empty($reports['data'])) {
                         $data['total_report'] += $reports['totalRecords'];
                         //get item of the report
                         foreach ($reports['data'] as $srow) {
                             $items = $item->getItemsByReport($srow['id']);
                             $data['total_item'] += $items['totalRecords'];
                         }
                     }
                 }
             }
         }
     }
     return view('dashboard', $data);
 }
示例#2
0
 public function show($id, Request $request)
 {
     $id = (int) my_decode($id);
     $data['user'] = $this->person->respondWithItem($this->person->get('person_' . $id), new UserTransformer());
     //get invidvidual reports
     $response = $this->report->individual($id);
     $data['totalIReport'] = 0;
     $data['individual'] = [];
     $item = new Item();
     if (!isset($response['error'])) {
         $data['individual'] = $this->report->respondWithCollection($response['data'], new ReportTransformer());
         foreach ($data['individual'] as $i => $row) {
             $items = $item->getItemsByReport((int) my_decode($row['id']));
             $data['individual'][$i]['items'] = $items['totalRecords'];
         }
         $data['totalIReport'] = $response['totalRecords'];
     }
     $response = $this->report->group($id);
     $data['totalGReport'] = 0;
     $data['group'] = [];
     if (!isset($response['error'])) {
         $data['group'] = $this->report->respondWithCollection($response['data'], new ReportTransformer());
         foreach ($data['group'] as $i => $row) {
             $items = $item->getItemsByReport((int) my_decode($row['id']));
             $data['group'][$i]['items'] = $items['totalRecords'];
         }
         $data['totalGReport'] = $response['totalRecords'];
     }
     return view('users_profile', $data);
 }