Solved

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

Posted on 2012-04-05
4
288 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 108

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 108

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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 the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now