Exemplo n.º 1
0
 function listAllData($page = 1)
 {
     $toReturn = array();
     $inventory = inventory::orderBy('id', 'DESC')->take('20')->skip(20 * ($page - 1))->get()->toArray();
     $toReturn['totalItems'] = inventory::orderBy('id', 'DESC')->count();
     $teachers = User::where('role', 'teacher')->where('activated', '1')->get()->toArray();
     $teacherArray = array();
     while (list(, $value) = each($teachers)) {
         $teacherArray[$value['id']] = $value['fullName'];
     }
     $toReturn['inventory'] = array();
     while (list(, $inventorry) = each($inventory)) {
         $toReturn['inventory'][] = array('id' => $inventorry['id'], "name" => $inventorry['name'], "inventorydate" => $inventorry['inventorydate'], "qty" => $inventorry['qty'], "total" => $inventorry['qty'], "status" => $inventorry['status'], "teachername" => isset($teacherArray[$inventorry['teacherId']]) ? $teacherArray[$inventorry['teacherId']] : "");
     }
     $toReturn['userRole'] = $this->data['users']->role;
     $newrole = $this->data['users']->newrole;
     $newrole_array = json_decode($newrole);
     /*$params= permissions::where('moduleId',1)->where('permission',1)->get();
     			foreach ($params as $param) {
     		$uniparam[]=$param->roleId;
     }*/
     $uniparam = array(9, 15);
     if ($toReturn['userRole'] == "teacher") {
         if (array_intersect($newrole_array, $uniparam)) {
             $toReturn['access'] = 1;
         } else {
             $toReturn['access'] = 0;
         }
     } elseif ($toReturn['userRole'] == "admin") {
         $toReturn['access'] = 1;
     } else {
         $toReturn['access'] = 0;
     }
     $toReturn['newuserRole'] = $this->data['users']->newrole;
     return $toReturn;
 }