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-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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $retType == "array" ? $this->diagram->toArray() : $this->diagram;
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->diagram)) {
|
|
|
|
|
throw new \Exception("Error: There is not an initialized diagram.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['ACT_UID'] = array_key_exists('ACT_UID', $data) ? $data['ACT_UID'] : Hash::generateUID();;
|
|
|
|
|
|
|
|
|
|
$activity = new Activity();
|
|
|
|
|
$activity->fromArray($data);
|
|
|
|
|
$activity->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$activity->setProUid($this->getProcess("object")->getProUid());
|
|
|
|
|
$activity->save();
|
|
|
|
|
|
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-05 12:33:36 -04:00
|
|
|
public function getActivities()
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-05 12:33:36 -04:00
|
|
|
return Activity::getAll($this->getUid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateActivity($actUid, $data)
|
|
|
|
|
{
|
|
|
|
|
$activity = ActivityPeer::retrieveByPk($actUid);
|
|
|
|
|
|
|
|
|
|
// fixing data
|
|
|
|
|
//$data['ELEMENT_UID'] = $data['BOU_ELEMENT_UID'];
|
|
|
|
|
//unset($data['BOU_ELEMENT_UID']);
|
|
|
|
|
|
|
|
|
|
$activity->fromArray($data);
|
|
|
|
|
$activity->save();
|
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)
|
|
|
|
|
{
|
|
|
|
|
$activity = ActivityPeer::retrieveByPK($actUid);
|
|
|
|
|
$activity->delete();
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addEvent($data)
|
|
|
|
|
{
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['EVN_UID'] = array_key_exists('EVN_UID', $data) ? $data['EVN_UID'] : Hash::generateUID();;
|
|
|
|
|
|
|
|
|
|
$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-04 20:50:18 -04:00
|
|
|
public function getEvents($retType)
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-04 20:50:18 -04:00
|
|
|
return Event::getAll($this->project->getPrjUid(), null, null, '', 'object');
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addGateway($data)
|
|
|
|
|
{
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['GAT_UID'] = array_key_exists('GAT_UID', $data) ? $data['GAT_UID'] : Hash::generateUID();;
|
|
|
|
|
|
|
|
|
|
$gateway = new Gateway();
|
|
|
|
|
$gateway->fromArray($data);
|
|
|
|
|
$gateway->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$gateway->setProUid($this->getProcess("object")->getProUid());
|
|
|
|
|
$gateway->save();
|
|
|
|
|
|
|
|
|
|
$this->gateways[$gateway->getGatUid()] = $gateway;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getGateway($gatUid)
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->gateways) || ! array_key_exists($gatUid, $this->gateways)) {
|
|
|
|
|
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
|
|
|
|
|
|
|
|
|
if (! is_object($gateway)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->gateways[$gatUid] = $gateway;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->gateways[$gatUid];
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
public function getGateways($retType = 'array')
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-04 20:50:18 -04:00
|
|
|
return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
2014-02-03 19:37:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addFlow($data)
|
|
|
|
|
{
|
|
|
|
|
// setting defaults
|
|
|
|
|
$data['GAT_UID'] = array_key_exists('GAT_UID', $data) ? $data['GAT_UID'] : Hash::generateUID();;
|
|
|
|
|
$data['FLO_STATE'] = json_encode($data['FLO_STATE']);
|
|
|
|
|
|
|
|
|
|
$flow = new Flow();
|
|
|
|
|
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$flow->setPrjUid($this->project->getPrjUid());
|
|
|
|
|
$flow->setDiaUid($this->getDiagram("object")->getDiaUid());
|
|
|
|
|
$flow->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getFlow($floUid)
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->flows) || ! array_key_exists($floUid, $this->flows)) {
|
|
|
|
|
$flow = GatewayPeer::retrieveByPK($floUid);
|
|
|
|
|
|
|
|
|
|
if (! is_object($flow)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->flows[$floUid] = $flow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->flows[$floUid];
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:50:18 -04:00
|
|
|
public function getFlows($retType = 'array')
|
2014-02-03 19:37:50 -04:00
|
|
|
{
|
2014-02-04 20:50:18 -04:00
|
|
|
return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
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.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addLane($data)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLane($lanUid)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLanes()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addLaneset($data)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLaneset($lnsUid)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLanesets()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
}
|