Load config from cache on user interface + <table> display
This commit is contained in:
parent
5b0666e89b
commit
6b7baa8729
|
@ -30,7 +30,7 @@
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Get config */
|
/* (1) Get config */
|
||||||
try{
|
try{
|
||||||
$config = Config::load("http://sciences.univ-pau.fr/edt/_ressource.js", "http://sciences.univ-pau.fr/edt/_periode.js");
|
$config = Config::loadCached();
|
||||||
|
|
||||||
/* (2) Error management */
|
/* (2) Error management */
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
|
@ -44,17 +44,22 @@
|
||||||
|
|
||||||
/* [2] Display the links
|
/* [2] Display the links
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
|
echo "<table><thead><tr><td>Diplome</td><td>Link</td></tr></thead><tbody>";
|
||||||
|
|
||||||
foreach($diplomes as $id=>$name){
|
foreach($diplomes as $id=>$name){
|
||||||
|
|
||||||
|
|
||||||
echo "<span>$name</span>";
|
echo "<tr><td>$name</td>";
|
||||||
|
|
||||||
$link = $_SERVER['HTTP_HOST']."/ics/$id.ics";
|
$link = $_SERVER['HTTP_HOST']."/ics/$id.ics";
|
||||||
if( file_exists(__ROOT__."/tmp/$id.ics") )
|
if( file_exists(__ROOT__."/tmp/$id.ics") )
|
||||||
echo " -> <a href='/ics/$id.ics'>https://$link</a><br>";
|
echo "<td><a href='/ics/$id.ics'>https://$link</a></td>";
|
||||||
|
|
||||||
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo "</tbody></table>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* POST-CALL
|
/* POST-CALL
|
||||||
|
|
|
@ -171,7 +171,60 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [4] Return the instance
|
/* [4] Return the instance + cache
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) Cache */
|
||||||
|
file_put_contents(__ROOT__."/tmp/diplomes.cache", json_encode($d_list));
|
||||||
|
file_put_contents(__ROOT__."/tmp/periods.cache", json_encode($p_list));
|
||||||
|
|
||||||
|
/* (2) Return the instance */
|
||||||
|
return new Config($d_list, $p_list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Loads the configuration from URL
|
||||||
|
*
|
||||||
|
* @return instance<Config> The created instance
|
||||||
|
* NULL on error
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
public static function loadCached(){
|
||||||
|
|
||||||
|
/* [1] Load cache
|
||||||
|
=========================================================*/ {
|
||||||
|
|
||||||
|
/* (1) Check files */
|
||||||
|
if( !file_exists(__ROOT__."/tmp/diplomes.cache") )
|
||||||
|
throw new \Exception("Diplomes cache is missing");
|
||||||
|
|
||||||
|
if( !file_exists(__ROOT__."/tmp/periods.cache") )
|
||||||
|
throw new \Exception("Periods cache is missing");
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Read files */
|
||||||
|
if( !($d_list=@file_get_contents(__ROOT__."/tmp/diplomes.cache")) )
|
||||||
|
throw new \Exception("Diplomes cache is not readable");
|
||||||
|
|
||||||
|
if( !($p_list=@file_get_contents(__ROOT__."/tmp/periods.cache")) )
|
||||||
|
throw new \Exception("Periods cache is not readable");
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Parse files */
|
||||||
|
if( is_null(( $d_list = json_decode($d_list, true) )) )
|
||||||
|
throw new \Exception("Cannot parse diplome list");
|
||||||
|
|
||||||
|
if( is_null(( $p_list = json_decode($p_list, true) )) )
|
||||||
|
throw new \Exception("Cannot parse periods list");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] Return the instance
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
return new Config($d_list, $p_list);
|
return new Config($d_list, $p_list);
|
||||||
|
|
||||||
|
@ -180,7 +233,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (3) Getter diplomes
|
/* (4) Getter diplomes
|
||||||
*
|
*
|
||||||
* @return diplomes<Array> Diplome list
|
* @return diplomes<Array> Diplome list
|
||||||
*
|
*
|
||||||
|
@ -192,7 +245,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (4) Getter periods
|
/* (5) Getter periods
|
||||||
*
|
*
|
||||||
* @return periods<Array> Period list
|
* @return periods<Array> Period list
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue