File: D:/HostingSpaces/SBogers64/klimroosbudel.nl/wwwroot/kms/lib/ui/item_list.class.php
<?php
/**
* item_list.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 4/11/13
*/
class Item_List
{
private $_name = '';
/*
* Data which can be displayed in the list.
*/
private $_items = [];
/*
* Does a list have actions
*/
private $_editable = true;
/*
* Recover button
*/
private $_recover;
/*
* Language
*/
private $_lang;
private $_urls;
/*
* Construct
*/
public function __construct()
{
if (defined('URL_LANG')) {
$LanguageHandler = new LanguageHandler();
$LanguageHandler->set(URL_LANG);
$this->_lang = $LanguageHandler->get();
$this->_urls = $LanguageHandler->getUrls();
if (defined('URL_PAGE')) {
$this->_name = $LanguageHandler->convert(URL_PAGE);
}
}
}
/*
* Set item list
* @param array
*/
public function set($prop, $val)
{
if (! empty($prop)) {
$this->{$prop} = $val;
}
}
/*
* Set item list
* @param array
*/
public function setItems($data)
{
if (is_array($data)) {
$this->_items = $data;
}
}
/*
* Add an item to the list
* @param array
*/
public function addItem($data)
{
if (is_array($data)) {
$this->_items[] = $data;
}
}
/*
* Display the list
*/
public function display()
{
$output = $this->_lang['no_items_found'];
if (count($this->_items) > 0) {
$output = '';
foreach ($this->_items as $key => $item) {
// Open list
$output .= '<li';
if ($key % 2 == 0) {
$output .= ' class="alt"';
}
$output .= '>';
// Thumbnail
$output .= '<span class="thumb">';
if (isset($item['images'])) {
if (isset($item['thumb'])) {
$thumb = $item['images'][$item['thumb']];
} else {
$thumb = $item['images'][key($item['images'])];
}
$output .= '<img src="'.UPLOADS_ROOT.$thumb['kms_thumb'].'" alt="'.$item['title'].'" />';
} elseif (isset($item['videos'])) {
$firstVideo = $item['videos'][key($item['videos'])];
list($w, $h) = getimagesize('http://img.youtube.com/vi/'.$firstVideo['youtube_id'].'/0.jpg');
$ratio = $w / $h;
if ($w > $h) {
$size = 'height:90px;';
$h = 90;
$w = 90 * $ratio;
} else {
$size = 'width:90px;';
$w = 90;
$h = 90 / $ratio;
}
$mt = $h / -2;
$ml = $w / -2;
$output .= '<img src="http://img.youtube.com/vi/'.$firstVideo['youtube_id'].'/0.jpg" alt="'.$item['title'].'" class="video" style="margin-top: '.$mt.'px;margin-left:'.$ml.'px;'.$size.'"/>';
}
$output .= '</span>';
// Information
$output .= '<span class="info">';
// Checkbox
if ($this->_editable) {
$output .= '<span class="cb">';
$output .= '<input type="checkbox" name="items[]" value="'.$item['id'].'" />';
$output .= '</span>';
}
// Title
$title = $item['title'];
$tLength = 60;
if (strlen($title) > $tLength) {
$title = substr($title, 0, ($tLength - 3)).'…';
}
$output .= '<span class="title"><a href="'.LANG_ROOT.URL_PAGE.'/'.$this->_urls['editItem'].'/'.$item['id'].'/">'.ucfirst($title).'</a></span><br />';
if (isset($item['location'])) {
// Date
$output .= '<span class="location">'.$item['location'].'</span>';
}
/*
if(isset($item['timest']))
{
$date = date('d / m / Y',$item['timest']);
// Date
$output .= '<span class="date">' . $date . '</span>';
}
*/
$output .= '</span>';
// Actions
if ($this->_editable) {
$output .= '<span class="action">';
$output .= '<a href="'.LANG_ROOT.URL_PAGE.'/'.$this->_urls['editItem'].'/'.$item['id'].'/">'.$this->_lang['edit'].'</a>';
if (URL_PAGE != 'home' && $this->_name != 'photo_sliders') {
$output .= '<a href="'.LANG_ROOT.URL_PAGE.'/'.$this->_urls['removeItem'].'/'.$item['id'].'/">'.$this->_lang['remove'].'</a>';
}
$output .= '</span>';
}
// Recover (for trash)
if ($this->_recover) {
$output .= '<span class="action">';
$output .= '<a href="'.LANG_ROOT.$this->_urls['trash'].'/recover/'.$item['trash_id'].'/">'.$this->_lang['recover'].'</a>';
$output .= '</span>';
}
$output .= '</li>';
}
}
return $output;
}
}