PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/workflow/engine/classes/model/InputDocument.php

https://bitbucket.org/ferOnti/processmaker
PHP | 316 lines | 197 code | 19 blank | 100 comment | 35 complexity | e6bd7675eb1639a958c8b63c6f0a14aa MD5 | raw file
  1. <?php
  2. /**
  3. * InputDocument.php
  4. *
  5. * @package workflow.engine.classes.model
  6. *
  7. * ProcessMaker Open Source Edition
  8. * Copyright (C) 2004 - 2011 Colosa Inc.
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
  24. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
  25. *
  26. */
  27. require_once 'classes/model/om/BaseInputDocument.php';
  28. require_once 'classes/model/Content.php';
  29. /**
  30. * Skeleton subclass for representing a row from the 'INPUT_DOCUMENT' table.
  31. *
  32. *
  33. *
  34. * You should add additional methods to this class to meet the
  35. * application requirements. This class will only be generated as
  36. * long as it does not already exist in the input directory.
  37. *
  38. * @package workflow.engine.classes.model
  39. */
  40. class InputDocument extends BaseInputDocument
  41. {
  42. /**
  43. * This value goes in the content table
  44. *
  45. * @var string
  46. */
  47. protected $inp_doc_title = '';
  48. /**
  49. * This value goes in the content table
  50. *
  51. * @var string
  52. */
  53. protected $inp_doc_description = '';
  54. /*
  55. * Load the application document registry
  56. * @param string $sAppDocUid
  57. * @return variant
  58. */
  59. public function load ($sInpDocUid)
  60. {
  61. try {
  62. $oInputDocument = InputDocumentPeer::retrieveByPK( $sInpDocUid );
  63. if (! is_null( $oInputDocument )) {
  64. $aFields = $oInputDocument->toArray( BasePeer::TYPE_FIELDNAME );
  65. $aFields['INP_DOC_TITLE'] = $oInputDocument->getInpDocTitle();
  66. $aFields['INP_DOC_DESCRIPTION'] = $oInputDocument->getInpDocDescription();
  67. $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
  68. return $aFields;
  69. } else {
  70. throw (new Exception( 'This row doesn\'t exist!' ));
  71. }
  72. } catch (Exception $oError) {
  73. throw ($oError);
  74. }
  75. }
  76. public function getByUid ($sInpDocUid)
  77. {
  78. try {
  79. $oInputDocument = InputDocumentPeer::retrieveByPK( $sInpDocUid );
  80. if (is_null( $oInputDocument )) {
  81. return false;
  82. }
  83. $aFields = $oInputDocument->toArray( BasePeer::TYPE_FIELDNAME );
  84. $aFields['INP_DOC_TITLE'] = $oInputDocument->getInpDocTitle();
  85. $aFields['INP_DOC_DESCRIPTION'] = $oInputDocument->getInpDocDescription();
  86. $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
  87. return $aFields;
  88. } catch (Exception $oError) {
  89. throw ($oError);
  90. }
  91. }
  92. /**
  93. * Create the application document registry
  94. *
  95. * @param array $aData
  96. * @return string
  97. *
  98. */
  99. public function create ($aData)
  100. {
  101. $oConnection = Propel::getConnection( InputDocumentPeer::DATABASE_NAME );
  102. try {
  103. if (isset( $aData['INP_DOC_UID'] ) && $aData['INP_DOC_UID'] == '') {
  104. unset( $aData['INP_DOC_UID'] );
  105. }
  106. if (! isset( $aData['INP_DOC_UID'] )) {
  107. $aData['INP_DOC_UID'] = G::generateUniqueID();
  108. }
  109. $oInputDocument = new InputDocument();
  110. $oInputDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
  111. if ($oInputDocument->validate()) {
  112. $oConnection->begin();
  113. if (isset( $aData['INP_DOC_TITLE'] )) {
  114. $oInputDocument->setInpDocTitle( $aData['INP_DOC_TITLE'] );
  115. }
  116. if (isset( $aData['INP_DOC_DESCRIPTION'] )) {
  117. $oInputDocument->setInpDocDescription( $aData['INP_DOC_DESCRIPTION'] );
  118. }
  119. $iResult = $oInputDocument->save();
  120. $oConnection->commit();
  121. return $aData['INP_DOC_UID'];
  122. } else {
  123. $sMessage = '';
  124. $aValidationFailures = $oInputDocument->getValidationFailures();
  125. foreach ($aValidationFailures as $oValidationFailure) {
  126. $sMessage .= $oValidationFailure->getMessage() . '<br />';
  127. }
  128. throw (new Exception( 'The registry cannot be created!<br />' . $sMessage ));
  129. }
  130. } catch (Exception $oError) {
  131. $oConnection->rollback();
  132. throw ($oError);
  133. }
  134. }
  135. /**
  136. * Update the application document registry
  137. *
  138. * @param array $aData
  139. * @return string
  140. *
  141. */
  142. public function update ($aData)
  143. {
  144. $oConnection = Propel::getConnection( InputDocumentPeer::DATABASE_NAME );
  145. try {
  146. $oInputDocument = InputDocumentPeer::retrieveByPK( $aData['INP_DOC_UID'] );
  147. if (! is_null( $oInputDocument )) {
  148. $oInputDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
  149. if ($oInputDocument->validate()) {
  150. $oConnection->begin();
  151. if (isset( $aData['INP_DOC_TITLE'] )) {
  152. $oInputDocument->setInpDocTitle( $aData['INP_DOC_TITLE'] );
  153. }
  154. if (isset( $aData['INP_DOC_DESCRIPTION'] )) {
  155. $oInputDocument->setInpDocDescription( $aData['INP_DOC_DESCRIPTION'] );
  156. }
  157. $iResult = $oInputDocument->save();
  158. $oConnection->commit();
  159. return $iResult;
  160. } else {
  161. $sMessage = '';
  162. $aValidationFailures = $oInputDocument->getValidationFailures();
  163. foreach ($aValidationFailures as $oValidationFailure) {
  164. $sMessage .= $oValidationFailure->getMessage() . '<br />';
  165. }
  166. throw (new Exception( 'The registry cannot be updated!<br />' . $sMessage ));
  167. }
  168. } else {
  169. throw (new Exception( 'This row doesn\'t exist!' ));
  170. }
  171. } catch (Exception $oError) {
  172. $oConnection->rollback();
  173. throw ($oError);
  174. }
  175. }
  176. /**
  177. * Remove the application document registry
  178. *
  179. * @param array $aData
  180. * @return string
  181. *
  182. */
  183. public function remove ($sInpDocUid)
  184. {
  185. $oConnection = Propel::getConnection( InputDocumentPeer::DATABASE_NAME );
  186. try {
  187. $oInputDocument = InputDocumentPeer::retrieveByPK( $sInpDocUid );
  188. if (! is_null( $oInputDocument )) {
  189. $oConnection->begin();
  190. Content::removeContent( 'INP_DOC_TITLE', '', $oInputDocument->getInpDocUid() );
  191. Content::removeContent( 'INP_DOC_DESCRIPTION', '', $oInputDocument->getInpDocUid() );
  192. $iResult = $oInputDocument->delete();
  193. $oConnection->commit();
  194. return $iResult;
  195. } else {
  196. throw (new Exception( 'This row doesn\'t exist!' ));
  197. }
  198. } catch (Exception $oError) {
  199. $oConnection->rollback();
  200. throw ($oError);
  201. }
  202. }
  203. /**
  204. * Get the [inp_doc_title] column value.
  205. *
  206. * @return string
  207. */
  208. public function getInpDocTitle ()
  209. {
  210. if ($this->inp_doc_title == '') {
  211. try {
  212. $this->inp_doc_title = Content::load( 'INP_DOC_TITLE', '', $this->getInpDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') );
  213. } catch (Exception $oError) {
  214. throw ($oError);
  215. }
  216. }
  217. return $this->inp_doc_title;
  218. }
  219. /**
  220. * Set the [inp_doc_title] column value.
  221. *
  222. * @param string $sValue new value
  223. * @return void
  224. */
  225. public function setInpDocTitle ($sValue)
  226. {
  227. if ($sValue !== null && ! is_string( $sValue )) {
  228. $sValue = (string) $sValue;
  229. }
  230. if ($this->inp_doc_title !== $sValue || $sValue === '') {
  231. try {
  232. $this->inp_doc_title = $sValue;
  233. $iResult = Content::addContent( 'INP_DOC_TITLE', '', $this->getInpDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->inp_doc_title );
  234. } catch (Exception $oError) {
  235. $this->inp_doc_title = '';
  236. throw ($oError);
  237. }
  238. }
  239. }
  240. /**
  241. * Get the [inp_doc_comment] column value.
  242. *
  243. * @return string
  244. */
  245. public function getInpDocDescription ()
  246. {
  247. if ($this->inp_doc_description == '') {
  248. try {
  249. $this->inp_doc_description = Content::load( 'INP_DOC_DESCRIPTION', '', $this->getInpDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') );
  250. } catch (Exception $oError) {
  251. throw ($oError);
  252. }
  253. }
  254. return $this->inp_doc_description;
  255. }
  256. /**
  257. * Set the [inp_doc_comment] column value.
  258. *
  259. * @param string $sValue new value
  260. * @return void
  261. */
  262. public function setInpDocDescription ($sValue)
  263. {
  264. if ($sValue !== null && ! is_string( $sValue )) {
  265. $sValue = (string) $sValue;
  266. }
  267. if ($this->inp_doc_description !== $sValue || $sValue === '') {
  268. try {
  269. $this->inp_doc_description = $sValue;
  270. $iResult = Content::addContent( 'INP_DOC_DESCRIPTION', '', $this->getInpDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->inp_doc_description );
  271. } catch (Exception $oError) {
  272. $this->inp_doc_description = '';
  273. throw ($oError);
  274. }
  275. }
  276. }
  277. /**
  278. * verify if Input row specified in [DynUid] exists.
  279. *
  280. * @param string $sUid the uid of the Prolication
  281. */
  282. public function InputExists ($sUid)
  283. {
  284. $con = Propel::getConnection( InputDocumentPeer::DATABASE_NAME );
  285. try {
  286. $oObj = InputDocumentPeer::retrieveByPk( $sUid );
  287. if (is_object( $oObj ) && get_class( $oObj ) == 'InputDocument') {
  288. return true;
  289. } else {
  290. return false;
  291. }
  292. } catch (Exception $oError) {
  293. throw ($oError);
  294. }
  295. }
  296. }
  297. // InputDocument