2012-08-20 18:33:25 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class Services_Rest_Translation
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Implementation for 'GET' method for Rest API
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $trnCategory, $trnId, $trnLang 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($trnCategory=null, $trnId=null, $trnLang=null)
|
|
|
|
|
{
|
|
|
|
|
$result = array();
|
|
|
|
|
try {
|
2012-09-24 15:09:48 -04:00
|
|
|
$noArguments = true;
|
|
|
|
|
$argumentList = func_get_args();
|
|
|
|
|
foreach ($argumentList as $arg) {
|
|
|
|
|
if (!is_null($arg)) {
|
|
|
|
|
$noArguments = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($noArguments) {
|
2012-08-20 18:33:25 -04:00
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(TranslationPeer::TRN_CATEGORY);
|
|
|
|
|
$criteria->addSelectColumn(TranslationPeer::TRN_ID);
|
|
|
|
|
$criteria->addSelectColumn(TranslationPeer::TRN_LANG);
|
|
|
|
|
$criteria->addSelectColumn(TranslationPeer::TRN_VALUE);
|
|
|
|
|
$criteria->addSelectColumn(TranslationPeer::TRN_UPDATE_DATE);
|
2013-03-14 15:15:04 -04:00
|
|
|
|
2012-08-20 18:33:25 -04:00
|
|
|
$dataset = AppEventPeer::doSelectRS($criteria);
|
|
|
|
|
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
while ($dataset->next()) {
|
|
|
|
|
$result[] = $dataset->getRow();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$record = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
|
2012-09-24 15:09:48 -04:00
|
|
|
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 Translation ($paramValues)" );
|
|
|
|
|
}
|
2012-08-20 18:33:25 -04:00
|
|
|
}
|
2012-09-24 15:09:48 -04:00
|
|
|
} catch (RestException $e) {
|
|
|
|
|
throw new RestException($e->getCode(), $e->getMessage());
|
2012-08-20 18:33:25 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw new RestException(412, $e->getMessage());
|
|
|
|
|
}
|
2012-09-24 15:09:48 -04:00
|
|
|
|
2012-08-20 18:33:25 -04:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 17:27:46 -04:00
|
|
|
/**
|
|
|
|
|
* Implementation for 'POST' method for Rest API
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $trnCategory, $trnId, $trnLang 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($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$result = array();
|
|
|
|
|
$obj = new Translation();
|
|
|
|
|
|
|
|
|
|
$obj->setTrnCategory($trnCategory);
|
|
|
|
|
$obj->setTrnId($trnId);
|
|
|
|
|
$obj->setTrnLang($trnLang);
|
|
|
|
|
$obj->setTrnValue($trnValue);
|
|
|
|
|
$obj->setTrnUpdateDate($trnUpdateDate);
|
2013-03-14 15:15:04 -04:00
|
|
|
|
2012-10-05 17:27:46 -04:00
|
|
|
$obj->save();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw new RestException(412, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implementation for 'PUT' method for Rest API
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $trnCategory, $trnId, $trnLang 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($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$obj = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
|
|
|
|
|
|
|
|
|
|
$obj->setTrnValue($trnValue);
|
|
|
|
|
$obj->setTrnUpdateDate($trnUpdateDate);
|
2013-03-14 15:15:04 -04:00
|
|
|
|
2012-10-05 17:27:46 -04:00
|
|
|
$obj->save();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw new RestException(412, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implementation for 'DELETE' method for Rest API
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $trnCategory, $trnId, $trnLang 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($trnCategory, $trnId, $trnLang)
|
|
|
|
|
{
|
|
|
|
|
$conn = Propel::getConnection(TranslationPeer::DATABASE_NAME);
|
2013-03-14 15:15:04 -04:00
|
|
|
|
2012-10-05 17:27:46 -04:00
|
|
|
try {
|
|
|
|
|
$conn->begin();
|
2013-03-14 15:15:04 -04:00
|
|
|
|
2012-10-05 17:27:46 -04:00
|
|
|
$obj = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
|
|
|
|
|
if (! is_object($obj)) {
|
2013-03-14 15:15:04 -04:00
|
|
|
throw new RestException(412, G::LoadTranslation('ID_RECORD_DOES_NOT_EXIST'));
|
2012-10-05 17:27:46 -04:00
|
|
|
}
|
|
|
|
|
$obj->delete();
|
2013-03-14 15:15:04 -04:00
|
|
|
|
2012-10-05 17:27:46 -04:00
|
|
|
$conn->commit();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$conn->rollback();
|
|
|
|
|
throw new RestException(412, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 18:33:25 -04:00
|
|
|
|
|
|
|
|
}
|