PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/workflow/engine/classes/model/Triggers.php

https://bitbucket.org/ferOnti/processmaker
PHP | 360 lines | 302 code | 7 blank | 51 comment | 10 complexity | 491a92388c9652bf4889ed212e47dae6 MD5 | raw file
  1. <?php
  2. /**
  3. * Triggers.php
  4. * @package workflow.engine.classes.model
  5. *
  6. * ProcessMaker Open Source Edition
  7. * Copyright (C) 2004 - 2011 Colosa Inc.
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
  23. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
  24. *
  25. */
  26. require_once 'classes/model/Content.php';
  27. require_once 'classes/model/om/BaseTriggers.php';
  28. /**
  29. * Skeleton subclass for representing a row from the 'TRIGGER' table.
  30. *
  31. *
  32. *
  33. * You should add additional methods to this class to meet the
  34. * application requirements. This class will only be generated as
  35. * long as it does not already exist in the output directory.
  36. *
  37. * @package workflow.engine.classes.model
  38. */
  39. class Triggers extends BaseTriggers
  40. {
  41. /**
  42. * This value goes in the content table
  43. * @var string
  44. */
  45. protected $tri_title = '';
  46. /**
  47. * Get the tri_title column value.
  48. * @return string
  49. */
  50. public function getTriTitle()
  51. {
  52. if ($this->getTriUid() == "") {
  53. throw ( new Exception( "Error in getTriTitle, the getTriUid() can't be blank") );
  54. }
  55. $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
  56. $this->tri_title = Content::load ( 'TRI_TITLE', '', $this->getTriUid(), $lang );
  57. return $this->tri_title;
  58. }
  59. /**
  60. * Set the tri_title column value.
  61. *
  62. * @param string $v new value
  63. * @return void
  64. */
  65. public function setTriTitle($v)
  66. {
  67. if ($this->getTriUid() == "") {
  68. throw ( new Exception( "Error in setTriTitle, the getTriUid() can't be blank") );
  69. }
  70. $v=isset($v)?((string)$v):'';
  71. $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
  72. if ($this->tri_title !== $v || $v==="") {
  73. $this->tri_title = $v;
  74. $res = Content::addContent( 'TRI_TITLE', '', $this->getTriUid(), $lang, $this->tri_title );
  75. return $res;
  76. }
  77. return 0;
  78. }
  79. /**
  80. * This value goes in the content table
  81. * @var string
  82. */
  83. protected $tri_description = '';
  84. /**
  85. * Get the tri_description column value.
  86. * @return string
  87. */
  88. public function getTriDescription()
  89. {
  90. if ($this->getTriUid() == "") {
  91. throw ( new Exception( "Error in getTriDescription, the getTriUid() can't be blank") );
  92. }
  93. $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
  94. $this->tri_description = Content::load ( 'TRI_DESCRIPTION', '', $this->getTriUid(), $lang );
  95. return $this->tri_description;
  96. }
  97. /**
  98. * Set the tri_description column value.
  99. *
  100. * @param string $v new value
  101. * @return void
  102. */
  103. public function setTriDescription($v)
  104. {
  105. if ($this->getTriUid() == "") {
  106. throw ( new Exception( "Error in setTriDescription, the getTriUid() can't be blank") );
  107. }
  108. $v=isset($v)?((string)$v):'';
  109. $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
  110. if ($this->tri_description !== $v || $v==="") {
  111. $this->tri_description = $v;
  112. $res = Content::addContent( 'TRI_DESCRIPTION', '', $this->getTriUid(), $lang, $this->tri_description );
  113. return $res;
  114. }
  115. return 0;
  116. }
  117. public function load($TriUid)
  118. {
  119. try {
  120. $oRow = TriggersPeer::retrieveByPK( $TriUid );
  121. if (!is_null($oRow)) {
  122. $aFields = $oRow->toArray(BasePeer::TYPE_FIELDNAME);
  123. $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME);
  124. $this->setNew(false);
  125. $this->setTriTitle($aFields['TRI_TITLE']=$this->getTriTitle());
  126. $this->setTriDescription($aFields['TRI_DESCRIPTION']=$this->getTriDescription());
  127. return $aFields;
  128. } else {
  129. throw( new Exception( "The row '$TriUid' in table TRIGGERS doesn't exist!" ));
  130. }
  131. } catch (Exception $oError) {
  132. throw($oError);
  133. }
  134. }
  135. public function create($aData)
  136. {
  137. $con = Propel::getConnection(TriggersPeer::DATABASE_NAME);
  138. try {
  139. $con->begin();
  140. if (isset ( $aData['TRI_UID'] ) && $aData['TRI_UID']== '') {
  141. unset ( $aData['TRI_UID'] );
  142. }
  143. if ( !isset ( $aData['TRI_UID'] ) ) {
  144. $this->setTriUid(G::generateUniqueID());
  145. } else {
  146. $this->setTriUid($aData['TRI_UID'] );
  147. }
  148. $this->setProUid($aData['PRO_UID']);
  149. $this->setTriType("SCRIPT");
  150. if (!isset ( $aData['TRI_WEBBOT'] )) {
  151. $this->setTriWebbot("");
  152. } else {
  153. $this->setTriWebbot( $aData['TRI_WEBBOT'] );
  154. }
  155. if ($this->validate()) {
  156. if (!isset ( $aData['TRI_TITLE'] )) {
  157. $this->setTriTitle("");
  158. } else {
  159. $this->setTriTitle( $aData['TRI_TITLE'] );
  160. }
  161. if (!isset ( $aData['TRI_DESCRIPTION'] )) {
  162. $this->setTriDescription("");
  163. } else {
  164. $this->setTriDescription( $aData['TRI_DESCRIPTION'] );
  165. }
  166. if (!isset ( $aData['TRI_PARAM'] )) {
  167. $this->setTriParam("");
  168. } else {
  169. $this->setTriParam( $aData['TRI_PARAM'] );
  170. }
  171. $result=$this->save();
  172. $con->commit();
  173. return $result;
  174. } else {
  175. $con->rollback();
  176. throw(new Exception("Failed Validation in class ".get_class($this)."."));
  177. }
  178. } catch (Exception $e) {
  179. $con->rollback();
  180. throw($e);
  181. }
  182. }
  183. public function update($fields)
  184. {
  185. $con = Propel::getConnection(TriggersPeer::DATABASE_NAME);
  186. try {
  187. $con->begin();
  188. $this->load($fields['TRI_UID']);
  189. $this->fromArray($fields,BasePeer::TYPE_FIELDNAME);
  190. if ($this->validate()) {
  191. $contentResult=0;
  192. if (array_key_exists("TRI_TITLE", $fields)) {
  193. $contentResult+=$this->setTriTitle($fields["TRI_TITLE"]);
  194. }
  195. if (array_key_exists("TRI_DESCRIPTION", $fields)) {
  196. $contentResult+=$this->setTriDescription($fields["TRI_DESCRIPTION"]);
  197. }
  198. $result=$this->save();
  199. $result=($result==0)?($contentResult>0?1:0):$result;
  200. $con->commit();
  201. return $result;
  202. } else {
  203. $con->rollback();
  204. $validationE=new Exception("Failed Validation in class ".get_class($this).".");
  205. $validationE->aValidationFailures = $this->getValidationFailures();
  206. throw($validationE);
  207. }
  208. } catch (Exception $e) {
  209. $con->rollback();
  210. throw($e);
  211. }
  212. }
  213. public function remove($TriUid)
  214. {
  215. $con = Propel::getConnection(TriggersPeer::DATABASE_NAME);
  216. try {
  217. $result = false;
  218. $con->begin();
  219. $oTri = TriggersPeer::retrieveByPK( $TriUid );
  220. if (!is_null($oTri)) {
  221. Content::removeContent( 'TRI_TITLE', '', $this->getTriUid());
  222. Content::removeContent( 'TRI_DESCRIPTION', '', $this->getTriUid());
  223. $result = $oTri->delete();
  224. $con->commit();
  225. }
  226. return $result;
  227. } catch (Exception $e) {
  228. $con->rollback();
  229. throw($e);
  230. }
  231. }
  232. /**
  233. * verify if Trigger row specified in [sUid] exists.
  234. *
  235. * @param string $sUid the uid of the Prolication
  236. */
  237. public function TriggerExists ($sUid)
  238. {
  239. $con = Propel::getConnection(TriggersPeer::DATABASE_NAME);
  240. try {
  241. $oObj = TriggersPeer::retrieveByPk( $sUid );
  242. if (is_object($oObj) && get_class ($oObj) == 'Triggers' ) {
  243. return true;
  244. } else {
  245. return false;
  246. }
  247. } catch (Exception $oError) {
  248. throw($oError);
  249. }
  250. }
  251. public function verifyDependecies($TRI_UID)
  252. {
  253. require_once "classes/model/Event.php";
  254. require_once "classes/model/StepTrigger.php";
  255. $oResult = new stdClass();
  256. $oResult->dependencies = Array();
  257. $oCriteria = new Criteria();
  258. $oCriteria->addSelectColumn(EventPeer::EVN_UID);
  259. $oCriteria->addSelectColumn(EventPeer::TRI_UID);
  260. $oCriteria->add(EventPeer::EVN_ACTION, '', Criteria::NOT_EQUAL);
  261. $oCriteria->add(EventPeer::TRI_UID, $TRI_UID);
  262. $oDataset = EventPeer::doSelectRS($oCriteria);
  263. $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
  264. $aRows = Array();
  265. while ($oDataset->next()) {
  266. array_push($aRows, $oDataset->getRow());
  267. }
  268. $oResult->dependencies['Events'] = Array();
  269. if (count($aRows) == 0) {
  270. $oResult->code = 0;
  271. } else {
  272. $oResult->code = 1;
  273. foreach ($aRows as $row) {
  274. $oTrigger = TriggersPeer::retrieveByPK($row['TRI_UID']);
  275. array_push($oResult->dependencies['Events'], Array('UID'=>($oTrigger->getTriUid()), 'DESCRIPTION'=>($oTrigger->getTriTitle())));
  276. }
  277. }
  278. //for tasks dependencies
  279. $oCriteria = new Criteria();
  280. $oCriteria->addSelectColumn(StepTriggerPeer::TAS_UID);
  281. $oCriteria->addSelectColumn(StepTriggerPeer::TRI_UID);
  282. $oCriteria->add(StepTriggerPeer::TRI_UID, $TRI_UID);
  283. $oDataset = StepTriggerPeer::doSelectRS($oCriteria);
  284. $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
  285. $aRows = Array();
  286. while ( $oDataset->next() ) {
  287. array_push($aRows, $oDataset->getRow());
  288. }
  289. $oResult->dependencies['Tasks'] = Array();
  290. if ($oResult->code == 0 && count($aRows) == 0) {
  291. $oResult->code = 0;
  292. } elseif (count($aRows) > 0) {
  293. $oResult->code = 1;
  294. foreach ($aRows as $row) {
  295. $oTask = TaskPeer::retrieveByPK($row['TAS_UID']);
  296. array_push($oResult->dependencies['Tasks'], Array('UID'=>($oTask->getTasUid()), 'DESCRIPTION'=>($oTask->getTasTitle())));
  297. }
  298. }
  299. //Tasks, assignment rules dependencies
  300. $criteria = new Criteria();
  301. $criteria->addSelectColumn(TaskPeer::TAS_UID);
  302. $criteria->add(TaskPeer::TAS_SELFSERVICE_TIMEOUT, 1);
  303. $criteria->add(TaskPeer::TAS_SELFSERVICE_TRIGGER_UID, $TRI_UID);
  304. $rsCriteria = TaskPeer::doSelectRS($criteria);
  305. $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
  306. $arrayRow = array();
  307. while ($rsCriteria->next()) {
  308. array_push($arrayRow, $rsCriteria->getRow());
  309. }
  310. $oResult->dependencies["Assignment rules"] = array();
  311. if ($oResult->code == 0 && count($arrayRow) == 0) {
  312. $oResult->code = 0;
  313. } else {
  314. if (count($arrayRow) > 0) {
  315. foreach ($arrayRow as $row) {
  316. $task = TaskPeer::retrieveByPK($row["TAS_UID"]);
  317. array_push($oResult->dependencies["Assignment rules"], array("UID" => $task->getTasUid(), "DESCRIPTION" => $task->getTasTitle()));
  318. }
  319. $oResult->code = 1;
  320. }
  321. }
  322. return $oResult;
  323. }
  324. }