/modules/teamroom/register.php

https://github.com/schoeller/ezteamroom · PHP · 156 lines · 110 code · 15 blank · 31 comment · 24 complexity · 1d7a365d1dd60d00f2575143b96f646e MD5 · raw file

  1. <?php
  2. //
  3. // Created on: <2008-09-15 16:13:42 ab>
  4. //
  5. // SOFTWARE NAME: eZ Teamroom extension for eZ Publish
  6. // SOFTWARE RELEASE: 0.x
  7. // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
  8. // SOFTWARE LICENSE: GNU General Public License v2.0
  9. // NOTICE: >
  10. // This program is free software; you can redistribute it and/or
  11. // modify it under the terms of version 2.0 of the GNU General
  12. // Public License as published by the Free Software Foundation.
  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 General Public License for more details.
  18. //
  19. // You should have received a copy of version 2.0 of the GNU General
  20. // Public License along with this program; if not, write to the Free
  21. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. // MA 02110-1301, USA.
  23. //
  24. //
  25. $Module = $Params['Module'];
  26. $teamroomID = $Params['TeamroomID'];
  27. $actionType = $Module->currentAction();
  28. $registerUrl = 'teamroom/register/'.$teamroomID;
  29. // get the teamroomObject and main_node
  30. if ( !is_numeric( $teamroomID ) ){
  31. return $Module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
  32. }
  33. $roomIdentifierMap = eZTeamroom::getRoomIdentifierList();
  34. $teamroomObject = eZContentObject::fetch( (int) $teamroomID);
  35. if ( !is_object( $teamroomObject ) || !in_array( $teamroomObject->attribute( 'class_identifier' ), $roomIdentifierMap ) )
  36. {
  37. return $Module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
  38. }
  39. $teamroomNode = $teamroomObject->attribute('main_node');
  40. if ( !is_object( $teamroomNode ) || !in_array( $teamroomNode->attribute( 'class_identifier' ), $roomIdentifierMap ) )
  41. {
  42. return $Module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
  43. }
  44. // check if user is allowed to register
  45. $teamroomSection = $teamroomObject->attribute( 'section_id' );
  46. if ( !eZTeamroom::checkTeamroomSubtreeAccess( 'teamroom', 'register', false, $teamroomSection ) ){
  47. return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
  48. }
  49. // check if user is already member
  50. $user = eZUser::currentUser();
  51. $userID = $user->attribute( 'contentobject_id' );
  52. $userContentObject = $user->attribute('contentobject') ;
  53. $subTreeParams = array( 'Depth' => 0,
  54. 'DepthOperator' => 'eq',
  55. 'Limitation' => array(),
  56. 'ClassFilterType' => 'include',
  57. 'ClassFilterArray' => array( 'user_group' )
  58. );
  59. $userGroupList = $teamroomNode->subTree( $subTreeParams );
  60. if ( !count($userGroupList) ){
  61. return $Module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
  62. }
  63. $parentNodeIDArray = eZTeamroom::parentNodeIDArray( $userContentObject );
  64. foreach ($userGroupList as $userGroup){
  65. $memberGroupNodeID = $userGroup->attribute( 'node_id' );;
  66. if( in_array( $memberGroupNodeID, $parentNodeIDArray ) )
  67. return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
  68. }
  69. $tplfile = 'register.tpl';
  70. if ( $actionType == 'Cancel' )
  71. {
  72. $Module->redirectTo( $teamroomNode->attribute( 'url_alias') );
  73. }
  74. elseif ( $actionType == 'Register' )
  75. {
  76. eZDebug::writeDebug( "eZOperationHandler::execute( 'teamroom', 'register', array( 'user_id' => $userID, 'teamroom_id' => $teamroomID, ) )", __FILE__.':'.__LINE__ );
  77. $operationResult = eZOperationHandler::execute( 'teamroom', 'register', array( 'teamroom_id' => $teamroomID,
  78. 'user_id' => $userID ) );
  79. eZDebug::writeDebug( $operationResult, __FILE__.':'.__LINE__.' $operationResult' );
  80. # STATUS_CONTINUE = 1
  81. # STATUS_CANCELLED = 2
  82. # STATUS_HALTED = 3 <-----
  83. if ( is_array( $operationResult ) && array_key_exists( 'status', $operationResult ) )
  84. {
  85. if ( $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE )
  86. {
  87. $tplfile = 'register_done.tpl';
  88. }
  89. elseif( $operationResult['status'] == eZModuleOperationInfo::STATUS_HALTED )
  90. {
  91. $tplfile = 'register_deferred.tpl';
  92. }
  93. elseif( $operationResult['status'] == eZModuleOperationInfo::STATUS_CANCELLED)
  94. {
  95. if ( isset( $operationResult['redirect_url'] ) )
  96. {
  97. return $Module->redirectTo( $operationResult['redirect_url'] );
  98. }
  99. else if ( isset( $operationResult['result'] ) )
  100. {
  101. $moduleResult = $operationResult['result'];
  102. $resultContent = false;
  103. if ( is_array( $moduleResult ) )
  104. {
  105. if ( isset( $moduleResult['content'] ) )
  106. $resultContent = $moduleResult['content'];
  107. }
  108. else
  109. {
  110. $resultContent = $moduleResult;
  111. }
  112. if ( strpos( $resultContent, 'Deffered to cron' ) === 0 )
  113. {
  114. $Result = null;
  115. }
  116. else
  117. {
  118. $Result['content'] = $resultContent;
  119. }
  120. }
  121. else
  122. {
  123. return $Module->redirectTo( $teamroomNode->attribute( 'url_alias') );
  124. }
  125. return;
  126. }
  127. }
  128. }
  129. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. //// Template
  131. $tpl = eZTemplate::factory();
  132. $tpl->setVariable( 'from_page', $registerUrl );
  133. $tpl->setVariable( 'teamroom', $teamroomNode );
  134. if (!$Result){
  135. $Result = array();
  136. $Result['content'] = $tpl->fetch( 'design:teamroom/'.$tplfile );
  137. }
  138. $Result['path'] = array(
  139. array( 'text' => $teamroomNode->attribute( 'name') , 'url' => $teamroomNode->attribute( 'url_alias') ),
  140. array( 'text' => ezpI18n::tr( 'ezteamroom/teamroom', 'Register' ), 'url' => 'teamroom/register/' . $teamroomNode->attribute( 'contentobject_id') ) );
  141. ?>