57 lines
2.1 KiB
Smarty
57 lines
2.1 KiB
Smarty
/**
|
|
* Implementation for 'GET' method for Rest API
|
|
*
|
|
{% for pk in primaryKeys %}* @param mixed {{ pk }} Primary key
|
|
{% endfor %}*
|
|
* @return array $result Returns array within multiple records or a single record depending if
|
|
* a single selection was requested passing id(s) as param
|
|
*/
|
|
protected function get({{ paramsStr }})
|
|
{
|
|
$result = array();
|
|
try {
|
|
$noArguments = true;
|
|
$argumentList = func_get_args();
|
|
foreach ($argumentList as $arg) {
|
|
if (!is_null($arg)) {
|
|
$noArguments = false;
|
|
}
|
|
}
|
|
|
|
if ($noArguments) {
|
|
$criteria = new Criteria('workflow');
|
|
|
|
{% for column in columns %}$criteria->addSelectColumn({{ classname }}Peer::{{column}});
|
|
{% endfor %}
|
|
$dataset = AppEventPeer::doSelectRS($criteria);
|
|
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
while ($dataset->next()) {
|
|
$result[] = $dataset->getRow();
|
|
}
|
|
} else {
|
|
$record = {{ classname }}Peer::retrieveByPK({{ primaryKeys }});
|
|
if ($record) {
|
|
$result = $record->toArray(BasePeer::TYPE_FIELDNAME);
|
|
} else {
|
|
$paramValues = "";
|
|
foreach ($argumentList as $arg) {
|
|
$paramValues .= (strlen($paramValues) ) ? ', ' : '';
|
|
if (!is_null($arg)) {
|
|
$paramValues .= "$arg";
|
|
} else {
|
|
$paramValues .= "NULL";
|
|
}
|
|
}
|
|
throw new RestException(417, "table {{ classname }} ($paramValues)" );
|
|
}
|
|
}
|
|
} catch (RestException $e) {
|
|
throw new RestException($e->getCode(), $e->getMessage());
|
|
} catch (Exception $e) {
|
|
throw new RestException(412, $e->getMessage());
|
|
}
|
|
|
|
return $result;
|
|
}
|