Ignore:
Timestamp:
Oct 9, 2010, 9:55:26 PM (14 years ago)
Author:
grum
Message:

add marker style management + minor bugs fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/GMaps/gmaps_aip.class.inc.php

    r7132 r7139  
    2727  {
    2828    parent::__construct($prefixeTable, $filelocation);
     29
    2930    $this->loadConfig();
    3031    $this->configForTemplate();
     
    3637
    3738    $this->tabsheet = new tabsheet();
    38 
    3939
    4040    if($this->amdState!='advanced')
     
    231231    $datas=Array(
    232232      'urlRequest' => $this->getAdminLink('ajax'),
    233       'cats' => $this->makeCategoriesTree(),
     233      'cats' => $this->makeCategoryList(),
    234234      'maps' => $this->makeMapsList(),
    235235      'icons' => $this->makeIconsList(),
     236      'markers' => $this->makeMarkersList(),
    236237      'kmlFiles'  => $this->makeKmlFilesList()
    237238    );
     
    322323
    323324
    324   /**
    325    * build the categories tree
    326    * @return Array : an array, ready to use in the template
    327    */
    328   private function makeCategoriesTree()
     325
     326  /**
     327   * build an ordered category list
     328   * returns an array, each item is an array like :
     329   *  'id'     => the category Id
     330   *  'name'   => the category name
     331   *  'rank'   => the category rank (global)
     332   *  'level'  => the category level
     333   *
     334   * @return Array : the list
     335   */
     336  protected function makeCategoryList()
    329337  {
    330338    $returned=array(
    331339      array(
    332         'id' => 0,
    333         'name' => '-- '.l10n('gmaps_applyForAllTheGallery').' --'
     340        'id'     => 0,
     341        'name'   => l10n('gmaps_applyForAllTheGallery'),
     342        'rank'   => '0000',
     343        'level'  => 0,
     344        'status' => 'public',
     345        'childs'  => false
    334346      )
    335347    );
    336348
    337     $sql="SELECT id, name, global_rank
    338           FROM ".CATEGORIES_TABLE."
    339           ORDER BY global_rank";
    340     $result = pwg_query($sql);
     349    $sql="SELECT DISTINCT pct.id, pct.name, pct.global_rank AS rank
     350          FROM ".CATEGORIES_TABLE." pct
     351            JOIN (
     352              SELECT DISTINCT pgat.cat_id AS catId FROM ".GROUP_ACCESS_TABLE." pgat
     353              UNION DISTINCT
     354              SELECT DISTINCT puat.cat_id AS catId FROM ".USER_ACCESS_TABLE." puat
     355                 ) pat
     356            ON (pat.catId = pct.id AND pct.status = 'private') OR (pct.status = 'public')
     357          ORDER BY global_rank;";
     358    $result=pwg_query($sql);
    341359    if($result)
    342360    {
    343       while ($row = pwg_db_fetch_assoc($result))
     361      while($row=pwg_db_fetch_assoc($result))
    344362      {
    345         $returned[]=array(
    346           'id' => $row['id'],
    347           'name' => str_repeat('  ', substr_count($row['global_rank'], '.')).$row['name']
    348         );
     363        $row['level']=1+substr_count($row['rank'], '.');
     364
     365        /* rank is in formated without leading zero, giving bad order
     366         *  1
     367         *  1.10
     368         *  1.11
     369         *  1.2
     370         *  1.3
     371         *  ....
     372         *
     373         *  this loop cp,vert all sub rank in four 0 format, allowing to order
     374         *  categories easily
     375         *  0001
     376         *  0001.0010
     377         *  0001.0011
     378         *  0001.0002
     379         *  0001.0003
     380         */
     381        $row['rank']=explode('.', $row['rank']);
     382        foreach($row['rank'] as $key=>$rank)
     383        {
     384          $row['rank'][$key]=str_pad($rank, 4, '0', STR_PAD_LEFT);
     385        }
     386        $row['rank']=implode('.', $row['rank']);
     387
     388        $returned[]=$row;
    349389      }
    350390    }
    351391
     392    usort($returned, array(&$this, 'compareCat'));
     393
    352394    return($returned);
    353   } //makeCategoriesTree
     395  }
     396
     397  /**
     398   * used for sort comparison
     399   * defined as public, but don't use it directly
     400   *
     401   * this function compare two categorie with their rank value
     402   */
     403  public function compareCat($catA, $catB)
     404  {
     405    if($catA['rank'] == $catB['rank'])
     406    {
     407      return(0);
     408    }
     409    return( ($catA['rank'] < $catB['rank'])?-1:1 );
     410  }
    354411
    355412
     
    400457      {
    401458        $returned[]=array(
    402           'type' => (strtolower(substr($file,0,1))=='i')?'img':'other',
    403459          'file' => $file
    404460        );
     
    409465  } //makeIconsList
    410466
     467
     468  /**
     469   * build the markers list
     470   * @return Array : an array, ready to use in the template
     471   */
     472  private function makeMarkersList()
     473  {
     474    $returned=array();
     475
     476    $directory=scandir(GMAPS_PATH.'img/');
     477    foreach($directory as $file)
     478    {
     479      $ext=(pathinfo($file, PATHINFO_EXTENSION));
     480      if(preg_match('/^mS(\d\d)_(\d\d)\.png$/i', $file))
     481      {
     482        $returned[]=array(
     483          'file' => $file
     484        );
     485      }
     486    }
     487
     488    return($returned);
     489  } //makeIconsList
    411490
    412491  /**
Note: See TracChangeset for help on using the changeset viewer.