PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/classes/workflowtypes/event/ezapprove/ezapprovetype.php

https://github.com/granitegreg/ezpublish
PHP | 786 lines | 639 code | 67 blank | 80 comment | 92 complexity | bc9983defe642b47b4b0351be595667e MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. //
  3. // Definition of eZApproveType class
  4. //
  5. // Created on: <16-Apr-2002 11:08:14 amos>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2011 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*!
  31. \class eZApproveType ezapprovetype.php
  32. \brief Event type for user approvals
  33. WorkflowEvent storage fields : data_text1 - selected_sections
  34. data_text2 - selected_usergroups
  35. data_text3 - approve_users
  36. data_text4 - approve_groups
  37. data_int2 - language_list
  38. data_int3 - content object version option
  39. */
  40. class eZApproveType extends eZWorkflowEventType
  41. {
  42. const WORKFLOW_TYPE_STRING = "ezapprove";
  43. const COLLABORATION_NOT_CREATED = 0;
  44. const COLLABORATION_CREATED = 1;
  45. const VERSION_OPTION_FIRST_ONLY = 1;
  46. const VERSION_OPTION_EXCEPT_FIRST = 2;
  47. const VERSION_OPTION_ALL = 3;
  48. function eZApproveType()
  49. {
  50. $this->eZWorkflowEventType( eZApproveType::WORKFLOW_TYPE_STRING, ezpI18n::tr( 'kernel/workflow/event', "Approve" ) );
  51. $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before' ) ) ) );
  52. }
  53. function attributeDecoder( $event, $attr )
  54. {
  55. switch ( $attr )
  56. {
  57. case 'selected_sections':
  58. {
  59. $attributeValue = trim( $event->attribute( 'data_text1' ) );
  60. $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue );
  61. }break;
  62. case 'approve_users':
  63. {
  64. $attributeValue = trim( $event->attribute( 'data_text3' ) );
  65. $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
  66. }break;
  67. case 'approve_groups':
  68. {
  69. $attributeValue = trim( $event->attribute( 'data_text4' ) );
  70. $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
  71. }break;
  72. case 'selected_usergroups':
  73. {
  74. $attributeValue = trim( $event->attribute( 'data_text2' ) );
  75. $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
  76. }break;
  77. case 'language_list':
  78. {
  79. $returnValue = array();
  80. $attributeValue = $event->attribute( 'data_int2' );
  81. if ( $attributeValue != 0 )
  82. {
  83. $languages = eZContentLanguage::languagesByMask( $attributeValue );
  84. foreach ( $languages as $language )
  85. {
  86. $returnValue[$language->attribute( 'id' )] = $language->attribute( 'name' );
  87. }
  88. }
  89. }break;
  90. case 'version_option':
  91. {
  92. $returnValue = eZApproveType::VERSION_OPTION_ALL & $event->attribute( 'data_int3' );
  93. }break;
  94. default:
  95. $returnValue = null;
  96. }
  97. return $returnValue;
  98. }
  99. function typeFunctionalAttributes( )
  100. {
  101. return array( 'selected_sections',
  102. 'approve_users',
  103. 'approve_groups',
  104. 'selected_usergroups',
  105. 'language_list',
  106. 'version_option' );
  107. }
  108. function attributes()
  109. {
  110. return array_merge( array( 'sections',
  111. 'languages',
  112. 'users',
  113. 'usergroups' ),
  114. eZWorkflowEventType::attributes() );
  115. }
  116. function hasAttribute( $attr )
  117. {
  118. return in_array( $attr, $this->attributes() );
  119. }
  120. function attribute( $attr )
  121. {
  122. switch( $attr )
  123. {
  124. case 'sections':
  125. {
  126. $sections = eZSection::fetchList( false );
  127. foreach ( $sections as $key => $section )
  128. {
  129. $sections[$key]['Name'] = $section['name'];
  130. $sections[$key]['value'] = $section['id'];
  131. }
  132. return $sections;
  133. }break;
  134. case 'languages':
  135. {
  136. return eZContentLanguage::fetchList();
  137. }break;
  138. }
  139. return eZWorkflowEventType::attribute( $attr );
  140. }
  141. function execute( $process, $event )
  142. {
  143. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process, 'eZApproveType::execute' );
  144. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'eZApproveType::execute' );
  145. $parameters = $process->attribute( 'parameter_list' );
  146. $versionID = $parameters['version'];
  147. $objectID = $parameters['object_id'];
  148. $object = eZContentObject::fetch( $objectID );
  149. if ( !$object )
  150. {
  151. eZDebugSetting::writeError( 'kernel-workflow-approve', "No object with ID $objectID", 'eZApproveType::execute' );
  152. return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
  153. }
  154. $version = $object->version( $versionID );
  155. if ( !$version )
  156. {
  157. eZDebugSetting::writeError( 'kernel-workflow-approve', "No version $versionID for object with ID $objectID", 'eZApproveType::execute' );
  158. return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
  159. }
  160. // only check this in cronjob
  161. if( $process->attribute( 'status' ) == eZWorkflow::STATUS_DEFERRED_TO_CRON )
  162. {
  163. $nodeAssignmentList = $version->attribute( 'node_assignments' );
  164. if( !empty( $nodeAssignmentList ) )
  165. {
  166. foreach ( $nodeAssignmentList as $nodeAssignment )
  167. {
  168. $parentNode = $nodeAssignment->getParentNode();
  169. if( $parentNode === null )
  170. {
  171. eZDebugSetting::writeError( 'kernel-workflow-approve', "No parent node for object with ID $objectID version $versionID", 'eZApproveType::execute' );
  172. return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
  173. }
  174. }
  175. }
  176. }
  177. // version option checking
  178. $version_option = $event->attribute( 'version_option' );
  179. if ( ( $version_option == eZApproveType::VERSION_OPTION_FIRST_ONLY and $parameters['version'] > 1 ) or
  180. ( $version_option == eZApproveType::VERSION_OPTION_EXCEPT_FIRST and $parameters['version'] == 1 ) )
  181. {
  182. return eZWorkflowType::STATUS_ACCEPTED;
  183. }
  184. /*
  185. If we run event first time ( when we click publish in admin ) we do not have user_id set in workflow process,
  186. so we take current user and store it in workflow process, so next time when we run event from cronjob we fetch
  187. user_id from there.
  188. */
  189. if ( $process->attribute( 'user_id' ) == 0 )
  190. {
  191. $user = eZUser::currentUser();
  192. $process->setAttribute( 'user_id', $user->id() );
  193. }
  194. else
  195. {
  196. $user = eZUser::instance( $process->attribute( 'user_id' ) );
  197. }
  198. $userGroups = array_merge( $user->attribute( 'groups' ), array( $user->attribute( 'contentobject_id' ) ) );
  199. $workflowSections = explode( ',', $event->attribute( 'data_text1' ) );
  200. $workflowGroups = $event->attribute( 'data_text2' ) == '' ? array() : explode( ',', $event->attribute( 'data_text2' ) );
  201. $editors = $event->attribute( 'data_text3' ) == '' ? array() : explode( ',', $event->attribute( 'data_text3' ) );
  202. $approveGroups = $event->attribute( 'data_text4' ) == '' ? array() : explode( ',', $event->attribute( 'data_text4' ) );
  203. $languageMask = $event->attribute( 'data_int2' );
  204. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user, 'eZApproveType::execute::user' );
  205. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, 'eZApproveType::execute::userGroups' );
  206. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $editors, 'eZApproveType::execute::editor' );
  207. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $approveGroups, 'eZApproveType::execute::approveGroups' );
  208. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections, 'eZApproveType::execute::workflowSections' );
  209. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, 'eZApproveType::execute::workflowGroups' );
  210. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $languageMask, 'eZApproveType::execute::languageMask' );
  211. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $object->attribute( 'section_id'), 'eZApproveType::execute::section_id' );
  212. $section = $object->attribute( 'section_id' );
  213. $correctSection = false;
  214. if ( !in_array( $section, $workflowSections ) && !in_array( -1, $workflowSections ) )
  215. {
  216. $assignedNodes = $object->attribute( 'assigned_nodes' );
  217. if ( $assignedNodes )
  218. {
  219. foreach( $assignedNodes as $assignedNode )
  220. {
  221. $parent = $assignedNode->attribute( 'parent' );
  222. $parentObject = $parent->object();
  223. $section = $parentObject->attribute( 'section_id');
  224. if ( in_array( $section, $workflowSections ) )
  225. {
  226. $correctSection = true;
  227. break;
  228. }
  229. }
  230. }
  231. }
  232. else
  233. $correctSection = true;
  234. $inExcludeGroups = count( array_intersect( $userGroups, $workflowGroups ) ) != 0;
  235. $userIsEditor = ( in_array( $user->id(), $editors ) ||
  236. count( array_intersect( $userGroups, $approveGroups ) ) != 0 );
  237. // All languages match by default
  238. $hasLanguageMatch = true;
  239. if ( $languageMask != 0 )
  240. {
  241. // Examine if the published version contains one of the languages we
  242. // match for.
  243. // If the language ID is part of the mask the result is non-zero.
  244. $languageID = (int)$version->attribute( 'initial_language_id' );
  245. $hasLanguageMatch = (bool)( $languageMask & $languageID );
  246. }
  247. if ( $hasLanguageMatch and
  248. !$userIsEditor and
  249. !$inExcludeGroups and
  250. $correctSection )
  251. {
  252. /* Get user IDs from approve user groups */
  253. $userClassIDArray = eZUser::contentClassIDs();
  254. $approveUserIDArray = array();
  255. foreach ( $approveGroups as $approveUserGroupID )
  256. {
  257. if ( $approveUserGroupID != false )
  258. {
  259. $approveUserGroup = eZContentObject::fetch( $approveUserGroupID );
  260. if ( isset( $approveUserGroup ) )
  261. {
  262. foreach ( $approveUserGroup->attribute( 'assigned_nodes' ) as $assignedNode )
  263. {
  264. $userNodeArray = $assignedNode->subTree( array( 'ClassFilterType' => 'include',
  265. 'ClassFilterArray' => $userClassIDArray,
  266. 'Limitation' => array() ) );
  267. foreach ( $userNodeArray as $userNode )
  268. {
  269. $approveUserIDArray[] = $userNode->attribute( 'contentobject_id' );
  270. }
  271. }
  272. }
  273. }
  274. }
  275. $approveUserIDArray = array_merge( $approveUserIDArray, $editors );
  276. $approveUserIDArray = array_unique( $approveUserIDArray );
  277. $collaborationID = false;
  278. $db = eZDb::instance();
  279. $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) );
  280. if ( count( $taskResult ) > 0 )
  281. $collaborationID = $taskResult[0]['collaboration_id'];
  282. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $collaborationID, 'approve collaborationID' );
  283. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process->attribute( 'event_state'), 'approve $process->attribute( \'event_state\')' );
  284. if ( $collaborationID === false )
  285. {
  286. $this->createApproveCollaboration( $process, $event, $user->id(), $object->attribute( 'id' ), $versionID, $approveUserIDArray );
  287. $this->setInformation( "We are going to create approval" );
  288. $process->setAttribute( 'event_state', eZApproveType::COLLABORATION_CREATED );
  289. $process->store();
  290. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve execute' );
  291. return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
  292. }
  293. else if ( $process->attribute( 'event_state') == eZApproveType::COLLABORATION_NOT_CREATED )
  294. {
  295. eZApproveCollaborationHandler::activateApproval( $collaborationID );
  296. $process->setAttribute( 'event_state', eZApproveType::COLLABORATION_CREATED );
  297. $process->store();
  298. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve re-execute' );
  299. return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
  300. }
  301. else //eZApproveType::COLLABORATION_CREATED
  302. {
  303. $this->setInformation( "we are checking approval now" );
  304. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'check approval' );
  305. return $this->checkApproveCollaboration( $process, $event );
  306. }
  307. }
  308. else
  309. {
  310. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections , "we are not going to create approval " . $object->attribute( 'section_id') );
  311. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, "we are not going to create approval" );
  312. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, "we are not going to create approval" );
  313. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user->id(), "we are not going to create approval " );
  314. return eZWorkflowType::STATUS_ACCEPTED;
  315. }
  316. }
  317. function initializeEvent( $event )
  318. {
  319. }
  320. function validateUserIDList( $userIDList, &$reason )
  321. {
  322. $returnState = eZInputValidator::STATE_ACCEPTED;
  323. foreach ( $userIDList as $userID )
  324. {
  325. if ( !is_numeric( $userID ) or
  326. !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) )
  327. {
  328. $returnState = eZInputValidator::STATE_INVALID;
  329. $reason[ 'list' ][] = $userID;
  330. }
  331. }
  332. $reason[ 'text' ] = "Some of passed user IDs are not valid, must be IDs of existing users only.";
  333. return $returnState;
  334. }
  335. function validateGroupIDList( $userGroupIDList, &$reason )
  336. {
  337. $returnState = eZInputValidator::STATE_ACCEPTED;
  338. $groupClassNames = eZUser::fetchUserGroupClassNames();
  339. if ( count( $groupClassNames ) > 0 )
  340. {
  341. foreach( $userGroupIDList as $userGroupID )
  342. {
  343. if ( !is_numeric( $userGroupID ) or
  344. !is_object( $userGroup = eZContentObject::fetch( $userGroupID ) ) or
  345. !in_array( $userGroup->attribute( 'class_identifier' ), $groupClassNames ) )
  346. {
  347. $returnState = eZInputValidator::STATE_INVALID;
  348. $reason[ 'list' ][] = $userGroupID;
  349. }
  350. }
  351. $reason[ 'text' ] = "Some of passed user-group IDs are not valid, must be IDs of existing user groups only.";
  352. }
  353. else
  354. {
  355. $returnState = eZInputValidator::STATE_INVALID;
  356. $reason[ 'text' ] = "There is no one user-group classes among the user accounts, please choose standalone users.";
  357. }
  358. return $returnState;
  359. }
  360. function validateHTTPInput( $http, $base, $workflowEvent, &$validation )
  361. {
  362. $returnState = eZInputValidator::STATE_ACCEPTED;
  363. $reason = array();
  364. if ( !$http->hasSessionVariable( 'BrowseParameters' ) )
  365. {
  366. // check approve-users
  367. $approversIDs = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_users' ) );
  368. if ( is_array( $approversIDs ) and
  369. count( $approversIDs ) > 0 )
  370. {
  371. $returnState = eZApproveType::validateUserIDList( $approversIDs, $reason );
  372. }
  373. else
  374. $returnState = false;
  375. if ( $returnState != eZInputValidator::STATE_INVALID )
  376. {
  377. // check approve-groups
  378. $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_groups' ) );
  379. if ( is_array( $userGroupIDList ) and
  380. count( $userGroupIDList ) > 0 )
  381. {
  382. $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason );
  383. }
  384. else if ( $returnState === false )
  385. {
  386. // if no one user or user-group was passed as approvers
  387. $returnState = eZInputValidator::STATE_INVALID;
  388. $reason[ 'text' ] = "There must be passed at least one valid user or user group who approves content for the event.";
  389. }
  390. // check excluded-users
  391. /*
  392. if ( $returnState != eZInputValidator::STATE_INVALID )
  393. {
  394. // TODO:
  395. // ....
  396. }
  397. */
  398. // check excluded-groups
  399. if ( $returnState != eZInputValidator::STATE_INVALID )
  400. {
  401. $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ) );
  402. if ( is_array( $userGroupIDList ) and
  403. count( $userGroupIDList ) > 0 )
  404. {
  405. $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason );
  406. }
  407. }
  408. }
  409. }
  410. else
  411. {
  412. $browseParameters = $http->sessionVariable( 'BrowseParameters' );
  413. if ( isset( $browseParameters['custom_action_data'] ) )
  414. {
  415. $customData = $browseParameters['custom_action_data'];
  416. if ( isset( $customData['event_id'] ) and
  417. $customData['event_id'] == $workflowEvent->attribute( 'id' ) )
  418. {
  419. if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and
  420. $http->hasPostVariable( 'SelectedObjectIDArray' ) )
  421. {
  422. $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' );
  423. if ( is_array( $objectIDArray ) and
  424. count( $objectIDArray ) > 0 )
  425. {
  426. switch( $customData['browse_action'] )
  427. {
  428. case "AddApproveUsers":
  429. {
  430. $returnState = eZApproveType::validateUserIDList( $objectIDArray, $reason );
  431. } break;
  432. case 'AddApproveGroups':
  433. case 'AddExcludeUser':
  434. {
  435. $returnState = eZApproveType::validateGroupIDList( $objectIDArray, $reason );
  436. } break;
  437. case 'AddExcludedGroups':
  438. {
  439. // TODO:
  440. // .....
  441. } break;
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. if ( $returnState == eZInputValidator::STATE_INVALID )
  449. {
  450. $validation[ 'processed' ] = true;
  451. $validation[ 'events' ][] = array( 'id' => $workflowEvent->attribute( 'id' ),
  452. 'placement' => $workflowEvent->attribute( 'placement' ),
  453. 'workflow_type' => &$this,
  454. 'reason' => $reason );
  455. }
  456. return $returnState;
  457. }
  458. function fetchHTTPInput( $http, $base, $event )
  459. {
  460. $sectionsVar = $base . "_event_ezapprove_section_" . $event->attribute( "id" );
  461. if ( $http->hasPostVariable( $sectionsVar ) )
  462. {
  463. $sectionsArray = $http->postVariable( $sectionsVar );
  464. if ( in_array( '-1', $sectionsArray ) )
  465. {
  466. $sectionsArray = array( -1 );
  467. }
  468. $sectionsString = implode( ',', $sectionsArray );
  469. $event->setAttribute( "data_text1", $sectionsString );
  470. }
  471. $languageVar = $base . "_event_ezapprove_languages_" . $event->attribute( "id" );
  472. if ( $http->hasPostVariable( $languageVar ) )
  473. {
  474. $languageArray = $http->postVariable( $languageVar );
  475. if ( in_array( '-1', $languageArray ) )
  476. {
  477. $languageArray = array();
  478. }
  479. $languageMask = 0;
  480. foreach ( $languageArray as $languageID )
  481. {
  482. $languageMask |= $languageID;
  483. }
  484. $event->setAttribute( "data_int2", $languageMask );
  485. }
  486. $versionOptionVar = $base . "_event_ezapprove_version_option_" . $event->attribute( "id" );
  487. if ( $http->hasPostVariable( $versionOptionVar ) )
  488. {
  489. $versionOptionArray = $http->postVariable( $versionOptionVar );
  490. $versionOption = 0;
  491. if ( is_array( $versionOptionArray ) )
  492. {
  493. foreach ( $versionOptionArray as $vv )
  494. {
  495. $versionOption = $versionOption | $vv;
  496. }
  497. }
  498. $versionOption = $versionOption & eZApproveType::VERSION_OPTION_ALL;
  499. $event->setAttribute( 'data_int3', $versionOption );
  500. }
  501. if ( $http->hasSessionVariable( 'BrowseParameters' ) )
  502. {
  503. $browseParameters = $http->sessionVariable( 'BrowseParameters' );
  504. if ( isset( $browseParameters['custom_action_data'] ) )
  505. {
  506. $customData = $browseParameters['custom_action_data'];
  507. if ( isset( $customData['event_id'] ) &&
  508. $customData['event_id'] == $event->attribute( 'id' ) )
  509. {
  510. if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and
  511. $http->hasPostVariable( 'SelectedObjectIDArray' ) )
  512. {
  513. $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' );
  514. if ( is_array( $objectIDArray ) and
  515. count( $objectIDArray ) > 0 )
  516. {
  517. switch( $customData['browse_action'] )
  518. {
  519. case 'AddApproveUsers':
  520. {
  521. foreach( $objectIDArray as $key => $userID )
  522. {
  523. if ( !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) )
  524. {
  525. unset( $objectIDArray[$key] );
  526. }
  527. }
  528. $event->setAttribute( 'data_text3', implode( ',',
  529. array_unique( array_merge( $this->attributeDecoder( $event, 'approve_users' ),
  530. $objectIDArray ) ) ) );
  531. } break;
  532. case 'AddApproveGroups':
  533. {
  534. $event->setAttribute( 'data_text4', implode( ',',
  535. array_unique( array_merge( $this->attributeDecoder( $event, 'approve_groups' ),
  536. $objectIDArray ) ) ) );
  537. } break;
  538. case 'AddExcludeUser':
  539. {
  540. $event->setAttribute( 'data_text2', implode( ',',
  541. array_unique( array_merge( $this->attributeDecoder( $event, 'selected_usergroups' ),
  542. $objectIDArray ) ) ) );
  543. } break;
  544. case 'AddExcludedGroups':
  545. {
  546. // TODO:
  547. // .....
  548. } break;
  549. }
  550. }
  551. $http->removeSessionVariable( 'BrowseParameters' );
  552. }
  553. }
  554. }
  555. }
  556. }
  557. function createApproveCollaboration( $process, $event, $userID, $contentobjectID, $contentobjectVersion, $editors )
  558. {
  559. if ( $editors === null )
  560. return false;
  561. $authorID = $userID;
  562. $collaborationItem = eZApproveCollaborationHandler::createApproval( $contentobjectID, $contentobjectVersion,
  563. $authorID, $editors );
  564. $db = eZDb::instance();
  565. $db->query( 'INSERT INTO ezapprove_items( workflow_process_id, collaboration_id )
  566. VALUES(' . $process->attribute( 'id' ) . ',' . $collaborationItem->attribute( 'id' ) . ' ) ' );
  567. }
  568. /*
  569. */
  570. function customWorkflowEventHTTPAction( $http, $action, $workflowEvent )
  571. {
  572. $eventID = $workflowEvent->attribute( "id" );
  573. $module =& $GLOBALS['eZRequestedModule'];
  574. //$siteIni = eZINI::instance();
  575. switch ( $action )
  576. {
  577. case 'AddApproveUsers' :
  578. {
  579. $userClassNames = eZUser::fetchUserClassNames();
  580. if ( count( $userClassNames ) > 0 )
  581. {
  582. eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers',
  583. 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ),
  584. 'custom_action_data' => array( 'event_id' => $eventID,
  585. 'browse_action' => $action ),
  586. 'class_array' => $userClassNames ),
  587. $module );
  588. }
  589. } break;
  590. case 'RemoveApproveUsers' :
  591. {
  592. if ( $http->hasPostVariable( 'DeleteApproveUserIDArray_' . $eventID ) )
  593. {
  594. $workflowEvent->setAttribute( 'data_text3', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_users' ),
  595. $http->postVariable( 'DeleteApproveUserIDArray_' . $eventID ) ) ) );
  596. }
  597. } break;
  598. case 'AddApproveGroups' :
  599. case 'AddExcludeUser' :
  600. {
  601. $groupClassNames = eZUser::fetchUserGroupClassNames();
  602. if ( count( $groupClassNames ) > 0 )
  603. {
  604. eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers',
  605. 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ),
  606. 'custom_action_data' => array( 'event_id' => $eventID,
  607. 'browse_action' => $action ),
  608. 'class_array' => $groupClassNames ),
  609. $module );
  610. }
  611. } break;
  612. case 'RemoveApproveGroups' :
  613. {
  614. if ( $http->hasPostVariable( 'DeleteApproveGroupIDArray_' . $eventID ) )
  615. {
  616. $workflowEvent->setAttribute( 'data_text4', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_groups' ),
  617. $http->postVariable( 'DeleteApproveGroupIDArray_' . $eventID ) ) ) );
  618. }
  619. } break;
  620. case 'RemoveExcludeUser' :
  621. {
  622. if ( $http->hasPostVariable( 'DeleteExcludeUserIDArray_' . $eventID ) )
  623. {
  624. $workflowEvent->setAttribute( 'data_text2', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ),
  625. $http->postVariable( 'DeleteExcludeUserIDArray_' . $eventID ) ) ) );
  626. }
  627. } break;
  628. case 'AddExcludedGroups' :
  629. {
  630. // TODO:
  631. // .....
  632. } break;
  633. case 'RemoveExcludedGroups' :
  634. {
  635. // TODO:
  636. // .....
  637. } break;
  638. }
  639. }
  640. /*
  641. */
  642. function cleanupAfterRemoving( $attr = array() )
  643. {
  644. foreach ( array_keys( $attr ) as $attrKey )
  645. {
  646. switch ( $attrKey )
  647. {
  648. case 'DeleteContentObject':
  649. {
  650. $contentObjectID = (int)$attr[ $attrKey ];
  651. $db = eZDb::instance();
  652. // Cleanup "User who approves content"
  653. $db->query( "UPDATE ezworkflow_event
  654. SET data_int1 = '0'
  655. WHERE workflow_type_string = '{$this->TypeString}' AND
  656. data_int1 = $contentObjectID" );
  657. // Cleanup "Excluded user groups"
  658. $excludedGroupsID = $db->arrayQuery( "SELECT data_text2, id
  659. FROM ezworkflow_event
  660. WHERE workflow_type_string = '{$this->TypeString}' AND
  661. data_text2 like '%$contentObjectID%'" );
  662. if ( is_array( $excludedGroupsID ) )
  663. {
  664. foreach ( $excludedGroupsID as $groupID )
  665. {
  666. // $IDArray will contain IDs of "Excluded user groups"
  667. $IDArray = explode( ',', $groupID[ 'data_text2' ] );
  668. // $newIDArray will contain array without $contentObjectID
  669. $newIDArray = array_filter( $IDArray, create_function( '$v', 'return ( $v != ' . $contentObjectID .' );' ) );
  670. $newValues = $db->escapeString( implode( ',', $newIDArray ) );
  671. $db->query( "UPDATE ezworkflow_event
  672. SET data_text2 = '$newValues'
  673. WHERE id = {$groupID['id']}" );
  674. }
  675. }
  676. } break;
  677. }
  678. }
  679. }
  680. function checkApproveCollaboration( $process, $event )
  681. {
  682. $db = eZDb::instance();
  683. $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) );
  684. $collaborationID = $taskResult[0]['collaboration_id'];
  685. $collaborationItem = eZCollaborationItem::fetch( $collaborationID );
  686. $contentObjectVersion = eZApproveCollaborationHandler::contentObjectVersion( $collaborationItem );
  687. $approvalStatus = eZApproveCollaborationHandler::checkApproval( $collaborationID );
  688. if ( $approvalStatus == eZApproveCollaborationHandler::STATUS_WAITING )
  689. {
  690. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval still waiting' );
  691. return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
  692. }
  693. else if ( $approvalStatus == eZApproveCollaborationHandler::STATUS_ACCEPTED )
  694. {
  695. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was accepted' );
  696. $status = eZWorkflowType::STATUS_ACCEPTED;
  697. }
  698. else if ( $approvalStatus == eZApproveCollaborationHandler::STATUS_DENIED or
  699. $approvalStatus == eZApproveCollaborationHandler::STATUS_DEFERRED )
  700. {
  701. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was denied' );
  702. $contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
  703. $status = eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
  704. }
  705. else
  706. {
  707. eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, "approval unknown status '$approvalStatus'" );
  708. $contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_REJECTED );
  709. $status = eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
  710. }
  711. $contentObjectVersion->sync();
  712. if ( $approvalStatus != eZApproveCollaborationHandler::STATUS_DEFERRED )
  713. $db->query( 'DELETE FROM ezapprove_items WHERE workflow_process_id = ' . $process->attribute( 'id' ) );
  714. return $status;
  715. }
  716. }
  717. eZWorkflowEventType::registerEventType( eZApproveType::WORKFLOW_TYPE_STRING, "eZApproveType" );
  718. ?>