Files
luos/workflow/engine/services/rest/crud/AppOwner.php
2012-10-05 17:27:46 -04:00

138 lines
4.4 KiB
PHP

<?php
class Services_Rest_AppOwner
{
/**
* Implementation for 'GET' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @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($appUid=null, $ownUid=null, $usrUid=null)
{
$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');
$criteria->addSelectColumn(AppOwnerPeer::APP_UID);
$criteria->addSelectColumn(AppOwnerPeer::OWN_UID);
$criteria->addSelectColumn(AppOwnerPeer::USR_UID);
$dataset = AppEventPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($dataset->next()) {
$result[] = $dataset->getRow();
}
} else {
$record = AppOwnerPeer::retrieveByPK($appUid, $ownUid, $usrUid);
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 AppOwner ($paramValues)" );
}
}
} catch (RestException $e) {
throw new RestException($e->getCode(), $e->getMessage());
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
return $result;
}
/**
* Implementation for 'POST' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @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 post($appUid, $ownUid, $usrUid)
{
try {
$result = array();
$obj = new AppOwner();
$obj->setAppUid($appUid);
$obj->setOwnUid($ownUid);
$obj->setUsrUid($usrUid);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'PUT' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @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 put($appUid, $ownUid, $usrUid)
{
try {
$obj = AppOwnerPeer::retrieveByPK($appUid, $ownUid, $usrUid);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'DELETE' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @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 delete($appUid, $ownUid, $usrUid)
{
$conn = Propel::getConnection(AppOwnerPeer::DATABASE_NAME);
try {
$conn->begin();
$obj = AppOwnerPeer::retrieveByPK($appUid, $ownUid, $usrUid);
if (! is_object($obj)) {
throw new RestException(412, 'Record does not exist.');
}
$obj->delete();
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw new RestException(412, $e->getMessage());
}
}
}