An XML file manage courses list
This commit is contained in:
parent
e86deee36e
commit
6e9554e2f2
2 changed files with 147 additions and 37 deletions
134
Course.class.php
Normal file
134
Course.class.php
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
class Course
|
||||
{
|
||||
private $id;
|
||||
private $name;
|
||||
private $code;
|
||||
private $branch;
|
||||
private $registerdate;
|
||||
private $validated = false;
|
||||
|
||||
public function __construct($node = null)
|
||||
{
|
||||
if (isset($node))
|
||||
{
|
||||
$this->id = $node->getAttribute("xml:id");
|
||||
$this->registerdate = $node->getAttribute("registerdate");
|
||||
if (intval($node->getAttribute("validated")))
|
||||
$this->validated = true;
|
||||
$this->name = $node->getAttribute("name");
|
||||
$this->code = $node->getAttribute("code");
|
||||
$this->branch = $node->getAttribute("branch");
|
||||
}
|
||||
}
|
||||
|
||||
public static function new_Course($name, $code, $branch = "")
|
||||
{
|
||||
$c = new Course();
|
||||
$c->id = sha1($code);
|
||||
$c->registerdate = time();
|
||||
$c->name = $name;
|
||||
$c->code = $code;
|
||||
$c->branch = $branch;
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
public static function getCourses($filename = "courses.xml")
|
||||
{
|
||||
$courses = array();
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
if (@$treeXML->load($filename))
|
||||
{
|
||||
$nodes = $treeXML->getElementsByTagName("course");
|
||||
foreach($nodes as $node)
|
||||
{
|
||||
$c = new Course($node);
|
||||
$courses[$c->id] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
public static function setCourses($courses, $filename = "courses.xml")
|
||||
{
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
$root_node = $treeXML->createElement("users");
|
||||
$treeXML->appendChild($root_node);
|
||||
|
||||
foreach ($courses as $course)
|
||||
$root_node->appendChild($course->to_xml($treeXML));
|
||||
|
||||
$treeXML->formatOutput = true;
|
||||
$treeXML->save($filename);
|
||||
}
|
||||
|
||||
public function to_xml($root)
|
||||
{
|
||||
$qnode = $root->createElement("course");
|
||||
|
||||
$qnode->setAttribute("xml:id", $this->id);
|
||||
$qnode->setAttribute("name", $this->name);
|
||||
$qnode->setAttribute("code", intval($this->code));
|
||||
$qnode->setAttribute("branch", $this->branch);
|
||||
$qnode->setAttribute("registerdate", $this->registerdate);
|
||||
$qnode->setAttribute("validated", $this->validated);
|
||||
|
||||
return $qnode;
|
||||
}
|
||||
|
||||
public function set_validated($validated)
|
||||
{
|
||||
$this->validated = $validated;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function isValidated()
|
||||
{
|
||||
return $this->validated;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
$cs = Course::getCourses();
|
||||
|
||||
foreach($cs as $c)
|
||||
$c->set_validated(true);
|
||||
Course::setCourses($cs);
|
||||
//*/
|
||||
/*
|
||||
$cs = Course::getCourses();
|
||||
|
||||
$c = Course::new_Course("Base de donnees", "RELA");
|
||||
$cs[] = $c;
|
||||
|
||||
$c = Course::new_Course("Compression de donnee", "CODO");
|
||||
$cs[] = $c;
|
||||
|
||||
$c = Course::new_Course("Protocole de liaisons", "PROLI");
|
||||
$cs[] = $c;
|
||||
|
||||
$c = Course::new_Course("Typologie des langages", "TYLA", "TDA;SRC");
|
||||
$cs[] = $c;
|
||||
|
||||
$c = Course::new_Course("Active directory", "ACDI");
|
||||
$cs[] = $c;
|
||||
|
||||
$c = Course::new_Course("Graphes reseaux flots", "GRF");
|
||||
$cs[] = $c;
|
||||
|
||||
Course::setCourses($cs);
|
||||
//*/
|
||||
?>
|
||||
Reference in a new issue