0.1.5
This commit is contained in:
70
public/rescan.php
Normal file
70
public/rescan.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
define("DIR","./data/class/");
|
||||
define("REG",'/([0-9A-z_, ]*).(?:jpg|svg|png|jpeg)/m');
|
||||
|
||||
class Scanner{
|
||||
private $rc = array('classes'=>[]);
|
||||
private $classes = null;
|
||||
private $rcwu = array('classes'=>[]);
|
||||
function __construct(){
|
||||
$this->classes = scandir(DIR);
|
||||
|
||||
foreach ($this->classes as $key => $value) {
|
||||
switch($value){
|
||||
case '.':
|
||||
case '..':
|
||||
case 'classes.json':
|
||||
case 'student.svg':
|
||||
break;
|
||||
default:
|
||||
$this->scanClass($value);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeFiles();
|
||||
}
|
||||
|
||||
|
||||
function scanClass($d){
|
||||
$sd = DIR.$d;
|
||||
$users_of_class = scandir($sd);
|
||||
$this->rc['classes'][]=$d;
|
||||
|
||||
$ruoc = [];
|
||||
foreach ($users_of_class as $i => $user) {
|
||||
if(preg_match_all(REG, $user, $matches, PREG_SET_ORDER, 0)){
|
||||
// delete the last 4 chars
|
||||
$ruoc[] = array(substr($user, 0, -4),substr($user,strlen($user)-3));
|
||||
}
|
||||
}
|
||||
$this->rcwu['classes'][$d]=$ruoc;
|
||||
}
|
||||
|
||||
|
||||
function writeFiles(){
|
||||
/**
|
||||
* WRITE classes.json FILE
|
||||
*/
|
||||
$fp = fopen(DIR.'classes.json', 'w');
|
||||
fwrite($fp, json_encode($this->rc));
|
||||
fclose($fp);
|
||||
/**
|
||||
* WRITE FOR EACH CLASS
|
||||
*/
|
||||
foreach ($this->rcwu['classes'] as $key => $value) {
|
||||
$fp = fopen(DIR.$key.'/user.json', 'w');
|
||||
fwrite($fp, json_encode(array('user'=>$this->rcwu['classes'][$key])));
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$s = new Scanner();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user