Adicion de ARTIFACTS en PROJECTS
This commit is contained in:
@@ -14,6 +14,169 @@ require_once 'classes/model/om/BaseBpmnArtifact.php';
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class BpmnArtifact extends BaseBpmnArtifact {
|
||||
class BpmnArtifact extends BaseBpmnArtifact
|
||||
{
|
||||
private $bound;
|
||||
|
||||
} // BpmnArtifact
|
||||
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->getArtUid());
|
||||
|
||||
$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 BpmnArtifactPeer::doSelect($c);
|
||||
}
|
||||
|
||||
public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||
{
|
||||
$c = new Criteria('workflow');
|
||||
$c->addSelectColumn("BPMN_ARTIFACT.*");
|
||||
$c->addSelectColumn("BPMN_BOUND.*");
|
||||
$c->addJoin(BpmnArtifactPeer::ART_UID, BpmnBoundPeer::ELEMENT_UID, Criteria::LEFT_JOIN);
|
||||
|
||||
if (! is_null($prjUid)) {
|
||||
$c->add(BpmnArtifactPeer::PRJ_UID, $prjUid, Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$rs = BpmnArtifactPeer::doSelectRS($c);
|
||||
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$artifacts = array();
|
||||
|
||||
while ($rs->next()) {
|
||||
$artifacts[] = $changeCaseTo !== CASE_UPPER ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||
}
|
||||
|
||||
return $artifacts;
|
||||
}
|
||||
|
||||
// OVERRIDES
|
||||
|
||||
public function setArtUid($artUid)
|
||||
{
|
||||
parent::setArtUid($artUid);
|
||||
$this->bound->setElementUid($this->getArtUid());
|
||||
}
|
||||
|
||||
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('Artifact', $this->getArtUid());
|
||||
}
|
||||
|
||||
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('Artifact', $this->getArtUid());
|
||||
|
||||
if (is_object($bound)) {
|
||||
$this->bound = $bound;
|
||||
} else {
|
||||
$this->bound = new BpmnBound();
|
||||
$this->bound->setBouUid(ProcessMaker\Util\Common::generateUID());
|
||||
}
|
||||
|
||||
if ($data['ART_TYPE'] == 'VERTICAL_LINE' || $data['ART_TYPE'] == 'HORIZONTAL_LINE') {
|
||||
unset($data['BOU_WIDTH']);
|
||||
unset($data['BOU_HEIGHT']);
|
||||
}
|
||||
|
||||
$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('Artifact', $this->getArtUid());
|
||||
|
||||
if (is_object($bound)) {
|
||||
$this->bound = $bound;
|
||||
}
|
||||
}
|
||||
|
||||
$data = array_merge($data, $this->bound->toArray($type));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function exists($artUid)
|
||||
{
|
||||
$c = new Criteria("workflow");
|
||||
$c->add(BpmnArtifactPeer::ART_UID, $artUid);
|
||||
|
||||
return BpmnArtifactPeer::doCount($c) > 0 ? true : false;
|
||||
}
|
||||
|
||||
} // BpmnActivity
|
||||
@@ -600,6 +600,41 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Diagram's Artifacts Handling
|
||||
*/
|
||||
$whiteList = array();
|
||||
foreach ($diagram["artifacts"] as $i => $artifactData) {
|
||||
$artifactData = array_change_key_case($artifactData, CASE_UPPER);
|
||||
unset($artifactData["_EXTENDED"]);
|
||||
$artifact = $bwp->getArtifact($artifactData["ART_UID"]);
|
||||
|
||||
if (is_null($artifact)) {
|
||||
if ($generateUid) {
|
||||
$oldArtUid = $artifactData["ART_UID"];
|
||||
|
||||
$artifactData["ART_UID"] = Util\Common::generateUID();
|
||||
$result[] = array("object" => "artifact", "new_uid" => $artifactData["ART_UID"], "old_uid" => $oldArtUid);
|
||||
}
|
||||
|
||||
$bwp->addArtifact($artifactData);
|
||||
} elseif (! $bwp->isEquals($artifact, $artifactData)) {
|
||||
$bwp->updateArtifact($artifactData["ART_UID"], $artifactData);
|
||||
} else {
|
||||
Util\Logger::log("Update Artifact ({$artifactData["GAT_UID"]}) Skipped - No changes required");
|
||||
}
|
||||
|
||||
$diagram["artifacts"][$i] = $artifactData;
|
||||
$whiteList[] = $artifactData["ART_UID"];
|
||||
}
|
||||
|
||||
$artifacts = $bwp->getArtifacts();
|
||||
// looking for removed elements
|
||||
foreach ($artifacts as $artifactData) {
|
||||
if (! in_array($artifactData["ART_UID"], $whiteList)) {
|
||||
$bwp->removeArtifact($artifactData["ART_UID"]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Diagram's Gateways Handling
|
||||
|
||||
@@ -67,6 +67,10 @@ class Bpmn extends Handler
|
||||
"gateway" => array("BOU_ELEMENT", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION", "BOU_SIZE_IDENTICAL", "BOU_UID",
|
||||
"DIA_UID", "ELEMENT_UID", "PRJ_UID", "PRO_UID"
|
||||
),
|
||||
"artifact" => array(
|
||||
"PRJ_UID", "PRO_UID", "BOU_ELEMENT", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL", "DIA_UID", "BOU_UID", "ELEMENT_UID"
|
||||
),
|
||||
"flow" => array("PRJ_UID", "DIA_UID", "FLO_ELEMENT_DEST_PORT", "FLO_ELEMENT_ORIGIN_PORT")
|
||||
);
|
||||
|
||||
@@ -682,18 +686,83 @@ class Bpmn extends Handler
|
||||
|
||||
public function addArtifact($data)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
// setting defaults
|
||||
$data['ART_UID'] = array_key_exists('ART_UID', $data) ? $data['ART_UID'] : Common::generateUID();
|
||||
try {
|
||||
self::log("Add Artifact with data: ", $data);
|
||||
$artifact = new Artifact();
|
||||
$artifact->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$artifact->setPrjUid($this->getUid());
|
||||
$artifact->setProUid($this->getProcess("object")->getProUid());
|
||||
$artifact->save();
|
||||
self::log("Add Artifact Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
|
||||
public function getArtifact($artUid)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
return $artifact->getArtUid();
|
||||
}
|
||||
|
||||
public function getArtifacts()
|
||||
public function updateArtifact($artUid, $data)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
return array();
|
||||
try {
|
||||
self::log("Update Artifact: $artUid", "With data: ", $data);
|
||||
|
||||
$artifact = ArtifactPeer::retrieveByPk($artUid);
|
||||
|
||||
$artifact->fromArray($data);
|
||||
$artifact->save();
|
||||
|
||||
self::log("Update Artifact Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getArtifact($artUid, $retType = 'array')
|
||||
{
|
||||
$artifact = ArtifactPeer::retrieveByPK($artUid);
|
||||
|
||||
if ($retType != "object" && ! empty($artifact)) {
|
||||
$artifact = $artifact->toArray();
|
||||
$artifact = self::filterArrayKeys($artifact, self::$excludeFields["artifact"]);
|
||||
}
|
||||
|
||||
return $artifact;
|
||||
}
|
||||
|
||||
public function getArtifacts($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||
{
|
||||
if (is_array($start)) {
|
||||
extract($start);
|
||||
}
|
||||
|
||||
$filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["artifact"]) : self::$excludeFields["artifact"];
|
||||
|
||||
return self::filterCollectionArrayKeys(
|
||||
Artifact::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo),
|
||||
$filter
|
||||
);
|
||||
}
|
||||
|
||||
public function removeArtifact($artUid)
|
||||
{
|
||||
try {
|
||||
self::log("Remove Artifact: $artUid");
|
||||
|
||||
$artifact = ArtifactPeer::retrieveByPK($artUid);
|
||||
$artifact->delete();
|
||||
|
||||
// remove related object (flows)
|
||||
Flow::removeAllRelated($artUid);
|
||||
|
||||
self::log("Remove Artifact Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function addLane($data)
|
||||
|
||||
@@ -514,7 +514,7 @@ class Cases extends Api
|
||||
$cat_uid = '',
|
||||
$pro_uid = '',
|
||||
$app_status = '',
|
||||
$user = '',
|
||||
$usr_uid = '',
|
||||
$date_from = '',
|
||||
$date_to = '',
|
||||
$search = ''
|
||||
@@ -532,7 +532,7 @@ class Cases extends Api
|
||||
$dataList['category'] = $cat_uid;
|
||||
$dataList['process'] = $pro_uid;
|
||||
$dataList['status'] = $app_status;
|
||||
$dataList['user'] = $user;
|
||||
$dataList['user'] = $usr_uid;
|
||||
$dataList['dateFrom'] = $date_from;
|
||||
$dataList['dateTo'] = $date_to;
|
||||
$dataList['search'] = $search;
|
||||
|
||||
Reference in New Issue
Block a user