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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
$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-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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$activities = $this->getActivities();
|
|
|
|
|
|
|
|
|
|
foreach ($activities as $activity) {
|
|
|
|
|
$this->removeActivity($activity["ACT_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-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-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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Activity::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo);
|
2014-02-05 12:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateActivity($actUid, $data)
|
|
|
|
|
{
|
2014-02-06 12:10:35 -04:00
|
|
|
try {
|
|
|
|
|
self::log("Update Activity: $actUid", "With data: ", $data);
|
|
|
|
|
|
|
|
|
|
$activity = ActivityPeer::retrieveByPk($actUid);
|
|
|
|
|
|
|
|
|
|
// fixing data
|
|
|
|
|
//$data['ELEMENT_UID'] = $data['BOU_ELEMENT_UID'];
|
|
|
|
|
//unset($data['BOU_ELEMENT_UID']);
|
2014-02-05 12:33:36 -04:00
|
|
|
|
2014-02-06 12:10:35 -04:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$event = new Event();
|
|
|
|
|
$event->fromArray($data);
|
|
|
|
|
$event->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$event->setProUid($this->getProcess("object")->getProUid());
|
|
|
|
|
$event->save();
|
|
|
|
|
|
|
|
|
|
$this->events[$event->getEvnUid()] = $event;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getEvent($evnUid)
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->events) || ! array_key_exists($evnUid, $this->activities)) {
|
|
|
|
|
$event = EventPeer::retrieveByPK($evnUid);
|
|
|
|
|
|
|
|
|
|
if (! is_object($event)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->events[$evnUid] = $event;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->events[$evnUid];
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 11:00:15 -04:00
|
|
|
public function getEvents($retType = "array")
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-06 11:00:15 -04:00
|
|
|
//return Event::getAll($this->project->getPrjUid(), null, null, '', 'object');
|
|
|
|
|
return array();
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Gateway::getAll($this->getUid(), null, null, '', $changeCaseTo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-06 20:30:27 -04:00
|
|
|
if ($retType != "object" && ! empty($activity)) {
|
|
|
|
|
$flow = $flow->toArray();
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Flow::getAll($this->getUid(), null, null, '', $changeCaseTo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Others functions/methods
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public static function getDiffFromProjects($updatedProject)
|
|
|
|
|
{
|
|
|
|
|
// preparing target project
|
|
|
|
|
$diagramElements = array(
|
|
|
|
|
'act_uid' => 'activities',
|
|
|
|
|
'evn_uid' => 'events',
|
|
|
|
|
'flo_uid' => 'flows',
|
|
|
|
|
'art_uid' => 'artifacts',
|
|
|
|
|
'lns_uid' => 'laneset',
|
|
|
|
|
'lan_uid' => 'lanes'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Getting Differences
|
|
|
|
|
$newRecords = array();
|
|
|
|
|
$newRecordsUids = array();
|
|
|
|
|
$deletedRecords = array();
|
|
|
|
|
$updatedRecords = array();
|
|
|
|
|
|
|
|
|
|
// Get new records
|
|
|
|
|
foreach ($diagramElements as $key => $element) {
|
|
|
|
|
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*print_r($savedProject['diagrams'][0][$element]);
|
|
|
|
|
print_r($updatedProject['diagrams'][0][$element]);
|
|
|
|
|
var_dump($key);*/
|
|
|
|
|
|
|
|
|
|
$arrayDiff = self::arrayDiff(
|
|
|
|
|
$savedProject['diagrams'][0][$element],
|
|
|
|
|
$updatedProject['diagrams'][0][$element],
|
|
|
|
|
$key
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (! empty($arrayDiff)) {
|
|
|
|
|
$newRecordsUids[$element] = $arrayDiff;
|
|
|
|
|
|
|
|
|
|
foreach ($updatedProject['diagrams'][0][$element] as $item) {
|
|
|
|
|
if (in_array($item[$key], $newRecordsUids[$element])) {
|
|
|
|
|
$newRecords[$element][] = $item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get deleted records
|
|
|
|
|
foreach ($diagramElements as $key => $element) {
|
|
|
|
|
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arrayDiff = self::arrayDiff(
|
|
|
|
|
$updatedProject['diagrams'][0][$element],
|
|
|
|
|
$savedProject['diagrams'][0][$element],
|
|
|
|
|
$key
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (! empty($arrayDiff)) {
|
|
|
|
|
$deletedRecords[$element] = $arrayDiff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get updated records
|
|
|
|
|
$checksum = array();
|
|
|
|
|
foreach ($diagramElements as $key => $element) {
|
|
|
|
|
$checksum[$element] = self::getArrayChecksum($savedProject['diagrams'][0][$element], $key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($diagramElements as $key => $element) {
|
|
|
|
|
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($updatedProject['diagrams'][0][$element] as $item) {
|
|
|
|
|
if ((array_key_exists($element, $newRecordsUids) && in_array($item[$key], $newRecordsUids[$element])) ||
|
|
|
|
|
(array_key_exists($element, $deletedRecords) && in_array($item[$key], $deletedRecords[$element]))
|
|
|
|
|
) {
|
|
|
|
|
// skip new or deleted records
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self::getChecksum($item) !== $checksum[$element][$item[$key]]) {
|
|
|
|
|
$updatedRecords[$element][] = $item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$diff = array(
|
|
|
|
|
'new' => $newRecords,
|
|
|
|
|
'deleted' => $deletedRecords,
|
|
|
|
|
'updated' => $updatedRecords
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $diff;
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
}
|