Sketch.class.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Define a sketch.
  4. * @author Idleman
  5. * @category Plugin
  6. * @license copyright
  7. */
  8. class Sketch extends Entity{
  9. public $id,$label,$state,$comment,$slug,$progress;
  10. protected $TABLE_NAME = 'hackpoint_sketch';
  11. public $fields =
  12. array(
  13. 'id' => 'key',
  14. 'label' => 'string',
  15. 'state' => 'string',
  16. 'comment' => 'longstring',
  17. 'progress' => 'int',
  18. 'slug' => 'string'
  19. );
  20. public $links = array(
  21. );
  22. public function picture(){
  23. $folder = $this->directory();
  24. if(!file_exists($folder)) mkdir($folder,0755,true);
  25. $picture = $folder.SLASH.'cover.jpg';
  26. if(!file_exists($picture)){
  27. copy(__DIR__.SLASH.'img'.SLASH.'default-sketch.jpg',$picture);
  28. }
  29. return 'action.php?action=hackpoint_download_file&file='.base64_encode('sketch'.SLASH.$this->id.SLASH.'cover.jpg');
  30. }
  31. public function directory(){
  32. return File::dir().'hackpoint'.SLASH.'sketch'.SLASH.$this->id;
  33. }
  34. public function save()
  35. {
  36. if ($this->id == 0) {
  37. $this->slug = slugify($this->label);
  38. }
  39. parent::save();
  40. }
  41. public static function removeById($id){
  42. require_once(__DIR__.SLASH.'Resource.class.php');
  43. $sketch = self::getById($id);
  44. self::deleteById($sketch->id);
  45. Resource::delete(array('sketch'=>$sketch->id));
  46. if(file_exists($sketch->directory())) delete_folder_tree($sketch->directory(),true);
  47. }
  48. }
  49. ?>