linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file class.yellowpages.php

Documentation is available at class.yellowpages.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage yellowpages
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Yellowpages Management
  10.  */
  11.  
  12. class yellowpages {
  13.   /* @param
  14.    * */
  15.   var $TDB_YELLOWPAGES = T_YELLOWPAGES// nom de la table.
  16.   var $ID;
  17.   var $NAME;
  18.   var $ACTIVITY;
  19.   var $THEME;
  20.   var $STREET;
  21.   var $POSTAL_CODE;
  22.   var $CITY;
  23.   var $COUNTRY;
  24.   var $PHONE;
  25.   var $FAX;
  26.   var $EMAIL;
  27.   var $WEBSITE;
  28.   var $LONG = 0;
  29.   var $LAT = 0;
  30.   var $DATE_CREA;
  31.   var $LAST_MODIFY;
  32.   var $STATUT;
  33.   protected $dispatcher = null;
  34.  
  35.   public function __construct()
  36.   {
  37.     $this->dispatcher = $GLOBALS['dispatcher'];
  38.   }
  39.  
  40.   public function __call($method$arguments)
  41.   {
  42.     $event $this->dispatcher->notifyUntil(new sfEvent($this'yellowpages.extensible_function'array(
  43.       'method'    => $method,
  44.       'arguments' => $arguments
  45.     )));
  46.     if (!$event->isProcessed())
  47.     {
  48.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  49.     }
  50.  
  51.     return $event->getReturnValue();
  52.   }
  53.  
  54.   /**
  55.    * yellowpages::CheckDataIntegrity()
  56.    * Vérification des données d'une entreprise
  57.    *
  58.    * @access public
  59.    * @param array $table_yp : contient les composants d'une entreprise
  60.    * @return boolean si ok renvoie true sinon message d'erreurs (string)
  61.    */
  62.   function CheckDataIntegrity($table)
  63.   {
  64.  
  65.       // Filter data event + return value
  66.       $r $this->dispatcher->filter(new sfEvent($this'yellowpages.before_datacheck'array('data' => $table))$table);
  67.       $table $r->getReturnValue();
  68.       
  69.     if (strlen($table[0]2return _t('yp','object_notname');
  70.     if (strlen($table[1]2return _t('yp','object_notactivity');
  71.     if (strlen($table[3]2return _t('yp','object_notstreet');
  72.     if (strlen($table[4]2return _t('yp','object_notpostal_code');
  73.     if (strlen($table[5]2return _t('yp','object_notcity');
  74.     //if (strlen($table[6]) < 2) return $notcountry;
  75.     $testmail $this->_checkEmailValidity($table[9]);
  76.     if ($testmail===falsereturn _t('yp','object_notemail');
  77.  
  78.     if (strlen($table[10]10{
  79.       if (!$this->IsValidProtocol($table[10])) return _t('yp','invalid_protocol');
  80.     }
  81.  
  82.     if (trim($table[7]!= '' && !is_numeric($table[7])) return _t('yp','object_notphone');
  83.     if (trim($table[8]!= '' && !is_numeric($table[8])) return _t('yp','object_notfax');
  84.     
  85.     // Notify the beginning of the current method
  86.     $this->dispatcher->notify(new sfEvent($this'yellowpages.after_datacheck'array('data' => $table)));
  87.     
  88.     return true;
  89.   }
  90.  
  91.   /**
  92.    * yellowpages::_checkEmailValidity()
  93.    * Vérification de la grammaire du mail
  94.    *
  95.    * @access private
  96.    * @param string $email 
  97.    * @return int 1 ou 0
  98.    */
  99.   function _checkEmailValidity($email)
  100.   {
  101.       $this->dispatcher->notify(new sfEvent($this'yellowpages.check_email_validity'array('email' => $email)));
  102.       
  103.     return validEmail($email);
  104.   }
  105.  
  106.   /**
  107.    * resources::IsValidProtocol()
  108.    * vérifie si une url donnée a un protocole reconnu par un client web standard
  109.    *
  110.    * @access public
  111.    * @param array $url : chemin absolu
  112.    * @return boolean 
  113.    */
  114.   function IsValidProtocol($url)
  115.   {
  116.       $this->dispatcher->notify(new sfEvent($this'yellowpages.is_valid_protocol'array('url' => $url)));
  117.       
  118.     if (substr($url07!= 'http://' && substr($url08!= 'https://' && substr($url06!= 'ftp://' && substr($url07!= 'ftps://'return false;
  119.     else return true;
  120.   }
  121.  
  122.   /**
  123.    * yellowpages::AddYellowPages()
  124.    * Ajout d'une nouvelle entreprise dans l'annuaire
  125.    *
  126.    * @access public
  127.    * @param array $table contient les composants d'une organisation
  128.    * @param object $sql_object 
  129.    * @return integer $last_id
  130.    */
  131.   function AddYellowPages($table$sql_object)
  132.   {
  133.       // Filter data event + return value
  134.       $r $this->dispatcher->filter(new sfEvent($this'yellowpages.before_add'array('data' => $table))$table);
  135.       $table $r->getReturnValue();
  136.       
  137.     $table=$sql_object->DBescape($table);
  138.  
  139.     $this->NAME = strip_input($table[0]);
  140.     $this->ACTIVITY = strip_input($table[1]);
  141.     $this->THEME = $table[2];
  142.     $this->STREET = strip_input($table[3]);
  143.     $this->POSTAL_CODE = strip_input($table[4]);
  144.     $this->CITY = strip_input($table[5]);
  145.     $this->COUNTRY = strip_input($table[6]);
  146.     $this->PHONE = strip_input($table[7]);
  147.     $this->FAX = strip_input($table[8]);
  148.     $this->EMAIL = strip_input($table[9]);
  149.     $this->WEBSITE = strip_input($table[10]);
  150.  
  151.     if ($table[11!= ''{
  152.       $table[11strtoupper($table[11]);
  153.       switch ($table[11]{
  154.         case 'P':
  155.           $this->STATUT = $table[11];
  156.           break;
  157.         case 'AA':
  158.           $this->STATUT = $table[11];
  159.           break;
  160.         case 'D':
  161.           $this->STATUT = $table[11];
  162.           break;
  163.         default:
  164.           $this->STATUT = 'AA';
  165.           break;
  166.       }
  167.     else $this->STATUT = 'AA';
  168.  
  169.     $this->_geocode();
  170.  
  171.     $q "INSERT INTO " $this->TDB_YELLOWPAGES . " (yellowp_name, yellowp_activity, yellowp_theme, yellowp_street, " "yellowp_postal_code, yellowp_city, yellowp_country, yellowp_phone, yellowp_fax, yellowp_email, " "yellowp_website, yellowp_longitude, yellowp_latitude,  yellowp_statut, yellowp_date_crea) " "VALUES('" $this->NAME . "', '" $this->ACTIVITY . "', " $this->THEME . ", '" $this->STREET . "', '" $this->POSTAL_CODE . "', '" $this->CITY . "', '" $this->COUNTRY . "', '" $this->PHONE . "', '" $this->FAX . "', '" $this->EMAIL . "', '" $this->WEBSITE . "', '" $this->LONG"', '" $this->LAT"', '" $this->STATUT . "', NOW());";
  172.     $last_id $sql_object->DBInsert ($q1);
  173.     
  174.     // Notify the end of the current method
  175.     $this->dispatcher->notify(new sfEvent($this'yellowpages.after_add'array('data' => $table'id' => $last_id)));
  176.     
  177.     return $last_id;
  178.   }
  179.  
  180.   /**
  181.    * yellowpages::StateYellowPages()
  182.    * modification du statut d'une organisation
  183.    *
  184.    * @access public
  185.    * @param int $ID identifiant de l'organisation
  186.    * @param string $state (facultatif) 'P' Public/'D' Draft/'AA' AdminArchive/'PA' PublicArchive
  187.    * @param object $sql_object 
  188.    * @return bool $result
  189.    */
  190.  
  191.   function StateYellowPages($ID$state$sql_object)
  192.   {
  193.       // Notify the end of the current method
  194.       $this->dispatcher->notify(new sfEvent($this'yellowpages.change_state'array('id' => $ID'state' => $state)));
  195.       
  196.     if (is_numeric($ID)) {
  197.       $this->ID = $ID;
  198.     }
  199.     $this->STATUT = $state;
  200.  
  201.     $q "UPDATE  " $this->TDB_YELLOWPAGES . " set yellowp_statut='" $this->STATUT . "' WHERE yellowp_id=" $this->ID . ";";
  202.     $result $sql_object->DBQuery($q);
  203.     return $result;
  204.   }
  205.  
  206.  
  207.   /*
  208.    * yellowpages::DeleteYellowPages()
  209.    * suppression d'une organisatione
  210.    *
  211.    * @access public
  212.    * @param int $ID identifiant de l'organisation
  213.    * @param object $sql_object
  214.    * @return bool $result
  215.    */
  216.   function DeleteYellowPages($ID$sql_object)
  217.   {
  218.       // Notify the end of the current method
  219.       $this->dispatcher->notify(new sfEvent($this'yellowpages.delete'array('id' => $ID)));
  220.       
  221.     $this->ID = $ID;
  222.     $q "UPDATE " $this->TDB_YELLOWPAGES . " SET yellowp_statut='E', yellowp_last_modify = NOW() WHERE yellowp_id=" $this->ID . ";";
  223.     $result $sql_object->DBQuery ($q);
  224.     return $result;
  225.   }
  226.  
  227.   /**
  228.    * yellowpages::ModifyYellowPages()
  229.    * modification d'une organisation
  230.    *
  231.    * @access public
  232.    * @param int $ID identifiant de l'organisation
  233.    * @param array $table contient les composants d'une entreprise
  234.    * @param object $sql_object 
  235.    * @return bool $result
  236.    */
  237.   function ModifyYellowPages($ID$table$sql_object)
  238.   {
  239.       // Filter data event + return value
  240.       $r $this->dispatcher->filter(new sfEvent($this'yellowpages.before_modify'array('data' => $table'id' => $ID))$table);
  241.       $table $r->getReturnValue();
  242.       
  243.     $table=$sql_object->DBescape($table);
  244.  
  245.     $this->ID = $ID;
  246.     $this->NAME = strip_input($table[0]);
  247.     $this->ACTIVITY = strip_input($table[1]);
  248.     $this->THEME = $table[2];
  249.     $this->STREET = strip_input($table[3]);
  250.     $this->POSTAL_CODE = strip_input($table[4]);
  251.     $this->CITY = strip_input($table[5]);
  252.     $this->COUNTRY = strip_input($table[6]);
  253.     $this->PHONE = strip_input($table[7]);
  254.     $this->FAX = strip_input($table[8]);
  255.     $this->EMAIL = strip_input($table[9]);
  256.     $this->WEBSITE = strip_input($table[10]);
  257.  
  258.     if ($table[11!= ''{
  259.       $table[11]=strtoupper($table[11]);
  260.       switch ($table[11]{
  261.         case 'P':
  262.           $this->STATUT = $table[11];
  263.           break;
  264.         case 'AA':
  265.           $this->STATUT = $table[11];
  266.           break;
  267.         case 'D':
  268.           $this->STATUT = $table[11];
  269.           break;
  270.         default:
  271.           $this->STATUT = 'AA';
  272.           break;
  273.       }
  274.     else $this->STATUT = 'AA';
  275.  
  276.     $this->_geocode();
  277.     
  278.     $q "UPDATE  " $this->TDB_YELLOWPAGES . " set yellowp_name='" $this->NAME . "', yellowp_activity='" $this->ACTIVITY . "' , yellowp_theme=" $this->THEME . ", yellowp_street='" $this->STREET . "', yellowp_postal_code='" $this->POSTAL_CODE . "', yellowp_city='" $this->CITY . "', yellowp_country='" $this->COUNTRY . "', yellowp_phone='" $this->PHONE . "', yellowp_fax='" $this->FAX . "', yellowp_email='" $this->EMAIL . "', yellowp_longitude='" $this->LONG . "', yellowp_latitude='" $this->LAT . "', yellowp_website='" $this->WEBSITE . "', yellowp_statut='" $this->STATUT . "', yellowp_last_modify = NOW() WHERE yellowp_id=" $this->ID . ";";
  279.  
  280.     $result $sql_object->DBQuery($q);
  281.     
  282.     // Notify the end of the current method
  283.     $this->dispatcher->notify(new sfEvent($this'yellowpages.after_modify'array('data' => $table'id' => $this->ID)));
  284.  
  285.     return $result;
  286.   }
  287.  
  288.   /**
  289.    * yellowpages::_geocode()
  290.    * prepare and geocode a given address
  291.    *
  292.    * @access private
  293.    */
  294.   private function _geocode({
  295.     
  296.       // Notify the end of the current method
  297.       $this->dispatcher->notify(new sfEvent($this'yellowpages.geocode_address'));
  298.       
  299.     $address $this->STREET .',' $this->CITY .',' $this->COUNTRY;
  300.     $o geocode($address);
  301.  
  302.     if($o->{'status'}=='OK'{
  303.       $this->LONG $o->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
  304.       $this->LAT =  $o->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
  305.     }
  306.     
  307.   }
  308.  
  309. }
  310.  
  311. ?>

Documentation generated on Thu, 20 Mar 2014 16:47:13 +0100 by phpDocumentor 1.4.1