From 287b60c46843516b043e02e5c3d249dfa1d375d8 Mon Sep 17 00:00:00 2001 From: Brayan Osmar Pereyra Suxo Date: Thu, 20 Feb 2014 16:30:08 -0400 Subject: [PATCH 1/2] Logica para drag de steps en una tarea --- workflow/engine/src/BusinessModel/Task.php | 72 +++++++++++++++++++ .../Api/ProcessMaker/Project/Activity.php | 25 +++++++ 2 files changed, 97 insertions(+) diff --git a/workflow/engine/src/BusinessModel/Task.php b/workflow/engine/src/BusinessModel/Task.php index a3d71488c..e6e21fa17 100644 --- a/workflow/engine/src/BusinessModel/Task.php +++ b/workflow/engine/src/BusinessModel/Task.php @@ -1891,6 +1891,78 @@ 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_uid_rel. Uid Step for relation + * @var string $type. Type relation + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return void + */ + public function moveSteps($pro_uid, $tas_uid, $step_uid, $step_uid_rel, $type) { + $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']; + } elseif ($dataStep['step_uid'] == $step_uid_rel) { + $seStepPos = (int)$dataStep['step_position']; + } + } + + //Principal Step is up + if ($prStepPos < $seStepPos) { + $modPos = 'UP'; + if ($type == 'DOWN') { + $newPos = $seStepPos; + $iniPos = $prStepPos+1; + $finPos = $seStepPos; + } else { + $newPos = $seStepPos-1; + $iniPos = $prStepPos+1; + $finPos = $seStepPos-1; + } + } else { + $modPos = 'DOWN'; + if ($type == 'UP') { + $newPos = $seStepPos; + $iniPos = $seStepPos; + $finPos = $prStepPos-1; + } else { + $newPos = $seStepPos-1; + $iniPos = $seStepPos-1; + $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']; + } + } + + foreach ($stepChangeIds as $value) { + if ($modPos == 'UP') { + G::pr("Cambiar el step $value por un pos mas bajo"); + } else { + G::pr("Cambiar el step $value por un pos mas alto"); + } + } + G::pr("Cambiar el step $step_uid por un pos $newPos"); + die; + } + /** * Validate Process Uid * @var string $pro_uid. Uid for process diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php index 20cc2daed..a70d7015a 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php @@ -147,6 +147,31 @@ 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_uid_rel {@min 1} {@max 32} + * @param string $type_change {@choice UP,DOWN} + * + * @access public + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return void + * + * @url GET /:prj_uid/activity/:act_uid/step-move/:step_uid/:step_uid_rel/:type_change + */ + public function doPutStepsMoves ($prj_uid, $act_uid, $step_uid, $step_uid_rel, $type_change) + { + try { + $task = new \BusinessModel\Task(); + $task->moveSteps($prj_uid, $act_uid, $step_uid, $step_uid_rel, $type_change); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } } From eb4347e36c19e5a143532d369fce8215067e70f6 Mon Sep 17 00:00:00 2001 From: Brayan Osmar Pereyra Suxo Date: Fri, 21 Feb 2014 10:27:18 -0400 Subject: [PATCH 2/2] Actualizacion de steps y reordenamiento --- workflow/engine/src/BusinessModel/Task.php | 31 ++++++++++++++++--- .../Api/ProcessMaker/Project/Activity.php | 3 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/workflow/engine/src/BusinessModel/Task.php b/workflow/engine/src/BusinessModel/Task.php index e6e21fa17..d4e71abf0 100644 --- a/workflow/engine/src/BusinessModel/Task.php +++ b/workflow/engine/src/BusinessModel/Task.php @@ -1949,18 +1949,39 @@ class Task 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 $value) { + foreach ($stepChangeIds as $key => $value) { if ($modPos == 'UP') { - G::pr("Cambiar el step $value por un pos mas bajo"); + $tempPos = ((int)$stepChangePos[$key])-1; + $this->changePosStep($value, $tempPos); } else { - G::pr("Cambiar el step $value por un pos mas alto"); + $tempPos = ((int)$stepChangePos[$key])+1; + $this->changePosStep($value, $tempPos); } } - G::pr("Cambiar el step $step_uid por un pos $newPos"); - die; + $this->changePosStep($step_uid, $newPos); + } + + /** + * Validate Process Uid + * @var string $pro_uid. Uid for process + * + * @author Brayan Pereyra (Cochalo) + * @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); } /** diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php index a70d7015a..fcad391f7 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity.php @@ -120,7 +120,6 @@ class Activity extends Api $task->setArrayParamException(array("taskUid" => "act_uid", "stepUid" => "step_uid")); $response = $task->getSteps($act_uid); - return $response; } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); @@ -161,7 +160,7 @@ class Activity extends Api * * @return void * - * @url GET /:prj_uid/activity/:act_uid/step-move/:step_uid/:step_uid_rel/:type_change + * @url PUT /:prj_uid/activity/:act_uid/step-move/:step_uid/:step_uid_rel/:type_change */ public function doPutStepsMoves ($prj_uid, $act_uid, $step_uid, $step_uid_rel, $type_change) {