?
Solved

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

Posted on 2012-04-05
4
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 111

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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)
Suggested Courses

770 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