diff --git a/workflow/engine/classes/model/BpmnActivity.php b/workflow/engine/classes/model/BpmnActivity.php index 1c4d1e626..841c8586b 100644 --- a/workflow/engine/classes/model/BpmnActivity.php +++ b/workflow/engine/classes/model/BpmnActivity.php @@ -32,8 +32,6 @@ class BpmnActivity extends BaseBpmnActivity private function setBoundDefaults() { $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); - $this->bound->setBouElement('pm_canvas'); - $this->bound->setBouContainer('bpmnDiagram'); $this->bound->setPrjUid($this->getPrjUid()); $this->bound->setElementUid($this->getActUid()); @@ -41,7 +39,16 @@ class BpmnActivity extends BaseBpmnActivity $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); if (is_object($process)) { + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } } } diff --git a/workflow/engine/classes/model/BpmnArtifact.php b/workflow/engine/classes/model/BpmnArtifact.php index 2c9adde16..ccefa79ec 100644 --- a/workflow/engine/classes/model/BpmnArtifact.php +++ b/workflow/engine/classes/model/BpmnArtifact.php @@ -32,8 +32,6 @@ class BpmnArtifact extends BaseBpmnArtifact private function setBoundDefaults() { $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); - $this->bound->setBouElement('pm_canvas'); - $this->bound->setBouContainer('bpmnDiagram'); $this->bound->setPrjUid($this->getPrjUid()); $this->bound->setElementUid($this->getArtUid()); @@ -41,7 +39,16 @@ class BpmnArtifact extends BaseBpmnArtifact $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); if (is_object($process)) { + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } } } diff --git a/workflow/engine/classes/model/BpmnData.php b/workflow/engine/classes/model/BpmnData.php index d64d88b50..b8385d626 100644 --- a/workflow/engine/classes/model/BpmnData.php +++ b/workflow/engine/classes/model/BpmnData.php @@ -32,8 +32,6 @@ class BpmnData extends BaseBpmnData private function setBoundDefaults() { $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); - $this->bound->setBouElement('pm_canvas'); - $this->bound->setBouContainer('bpmnDiagram'); $this->bound->setPrjUid($this->getPrjUid()); $this->bound->setElementUid($this->getDatUid()); @@ -41,7 +39,16 @@ class BpmnData extends BaseBpmnData $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); if (is_object($process)) { + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } } } diff --git a/workflow/engine/classes/model/BpmnEvent.php b/workflow/engine/classes/model/BpmnEvent.php index 57859f34c..d799dd0ea 100644 --- a/workflow/engine/classes/model/BpmnEvent.php +++ b/workflow/engine/classes/model/BpmnEvent.php @@ -32,8 +32,6 @@ class BpmnEvent extends BaseBpmnEvent private function setBoundDefaults() { $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); - $this->bound->setBouElement('pm_canvas'); - $this->bound->setBouContainer('bpmnDiagram'); $this->bound->setPrjUid($this->getPrjUid()); $this->bound->setElementUid($this->getEvnUid()); @@ -41,7 +39,16 @@ class BpmnEvent extends BaseBpmnEvent $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); if (is_object($process)) { + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } } } diff --git a/workflow/engine/classes/model/BpmnGateway.php b/workflow/engine/classes/model/BpmnGateway.php index c402532e7..6d9a43107 100644 --- a/workflow/engine/classes/model/BpmnGateway.php +++ b/workflow/engine/classes/model/BpmnGateway.php @@ -32,8 +32,6 @@ class BpmnGateway extends BaseBpmnGateway private function setBoundDefaults() { $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); - $this->bound->setBouElement('pm_canvas'); - $this->bound->setBouContainer('bpmnDiagram'); $this->bound->setPrjUid($this->getPrjUid()); $this->bound->setElementUid($this->getGatUid()); @@ -41,7 +39,16 @@ class BpmnGateway extends BaseBpmnGateway $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); if (is_object($process)) { + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } } } diff --git a/workflow/engine/classes/model/BpmnLane.php b/workflow/engine/classes/model/BpmnLane.php index bc7152374..d80dcd539 100644 --- a/workflow/engine/classes/model/BpmnLane.php +++ b/workflow/engine/classes/model/BpmnLane.php @@ -16,4 +16,161 @@ require_once 'classes/model/om/BaseBpmnLane.php'; */ class BpmnLane extends BaseBpmnLane { + private $bound; + + public function __construct($generateUid = true) + { + $this->bound = new BpmnBound(); + $this->setBoundDefaults(); + } + + public function getBound() + { + return $this->bound; + } + + private function setBoundDefaults() + { + $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); + + $this->bound->setPrjUid($this->getPrjUid()); + $this->bound->setElementUid($this->getLanUid()); + + $project = BpmnProjectPeer::retrieveByPK($this->getPrjUid()); + + if (is_object($project)) { + $criteria = new Criteria('workflow'); + $criteria->addSelectColumn(BpmnProcessPeer::DIA_UID); + $criteria->add(BpmnProcessPeer::PRJ_UID, $this->getPrjUid(), \Criteria::EQUAL); + $rsCriteria = BpmnProcessPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $rsCriteria->next(); + $row = $rsCriteria->getRow(); + $this->bound->setDiaUid($row["DIA_UID"]); + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($row["DIA_UID"]); + } + } + + public static function findOneBy($field, $value) + { + $rows = self::findAllBy($field, $value); + + return empty($rows) ? null : $rows[0]; + } + + public static function findAllBy($field, $value) + { + $c = new Criteria('workflow'); + $c->add($field, $value, Criteria::EQUAL); + + return BpmnLanePeer::doSelect($c); + } + + public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER) + { + $c = new Criteria('workflow'); + $c->addSelectColumn("BPMN_LANE.*"); + $c->addSelectColumn("BPMN_BOUND.*"); + $c->addJoin(BpmnLanePeer::LAN_UID, BpmnBoundPeer::ELEMENT_UID, Criteria::LEFT_JOIN); + + if (! is_null($prjUid)) { + $c->add(BpmnLanePeer::PRJ_UID, $prjUid, Criteria::EQUAL); + } + + $rs = BpmnLanePeer::doSelectRS($c); + $rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + $lanes = array(); + + while ($rs->next()) { + $lanes[] = $changeCaseTo !== CASE_UPPER ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow(); + } + + return $lanes; + } + + // OVERRIDES + + public function setLanUid($actUid) + { + parent::setLanUid($actUid); + $this->bound->setElementUid($this->getLanUid()); + } + + public function setPrjUid($prjUid) + { + parent::setPrjUid($prjUid); + $this->bound->setPrjUid($this->getPrjUid()); + } + + public function save($con = null) + { + parent::save($con); + + $this->setBoundDefaults(); + + if ($this->bound->getBouUid() == "") { + $this->bound->setBouUid(\ProcessMaker\Util\Common::generateUID()); + } + + $this->bound->save($con); + } + + public function delete($con = null) + { + // first, delete the related bound object + if (! is_object($this->bound) || $this->bound->getBouUid() == "") { + $this->bound = BpmnBound::findByElement('Lane', $this->getLanUid()); + } + + if (is_object($this->bound)) { + $this->bound->delete($con); + } + + parent::delete($con); + } + + public function fromArray($data, $type = BasePeer::TYPE_FIELDNAME) + { + parent::fromArray($data, $type); + + $bound = BpmnBound::findByElement('Lane', $this->getLanUid()); + + if (is_object($bound)) { + $this->bound = $bound; + } else { + $this->bound = new BpmnBound(); + $this->bound->setBouUid(ProcessMaker\Util\Common::generateUID()); + } + + $this->bound->fromArray($data, BasePeer::TYPE_FIELDNAME); + } + + public function toArray($type = BasePeer::TYPE_FIELDNAME) + { + $data = parent::toArray($type); + $bouUid = $this->bound->getBouUid(); + + if (empty($bouUid)) { + $bound = BpmnBound::findByElement('Lane', $this->getLanUid()); + + if (is_object($bound)) { + $this->bound = $bound; + } + } + + $data = array_merge($data, $this->bound->toArray($type)); + + return $data; + } + + public static function exists($actUid) + { + $c = new Criteria("workflow"); + $c->add(BpmnlanesPeer::LAN_UID, $actUid); + + return BpmnlanesPeer::doCount($c) > 0 ? true : false; + } + } // BpmnLane diff --git a/workflow/engine/classes/model/BpmnLaneset.php b/workflow/engine/classes/model/BpmnLaneset.php index ce8823e77..46d332ac9 100644 --- a/workflow/engine/classes/model/BpmnLaneset.php +++ b/workflow/engine/classes/model/BpmnLaneset.php @@ -15,5 +15,170 @@ require_once 'classes/model/om/BaseBpmnLaneset.php'; * @package classes.model */ class BpmnLaneset extends BaseBpmnLaneset { + private $bound; + + public function __construct($generateUid = true) + { + $this->bound = new BpmnBound(); + $this->setBoundDefaults(); + } + + public function getBound() + { + return $this->bound; + } + + private function setBoundDefaults() + { + $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); + + $this->bound->setPrjUid($this->getPrjUid()); + $this->bound->setElementUid($this->getLnsUid()); + + $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); + + if (is_object($process)) { + + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } + } + } + + public static function findOneBy($field, $value) + { + $rows = self::findAllBy($field, $value); + + return empty($rows) ? null : $rows[0]; + } + + public static function findAllBy($field, $value) + { + $c = new Criteria('workflow'); + $c->add($field, $value, Criteria::EQUAL); + + return BpmnLanesetPeer::doSelect($c); + } + + public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER) + { + $c = new Criteria('workflow'); + $c->addSelectColumn("BPMN_LANESET.*"); + $c->addSelectColumn("BPMN_BOUND.*"); + $c->addJoin(BpmnLanesetPeer::LNS_UID, BpmnBoundPeer::ELEMENT_UID, Criteria::LEFT_JOIN); + + if (! is_null($prjUid)) { + $c->add(BpmnLanesetPeer::PRJ_UID, $prjUid, Criteria::EQUAL); + } + + $rs = BpmnLanesetPeer::doSelectRS($c); + $rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + $laneSet = array(); + + while ($rs->next()) { + $laneSet[] = $changeCaseTo !== CASE_UPPER ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow(); + } + + return $laneSet; + } + + // OVERRIDES + + public function setLnsUid($actUid) + { + parent::setLnsUid($actUid); + $this->bound->setElementUid($this->getLnsUid()); + } + + public function setPrjUid($prjUid) + { + parent::setPrjUid($prjUid); + $this->bound->setPrjUid($this->getPrjUid()); + } + + public function setProUid($proUid) + { + parent::setProUid($proUid); + + $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); + $this->bound->setDiaUid($process->getDiaUid()); + } + + public function save($con = null) + { + parent::save($con); + + $this->setBoundDefaults(); + + if ($this->bound->getBouUid() == "") { + $this->bound->setBouUid(\ProcessMaker\Util\Common::generateUID()); + } + + $this->bound->save($con); + } + + public function delete($con = null) + { + // first, delete the related bound object + if (! is_object($this->bound) || $this->bound->getBouUid() == "") { + $this->bound = BpmnBound::findByElement('LaneSet', $this->getLnsUid()); + } + + if (is_object($this->bound)) { + $this->bound->delete($con); + } + + parent::delete($con); + } + + public function fromArray($data, $type = BasePeer::TYPE_FIELDNAME) + { + parent::fromArray($data, $type); + + $bound = BpmnBound::findByElement('LaneSet', $this->getLnsUid()); + + if (is_object($bound)) { + $this->bound = $bound; + } else { + $this->bound = new BpmnBound(); + $this->bound->setBouUid(ProcessMaker\Util\Common::generateUID()); + } + + $this->bound->fromArray($data, BasePeer::TYPE_FIELDNAME); + } + + public function toArray($type = BasePeer::TYPE_FIELDNAME) + { + $data = parent::toArray($type); + $bouUid = $this->bound->getBouUid(); + + if (empty($bouUid)) { + $bound = BpmnBound::findByElement('LaneSet', $this->getLnsUid()); + + if (is_object($bound)) { + $this->bound = $bound; + } + } + + $data = array_merge($data, $this->bound->toArray($type)); + + return $data; + } + + public static function exists($actUid) + { + $c = new Criteria("workflow"); + $c->add(BpmnLanesetPeer::LNS_UID, $actUid); + + return BpmnLanesetPeer::doCount($c) > 0 ? true : false; + } + } // BpmnLaneset diff --git a/workflow/engine/classes/model/BpmnParticipant.php b/workflow/engine/classes/model/BpmnParticipant.php index b74b2245e..33659ec60 100644 --- a/workflow/engine/classes/model/BpmnParticipant.php +++ b/workflow/engine/classes/model/BpmnParticipant.php @@ -32,8 +32,6 @@ class BpmnParticipant extends BaseBpmnParticipant private function setBoundDefaults() { $this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__))); - $this->bound->setBouElement('pm_canvas'); - $this->bound->setBouContainer('bpmnDiagram'); $this->bound->setPrjUid($this->getPrjUid()); $this->bound->setElementUid($this->getParUid()); @@ -41,7 +39,16 @@ class BpmnParticipant extends BaseBpmnParticipant $process = BpmnProcessPeer::retrieveByPK($this->getProUid()); if (is_object($process)) { + $this->bound->setDiaUid($process->getDiaUid()); + + if ($this->bound->getBouElement() == null && $this->bound->getBouElement() == '' && $this->bound->getBouElement() == $process->getDiaUid()) { + $this->bound->setBouContainer('bpmnDiagram'); + $this->bound->setBouElement($process->getDiaUid()); + } else { + $this->bound->setBouContainer('bpmnLane'); + $this->bound->setBouElement($this->bound->getBouElement()); + } } } diff --git a/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php b/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php index d84b383e1..3eca7e1b1 100644 --- a/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php +++ b/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php @@ -671,6 +671,8 @@ class BpmnWorkflow extends Project\Bpmn $diagram["lanes"] = $bwp->getLanes($configList); $diagram["data"] = $bwp->getDataCollection($configList); $diagram["participants"] = $bwp->getParticipants($configList); + $diagram["lanesets"] = $bwp->getLanesets($configList); + $diagram["lanes"] = $bwp->getLanes($configList); $project["diagrams"][] = $diagram; } @@ -726,6 +728,8 @@ class BpmnWorkflow extends Project\Bpmn $diagram["events"] = isset($diagram["events"])? $diagram["events"]: array(); $diagram["data"] = isset($diagram["data"])? $diagram["data"]: array(); $diagram["participants"] = isset($diagram["participants"])? $diagram["participants"]: array(); + $diagram["lanesets"] = isset($diagram["lanesets"])? $diagram["lanesets"]: array(); + $diagram["lanes"] = isset($diagram["lanes"])? $diagram["lanes"]: array(); $result = array(); $projectData['prj_uid'] = $prjUid; @@ -1032,6 +1036,97 @@ class BpmnWorkflow extends Project\Bpmn } } + //// + /* + * Diagram's Laneset Handling + */ + $whiteList = array(); + foreach ($diagram["laneset"] as $i => $lanesetData) { + $lanesetData = array_change_key_case($lanesetData, CASE_UPPER); + + $dataObject = $bwp->getLaneset($lanesetData["LNS_UID"]); + + if ($forceInsert || is_null($dataObject)) { + if ($generateUid) { + //Laneset + unset($lanesetData["BOU_UID"]); + + $uidOld = $lanesetData["LNS_UID"]; + $lanesetData["LNS_UID"] = Util\Common::generateUID(); + + $result[] = array( + "object" => "laneset", + "old_uid" => $uidOld, + "new_uid" => $lanesetData["LNS_UID"] + ); + } + $bwp->addLaneset($lanesetData); + } elseif (! $bwp->isEquals($dataObject, $lanesetData)) { + $bwp->updateLanseset($lanesetData["LNS_UID"], $lanesetData); + } else { + Util\Logger::log("Update Laneset ({$lanesetData["LNS_UID"]}) Skipped - No changes required"); + } + + $diagram["laneset"][$i] = $lanesetData; + $whiteList[] = $lanesetData["LNS_UID"]; + } + + $dataCollection = $bwp->getLanesets(); + + // looking for removed elements + foreach ($dataCollection as $lanesetData) { + if (! in_array($lanesetData["LNS_UID"], $whiteList)) { + // If it is not in the white list, then remove them + $bwp->removeLaneset($lanesetData["LNS_UID"]); + } + } + + //// + /* + * Diagram's Lane Handling + */ + $whiteList = array(); + foreach ($diagram["lanes"] as $i => $laneData) { + $laneData = array_change_key_case($laneData, CASE_UPPER); + + $dataObject = $bwp->getLane($laneData["LAN_UID"]); + + if ($forceInsert || is_null($dataObject)) { + if ($generateUid) { + //Laneset + unset($laneData["BOU_UID"]); + + $uidOld = $laneData["LAN_UID"]; + $laneData["LAN_UID"] = Util\Common::generateUID(); + + $result[] = array( + "object" => "lane", + "old_uid" => $uidOld, + "new_uid" => $laneData["LAN_UID"] + ); + } + $bwp->addLane($laneData); + } elseif (! $bwp->isEquals($dataObject, $laneData)) { + $bwp->updateLanse($laneData["LAN_UID"], $laneData); + } else { + Util\Logger::log("Update Lane ({$laneData["LAN_UID"]}) Skipped - No changes required"); + } + + $diagram["lane"][$i] = $laneData; + $whiteList[] = $laneData["LAN_UID"]; + } + + $dataCollection = $bwp->getLanes(); + + // looking for removed elements + foreach ($dataCollection as $laneData) { + if (! in_array($laneData["LAN_UID"], $whiteList)) { + // If it is not in the white list, then remove them + $bwp->removeLane($laneData["LAN_UID"]); + } + } + + /* * Diagram's Flows Handling */ diff --git a/workflow/engine/src/ProcessMaker/Project/Bpmn.php b/workflow/engine/src/ProcessMaker/Project/Bpmn.php index f330f9091..9ddfdd72e 100644 --- a/workflow/engine/src/ProcessMaker/Project/Bpmn.php +++ b/workflow/engine/src/ProcessMaker/Project/Bpmn.php @@ -4,8 +4,6 @@ namespace ProcessMaker\Project; use \BpmnProject as Project; use \BpmnProcess as Process; use \BpmnDiagram as Diagram; -use \BpmnLaneset as Laneset; -use \BpmnLane as Lane; use \BpmnActivity as Activity; use \BpmnBound as Bound; use \BpmnEvent as Event; @@ -16,8 +14,7 @@ use \BpmnArtifact as Artifact; use \BpmnProjectPeer as ProjectPeer; use \BpmnProcessPeer as ProcessPeer; use \BpmnDiagramPeer as DiagramPeer; -use \BpmnLanesetPeer as LanesetPeer; -use \BpmnLanePeer as LanePeer; + use \BpmnActivityPeer as ActivityPeer; use \BpmnBoundPeer as BoundPeer; use \BpmnEventPeer as EventPeer; @@ -26,6 +23,10 @@ use \BpmnFlowPeer as FlowPeer; use \BpmnArtifactPeer as ArtifactPeer; use \BpmnParticipant as Participant; use \BpmnParticipantPeer as ParticipantPeer; +use \BpmnLaneset as Laneset; +use \BpmnLanesetPeer as LanesetPeer; +use \BpmnLane as Lane; +use \BpmnLanePeer as LanePeer; use \BasePeer; use \Criteria as Criteria; @@ -78,6 +79,8 @@ class Bpmn extends Handler "flow" => array("PRJ_UID", "DIA_UID", "FLO_ELEMENT_DEST_PORT", "FLO_ELEMENT_ORIGIN_PORT"), "data" => array("PRJ_UID"), "participant" => array("PRJ_UID"), + "laneset" => array(), + "lane" => array() ); @@ -179,7 +182,12 @@ class Bpmn extends Handler foreach ($this->getParticipants() as $participant) { $this->removeParticipant($participant["PAR_UID"]); } - + foreach ($this->getLanesets() as $laneset) { + $this->removeLaneset($laneset["LNS_UID"]); + } + foreach ($this->getLanes() as $lane) { + $this->removeLane($lane["LAN_UID"]); + } if ($process = $this->getProcess("object")) { $process->delete(); } @@ -635,6 +643,8 @@ class Bpmn extends Handler case "bpmnArtifact": $class = "BpmnArtifact"; break; case "bpmnData": $class = "BpmnData"; break; case "bpmnParticipant": $class = "BpmnParticipant"; break; + case "bpmnLaneset": $class = "BpmnLaneset"; break; + case "bpmnLane": $class = "BpmnLane"; break; default: throw new \RuntimeException(sprintf("Invalid Object type, accepted types: [%s|%s|%s|%s], given %s.", "BpmnActivity", "BpmnBpmnGateway", "BpmnEvent", "bpmnArtifact", $data["FLO_ELEMENT_ORIGIN_TYPE"] @@ -655,6 +665,8 @@ class Bpmn extends Handler case "bpmnArtifact": $class = "BpmnArtifact"; break; case "bpmnData": $class = "BpmnData"; break; case "bpmnParticipant": $class = "BpmnParticipant"; break; + case "bpmnLaneset": $class = "BpmnLaneset"; break; + case "bpmnLane": $class = "BpmnLane"; break; default: throw new \RuntimeException(sprintf("Invalid Object type, accepted types: [%s|%s|%s|%s], given %s.", "BpmnActivity", "BpmnBpmnGateway", "BpmnEvent", "bpmnArtifact", $data["FLO_ELEMENT_DEST_TYPE"] @@ -1005,36 +1017,136 @@ class Bpmn extends Handler public function addLane($data) { - // TODO: Implement update() method. + // setting defaults + $processUid = $this->getProcess("object")->getProUid(); + + $data['LAN_UID'] = array_key_exists('LAN_UID', $data) ? $data['LAN_UID'] : Common::generateUID(); + $data["PRO_UID"] = $processUid; + + try { + self::log("Add Lane with data: ", $data); + $lane = new Lane(); + $lane->fromArray($data, BasePeer::TYPE_FIELDNAME); + $lane->setPrjUid($this->getUid()); + //$lane->setProUid($this->getProcess("object")->getProUid()); + $lane->save(); + self::log("Add Lane Success!"); + } catch (\Exception $e) { + self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString()); + throw $e; + } + + return $lane->getLanUid(); } - public function getLane($lanUid) + public function getLane($lanUid, $retType = 'array') { - // TODO: Implement update() method. + $lane = LanePeer::retrieveByPK($lanUid); + + if ($retType != "object" && ! empty($lane)) { + $lane = $lane->toArray(); + $lane = self::filterArrayKeys($lane, self::$excludeFields["lane"]); + } + + return $lane; } - public function getLanes() + public function getLanes($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER) { - // TODO: Implement update() method. - return array(); + if (is_array($start)) { + extract($start); + } + + $filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["lane"]) : self::$excludeFields["lane"]; + + return self::filterCollectionArrayKeys( + Lane::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo), + $filter + ); + } + + public function removeLane($lanUid) + { + try { + self::log("Remove Lane: $lanUid"); + + $lane = LanePeer::retrieveByPK($lanUid); + $lane->delete(); + + // remove related object (flows) + Flow::removeAllRelated($lanUid); + + self::log("Remove Lane Success!"); + } catch (\Exception $e) { + self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString()); + throw $e; + } } public function addLaneset($data) { - // TODO: Implement update() method. + // setting defaults + $processUid = $this->getProcess("object")->getProUid(); + $data['LNS_UID'] = array_key_exists('LNS_UID', $data) ? $data['LNS_UID'] : Common::generateUID(); + $data["PRO_UID"] = $processUid; + + try { + self::log("Add Laneset with data: ", $data); + $laneset = new Laneset(); + $laneset->fromArray($data, BasePeer::TYPE_FIELDNAME); + $laneset->setPrjUid($this->getUid()); + $laneset->setProUid($this->getProcess("object")->getProUid()); + $laneset->save(); + self::log("Add Laneset Success!"); + } catch (\Exception $e) { + self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString()); + throw $e; + } + + return $laneset->getLnsUid(); } - public function getLaneset($lnsUid) + public function getLaneset($lnsUid, $retType = 'array') { - // TODO: Implement update() method. + $laneset = LanesetPeer::retrieveByPK($lnsUid); + + if ($retType != "object" && ! empty($laneset)) { + $laneset = $laneset->toArray(); + $laneset = self::filterArrayKeys($laneset, self::$excludeFields["laneset"]); + } + + return $laneset; } - public function getLanesets() + public function getLanesets($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER) { - // TODO: Implement update() method. - return array(); + if (is_array($start)) { + extract($start); + } + $filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["laneset"]) : self::$excludeFields["laneset"]; + return self::filterCollectionArrayKeys( + Laneset::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo), + $filter + ); } + public function removeLaneset($lnsUid) + { + try { + self::log("Remove Laneset: $lnsUid"); + + $laneset = LanesetPeer::retrieveByPK($lnsUid); + $laneset->delete(); + + // remove related object (flows) + Flow::removeAllRelated($lnsUid); + + self::log("Remove Laneset Success!"); + } catch (\Exception $e) { + self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString()); + throw $e; + } + } public function isModified($element, $uid, $newData) {