Firm.class.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Define a sub firm.
  4. * @author valentin carruesco
  5. * @category Core
  6. * @license copyright
  7. */
  8. class Firm extends Entity{
  9. public $id,$label,$description,$mail,$phone,$fax,$street,$street2,$city,$zipcode,$siret,$iban;
  10. protected $fields =
  11. array(
  12. 'id' => 'key',
  13. 'label' => 'string',
  14. 'description' => 'longstring',
  15. 'mail' => 'string',
  16. 'phone' => 'string',
  17. 'fax' => 'string',
  18. 'street' => 'longstring',
  19. 'street2' => 'longstring',
  20. 'city' => 'string',
  21. 'zipcode' => 'string',
  22. 'siret' => 'string',
  23. 'iban' => 'string'
  24. );
  25. public static function logo_path(){
  26. return 'firm'.SLASH;
  27. }
  28. public function address(){
  29. return $this->street.' '.$this->street2.' '.$this->zipcode.' '.$this->city;
  30. }
  31. public function __sleep(){
  32. return array_merge(array_keys($this->toArray()));
  33. }
  34. public function logo($key=null){
  35. $finded = false;
  36. $image = array();
  37. $paths = array(
  38. 'jpg' => FILE_PATH.self::logo_path().$this->id.'.jpg',
  39. 'jpeg' => FILE_PATH.self::logo_path().$this->id.'.jpeg',
  40. 'png' => FILE_PATH.self::logo_path().$this->id.'.png',
  41. );
  42. $image['url'] = $image['path'] = 'img'.SLASH.'default-image.png';
  43. foreach ($paths as $extension => $path) {
  44. if (file_exists( __ROOT__.$path) && !$finded) {
  45. $image['path'] = __ROOT__.$path;
  46. $image['url'] = 'action.php?action=firm_logo_download&firm='.$this->id.'&extension='.$extension;
  47. $finded = true;
  48. }
  49. }
  50. return isset($key) && isset($image[$key]) ? $image[$key] : $image['url'];
  51. }
  52. public function has_plugin($plugin){
  53. $states = Plugin::states();
  54. if(!isset($states[$plugin]) || !in_array($this->id, $states[$plugin])) return false;
  55. return true;
  56. }
  57. }
  58. ?>