Cambio de metodo en change position en STEPS

This commit is contained in:
Brayan Osmar Pereyra Suxo
2014-02-24 11:20:35 -04:00
parent eb83f4ae4b
commit eed4d9ff36
4 changed files with 132 additions and 109 deletions

View File

@@ -13,9 +13,11 @@ Feature: Reorder Steps
Given that I have a valid access_token
And PUT this data:
"""
{}
{
"step_position": "3"
}
"""
And I request "project/98002714453076320a06cb4009450121/activity/8251872975307632a765f34007266075/step-move/285219904530763bb5c4367074373078/3"
And I request "project/98002714453076320a06cb4009450121/activity/8251872975307632a765f34007266075/step/285219904530763bb5c4367074373078"
Then the response status code should be 200
Scenario: List all the Sub Processs (result 0 Sub Processs)
@@ -30,9 +32,11 @@ Feature: Reorder Steps
Given that I have a valid access_token
And PUT this data:
"""
{}
{
"step_position": "1"
}
"""
And I request "project/98002714453076320a06cb4009450121/activity/8251872975307632a765f34007266075/step-move/285219904530763bb5c4367074373078/1"
And I request "project/98002714453076320a06cb4009450121/activity/8251872975307632a765f34007266075/step/285219904530763bb5c4367074373078"
Then the response status code should be 200
Scenario: List all the Sub Processs (result 0 Sub Processs)

View File

@@ -373,6 +373,7 @@ class Step
$arrayStepData = $step->load($stepUid);
$taskUid = $arrayStepData["TAS_UID"];
$proUid = $arrayStepData["PRO_UID"];
//Verify data
if (isset($arrayData["STEP_TYPE_OBJ"]) && !isset($arrayData["STEP_UID_OBJ"])) {
@@ -427,8 +428,8 @@ class Step
}
}
if (isset($arrayData["STEP_POSITION"]) && $this->existsRecord($taskUid, "", "", $arrayData["STEP_POSITION"], $stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["STEP_POSITION"], $taskUid . ", " . $arrayData["STEP_POSITION"], "STEP"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
if (isset($arrayData["STEP_POSITION"]) && ($arrayData["STEP_POSITION"] != $arrayStepData["STEP_POSITION"])) {
$this->moveSteps($proUid, $taskUid, $stepUid, $arrayData["STEP_POSITION"]);
}
//Update
@@ -488,6 +489,51 @@ class Step
}
}
/**
* Get all Steps of a Task
*
* @param string $taskUid Unique id of Task
*
* return array Return an array with all Steps of a Task
*/
public function getSteps($taskUid)
{
try {
$arrayStep = array();
$step = new \BusinessModel\Step();
$step->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$step->setArrayParamException($this->arrayParamException);
//Verify data
$this->throwExceptionIfNoExistsTask($taskUid);
//Get data
$criteria = new \Criteria("workflow");
$criteria->add(\StepPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
$criteria->addAscendingOrderByColumn(\StepPeer::STEP_POSITION);
$rsCriteria = \StepPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayData = $step->getStep($row["STEP_UID"]);
if (count($arrayData) > 0) {
$arrayStep[] = $arrayData;
}
}
//Return
return $arrayStep;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Step
*
@@ -803,5 +849,81 @@ class Step
throw $e;
}
}
/**
* Validate Process Uid
* @var string $pro_uid. Uid for Process
* @var string $tas_uid. Uid for Task
* @var string $step_uid. Uid for Step
* @var string $step_pos. Position for Step
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function moveSteps($pro_uid, $tas_uid, $step_uid, $step_pos) {
$this->setFormatFieldNameInUppercase(false);
$this->setArrayParamException(array("taskUid" => "act_uid"));
$aSteps = $this->getSteps($tas_uid);
foreach ($aSteps as $dataStep) {
if ($dataStep['step_uid'] == $step_uid) {
$prStepPos = (int)$dataStep['step_position'];
}
}
$seStepPos = $step_pos;
//Principal Step is up
if ($prStepPos < $seStepPos) {
$modPos = 'UP';
$newPos = $seStepPos;
$iniPos = $prStepPos+1;
$finPos = $seStepPos;
} else {
$modPos = 'DOWN';
$newPos = $seStepPos;
$iniPos = $seStepPos;
$finPos = $prStepPos-1;
}
$range = range($iniPos, $finPos);
foreach ($aSteps as $dataStep) {
if ((in_array($dataStep['step_position'], $range)) && ($dataStep['step_uid'] != $step_uid)) {
$stepChangeIds[] = $dataStep['step_uid'];
$stepChangePos[] = $dataStep['step_position'];
}
}
foreach ($stepChangeIds as $key => $value) {
if ($modPos == 'UP') {
$tempPos = ((int)$stepChangePos[$key])-1;
$this->changePosStep($value, $tempPos);
} else {
$tempPos = ((int)$stepChangePos[$key])+1;
$this->changePosStep($value, $tempPos);
}
}
$this->changePosStep($step_uid, $newPos);
}
/**
* Validate Process Uid
* @var string $pro_uid. Uid for process
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return string
*/
public function changePosStep ($step_uid, $pos)
{
$data = array(
'STEP_UID' => $step_uid,
'STEP_POSITION' => $pos
);
$oStep = new \Step();
$oStep->update($data);
}
}

View File

@@ -1854,85 +1854,6 @@ class Task
}
}
/**
* Validate Process Uid
* @var string $pro_uid. Uid for Process
* @var string $tas_uid. Uid for Task
* @var string $step_uid. Uid for Step
* @var string $step_pos. Position for Step
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function moveSteps($pro_uid, $tas_uid, $step_uid, $step_pos) {
$pro_uid = $this->validateProUid($pro_uid);
$tas_uid = $this->validateActUid($tas_uid);
$this->setFormatFieldNameInUppercase(false);
$this->setArrayParamException(array("taskUid" => "act_uid"));
$aSteps = $this->getSteps($tas_uid);
foreach ($aSteps as $dataStep) {
if ($dataStep['step_uid'] == $step_uid) {
$prStepPos = (int)$dataStep['step_position'];
}
}
$seStepPos = $step_pos;
//Principal Step is up
if ($prStepPos < $seStepPos) {
$modPos = 'UP';
$newPos = $seStepPos;
$iniPos = $prStepPos+1;
$finPos = $seStepPos;
} else {
$modPos = 'DOWN';
$newPos = $seStepPos;
$iniPos = $seStepPos;
$finPos = $prStepPos-1;
}
$range = range($iniPos, $finPos);
foreach ($aSteps as $dataStep) {
if ((in_array($dataStep['step_position'], $range)) && ($dataStep['step_uid'] != $step_uid)) {
$stepChangeIds[] = $dataStep['step_uid'];
$stepChangePos[] = $dataStep['step_position'];
}
}
foreach ($stepChangeIds as $key => $value) {
if ($modPos == 'UP') {
$tempPos = ((int)$stepChangePos[$key])-1;
$this->changePosStep($value, $tempPos);
} else {
$tempPos = ((int)$stepChangePos[$key])+1;
$this->changePosStep($value, $tempPos);
}
}
$this->changePosStep($step_uid, $newPos);
}
/**
* Validate Process Uid
* @var string $pro_uid. Uid for process
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return string
*/
public function changePosStep ($step_uid, $pos)
{
$data = array(
'STEP_UID' => $step_uid,
'STEP_POSITION' => $pos
);
$oStep = new \Step();
$oStep->update($data);
}
/**
* Validate Process Uid
* @var string $pro_uid. Uid for process

View File

@@ -146,30 +146,6 @@ class Activity extends Api
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $prj_uid {@min 1} {@max 32}
* @param string $act_uid {@min 1} {@max 32}
* @param string $step_uid {@min 1} {@max 32}
* @param string $step_pos
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*
* @url PUT /:prj_uid/activity/:act_uid/step-move/:step_uid/:step_pos
*/
public function doPutStepsMoves ($prj_uid, $act_uid, $step_uid, $step_pos)
{
try {
$task = new \BusinessModel\Task();
$task->moveSteps($prj_uid, $act_uid, $step_uid, $step_pos);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}