Advertisement
Guest User

Sample Implementation of Yii Extension, GmapMultiplot

a guest
Oct 3rd, 2010
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. <?php
  2.   /**
  3.   *  PLOTING MULTIPLE LOCATIONS OF THE SAME BUSINESS
  4.   *
  5.   *  This extension was originally created to display the location(s) or a particular business. Therefore,
  6.   *  the extension, as is, expects certain attributes to be passed to it.
  7.   *
  8.   *  The required attributes include:      
  9.   *    @var string $address1
  10.   *    @var string $address2
  11.   *    @var string $city
  12.   *    @var string $state
  13.   *    @var string $zip
  14.   *    @var string $bphone
  15.   *
  16.   *  These names of these attributes can be changed in GMapMultiplot.php Lines 142-150
  17.   *
  18.   *  In this scenario the business have a One-To-Many relationship to locations:
  19.   */
  20.  
  21.    // CONTROLLER EXAMPLE
  22.    
  23.    public function actionViewmap()
  24.    {
  25.         // Business ID is passed through $_GET parameter  
  26.         $businessId = $_GET['id'];
  27.        
  28.         // Retrive business infomation
  29.         $businessInfo = business::model()->findByPk($businessId);
  30.        
  31.         // Retrieve business locations
  32.         $locations = locations::model()->findAll('id=:id', array(':id'=>$businessId));
  33.        
  34.         $this->render('viewmap', array('businessInfo'=>$businessInfo, 'locations'=>$locations))
  35.    }
  36.    
  37.    
  38.    // VIEW EXAMPLE
  39.    $this->widget('application.extensions.gmapmultiplot.GMapMultiplot', array(
  40.         'id' => 'gmap',//id of the <div> container created
  41.         'label' => $businessInfo->tradename, //text written in the text bubble
  42.         'address' =>  $locations,  // We feed the array of 'location' objects to the extension
  43.     ));
  44.  
  45.  
  46.   /**
  47.   *     PLOTING LOCATIONS OF MULTIPLE BUSINESS 0N ONE MAP  
  48.   *
  49.   *   Alternatively, locations could be a table of businesses with single locations.
  50.   *   For example you may have the following model schema:
  51.   *  
  52.   *    @var string $businessName
  53.   *    @var string $address1
  54.   *    @var string $address2
  55.   *    @var string $city
  56.   *    @var string $state
  57.   *    @var string $zip
  58.   *    @var string $bphone
  59.   *
  60.   *     If this is the case, you can simply not feed a label to the extension and make a minor change within
  61.   *     GmapMultiplot.php
  62.   */
  63.  
  64.          // CONTROLLER EXAMPLE
  65.    
  66.    public function actionViewmap()
  67.    {
  68.         // Retrive business infomation
  69.         $businesses = business::model()->findAll();                                          
  70.        
  71.         $this->render('viewmap', array('businesses'=>$bussinesses))
  72.    }
  73.    
  74.    
  75.    // VIEW EXAMPLE
  76.    $this->widget('application.extensions.gmapmultiplot.GMapMultiplot', array(
  77.         'id' => 'gmap',//id of the <div> container created                    
  78.         'address' =>  $locations,  // We feed the array of 'location' objects to the extension
  79.     ));
  80.    
  81.    
  82.     // MAKE CHANGE TO GMapMultiPlot.php LINE: 150
  83.    
  84.     // BEFORE CHANGE
  85.     $ret .= 'geocode("'.$address.'", "'.$item->bphone.'", "'.$this->label.'", '.$only.');';
  86.    
  87.     // AFTER CHANGE
  88.     $ret .= 'geocode("'.$address.'", "'.$item->bphone.'", "'.$item->businessname.'", '.$only.');';
  89.  
  90.  
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement