public function setSource($model, $table)
{
if (!is_array($table)) {
throw $this->exception('Wrong type: expected array')->addMoreInfo('source', $table);
}
if (!$model->hasMethod('push')) {
$model->addMethod('push', $this);
}
// convert single dimension arrays
reset($table);
list(, $firstrow) = each($table);
if (!is_array($firstrow)) {
// assuming that this array needs to be converted
foreach ($table as $key => &$name) {
$name = array($model->id_field => $key, $model->title_field => $name);
}
return parent::setSource($model, $table);
}
$data = array();
foreach ($table as $key => $row) {
$id = isset($row[$model->id_field]) ? $row[$model->id_field] : $key;
$data[$id] = $row;
}
return parent::setSource($model, $data);
}