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]