Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

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

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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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.
Avatar of MJ

ASKER

I want to display a specific file name first.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial