Displaying mysql results

Currently I am using arfooo as a directory on my website. On the index page of that website the entries in the directory are displayed in random based on the following code…

sitecontroller.php
[php]/**
* Get random sites on index page
*/
function randomListAction()
{
$cache = Cacher::getInstance();

    //get last time generated
    $generationDate = Config::get('selectionGenerationDate');

    $period = Config::get('selectionPeriod');
    $todayDate = date("Y-m-d");

    //if doesn't exists last refresh or is overtime
    $refreshNeeded = (!preg_match('#^[0-9]{4}-[0-9]{2}-[0-9]{2}$#', $generationDate) || strtotime($generationDate . "+" . $period . " days") <= strtotime($todayDate));

    $cacheItemName = "indexRandomSites" . Config::get("language") . "Template" . Config::get("templateName");

    //if force refresh or cache donesn't exists
    if ($refreshNeeded || ($indexRandomSitesHtml = $cache->load($cacheItemName, false)) === null) {
        $data = $this->siteList->getIndexRandomList($refreshNeeded);
        $this->set("randomSites", $data);
        $indexRandomSitesHtml = $this->render();
        $cache->save($indexRandomSitesHtml, $cacheItemName, false, array("site", "setting"));
    }

    return $indexRandomSitesHtml;
}[/php]

randomlist.tpl

{foreach from=$randomSites value=site} <a href="{$site|objurl:'siteDetails'}" class="link_black_blue_b_u">{$site.siteTitle}</a> {/foreach}

index.tpl

[code]

{'mainIndex_h2'|lang}

{'/site/randomList'|action}
[/code]

The problem is I no longer want the entries to be displayed randomly but rather in alphabetical order based on siteTitle. But clicking siteTitle still needs to open siteDetails as seen in randomlist.tpl

I have put a lot time into this and am now more confused than when I started. Any help would be greatly appreciated…

Ok I’ve never used Arfooo before but downloaded the code and took a look. First your list is generated with this line of code:

[php]$data = $this->siteList->getIndexRandomList($refreshNeeded);[/php]

That’s a function that already written inside the SiteListModel.php file, I looked and there doesn’t seem to be a function for exactly what you need but you can create a new one using the code from getIndexRandomList.

Take the function:

[php]function getIndexRandomList($refreshNeeded)
{
if (!$refreshNeeded) {
$siteIds = explode(",", Config::get(“selectionSiteIds”));
}
if ($refreshNeeded) {
$siteIds = $this->generateNewSelection();
}
if (empty($siteIds)) {
return array();
}

    $c = new Criteria();
    $c->add("siteId", $siteIds, "IN");

    $sites = $this->selectWithNewFlag($c);
    $this->attachParents($sites);

    foreach ($sites as $key => $site) {
        $sites[$key] = $site;
    }

    return $sites;
}[/php]

name it something else like getIndexSortedList. Next add the line of code that adds a sorting variable to the list, for example:

[php]$c->addOrder(“creationDate ASC”);[/php]

you will need to replace the ‘creationDate’ name with the name you want to sort from your database, that you will need to check on your own. Also that line of code needs to go after your $c = new Criteria(); line in your function otherwise you will get errors that you are accessing a variable that doesn’t exist.

finally after your new function is created replace the line

[php]$data = $this->siteList->getIndexRandomList($refreshNeeded);[/php]

with your new function name to call the new function you just made. Note: I didn’t test any of this so you’ll have to play around with it to make it work, for example:

[php]$data = $this->siteList->getIndexSortedList($refreshNeeded);[/php]

Thanks Kajih! It works perfectly now! :slight_smile:

Glad I could help! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service