adding Bpmn Participant handling support
This commit is contained in:
@@ -14,6 +14,163 @@ require_once 'classes/model/om/BaseBpmnParticipant.php';
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class BpmnParticipant extends BaseBpmnParticipant {
|
||||
class BpmnParticipant extends BaseBpmnParticipant
|
||||
{
|
||||
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->setBouElement('pm_canvas');
|
||||
$this->bound->setBouContainer('bpmnDiagram');
|
||||
|
||||
$this->bound->setPrjUid($this->getPrjUid());
|
||||
$this->bound->setElementUid($this->getParUid());
|
||||
|
||||
$process = BpmnProcessPeer::retrieveByPK($this->getProUid());
|
||||
|
||||
if (is_object($process)) {
|
||||
$this->bound->setDiaUid($process->getDiaUid());
|
||||
}
|
||||
}
|
||||
|
||||
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 BpmnParticipantPeer::doSelect($c);
|
||||
}
|
||||
|
||||
public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||
{
|
||||
$c = new Criteria('workflow');
|
||||
$c->addSelectColumn("BPMN_PARTICIPANT.*");
|
||||
$c->addSelectColumn("BPMN_BOUND.*");
|
||||
$c->addJoin(BpmnParticipantPeer::PAR_UID, BpmnBoundPeer::ELEMENT_UID, Criteria::LEFT_JOIN);
|
||||
|
||||
if (! is_null($prjUid)) {
|
||||
$c->add(BpmnParticipantPeer::PRJ_UID, $prjUid, Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$rs = BpmnParticipantPeer::doSelectRS($c);
|
||||
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$participants = array();
|
||||
|
||||
while ($rs->next()) {
|
||||
$participants[] = $changeCaseTo !== CASE_UPPER ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||
}
|
||||
|
||||
return $participants;
|
||||
}
|
||||
|
||||
// OVERRIDES
|
||||
|
||||
public function setParUid($actUid)
|
||||
{
|
||||
parent::setParUid($actUid);
|
||||
$this->bound->setElementUid($this->getParUid());
|
||||
}
|
||||
|
||||
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('Participant', $this->getParUid());
|
||||
}
|
||||
|
||||
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('Participant', $this->getParUid());
|
||||
|
||||
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('Participant', $this->getParUid());
|
||||
|
||||
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(BpmnParticipantPeer::PAR_UID, $actUid);
|
||||
|
||||
return BpmnParticipantPeer::doCount($c) > 0 ? true : false;
|
||||
}
|
||||
} // BpmnParticipant
|
||||
|
||||
@@ -673,6 +673,7 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
$diagram["laneset"] = $bwp->getLanesets($configList);
|
||||
$diagram["lanes"] = $bwp->getLanes($configList);
|
||||
$diagram["data"] = $bwp->getDataCollection($configList);
|
||||
$diagram["participants"] = $bwp->getParticipants($configList);
|
||||
$project["diagrams"][] = $diagram;
|
||||
}
|
||||
|
||||
@@ -962,6 +963,53 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
}
|
||||
}
|
||||
|
||||
////
|
||||
/*
|
||||
* Diagram's Participant Handling
|
||||
*/
|
||||
$whiteList = array();
|
||||
foreach ($diagram["participants"] as $i => $participantData) {
|
||||
$participantData = array_change_key_case($participantData, CASE_UPPER);
|
||||
unset($participantData["_EXTENDED"]);
|
||||
|
||||
$dataObject = $bwp->getParticipant($participantData["PAR_UID"]);
|
||||
|
||||
if ($forceInsert || is_null($dataObject)) {
|
||||
if ($generateUid) {
|
||||
//Event
|
||||
unset($participantData["BOU_UID"]);
|
||||
|
||||
$uidOld = $participantData["PAR_UID"];
|
||||
$participantData["PAR_UID"] = Util\Common::generateUID();
|
||||
|
||||
$result[] = array(
|
||||
"object" => "participant",
|
||||
"old_uid" => $uidOld,
|
||||
"new_uid" => $participantData["PAR_UID"]
|
||||
);
|
||||
}
|
||||
|
||||
$bwp->addParticipant($participantData);
|
||||
} elseif (! $bwp->isEquals($dataObject, $participantData)) {
|
||||
$bwp->updateParticipant($participantData["PAR_UID"], $participantData);
|
||||
} else {
|
||||
Util\Logger::log("Update Participant ({$participantData["PAR_UID"]}) Skipped - No changes required");
|
||||
}
|
||||
|
||||
$diagram["participant"][$i] = $participantData;
|
||||
$whiteList[] = $participantData["PAR_UID"];
|
||||
}
|
||||
|
||||
$dataCollection = $bwp->getParticipants();
|
||||
|
||||
// looking for removed elements
|
||||
foreach ($dataCollection as $participantData) {
|
||||
if (! in_array($participantData["PAR_UID"], $whiteList)) {
|
||||
// If it is not in the white list, then remove them
|
||||
$bwp->removeParticipant($participantData["PAR_UID"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Diagram's Flows Handling
|
||||
|
||||
@@ -24,6 +24,8 @@ use \BpmnEventPeer as EventPeer;
|
||||
use \BpmnGatewayPeer as GatewayPeer;
|
||||
use \BpmnFlowPeer as FlowPeer;
|
||||
use \BpmnArtifactPeer as ArtifactPeer;
|
||||
use \BpmnParticipant as Participant;
|
||||
use \BpmnParticipantPeer as ParticipantPeer;
|
||||
|
||||
use \BasePeer;
|
||||
|
||||
@@ -73,6 +75,7 @@ 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"),
|
||||
);
|
||||
|
||||
|
||||
@@ -872,6 +875,87 @@ class Bpmn extends Handler
|
||||
}
|
||||
//////2222
|
||||
|
||||
public function addParticipant($data)
|
||||
{
|
||||
// setting defaults
|
||||
$data['PAR_UID'] = array_key_exists('PAR_UID', $data) ? $data['PAR_UID'] : Common::generateUID();
|
||||
try {
|
||||
self::log("Add Participant with data: ", $data);
|
||||
$participant = new Participant();
|
||||
$participant->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$participant->setPrjUid($this->getUid());
|
||||
$participant->setProUid($this->getProcess("object")->getProUid());
|
||||
$participant->save();
|
||||
self::log("Add Participant Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $participant->getParUid();
|
||||
}
|
||||
|
||||
public function updateParticipant($parUid, $data)
|
||||
{
|
||||
try {
|
||||
self::log("Update Participant: $parUid", "With data: ", $data);
|
||||
|
||||
$participant = ParticipantPeer::retrieveByPk($parUid);
|
||||
|
||||
$participant->fromArray($data);
|
||||
$participant->save();
|
||||
|
||||
self::log("Update Participant Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getParticipant($parUid, $retType = 'array')
|
||||
{
|
||||
$participant = ParticipantPeer::retrieveByPK($parUid);
|
||||
|
||||
if ($retType != "object" && ! empty($participant)) {
|
||||
$participant = $participant->toArray();
|
||||
$participant = self::filterArrayKeys($participant, self::$excludeFields["participant"]);
|
||||
}
|
||||
|
||||
return $participant;
|
||||
}
|
||||
|
||||
public function getParticipants($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||
{
|
||||
if (is_array($start)) {
|
||||
extract($start);
|
||||
}
|
||||
|
||||
$filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["participant"]) : self::$excludeFields["participant"];
|
||||
|
||||
return self::filterCollectionArrayKeys(
|
||||
Participant::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo),
|
||||
$filter
|
||||
);
|
||||
}
|
||||
|
||||
public function removeParticipant($parUid)
|
||||
{
|
||||
try {
|
||||
self::log("Remove Participant: $parUid");
|
||||
|
||||
$participant = ParticipantPeer::retrieveByPK($parUid);
|
||||
$participant->delete();
|
||||
|
||||
// remove related object (flows)
|
||||
Flow::removeAllRelated($parUid);
|
||||
|
||||
self::log("Remove Participant Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function addLane($data)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
|
||||
Reference in New Issue
Block a user