<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/



class lc_album_albums
{
	var $page=1;
	var $total=0;
	var $items_at_page=10;
	public $pager=array();
	
	public function getList($page)
	{
		if ($page) $this->page=$page;
		if (!$this->total) $this->total=Db::i()->selectCell("SELECT COUNT(album_id) FROM ".config::get('table_albums'));
		if ($this->total) {
			$result=array();
			$albums=Db::i()->select(
				"SELECT * FROM ".config::get('table_albums')."
				ORDER BY sort
				LIMIT ?d, ?d", $this->_getStart(), $this->items_at_page
			);
			if ($albums) foreach ($albums as $key=>$album) {
				$result[$key]=Factory::create('lc_album.album');
				$result[$key]->set($album);
			}
			return $result;
		}
	}
	
	public function getAll()
	{
		return Db::i()->selectCol("SELECT album_id AS ARRAY_KEY, name FROM ".config::get('table_albums'));
	}
	
	protected function _getStart()
	{
		$pg=Factory::create('Paginator', $this->total, $this->items_at_page, $this->page);
		$this->pager=$pg->getPages();
		$this->page=$this->pager['current'];
		return $this->pager['sql_start'];
	}
}