Solved

How to control order of files being displayed in dynamic select box

Posted on 2012-04-05
4
303 Views
Last Modified: 2012-04-06
I haven't touched PHP in about 11 years so be kind to me! I need to update code that builds a dynamic select on a page. It just reads in the files. How can I control the order of the files displayed? I want a specific file to be first.
/////////////////////////////////////////////////////////////////////
function load($htmlFrm, $cancelFormSubmission){
            global $OMNITURE_REPORTS_DIR;
            
            // load the drop down data
            $type = $this->dataRow['type']->getValue();
            $typeFilter = "val not like 'locale%'"; // by default do not show locale types.
            if (preg_match('/locale/', $type)){
                  $typeFilter = "val like 'locale%'";
            }
            $this->typeList = new CSimpleDataSet($this->db, new CQuery(new CString("SELECT caption, val FROM lists WHERE groupName='opsr2.omniture.type' AND $typeFilter ORDER BY priority ASC")));
            $this->typeList->loadData();

            // get the report template file list;
            if (self::$reportList === null){
                  self::$reportList = array();
                  foreach (scandir($OMNITURE_REPORTS_DIR) as $file){
                        // only show files in the reports menu, not directories.
                        if (is_file("$OMNITURE_REPORTS_DIR/$file")){
                              self::$reportList[] = new CString($file);
                        }
                  }
            }
/////////////////////////////////////////////////////////////////////////////////////////
// generate a report list pulldown menu:
                  if (count(self::$reportList)){
                        $reportSel = new CSelect($this->parentReport->getHtmlFrm(), new CString("reportSelector"), new CString(''));
                        $reportSel->setClassName('reportSelector');
                        foreach (self::$reportList as $file){
                              $reportSel->addOption($file,$file);
                        }
                        $tpl->assign('html_reportSelector',$reportSel->getHtml());
                  } // end: if
0
Comment
Question by:894359
  • 2
4 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37814584
What are these classes from (maybe part of a larger framework?)  How do you know which file you want to display first?  File name?  Oldest?  Newest?  There are probably some ways to make an array of objects that would allow many different ways to sort the list of files or pick out the one you want first.
0
 

Author Comment

by:894359
ID: 37814588
I want to display a specific file name first.
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 37814600
I believe that scandir() returns an array of file names.  There is this line in the code:  foreach (scandir($OMNITURE_REPORTS_DIR) as $file){  That would suggest to me that you might look at the file names inside the iterator loop created by foreach() and select the desired file.  Add it to an output array at position zero.  Remove it from the scandir() results.  Then iterate over the scandir() results again, adding the rest of the file names to the output array.
0
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 250 total points
ID: 37814655
You could also use the dir() class in php.

http://php.net/manual/en/function.dir.php

The page also has an example.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question