Firm.class.php 2.5 KB

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