<?php 

namespace app\models;

class Kdrama extends \lithium\data\Model {
	protected $_meta = array('key' => '_id', 'source' => 'kdrama', 'connection' => 'mongo');

	public static function search($query, $page = 1, $by = 'title') 
	{
		$defaults = array('limit' => 20);
		$limit = 20;

		switch($by) {
			case 'special_id':
			
			$content = parent::find('first',
				array('conditions' => array(
						$by => $query
					),
					'limit' => $limit,
					'page' => $page
				));


		
			$total = parent::count(array($by => $query)); 
			break;
			
			default:
			$content = parent::find('all',
				array('conditions' => array(
						$by => array('like' => $query)
					),
					'limit' => $limit,
					'page' => $page
				));
				$total = parent::count(array($by => array('like' => $query)));
	}
	return compact('content', 'by', 'limit', 'total', 'page');
	}
}