Development

Changeset 5560

You must first sign up to be able to contribute.

Changeset 5560

Show
Ignore:
Timestamp:
10/17/07 10:51:04 (2 years ago)
Author:
fabien
Message:

added the ability to sort results in sfFinder (closes #1609 - patch from francois)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/util/sfFinder.class.php

    r5110 r5560  
    4848  protected $relative    = false; 
    4949  protected $follow_link = false; 
     50  protected $sort        = false; 
    5051 
    5152  /** 
     
    247248 
    248249    return $this->discard($ignores)->prune($ignores); 
     250  } 
     251 
     252  /** 
     253   * Returns files and directories ordered by name 
     254   * 
     255   * @return object current sfFinder object 
     256   */ 
     257  public function sort_by_name() 
     258  { 
     259    $this->sort = 'name'; 
     260 
     261    return $this; 
     262  } 
     263 
     264  /** 
     265   * Returns files and directories ordered by type (directories before files), then by name 
     266   * 
     267   * @return object current sfFinder object 
     268   */ 
     269  public function sort_by_type() 
     270  { 
     271    $this->sort = 'type'; 
     272 
     273    return $this; 
    249274  } 
    250275 
     
    352377    } 
    353378 
     379    if ($this->sort == 'name') 
     380    { 
     381      sort($files); 
     382    } 
     383 
    354384    return array_unique($files); 
    355385  } 
     
    368398 
    369399    $files = array(); 
    370  
     400    $temp_files = array(); 
     401    $temp_folders = array(); 
    371402    if (is_dir($dir)) 
    372403    { 
     
    383414 
    384415        if (is_dir($current_entry)) 
     416        { 
     417          if ($this->sort == 'type') 
     418          { 
     419            $temp_folders[$entryname] = $current_entry; 
     420          } 
     421          else 
     422          { 
     423            if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
     424            { 
     425              $files[] = realpath($current_entry); 
     426            } 
     427 
     428            if (!$this->is_pruned($dir, $entryname)) 
     429            { 
     430              $files = array_merge($files, $this->search_in($current_entry, $depth + 1)); 
     431            } 
     432          } 
     433        } 
     434        else 
     435        { 
     436          if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
     437          { 
     438            if ($this->sort == 'type') 
     439            { 
     440              $temp_files[] = realpath($current_entry); 
     441            } 
     442            else 
     443            { 
     444              $files[] = realpath($current_entry); 
     445            } 
     446          } 
     447        } 
     448      } 
     449 
     450      if ($this->sort == 'type') 
     451      { 
     452        ksort($temp_folders); 
     453        foreach($temp_folders as $entryname => $current_entry) 
    385454        { 
    386455          if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
     
    394463          } 
    395464        } 
    396         else 
    397         { 
    398           if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname)) 
    399           { 
    400             $files[] = realpath($current_entry); 
    401           } 
    402         } 
    403       } 
     465 
     466        sort($temp_files); 
     467        $files = array_merge($files, $temp_files); 
     468      } 
     469 
    404470      closedir($current_dir); 
    405471    } 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.