Section.class.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. @nom: Section
  4. @auteur: Idleman (idleman@idleman.fr)
  5. @description: Classe de gestion des sections
  6. */
  7. class Section extends SQLiteEntity{
  8. protected $id,$label,$description;
  9. protected $TABLE_NAME = 'section';
  10. protected $CLASS_NAME = 'Section';
  11. protected $object_fields =
  12. array(
  13. 'id'=>'key',
  14. 'label'=>'string',
  15. 'description'=>'longstring'
  16. );
  17. public static function add($name,$description="",$grantAdmin = true){
  18. $sectionManager = new Section();
  19. if($sectionManager->rowCount(array('label'=>$name))==0){
  20. $sectionManager->setLabel($name);
  21. $sectionManager->setDescription($description);
  22. $sectionManager->save();
  23. if($grantAdmin){
  24. $right = new Right();
  25. $right = $right->load(array('section'=>$sectionManager->getLabel(),'rank'=>1));
  26. $right = (!$right?new Right():$right);
  27. $right->setSection($sectionManager->getId());
  28. $right->setCreate(1);
  29. $right->setRead(1);
  30. $right->setUpdate(1);
  31. $right->setDelete(1);
  32. $right->setRank(1);
  33. $right->save();
  34. }
  35. }
  36. }
  37. public static function remove($name){
  38. $sectionManager = new Section();
  39. $sectionManager->load(array('label'=>$name));
  40. $rightManager = new Right();
  41. $rightManager->delete(array('section'=>$sectionManager->getId()));
  42. $sectionManager->delete(array('id'=>$sectionManager->getId()));
  43. }
  44. function __construct(){
  45. parent::__construct();
  46. }
  47. function setId($id){
  48. $this->id = $id;
  49. }
  50. function getId(){
  51. return $this->id;
  52. }
  53. function getLabel(){
  54. return $this->label;
  55. }
  56. function setLabel($label){
  57. $this->label = $label;
  58. }
  59. function getDescription(){
  60. return $this->description;
  61. }
  62. function setDescription($description){
  63. $this->description = $description;
  64. }
  65. }
  66. ?>