2014-02-03 19:37:50 -04:00
|
|
|
<?php
|
|
|
|
|
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;
|
|
|
|
|
use \BpmnGateway as Gateway;
|
|
|
|
|
use \BpmnFlow as Flow;
|
|
|
|
|
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;
|
|
|
|
|
use \BpmnGatewayPeer as GatewayPeer;
|
|
|
|
|
use \BpmnFlowPeer as FlowPeer;
|
|
|
|
|
use \BpmnArtifactPeer as ArtifactPeer;
|
|
|
|
|
|
|
|
|
|
use \BasePeer;
|
|
|
|
|
|
|
|
|
|
use ProcessMaker\Util\Hash;
|
2014-02-05 11:39:15 -04:00
|
|
|
use ProcessMaker\Exception;
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-10 13:09:50 -04:00
|
|
|
/**
|
|
|
|
|
* Class Bpmn
|
|
|
|
|
*
|
|
|
|
|
* @package ProcessMaker\Project
|
|
|
|
|
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
|
|
|
|
|
*/
|
2014-02-05 11:39:15 -04:00
|
|
|
class Bpmn extends Handler
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var \BpmnProject
|
|
|
|
|
*/
|
|
|
|
|
protected $project;
|
|
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
protected $prjUid;
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
/**
|
|
|
|
|
* @var \BpmnProcess
|
|
|
|
|
*/
|
|
|
|
|
protected $process;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var \BpmnDiagram
|
|
|
|
|
*/
|
|
|
|
|
protected $diagram;
|
|
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
protected static $excludeFields = array(
|
|
|
|
|
"activity" => array(
|
|
|
|
|
"PRJ_UID", "PRO_UID", "BOU_ELEMENT", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION",
|
|
|
|
|
"BOU_SIZE_IDENTICAL", "DIA_UID", "BOU_UID", "ELEMENT_UID"
|
|
|
|
|
),
|
2014-02-19 13:31:02 -04:00
|
|
|
"event" => array(
|
|
|
|
|
"PRJ_UID", "PRO_UID", "BOU_ELEMENT", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION",
|
|
|
|
|
"BOU_SIZE_IDENTICAL", "DIA_UID", "BOU_UID", "ELEMENT_UID", "EVN_ATTACHED_TO", "EVN_CONDITION"
|
|
|
|
|
),
|
2014-02-18 17:41:45 -04:00
|
|
|
"flow" => array("PRJ_UID", "DIA_UID", "FLO_ELEMENT_DEST_PORT", "FLO_ELEMENT_ORIGIN_PORT")
|
|
|
|
|
);
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
|
|
|
|
|
public function __construct($data = null)
|
|
|
|
|
{
|
|
|
|
|
if (! is_null($data)) {
|
|
|
|
|
$this->create($data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function load($prjUid)
|
|
|
|
|
{
|
2014-02-05 11:39:15 -04:00
|
|
|
$me = new self();
|
2014-02-04 20:50:18 -04:00
|
|
|
$project = ProjectPeer::retrieveByPK($prjUid);
|
|
|
|
|
|
|
|
|
|
if (! is_object($project)) {
|
2014-02-05 11:39:15 -04:00
|
|
|
throw new Exception\ProjectNotFound($me, $prjUid);
|
2014-02-04 20:50:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$me->project = $project;
|
|
|
|
|
$me->prjUid = $me->project->getPrjUid();
|
2014-02-03 19:37:50 -04:00
|
|
|
|
|
|
|
|
return $me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-05 11:39:15 -04:00
|
|
|
* @param array| $data array attributes to create and initialize a BpmnProject
|
2014-02-03 19:37:50 -04:00
|
|
|
*/
|
|
|
|
|
public function create($data)
|
|
|
|
|
{
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['PRJ_UID'] = array_key_exists('PRJ_UID', $data) ? $data['PRJ_UID'] : Hash::generateUID();
|
|
|
|
|
|
2014-02-12 17:01:19 -04:00
|
|
|
self::log("Create Project with data: ", $data);
|
2014-02-03 19:37:50 -04:00
|
|
|
$this->project = new Project();
|
|
|
|
|
$this->project->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$this->project->setPrjCreateDate(date("Y-m-d H:i:s"));
|
|
|
|
|
$this->project->save();
|
2014-02-04 20:50:18 -04:00
|
|
|
|
|
|
|
|
$this->prjUid = $this->project->getPrjUid();
|
2014-02-12 17:01:19 -04:00
|
|
|
self::log("Create Project Success!");
|
2014-02-04 20:50:18 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 14:09:48 -04:00
|
|
|
public function update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
public function remove()
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* 1. Remove Diagram related objects
|
|
|
|
|
* 2. Remove Project related objects
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-12 17:01:19 -04:00
|
|
|
self::log("Remove Project With Uid: {$this->prjUid}");
|
|
|
|
|
foreach ($this->getActivities() as $activity) {
|
2014-02-04 20:50:18 -04:00
|
|
|
$this->removeActivity($activity["ACT_UID"]);
|
|
|
|
|
}
|
2014-02-12 17:01:19 -04:00
|
|
|
foreach ($this->getGateways() as $gateway) {
|
|
|
|
|
$this->removeGateway($gateway["GAT_UID"]);
|
|
|
|
|
}
|
|
|
|
|
foreach ($this->getEvents() as $event) {
|
|
|
|
|
$this->removeEvent($event["EVN_UID"]);
|
|
|
|
|
}
|
|
|
|
|
foreach ($this->getFlows() as $flow) {
|
|
|
|
|
$this->removeFlow($flow["FLO_UID"]);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 14:09:48 -04:00
|
|
|
if ($process = $this->getProcess("object")) {
|
|
|
|
|
$process->delete();
|
|
|
|
|
}
|
|
|
|
|
if ($diagram = $this->getDiagram("object")) {
|
|
|
|
|
$diagram->delete();
|
|
|
|
|
}
|
|
|
|
|
if ($project = $this->getProject("object")) {
|
|
|
|
|
$project->delete();
|
|
|
|
|
}
|
2014-02-12 17:01:19 -04:00
|
|
|
self::log("Remove Project Success!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function removeIfExists($prjUid)
|
|
|
|
|
{
|
|
|
|
|
$project = ProjectPeer::retrieveByPK($prjUid);
|
|
|
|
|
|
|
|
|
|
if ($project) {
|
|
|
|
|
$me = new self();
|
|
|
|
|
$me->prjUid = $project->getPrjUid();
|
|
|
|
|
$me->project = $project;
|
|
|
|
|
$me->remove();
|
|
|
|
|
}
|
2014-02-05 12:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
|
|
|
|
{
|
|
|
|
|
return Project::getAll($start, $limit, $filter, $changeCaseTo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUid()
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->project)) {
|
|
|
|
|
throw new \RuntimeException("Error: There is not an initialized project.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->prjUid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProject($retType = "array")
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->project)) {
|
|
|
|
|
throw new \RuntimeException("Error: There is not an initialized project.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $retType == "array" ? $this->project->toArray() : $this->project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Projects elements handlers
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
public function addDiagram($data = array())
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->project)) {
|
|
|
|
|
throw new \Exception("Error: There is not an initialized project.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['DIA_UID'] = array_key_exists('DIA_UID', $data) ? $data['DIA_UID'] : Hash::generateUID();
|
|
|
|
|
$data['DIA_NAME'] = array_key_exists('DIA_NAME', $data) ? $data['DIA_NAME'] : $this->project->getPrjName();
|
|
|
|
|
|
|
|
|
|
$this->diagram = new Diagram();
|
|
|
|
|
$this->diagram->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$this->diagram->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$this->diagram->save();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
public function getDiagram($retType = "array")
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->diagram)) {
|
|
|
|
|
$diagrams = Diagram::findAllByProUid($this->getUid());
|
|
|
|
|
|
|
|
|
|
if (! empty($diagrams)) {
|
|
|
|
|
//NOTICE for ProcessMaker we're just handling a "one to one" relationship between project and process
|
|
|
|
|
$this->diagram = $diagrams[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 11:00:15 -04:00
|
|
|
return ($retType == "array" && is_object($this->diagram)) ? $this->diagram->toArray() : $this->diagram;
|
2014-02-05 12:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
public function addProcess($data = array())
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->diagram)) {
|
|
|
|
|
throw new \Exception("Error: There is not an initialized diagram.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['PRO_UID'] = array_key_exists('PRO_UID', $data) ? $data['PRO_UID'] : Hash::generateUID();;
|
|
|
|
|
$data['PRO_NAME'] = array_key_exists('PRO_NAME', $data) ? $data['PRO_NAME'] : $this->diagram->getDiaName();
|
|
|
|
|
|
|
|
|
|
$this->process = new Process();
|
|
|
|
|
$this->process->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$this->process->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$this->process->setDiaUid($this->getDiagram("object")->getDiaUid());
|
|
|
|
|
$this->process->save();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
public function getProcess($retType = "array")
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->process)) {
|
|
|
|
|
$processes = Process::findAllByProUid($this->getUid());
|
|
|
|
|
|
|
|
|
|
if (! empty($processes)) {
|
|
|
|
|
//NOTICE for ProcessMaker we're just handling a "one to one" relationship between project and process
|
|
|
|
|
$this->process = $processes[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $retType == "array" ? $this->process->toArray() : $this->process;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
public function addActivity($data)
|
|
|
|
|
{
|
2014-02-06 11:29:45 -04:00
|
|
|
if (! ($process = $this->getProcess("object"))) {
|
|
|
|
|
throw new \Exception(sprintf("Error: There is not an initialized diagram for Project with prj_uid: %s.", $this->getUid()));
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
// setting defaults
|
|
|
|
|
$data['ACT_UID'] = array_key_exists('ACT_UID', $data) ? $data['ACT_UID'] : Hash::generateUID();;
|
|
|
|
|
|
2014-02-06 12:10:35 -04:00
|
|
|
try {
|
|
|
|
|
self::log("Add Activity with data: ", $data);
|
|
|
|
|
|
|
|
|
|
$activity = new Activity();
|
|
|
|
|
$activity->fromArray($data);
|
|
|
|
|
$activity->setPrjUid($this->getUid());
|
|
|
|
|
$activity->setProUid($process->getProUid());
|
|
|
|
|
$activity->save();
|
|
|
|
|
|
|
|
|
|
self::log("Add Activity Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
return $activity->getActUid();
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
public function getActivity($actUid, $retType = 'array')
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-04 20:50:18 -04:00
|
|
|
$activity = ActivityPeer::retrieveByPK($actUid);
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
if ($retType != "object" && ! empty($activity)) {
|
|
|
|
|
$activity = $activity->toArray();
|
2014-02-18 17:41:45 -04:00
|
|
|
$activity = self::filterArrayKeys($activity, self::$excludeFields["activity"]);
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
return $activity;
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-06 11:00:15 -04:00
|
|
|
public function getActivities($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-06 11:00:15 -04:00
|
|
|
if (is_array($start)) {
|
|
|
|
|
extract($start);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
$filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["activity"]) : self::$excludeFields["activity"];
|
|
|
|
|
|
|
|
|
|
return self::filterCollectionArrayKeys(
|
|
|
|
|
Activity::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo),
|
|
|
|
|
$filter
|
|
|
|
|
);
|
2014-02-05 12:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateActivity($actUid, $data)
|
|
|
|
|
{
|
2014-02-06 12:10:35 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Update Activity: $actUid, with data: ", $data);
|
2014-02-06 12:10:35 -04:00
|
|
|
|
|
|
|
|
$activity = ActivityPeer::retrieveByPk($actUid);
|
|
|
|
|
$activity->fromArray($data);
|
|
|
|
|
$activity->save();
|
2014-02-05 12:33:36 -04:00
|
|
|
|
2014-02-06 12:10:35 -04:00
|
|
|
self::log("Update Activity Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-04 20:50:18 -04:00
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
public function removeActivity($actUid)
|
|
|
|
|
{
|
2014-02-06 12:10:35 -04:00
|
|
|
try {
|
|
|
|
|
self::log("Remove Activity: $actUid");
|
|
|
|
|
|
|
|
|
|
$activity = ActivityPeer::retrieveByPK($actUid);
|
|
|
|
|
$activity->delete();
|
|
|
|
|
|
|
|
|
|
self::log("Remove Activity Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
public function activityExists($actUid)
|
|
|
|
|
{
|
|
|
|
|
return \BpmnActivity::exists($actUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
public function addEvent($data)
|
|
|
|
|
{
|
|
|
|
|
// setting defaults
|
2014-02-06 20:30:27 -04:00
|
|
|
$data['EVN_UID'] = array_key_exists('EVN_UID', $data) ? $data['EVN_UID'] : Hash::generateUID();
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-10 19:43:54 -04:00
|
|
|
try {
|
|
|
|
|
self::log("Add Event with data: ", $data);
|
|
|
|
|
|
|
|
|
|
$event = new Event();
|
|
|
|
|
$event->fromArray($data);
|
|
|
|
|
$event->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$event->setProUid($this->getProcess("object")->getProUid());
|
|
|
|
|
$event->save();
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-10 19:43:54 -04:00
|
|
|
self::log("Add Event Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-11 17:50:14 -04:00
|
|
|
public function getEvent($evnUid, $retType = 'array')
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-11 17:50:14 -04:00
|
|
|
$event = EventPeer::retrieveByPK($evnUid);
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-19 13:31:02 -04:00
|
|
|
if ($retType != "object" && ! empty($event)) {
|
2014-02-11 17:50:14 -04:00
|
|
|
$event = $event->toArray();
|
2014-02-19 13:31:02 -04:00
|
|
|
$event = self::filterArrayKeys($event, self::$excludeFields["event"]);
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-11 17:50:14 -04:00
|
|
|
return $event;
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-10 19:43:54 -04:00
|
|
|
public function getEvents($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
|
|
|
|
{
|
|
|
|
|
if (is_array($start)) {
|
|
|
|
|
extract($start);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 13:31:02 -04:00
|
|
|
//return Event::getAll($this->project->getPrjUid(), null, null, '', $changeCaseTo);
|
|
|
|
|
|
|
|
|
|
$filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["event"]) : self::$excludeFields["event"];
|
|
|
|
|
|
|
|
|
|
return self::filterCollectionArrayKeys(
|
|
|
|
|
Event::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo),
|
|
|
|
|
$filter
|
|
|
|
|
);
|
2014-02-10 19:43:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateEvent($evnUid, $data)
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-19 19:32:19 -04:00
|
|
|
if (array_key_exists("EVN_CANCEL_ACTIVITY", $data)) {
|
|
|
|
|
$data["EVN_CANCEL_ACTIVITY"] = $data["EVN_CANCEL_ACTIVITY"] ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (array_key_exists("EVN_WAIT_FOR_COMPLETION", $data)) {
|
|
|
|
|
$data["EVN_WAIT_FOR_COMPLETION"] = $data["EVN_WAIT_FOR_COMPLETION"] ? 1 : 0;
|
|
|
|
|
}
|
2014-02-19 13:31:02 -04:00
|
|
|
|
2014-02-10 19:43:54 -04:00
|
|
|
try {
|
|
|
|
|
self::log("Update Event: $evnUid", "With data: ", $data);
|
|
|
|
|
|
|
|
|
|
$event = EventPeer::retrieveByPk($evnUid);
|
|
|
|
|
$event->fromArray($data);
|
|
|
|
|
$event->save();
|
|
|
|
|
|
|
|
|
|
self::log("Update Event Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeEvent($evnUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Remove Event: $evnUid");
|
|
|
|
|
|
|
|
|
|
$event = EventPeer::retrieveByPK($evnUid);
|
|
|
|
|
$event->delete();
|
|
|
|
|
|
|
|
|
|
self::log("Remove Event Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addGateway($data)
|
|
|
|
|
{
|
|
|
|
|
// setting defaults
|
2014-02-06 20:30:27 -04:00
|
|
|
$data['GAT_UID'] = array_key_exists('GAT_UID', $data) ? $data['GAT_UID'] : Hash::generateUID();
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
try {
|
|
|
|
|
self::log("Add Gateway with data: ", $data);
|
|
|
|
|
$gateway = new Gateway();
|
|
|
|
|
$gateway->fromArray($data);
|
|
|
|
|
$gateway->setPrjUid($this->getUid());
|
|
|
|
|
$gateway->setProUid($this->getProcess("object")->getProUid());
|
|
|
|
|
$gateway->save();
|
|
|
|
|
|
|
|
|
|
self::log("Add Gateway Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
return $gateway->getGatUid();
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
public function updateGateway($gatUid, $data)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Update Gateway: $gatUid", "With data: ", $data);
|
|
|
|
|
|
|
|
|
|
$gateway = GatewayPeer::retrieveByPk($gatUid);
|
|
|
|
|
|
|
|
|
|
$gateway->fromArray($data);
|
|
|
|
|
$gateway->save();
|
|
|
|
|
|
|
|
|
|
self::log("Update Gateway Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
public function getGateway($gatUid, $retType = 'array')
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-07 08:41:11 -04:00
|
|
|
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
if ($retType != "object" && ! empty($gateway)) {
|
|
|
|
|
$gateway = $gateway->toArray();
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
return $gateway;
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
public function getGateways($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-07 15:42:24 -04:00
|
|
|
if (is_array($start)) {
|
|
|
|
|
extract($start);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 19:43:54 -04:00
|
|
|
return Gateway::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo);
|
2014-02-07 15:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeGateway($gatUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Remove Gateway: $gatUid");
|
|
|
|
|
|
|
|
|
|
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
|
|
|
|
$gateway->delete();
|
|
|
|
|
|
|
|
|
|
self::log("Remove Gateway Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addFlow($data)
|
|
|
|
|
{
|
2014-02-07 15:42:24 -04:00
|
|
|
self::log("Add Flow with data: ", $data);
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
// setting defaults
|
2014-02-06 20:30:27 -04:00
|
|
|
$data['FLO_UID'] = array_key_exists('FLO_UID', $data) ? $data['FLO_UID'] : Hash::generateUID();
|
2014-02-07 15:42:24 -04:00
|
|
|
if (array_key_exists('FLO_STATE', $data)) {
|
|
|
|
|
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
|
|
|
|
|
}
|
2014-02-06 20:30:27 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$flow = new Flow();
|
|
|
|
|
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$flow->setPrjUid($this->getUid());
|
|
|
|
|
$flow->setDiaUid($this->getDiagram("object")->getDiaUid());
|
|
|
|
|
$flow->save();
|
|
|
|
|
|
|
|
|
|
self::log("Add Flow Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
public function updateFlow($floUid, $data)
|
|
|
|
|
{
|
|
|
|
|
self::log("Update Flow: $floUid", "With data: ", $data);
|
|
|
|
|
|
|
|
|
|
// setting defaults
|
|
|
|
|
if (array_key_exists('FLO_STATE', $data)) {
|
|
|
|
|
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
$flow = FlowPeer::retrieveByPk($floUid);
|
|
|
|
|
$flow->fromArray($data);
|
|
|
|
|
$flow->save();
|
|
|
|
|
|
|
|
|
|
self::log("Update Flow Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 20:30:27 -04:00
|
|
|
public function getFlow($floUid, $retType = 'array')
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-06 20:30:27 -04:00
|
|
|
$flow = FlowPeer::retrieveByPK($floUid);
|
2014-02-03 19:37:50 -04:00
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
if ($retType != "object" && ! empty($flow)) {
|
2014-02-06 20:30:27 -04:00
|
|
|
$flow = $flow->toArray();
|
2014-02-18 17:41:45 -04:00
|
|
|
$flow = self::filterArrayKeys($flow, self::$excludeFields["flow"]);
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-06 20:30:27 -04:00
|
|
|
return $flow;
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
public function getFlows($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-07 15:42:24 -04:00
|
|
|
if (is_array($start)) {
|
|
|
|
|
extract($start);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
$filter = $changeCaseTo != CASE_UPPER ? array_map("strtolower", self::$excludeFields["flow"]) : self::$excludeFields["flow"];
|
|
|
|
|
|
|
|
|
|
return self::filterCollectionArrayKeys(
|
|
|
|
|
Flow::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo),
|
|
|
|
|
$filter
|
|
|
|
|
);
|
2014-02-07 15:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeFlow($floUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Remove Flow: $floUid");
|
|
|
|
|
|
|
|
|
|
$flow = FlowPeer::retrieveByPK($floUid);
|
|
|
|
|
$flow->delete();
|
|
|
|
|
|
|
|
|
|
self::log("Remove Flow Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
public function flowExists($floUid)
|
|
|
|
|
{
|
|
|
|
|
return \BpmnFlow::exists($floUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 19:37:50 -04:00
|
|
|
public function addArtifact($data)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getArtifact($artUid)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getArtifacts()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
2014-02-06 11:00:15 -04:00
|
|
|
return array();
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addLane($data)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLane($lanUid)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLanes()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
2014-02-06 11:00:15 -04:00
|
|
|
return array();
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addLaneset($data)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLaneset($lnsUid)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLanesets()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
2014-02-06 11:00:15 -04:00
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
public function isModified($element, $uid, $newData)
|
2014-02-06 11:00:15 -04:00
|
|
|
{
|
2014-02-18 17:41:45 -04:00
|
|
|
$data = array();
|
2014-02-06 11:00:15 -04:00
|
|
|
|
2014-02-18 17:41:45 -04:00
|
|
|
switch ($element) {
|
|
|
|
|
case "activity": $data = $this->getActivity($uid); break;
|
|
|
|
|
case "gateway": $data = $this->getGateway($uid); break;
|
|
|
|
|
case "event": $data = $this->getEvent($uid); break;
|
|
|
|
|
case "flow": $data = $this->getFlow($uid); break;
|
2014-02-06 11:00:15 -04:00
|
|
|
}
|
2014-02-19 13:31:02 -04:00
|
|
|
//self::log("saved data: ", $data, "new data: ", $newData);
|
|
|
|
|
//self::log("checksum saved data: ", self::getChecksum($data), "checksum new data: ", self::getChecksum($newData));
|
2014-02-18 17:41:45 -04:00
|
|
|
return (self::getChecksum($data) !== self::getChecksum($newData));
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
}
|