Rubbish at PHP and could do with an expert eye

Hello World!!

I’ve got a Concrete5 site that has courses which I want to list in date order, could anyone take a look at this and let me know why only one course is displayed when two (or more) courses start on the same date?

The code isn’t mine, but I can’t go back to who created it as the company has fallen out of favour, if you get my drift.

Any help would be very gratefully received.

Thank you

[php]

public function on_start() {
//echo ‘on_start’;exit;
}

public function lists() {
    $productss = array();
    //$order = new CoreCommerceProduct();
    $db = Loader::db();
    $sql = $this->getAllProductFromSearch(); //'select * from corecommerceproducts';
    $rows = $db->GetAll($sql);
    foreach ($rows as $row) {
        $products = CoreCommerceProduct::getByID($row['productID']);
        if (!is_object($products) OR $products->isSoldOut() OR !$products->isProductEnabled()) {
            continue;
        }
        array_push($productss, $products);
    }

    $this->set('products', $this->filterProducts($productss));
}

public function filterProducts($products) {
    $p = array();
    $filter =array();
    if(isset($_REQUEST['filter']))
        $filter = array_map('urldecode',$_REQUEST['filter']);
    $interestedCategories = array('Event', 'General Course', 'Pathway Course');
    foreach ($products as $product) {
        if (!in_array($product->getAttribute('category'), $interestedCategories))
            continue;
        //if course type filter is submitted
        $coursetype = $product->getAttribute('course_types'); 
        if( gettype($coursetype) == "object"){   //must make sure this is an object before we try and call methods
            $r = $coursetype->get('0');
            if(gettype($r) == "object"){
                $coursetype = $r->getSelectAttributeOptionValue() ;
            }
         }
        
        if(count($filter) && !in_array(trim($coursetype), $filter)){
            continue;
        }
        array_push($p, $product);
    }
    return $p;
}

[/php]

I am not a fan of Concrete5, but I would be dropping some print_r() statements throughout to see what values are being shown when.

Thank you for taking the trouble to reply, I’ll give that a go and see what happens.
I’m no great fan of Concrete5 either, more of a Joomla! person really; but this is the site I have to work with. It could be worse though!
Thanks very much again.

Sponsor our Newsletter | Privacy Policy | Terms of Service