你怎么看这段代码?最好只编写一个方法 getByPoint() 并传递一个进一步的字符串参数'open','close'?
否则包装函数 getOpenedByPoint() 和 getClosedByPoint() 是否合理?
谢谢你的回答;)
/**
* Get all opened verbals, not cancelled, for a point
* @param type $point_id
* @return array
*/
public function getOpenedByPoint($point_id = null)
{
$conditions = array('Verbal.cancelled' => 0, 'Verbal.close' => 0);
return $this->getByPoint($point_id, $conditions);
}
/**
* Get all closed verbals, not cancelled, for a point
* @param type $point_id
* @return array
*/
public function getClosedByPoint($point_id = null)
{
$conditions = array('Verbal.cancelled' => 0, 'Verbal.close' => 1);
return $this->getByPoint($point_id, $conditions);
}
/**
* Get all verbals for a point
* @param type $point_id
* @return array
*/
public function getByPoint($point_id = null, $conditions = array())
{
if($point_id) {
$conditions = Hash::merge(array('Verbal.point_id' => $point_id), $conditions);
return $this->find('all', array(
'contain' => array('Driver','Car'),
'fields' => array('Verbal.number','Verbal.year','Verbal.data_out','Driver.cognome','Driver.nome','Car.model','Car.plate'),
'conditions' => $conditions,
'order' => array('Verbal.data_out' => 'ASC')
));
}
return array();
}