File: D:/HostingSpaces/SBogers64/klimroosbudel.nl/wwwroot/lib/mvc/model.class.php
<?php
/**
* model.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 3/20/13
*/
class Site_Model
{
// Errors
protected $errors;
// Language
protected $lang = array();
protected $urls = array();
private $_name;
private $_pageId;
/*
* Construct
*/
public function __construct()
{
$this->Db = new DatabaseHandler();
}
public function set($prop, $val)
{
$this->{$prop}=$val;
}
/*
* This function is called by a controller when something goes wrong.
* If any errors are set, return them to the controller.
*/
public function getErrors()
{
if(count($this->errors) > 0)
{
return $this->errors;
}
return false;
}
/*
* Set the language property
*/
public function setLang($lang, $urls)
{
$this->lang = $lang;
$this->urls = $urls;
}
public function getTableData($order = null)
{
$itemsTable = TABLE_PREFIX . $this->_name . '_items';
$this->Db->setTableName($itemsTable);
$this->Db->setActiveOnly(true, $this->_pageId);
if($order == null)
{
$this->Db->setOrder('itemOrder', 'DESC');
}
else
{
$this->Db->setOrder($order[0], $order[1]);
}
if ($result = $this->Db->select())
{
//return $this->Db->twoDimensional($result);
$items = $this->Db->twoDimensional($result);
$imagesTable = TABLE_PREFIX . $this->_name . '_images';
$imageDb = new DatabaseHandler();
$imageDb->setTableName($imagesTable);
$imageDb->setOrder('id','ASC');
foreach ($items as $key => $item)
{
$imageDb->addRule('itemId', $item['id'] );
if ($result = $imageDb->select())
{
$images = $imageDb->twoDimensional($result);
$items[$key]['images'] = $images;
}
else
{
//unset($items[$key]);
}
$imageDb->clearRule();
}
return $items;
}
return false;
}
}