Adding more rest end points and finishing the save load configuration feature.

This commit is contained in:
Gustavo Cruz
2015-03-02 17:42:19 -04:00
parent 92245527cf
commit c7208a6463
5 changed files with 84 additions and 19 deletions

View File

@@ -345,7 +345,7 @@ class WebApplication
foreach ($featureApiClassList as $classFile) { foreach ($featureApiClassList as $classFile) {
if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') { if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') {
$relClassPath = str_replace('.php', '', str_replace($servicesDir, '', $classFile)); $relClassPath = str_replace('.php', '', str_replace($servicesDir, '', $classFile));
$namespace = '\\ProcessMaker\\Services\\Api\\'.basename($classFile, '.php'); $namespace = '\\ProcessMaker\\Services\\Api\\' . basename($classFile, '.php');
$namespace = strpos($namespace, "//") === false? $namespace: str_replace("//", '', $namespace); $namespace = strpos($namespace, "//") === false? $namespace: str_replace("//", '', $namespace);
require_once $classFile; require_once $classFile;
$this->rest->addAPIClass($namespace); $this->rest->addAPIClass($namespace);

View File

@@ -12,10 +12,42 @@ class ActionsByEmailService
case 'configuration': case 'configuration':
require_once 'classes/model/AbeConfiguration.php'; require_once 'classes/model/AbeConfiguration.php';
$abeConfigurationInstance = new \AbeConfiguration(); $abeConfigurationInstance = new \AbeConfiguration();
$noteValues = json_decode($params['fields']['ABE_CASE_NOTE_IN_RESPONSE']);
foreach ($noteValues as $value) {
$params['fields']['ABE_CASE_NOTE_IN_RESPONSE'] = $value;
}
$abeConfigurationInstance->createOrUpdate($params['fields']); $abeConfigurationInstance->createOrUpdate($params['fields']);
break; break;
default: default:
break; break;
} }
} }
public function loadConfiguration($params)
{
if ($params['type'] != 'activity') {
return NULL;
}
set_include_path(PATH_FEATURES . 'ActionsByEmail' . PATH_SEPARATOR . get_include_path());
require_once 'classes/model/AbeConfiguration.php';
$criteria = new \Criteria();
$criteria->add(\AbeConfigurationPeer::PRO_UID, $params['PRO_UID']);
$criteria->add(\AbeConfigurationPeer::TAS_UID, $params['TAS_UID']);
$result = \AbeConfigurationPeer::doSelectRS($criteria);
$result->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$result->next();
$configuration = array();
if ($configuration = $result->getRow()) {
$configuration['ABE_EMAIL_FIELD_VALUE'] = $configuration['ABE_EMAIL_FIELD'];
$configuration['ABE_ACTION_FIELD_VALUE'] = $configuration['ABE_ACTION_FIELD'];
$configuration['ABE_CASE_NOTE_IN_RESPONSE'] = $configuration['ABE_CASE_NOTE_IN_RESPONSE'] ? '["1"]' : '[]';
}
$configuration['feature'] = 'ActionsByEmail';
$configuration['prefix'] = 'abe';
$configuration['PRO_UID'] = $params['PRO_UID'];
$configuration['TAS_UID'] = $params['TAS_UID'];
$configuration['SYS_LANG'] = SYS_LANG;
return $configuration;
}
} }

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace Features\ActionsByEmail\Services; namespace ProcessMaker\Services\Api;
use \ProcessMaker\Services\Api; use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException; use \Luracast\Restler\RestException;
@@ -13,12 +13,12 @@ require_once 'classes/model/Application.php';
require_once 'classes/model/Users.php'; require_once 'classes/model/Users.php';
/** /**
* Class ActionsByEmailApi * Class ActionsByEmail
* *
* @author gustavo cruz <gustavo.cruz@colosa.com> * @author gustavo cruz <gustavo.cruz@colosa.com>
* @protected * @protected
*/ */
class ActionsByEmailApi extends Api class ActionsByEmail extends Api
{ {
/** /**
@@ -515,5 +515,35 @@ class ActionsByEmailApi extends Api
} }
return $message; return $message;
} }
/**
*
* @url GET /Templates/:proId
*/
public function getTemplates($proId)
{
$templates = array();
$path = PATH_DATA_MAILTEMPLATES . $proId . PATH_SEP;
\G::verifyPath($path, true);
if (defined('PARTNER_FLAG')) {
if (!file_exists($path . 'actionsByEmailPartner.html')) {
@copy(PATH_FEATURES . 'ActionsByEmail' . PATH_SEP . 'data' . PATH_SEP . 'actionsByEmailPartner.html', $path . 'actionsByEmail.html');
}
} else {
if (!file_exists($path . 'actionsByEmail.html')) {
@copy(PATH_FEATURES . 'ActionsByEmail' . PATH_SEP . 'data' . PATH_SEP . 'actionsByEmail.html', $path . 'actionsByEmail.html');
}
}
$directory = dir($path);
while ($object = $directory->read()) {
if (($object !== '.') && ($object !== '..') && ($object !== 'alert_message.html')) {
$templates[] = array('FILE' => $object, 'NAME' => $object);
}
}
return $templates;
}
} }

View File

@@ -13,14 +13,17 @@ class FeaturesHandler
} }
} }
public function retrieveConfiguration($params) public function loadConfiguration($params)
{ {
foreach ($this->getFeatureList() as $feature) { $features = $this->getFeatureList();
foreach ($features as $feature) {
$service = $this->getFeatureService(array('name' => $feature->name));
$configurations[] = $service->loadConfiguration($params);
} }
return array_filter($configurations);
} }
public function saveConfiguration($type, $configurationForms) public function saveConfiguration($configurationForms)
{ {
foreach ($configurationForms as $feature => $form) { foreach ($configurationForms as $feature => $form) {
$service = $this->getFeatureService(array('name' => $feature)); $service = $this->getFeatureService(array('name' => $feature));

View File

@@ -61,25 +61,25 @@ class Activity extends Api
} }
/** /**
* @param string $prj_uid {@min 32} {@max 32} * @param string $pro_uid {@min 32} {@max 32}
* @param string $act_uid {@min 32} {@max 32} * @param string $tas_uid {@min 32} {@max 32}
* @param string $filter {@choice definition,,properties} * @param string $filter {@choice definition,,properties}
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Gustavo Cruz <gustavo.cruz@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
* @return array * @return array
* *
* @url GET /:prj_uid/activity/:act_uid/feature-configuration * @url GET /:pro_uid/activity/:tas_uid/feature-configuration
*/ */
public function doGetProjectActivityFeatureConfiguration($prj_uid, $act_uid, $filter = '') public function doGetProjectActivityFeatureConfiguration($pro_uid, $tas_uid, $filter = '')
{ {
try { try {
$featureServices = new \Features\FeatureServices(); $featureHandler = new \Features\FeaturesHandler();
$configuration = $featureServices->retrieveView(array( $configuration = $featureHandler->loadConfiguration(array(
'type' => 'activity', 'type' => 'activity',
'view' => 'configuration', 'form' => 'configuration',
'prj_uid' => $prj_uid, 'PRO_UID' => $pro_uid,
'act_uid' => $act_uid 'TAS_UID' => $tas_uid
)); ));
return $configuration; return $configuration;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -108,7 +108,7 @@ class Activity extends Api
$properties = $task->updateProperties($prj_uid, $act_uid, $request_data); $properties = $task->updateProperties($prj_uid, $act_uid, $request_data);
/** features */ /** features */
$featureHandler = new \Features\FeaturesHandler(); $featureHandler = new \Features\FeaturesHandler();
$featureHandler->saveConfiguration('activity', $request_data['properties']['_features']); $featureHandler->saveConfiguration($request_data['properties']['_features']);
/** features */ /** features */
} catch (\Exception $e) { } catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());