<?php
/*
 * @version			$Id: index.php 10381 2008-06-01 03:35:53Z $
 * @package			Carteasy
 * @copyright		Copyright (C) 2005 - 2011 Wlanium
 * @license			proprietary
 * @author			Thomas Bartelt
 * Carteasy is a web shop system
 */

class Vendors_List {

	private $base_object;
	private $db;

	public function __construct($base_object) {
		$this->base_object = $base_object;
		$this->db = $base_object->db;
	} // end __construct

	public function get_number_of_pages($items, $filter = false) {
		$sql = 'SELECT * FROM herstellerinformationen';

		$result = $this->db->query($sql);

		return (int)ceil($result->num_rows / $items);
	} // end get_number_of_pages

	public function get_pagination_array($items, $page, $filter = false) {
		$sql = 'SELECT * FROM herstellerinformationen';

		$result = $this->db->query($sql);

		$num = $result->num_rows;

		$pages = (int)ceil($num / $items);

		while ($i < $pages) {
			$data[] = ++$i;
		}

		if ($pages > 10) {
			if ($page <= 5) {
				$data = array_slice($data, 0, 10);
			} else if ($page > ($pages - 4)) {
				$data = array_slice($data, $pages-10, 10);
			} else {
				$data = array_slice($data, $page -5, 10);
			}
		}

		return $data;
	} // end get_pagination_array

	public function get_all_paginated($items, $page, $sortation, $sortation_direction, $filter = false) {
		$sql = 'SELECT * FROM herstellerinformationen';

		if ($sortation) {
			$sql .= ' ORDER BY ' . $sortation . ' ' . $sortation_direction;
		} else {
			$sql .= ' ORDER BY hersteller_name ASC';
		}

		$sql .= ' LIMIT ' . ($page - 1) * $items . ', ' . $items;

		$result = $this->db->query($sql);

		$data = array();
		while ($row = $result->fetch_object()) {
			$data[$row->hersteller_id] = $row;
		}

		return $data;
	} // end get_all_paginated

} // end Vendors_List

/* EOF */