/**
  * This method controls what happens when you move to /dashboard/index in your app.
  */
 public function index($pageToShow = 0)
 {
     $page = false;
     if (isset($_POST['suggestion'])) {
         $suggestion = $_POST['suggestion'];
     } else {
         $suggestion = '';
     }
     if (isset($pageToShow)) {
         $page = $pageToShow;
     }
     if (isset($_POST['itemsToShow'])) {
         $itemsToShow = $_POST['itemsToShow'];
     } else {
         $itemsToShow = 3;
     }
     if (isset($_POST['orderBy'])) {
         $orderBy = $_POST['orderBy'];
     } else {
         $orderBy = 'material_id';
     }
     if (!$page) {
         $start = 0;
         $page = 1;
     } else {
         $start = ($page - 1) * $itemsToShow;
     }
     $numTotalRegister = MaterialModel::getNumRowAllMaterialsSuggested($suggestion);
     $totalPages = ceil($numTotalRegister / $itemsToShow);
     $this->View->render('dashboard/index', array('totalPages' => $totalPages, 'page' => $page, 'suggestion' => $suggestion, 'itemsToShow' => $itemsToShow, 'orderBy' => $orderBy, 'oeuvres' => OeuvreModel::getAllOeuvreByEmployee(Session::get('user_id')), 'oeuvres_materials' => DashboardModel::getAllOeuvreMaterials(), 'oeuvres_photos' => DashboardModel::getAllOeuvrePhotos(), 'materials' => MaterialModel::getMaterialsSuggestedPaginatedOrderBy($suggestion, $start, $itemsToShow, $orderBy)));
 }
 public static function getAllOeuvreMaterials()
 {
     $database = DatabaseFactory::getFactory()->getConnection();
     $sql = "SELECT o.oeuvre_id, o.oeuvre_name, m.material_id, material_name, material_price, material_weight, material_dimension_high, material_dimension_width,\n                       material_dimension_profound, material_provider_id, material_has_photoMaterial, material_description, quantity\n                FROM oeuvres_materials AS om, materials AS m, oeuvres AS o WHERE m.material_id = om.material_id AND o.oeuvre_id = om.oeuvre_id ";
     $query = $database->prepare($sql);
     $query->execute();
     $all_materials = array();
     foreach ($query->fetchAll() as $material) {
         // all elements of array passed to Filter::XSSFilter for XSS sanitation, have a look into
         // application/core/Filter.php for more info on how to use. Removes (possibly bad) JavaScript etc from
         // the material's values
         array_walk_recursive($material, 'Filter::XSSFilter');
         $all_materials[$material->material_id] = new stdClass();
         $all_materials[$material->material_id]->oeuvre_id = $material->oeuvre_id;
         $all_materials[$material->material_id]->oeuvre_name = $material->oeuvre_name;
         $all_materials[$material->material_id]->material_id = $material->material_id;
         $all_materials[$material->material_id]->material_name = $material->material_name;
         $all_materials[$material->material_id]->material_price = $material->material_price;
         $all_materials[$material->material_id]->material_weight = $material->material_weight;
         $all_materials[$material->material_id]->material_dimension_high = $material->material_dimension_high;
         $all_materials[$material->material_id]->material_dimension_width = $material->material_dimension_width;
         $all_materials[$material->material_id]->material_dimension_profound = $material->material_dimension_profound;
         $all_materials[$material->material_id]->material_provider_id = $material->material_provider_id;
         $all_materials[$material->material_id]->material_photoMaterial_link = Config::get('USE_GRAVATAR') ? AvatarModel::getGravatarLinkByEmail($user->user_email) : MaterialModel::getPublicPhotoMaterialFilePathOfMaterial($material->material_has_photoMaterial, $material->material_id);
         $all_materials[$material->material_id]->material_description = $material->material_description;
         $all_materials[$material->material_id]->quantity = $material->quantity;
     }
     return $all_materials;
 }
 public function deletePhotoMaterial_action($material_id)
 {
     // All methods inside this controller are only accessible for admins (= users that have role type 7)
     Auth::checkAdminAuthentication();
     MaterialModel::deletePhotoMaterial($material_id);
     Redirect::to('material/index/0');
 }
 public function dadosexaminationmaterialAction()
 {
     $this->_helper->layout->disableLayout();
     $page = $this->_request->getParam("page", 1);
     $limit = $this->_request->getParam("rows");
     //        $sidx = $this->_request->getParam("sidx", 1);
     //        $sord = $this->_request->getParam("sord");
     $cdexamination = $this->_request->getParam("cdexamination");
     $materialModel = new MaterialModel();
     $examinationmaterialData = $materialModel->fetchAll($materialModel->getMaterialByExamination($cdexamination));
     $count = count($examinationmaterialData);
     if ($count > 0 && $limit != 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     //  $examinationData = $examinationModel->fetchAll(null, "$sidx $sord", $limit, ($page*$limit-$limit));
     $responce = new stdClass();
     $responce->page = $page;
     $responce->total = $total_pages;
     $responce->records = $count;
     $i = 0;
     foreach ($examinationmaterialData as $row) {
         $responce->rows[$i]['cdmaterial'] = $row->cdmaterial;
         $responce->rows[$i]['cell'] = array($row->cdexaminationmaterial, $row->cdmaterial, $row->nmmaterial, $row->nmdepartment);
         $i++;
     }
     $this->view->examinationmaterial = $responce;
 }