File: D:/HostingSpaces/SBogers10/keystud.komma-mediadesign.nl/wwwroot/app/models/m_news.class.php
<?php
/**
* m_news.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 8/30/13
*/
class News_Model extends Model
{
private $_lang;
private $_urls;
public function __construct()
{
parent::__construct();
}
public function set($var,$val)
{
$this->{$var} = $val;
}
public function get($id = null)
{
$Db = new DatabaseHandler();
$Db->setTableName(TABLE_PREFIX . 'news_items');
$Db->setOrder('date','DESC');
$Db->setActiveOnly(TRUE,5);
$Db->addRule('active',1);
$ImageDb = new DatabaseHandler();
$ImageDb->setTableName(TABLE_PREFIX . 'news_images');
$ImageDb->setScope(0,1);
if($id != null)
{
// Get News item by id
$Db->addRule('id',$id);
$first = $Db->select();
// Get Other three newest items
$Db->clearRule();
$Db->addRule('active',1);
$Db->addRule('id',$id, 'AND NOT');
$Db->setScope(0,3);
$other = $Db->select();
$other = $Db->twoDimensional($other);
// Get images
$ImageDb->addRule('itemId',$id);
$image = $ImageDb->select();
}
else
{
// Get Last News item
$Db->setScope(0,4);
$result = $Db->select();
$result = $Db->twoDimensional($result);
$first = $result[0];
unset($result[0]);
// Get images
$ImageDb->addRule('itemId',$first['id']);
$image = $ImageDb->select();
// Other three newest items
$other = array_values($result);
}
return array($first,$other,$image);
}
/*
* Get ID by a title in the url
*/
function getId($urlTitle)
{
$id = false;
$news = $this->get();
$first = array($news[0]);
$other = $news[1];
$items = array_merge($first,$other);
foreach($items as $item)
{
if($this->Functions->encodeUrl($item['title']) == $urlTitle)
{
$id = $item['id'];
}
}
return $id;
}
/*
* Create other news blocks
*/
public function createNewsBlocks($items)
{
$output = '';
$Functions = new Functions();
foreach($items as $key => $item)
{
$key % 2 == 0 ? $alt = ' alt' : $alt = '';
$date = date('d / m / Y',$item['date']);
$linkTitle = $Functions->encodeUrl($item['title']);
URL_LANG == 'nl' ? $title = $item['title'] : $title = $item['title_en'];
if(empty($title)) $title = $item['title'];
$output .= '<div class="news_holder' . $alt . '">
<div class="hover">
<div class="text respH">
<div class="icon sprite"></div>
<span class="title"><a href="' . LANG_ROOT . $this->_urls['news'] . '/' . $linkTitle . '">' . $title . '</a></span>
<span class="posted">' . $this->_lang['posted'] . '</span>
<span class="date">- ' . $date . ' -</span>
</div>
<div class="bg"></div>
</div>
</div>';
}
return $output;
}
}