<?php

App::uses('Model', 'Model');

/**
 * Application model for Cake.
 *
 * Add your application-wide methods in the class below, your models
 * will inherit them.
 *
 * @package       app.Model
 */

class Region extends AppModel {
	
	public function getList($division_id=NULL){
        $conditions = array();
	    if(!empty($division_id)){
            $divisionRegion=  ClassRegistry::init('DivisionsRegion');
            $rIds = $divisionRegion->find('list', array('fields'=>array('region_id'),'conditions'=>array('division_id'=>$division_id)));
            return $this->find('list', array('fields'=>array('id','title'),'conditions' => array('id' =>$rIds), 'order'=>array('title'=>'asc')));
        }else{
            return $this->find('list', array( 'fields'=>array('id', 'title'),'conditions'=>$conditions, 'order'=>array('title'=>'asc')));
        }
	}

}