Firm.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Define a sub firm.
  4. * @author valentin carruesco
  5. * @category Core
  6. * @license MIT
  7. */
  8. class Firm extends Entity{
  9. public $id,$label,$description,$mail,$phone,$fax,$street,$street2,$city,$zipcode,$siret,$iban;
  10. public $entityLabel = 'Etablissement';
  11. public $fields =
  12. array(
  13. 'id' => array('label'=>'Identifiant', 'type'=>'key'),
  14. 'label' => array('label'=>'Libellé', 'type'=>'text'),
  15. 'description' => array('label'=>'Description', 'type'=>'textarea'),
  16. 'mail' => array('label'=>'E-mail', 'type'=>'mail'),
  17. 'phone' => array('label'=>'N° Téléphone', 'type'=>'phone'),
  18. 'fax' => array('label'=>'N° FAX', 'type'=>'phone'),
  19. 'street' => array('label'=>'Rue', 'type'=>'textarea'),
  20. 'street2' => array('label'=>'Complément d\'adresse', 'type'=>'textarea'),
  21. 'city' => array('label'=>'Ville', 'type'=>'text'),
  22. 'zipcode' => array('label'=>'Code postal', 'type'=>'text'),
  23. 'siret' => array('label'=>'N° SIRET', 'type'=>'text'),
  24. 'iban' => array('label'=>'N° IBAN', 'type'=>'text')
  25. );
  26. //Déclaration de l'établissement anonyme (pour les non connectés)
  27. public static function anonymous_firm(){
  28. $firm = new Firm;
  29. $firm->id = -1;
  30. $firm->label = 'Sans établissement';
  31. return $firm;
  32. }
  33. public static function logo_path(){
  34. return 'core'.SLASH.'public'.SLASH.'firm'.SLASH;
  35. }
  36. public function address(){
  37. return $this->street.' '.$this->street2.' '.$this->zipcode.' '.$this->city;
  38. }
  39. public function __sleep(){
  40. return array_merge(array_keys($this->toArray()));
  41. }
  42. public function logo($key=null){
  43. $finded = false;
  44. $image = array();
  45. $paths = array(
  46. 'jpg' => FILE_PATH.self::logo_path().$this->id.SLASH.'logo.jpg',
  47. 'jpeg' => FILE_PATH.self::logo_path().$this->id.SLASH.'logo.jpeg',
  48. 'png' => FILE_PATH.self::logo_path().$this->id.SLASH.'logo.png',
  49. );
  50. $image['url'] = $image['path'] = 'img'.SLASH.'logo'.SLASH.'default-logo.png';
  51. foreach ($paths as $extension => $path) {
  52. if (file_exists( __ROOT__.$path) && !$finded) {
  53. $image['path'] = __ROOT__.$path;
  54. $image['publicPath'] = ROOT_URL.SLASH.'media'.SLASH.self::logo_path().$this->id.SLASH.'logo.'.$extension;
  55. $image['url'] = 'action.php?action=core_firm_logo&type=download&path='.base64_encode('core/public/firm/'.$this->id.'/logo.*');
  56. $finded = true;
  57. }
  58. }
  59. return isset($key) && isset($image[$key]) ? $image[$key] : $image['url'];
  60. }
  61. public function has_plugin($plugin){
  62. $states = Plugin::states();
  63. if(!isset($states[$plugin]) || !in_array($this->id, $states[$plugin])) return false;
  64. return true;
  65. }
  66. }
  67. ?>