public static function getPlanning($year, $group, $week, $h = false) { $groupModel = new GroupsModel(); $ids = $groupModel->getIDs($year, $group); $ids = $ids[0]; $identFile = new ConfigFileParser('app/config/ident.json'); $ident = $identFile->getEntry('ident'); $fileName = 'public/img/img_planning/' . $ids['ID'] . '_' . $week . ($h ? '_h' : '') . '.png'; try { $file = new \SplFileObject($fileName, 'rw'); if ($file->getMTime() < time() - 900) { throw new \RuntimeException(); } } catch (\RuntimeException $e) { $fp = fopen($fileName, 'w+'); $url = 'http://planning.univ-amu.fr/ade/imageEt?identifier=' . $ident . '&projectId=8&idPianoWeek=' . $week . '&idPianoDay=0,1,2,3,4,5&idTree=' . $ids['IDTREE'] . '&width=1000&height=700&lunchName=REPAS&displayMode=1057855&showLoad=false&ttl=1405063872880000&displayConfId=' . ($h ? '60' : '59'); $ch = curl_init(str_replace(" ", "%20", $url)); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); curl_close($ch); } return '/' . $fileName; }
public function index() { try { $params = $this->getParams(); if (count($params) > 3 || count($params) < 3) { throw new MissingParamsException(); } $newParams = Cleaner::clean($params); if ($params != $newParams) { $this->getView()->redirect('/view/p/' . $newParams[0] . '/' . $newParams[1] . '/' . $newParams[2]); } $params = $newParams; $img = Planning::getPlanning($params[0], $params[1], $params[2]); $groupsModel = new GroupsModel(); $groups = $groupsModel->getGroups(); $years = ['week' => date('W') + 17, 'years' => []]; $i = 0; $j = 0; foreach ($groups as $group) { if ($group['ANNEE'] != $i) { $years['years'][] = ['year' => $group['ANNEE'], 'groups' => []]; ++$i; $j = 0; } else { $years['years'][$i - 1]['groups'][$j] = ['group' => $group['GROUPE']]; ++$j; } } $planningModel = new PlanningModel(); $weeks = $planningModel->getWeeks(); $viewParams = ['year' => $params[0], 'group' => $params[1], 'week' => $params[2], 'img' => $img, 'years' => $years, 'weeks' => $weeks]; $this->getView()->render('home/index', $viewParams); } catch (MissingParamsException $e) { $default = Cleaner::defaultValues(); $this->getView()->redirect('/view/p/' . $default[0] . '/' . $default[1] . '/' . $default[2]); } }