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

/workflow/engine/controllers/processProxy.php

https://bitbucket.org/ferOnti/processmaker
PHP | 430 lines | 303 code | 56 blank | 71 comment | 34 complexity | ff6eb39beead78b93beab4e71b71d964 MD5 | raw file
  1. <?php
  2. class ProcessProxy extends HttpProxyController
  3. {
  4. /**
  5. * get Process Categories List with defailt value (empty option) and -All- aoption
  6. */
  7. public function categoriesList ()
  8. {
  9. $data = $this->getCategoriesList();
  10. $defaultOption[] = Array ('CATEGORY_UID' => '<reset>','CATEGORY_NAME' => G::LoadTranslation( 'ID_ALL' ));
  11. return array_merge( $defaultOption, $data );
  12. }
  13. /**
  14. * Get Process categories list with defailt value (empty option)
  15. *
  16. * @return array
  17. */
  18. public function getCategoriesList ()
  19. {
  20. require_once "classes/model/ProcessCategory.php";
  21. $processCategory = new ProcessCategory();
  22. $defaultOption = Array ();
  23. $defaultOption[] = Array ('CATEGORY_UID' => '','CATEGORY_NAME' => G::LoadTranslation( 'ID_PROCESS_NO_CATEGORY' ));
  24. return array_merge( $defaultOption, $processCategory->getAll( 'array' ) );
  25. }
  26. /**
  27. * Save new process
  28. *
  29. * @param object $httpData
  30. */
  31. public function saveProcess ($httpData)
  32. {
  33. require_once 'classes/model/Task.php';
  34. G::LoadClass( 'processMap' );
  35. $oProcessMap = new ProcessMap();
  36. $httpData->PRO_TITLE = trim( $httpData->PRO_TITLE );
  37. if (! isset( $httpData->PRO_UID )) {
  38. if (Process::existsByProTitle( $httpData->PRO_TITLE )) {
  39. $result = array ('success' => false,'msg' => G::LoadTranslation( 'ID_SAVE_PROCESS_ERROR' ),'errors' => array ('PRO_TITLE' => G::LoadTranslation( 'ID_PROCESSTITLE_ALREADY_EXISTS', SYS_LANG, Array ('PRO_TITLE' => $httpData->PRO_TITLE
  40. ) )
  41. )
  42. );
  43. print G::json_encode( $result );
  44. exit( 0 );
  45. }
  46. $processData['USR_UID'] = $_SESSION['USER_LOGGED'];
  47. $processData['PRO_TITLE'] = $httpData->PRO_TITLE;
  48. $processData['PRO_DESCRIPTION'] = $httpData->PRO_DESCRIPTION;
  49. $processData['PRO_CATEGORY'] = $httpData->PRO_CATEGORY;
  50. $sProUid = $oProcessMap->createProcess( $processData );
  51. //call plugins
  52. $oData['PRO_UID'] = $sProUid;
  53. $oData['PRO_TEMPLATE'] = isset( $httpData->PRO_TEMPLATE ) && $httpData->PRO_TEMPLATE != '' ? $httpData->PRO_TEMPLATE : '';
  54. $oData['PROCESSMAP'] = $oProcessMap;
  55. $oPluginRegistry = & PMPluginRegistry::getSingleton();
  56. $oPluginRegistry->executeTriggers( PM_NEW_PROCESS_SAVE, $oData );
  57. } else {
  58. //$oProcessMap->updateProcess($_POST['form']);
  59. $sProUid = $httpData->PRO_UID;
  60. }
  61. //Save Calendar ID for this process
  62. if (isset( $httpData->PRO_CALENDAR )) {
  63. G::LoadClass( "calendar" );
  64. $calendarObj = new Calendar();
  65. $calendarObj->assignCalendarTo( $sProUid, $httpData->PRO_CALENDAR, 'PROCESS' );
  66. }
  67. $this->success = true;
  68. $this->PRO_UID = $sProUid;
  69. $this->msg = G::LoadTranslation( 'ID_CREATE_PROCESS_SUCCESS' );
  70. }
  71. /**
  72. * Change process status
  73. */
  74. public function changeStatus ()
  75. {
  76. $ids = explode( ',', $_REQUEST['UIDS'] );
  77. G::LoadClass( 'processes' );
  78. $oProcess = new Processes();
  79. if (count( $ids ) > 0) {
  80. foreach ($ids as $id) {
  81. $oProcess->changeStatus( $id );
  82. }
  83. }
  84. }
  85. /**
  86. * Change process debug mode
  87. */
  88. public function changeDebugMode ()
  89. {
  90. $ids = explode( ',', $_REQUEST['UIDS'] );
  91. G::LoadClass( 'processes' );
  92. $oProcess = new Processes();
  93. if (count( $ids ) > 0) {
  94. foreach ($ids as $id) {
  95. $oProcess->changeDebugMode( $id );
  96. }
  97. }
  98. }
  99. /**
  100. * Get users list
  101. *
  102. * @param $params httpdata object
  103. */
  104. public function getUsers ($params)
  105. {
  106. require_once 'classes/model/Users.php';
  107. $search = isset( $params->search ) ? $params->search : null;
  108. return Users::getAll( $params->start, $params->limit, $search );
  109. }
  110. /**
  111. * Get groups list
  112. *
  113. * @param $params httpdata object
  114. */
  115. public function getGroups ($params)
  116. {
  117. require_once 'classes/model/Groupwf.php';
  118. $search = isset( $params->search ) ? $params->search : null;
  119. return Groupwf::getAll( $params->start, $params->limit, $search );
  120. }
  121. /**
  122. * Assign actors to task
  123. *
  124. * @param unknown_type $param
  125. */
  126. public function assignActorsTask ($param)
  127. {
  128. require_once 'classes/model/TaskUser.php';
  129. require_once 'classes/model/Task.php';
  130. $oTaskUser = new TaskUser();
  131. $UIDS = explode( ',', $param->UIDS );
  132. $TU_TYPE = $param->TU_TYPE;
  133. $TAS_UID = $param->TAS_UID;
  134. foreach ($UIDS as $UID) {
  135. if ($param->TU_RELATION == '1') {
  136. $res[] = $oTaskUser->create( array ('TAS_UID' => $TAS_UID,'USR_UID' => $UID,'TU_TYPE' => $TU_TYPE,'TU_RELATION' => 1) );
  137. } else {
  138. $res[] = $oTaskUser->create( array ('TAS_UID' => $TAS_UID,'USR_UID' => $UID,'TU_TYPE' => $TU_TYPE,'TU_RELATION' => 2) );
  139. }
  140. }
  141. $task = TaskPeer::retrieveByPk( $TAS_UID );
  142. $this->success = true;
  143. if (! in_array( '-1', $res )) {
  144. if (count( $UIDS ) == 1) {
  145. $this->msg = __( 'ID_ACTOR_ASSIGNED_SUCESSFULLY', SYS_LANG, Array ('tas_title' => $task->getTasTitle()) );
  146. } else {
  147. $this->msg = __( 'ID_ACTORS_ASSIGNED_SUCESSFULLY', SYS_LANG, Array (count( $UIDS ),$task->getTasTitle()) );
  148. }
  149. } else {
  150. if (count( $UIDS ) == 1) {
  151. $this->msg = __( 'ID_ACTOR_ALREADY_ASSIGNED', SYS_LANG, Array ($task->getTasTitle()) );
  152. } else {
  153. $this->msg = __( 'ID_SOME_ACTORS_ALREADY_ASSIGNED', SYS_LANG, Array ($task->getTasTitle()) );
  154. }
  155. }
  156. }
  157. /**
  158. * Remove Actors from Task
  159. *
  160. * @param $param
  161. */
  162. public function removeActorsTask ($param)
  163. {
  164. require_once 'classes/model/TaskUser.php';
  165. $oTaskUser = new TaskUser();
  166. $USR_UIDS = explode( ',', $param->USR_UID );
  167. $TU_RELATIONS = explode( ',', $param->TU_RELATION );
  168. $TU_TYPE = $param->TU_TYPE;
  169. foreach ($USR_UIDS as $i => $USR_UID) {
  170. if ($TU_RELATIONS[$i] == 1) {
  171. $oTaskUser->remove( $param->TAS_UID, $USR_UID, $TU_TYPE, 1 );
  172. } else {
  173. $oTaskUser->remove( $param->TAS_UID, $USR_UID, $TU_TYPE, 2 );
  174. }
  175. }
  176. $this->success = true;
  177. $this->msg = '';
  178. }
  179. /**
  180. * Get actors asssigned to task
  181. *
  182. * @param object $httpData{tas_uid, tu_type},
  183. */
  184. public function getActorsTask ($httpData)
  185. {
  186. require_once 'classes/model/TaskUser.php';
  187. $usersTaskList = Array ();
  188. $task = new TaskUser();
  189. $usersTask = $task->getUsersTask( $httpData->tas_uid, $httpData->tu_type );
  190. foreach ($usersTask->data as $userTask) {
  191. $usersTaskListItem['TAS_UID'] = $userTask['TAS_UID'];
  192. if ($userTask['TU_RELATION'] == 1) {
  193. $usersTaskListItem['USR_USERNAME'] = $userTask['USR_USERNAME'];
  194. $usersTaskListItem['USR_FIRSTNAME'] = $userTask['USR_FIRSTNAME'];
  195. $usersTaskListItem['USR_LASTNAME'] = $userTask['USR_LASTNAME'];
  196. } else {
  197. $usersTaskListItem['NAME'] = $userTask['GRP_TITLE'];
  198. }
  199. $usersTaskListItem['TU_RELATION'] = $userTask['TU_RELATION'];
  200. $usersTaskListItem['USR_UID'] = $userTask['USR_UID'];
  201. $usersTaskList[] = $usersTaskListItem;
  202. }
  203. $this->data = $usersTaskList;
  204. $this->totalCount = $usersTask->totalCount;
  205. }
  206. /**
  207. * Get Process details
  208. *
  209. * @param object $httpData{PRO_UID}
  210. * @return array
  211. */
  212. public function getProcessDetail ($httpData)
  213. {
  214. require_once 'classes/model/Process.php';
  215. G::loadClass( 'tasks' );
  216. $tasks = new Tasks();
  217. $PRO_UID = $httpData->PRO_UID;
  218. $process = ProcessPeer::retrieveByPk( $PRO_UID );
  219. $tasksList = $tasks->getAllTasks( $PRO_UID );
  220. $rootNode->id = $process->getProUid();
  221. $rootNode->type = 'process';
  222. $rootNode->typeLabel = G::LoadTranslation( 'ID_PROCESS' );
  223. $rootNode->text = $process->getProTitle();
  224. $rootNode->leaf = count( $tasksList ) > 0 ? false : true;
  225. $rootNode->iconCls = 'ss_sprite ss_application';
  226. $rootNode->expanded = true;
  227. foreach ($tasksList as $task) {
  228. $node = new stdClass();
  229. $node->id = $task['TAS_UID'];
  230. $node->type = 'task';
  231. $node->typeLabel = G::LoadTranslation( 'ID_TASK' );
  232. $node->text = $task['TAS_TITLE'];
  233. $node->iconCls = 'ss_sprite ss_layout';
  234. $node->leaf = true;
  235. $rootNode->children[] = $node;
  236. }
  237. $treeDetail[] = $rootNode;
  238. return $treeDetail;
  239. }
  240. /**
  241. * Get process and task properties
  242. *
  243. * @param object $httpData{type, UID}
  244. */
  245. public function getProperties ($httpData)
  246. {
  247. switch ($httpData->type) {
  248. case 'process':
  249. require_once 'classes/model/ProcessCategory.php';
  250. require_once 'classes/model/CalendarDefinition.php';
  251. G::LoadClass( 'processMap' );
  252. $oProcessMap = new processMap( new DBConnection() );
  253. $process = $oProcessMap->editProcessNew( $httpData->UID );
  254. $category = ProcessCategoryPeer::retrieveByPk( $process['PRO_CATEGORY'] );
  255. $categoryName = is_object( $category ) ? $category->getCategoryName() : '';
  256. $calendar = CalendarDefinitionPeer::retrieveByPk( $process['PRO_CALENDAR'] );
  257. $calendarName = is_object( $calendar ) ? $calendar->getCalendarName() : '';
  258. $properties['Title'] = $process['PRO_TITLE'];
  259. $properties['Description'] = $process['PRO_DESCRIPTION'];
  260. $properties['Calendar'] = $calendarName;
  261. $properties['Category'] = $categoryName;
  262. $properties['Debug'] = $process['PRO_DEBUG'] == '1' ? true : false;
  263. $this->sucess = true;
  264. $this->prop = $properties;
  265. break;
  266. case 'task':
  267. require_once 'classes/model/Task.php';
  268. $task = new Task();
  269. $taskData = $task->load( $httpData->UID );
  270. $properties['Title'] = $taskData['TAS_TITLE'];
  271. $properties['Description'] = $taskData['TAS_DESCRIPTION'];
  272. $properties['Variable for case priority'] = $taskData['TAS_PRIORITY_VARIABLE'];
  273. $properties['Starting Task'] = $taskData['TAS_START'] == 'TRUE' ? true : false;
  274. $this->sucess = true;
  275. $this->prop = $properties;
  276. break;
  277. }
  278. }
  279. /**
  280. * Save process and task propeties
  281. *
  282. * @param object $httpData{UID, type, property, value}
  283. */
  284. public function saveProperties ($httpData)
  285. {
  286. switch ($httpData->type) {
  287. case 'process':
  288. require_once 'classes/model/ProcessCategory.php';
  289. require_once 'classes/model/CalendarDefinition.php';
  290. G::LoadClass( 'processMap' );
  291. $oProcessMap = new ProcessMap();
  292. $process['PRO_UID'] = $httpData->UID;
  293. switch ($httpData->property) {
  294. case 'Title':
  295. $fieldName = 'PRO_TITLE';
  296. break;
  297. case 'Description':
  298. $fieldName = 'PRO_DESCRIPTION';
  299. break;
  300. case 'Debug':
  301. $fieldName = 'PRO_DEBUG';
  302. $httpData->value = $httpData->value == 'true' ? '1' : '0';
  303. break;
  304. case 'Category':
  305. $fieldName = 'PRO_CATEGORY';
  306. $category = ProcessCategory::loadByCategoryName( $httpData->value );
  307. $httpData->value = $category['CATEGORY_UID'];
  308. break;
  309. case 'Calendar':
  310. $fieldName = 'PRO_CALENDAR';
  311. $calendar = CalendarDefinition::loadByCalendarName( $httpData->value );
  312. G::LoadClass( "calendar" );
  313. $calendarObj = new Calendar();
  314. $calendarObj->assignCalendarTo( $process['PRO_UID'], $calendar['CALENDAR_UID'], 'PROCESS' );
  315. break;
  316. }
  317. if ($fieldName != 'PRO_CALENDAR') {
  318. $process[$fieldName] = $httpData->value;
  319. $oProcessMap->updateProcess( $process );
  320. }
  321. break;
  322. case 'task':
  323. require_once 'classes/model/Task.php';
  324. $oTask = new Task();
  325. $task['TAS_UID'] = $httpData->UID;
  326. switch ($httpData->property) {
  327. case 'Title':
  328. $fieldName = 'TAS_TITLE';
  329. break;
  330. case 'Description':
  331. $fieldName = 'TAS_DESCRIPTION';
  332. break;
  333. case 'Variable for case priority':
  334. $fieldName = 'TAS_PRIORITY_VARIABLE';
  335. break;
  336. case 'Starting Task':
  337. $fieldName = 'TAS_START';
  338. $httpData->value = strtoupper( $httpData->value );
  339. break;
  340. }
  341. $task[$fieldName] = $httpData->value;
  342. $oTask->update( $task );
  343. break;
  344. }
  345. $this->sucess = true;
  346. }
  347. /**
  348. * get calendar list
  349. */
  350. public function getCaledarList ()
  351. {
  352. G::LoadClass( 'calendar' );
  353. $calendar = new CalendarDefinition();
  354. $calendarObj = $calendar->getCalendarList( true, true );
  355. $calendarObj['array'][0] = Array ('CALENDAR_UID' => '','CALENDAR_NAME' => ''
  356. );
  357. $this->rows = $calendarObj['array'];
  358. }
  359. /**
  360. * Get PM Variables
  361. *
  362. * @param $param{PRO_UID}
  363. */
  364. public function getPMVariables ($param)
  365. {
  366. G::LoadClass( 'processMap' );
  367. $oProcessMap = new processMap( new DBConnection() );
  368. $rows = getDynaformsVars( $param->PRO_UID );
  369. foreach ($rows as $i => $var) {
  370. $rows[$i]['sName'] = "@@{$var['sName']}";
  371. }
  372. $this->rows = $rows;
  373. }
  374. }