#5923: Notify per email if groups are selected instead of single users
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / class.tx_version_tcemain.php
index fb6a95f..9e1ca89 100644 (file)
@@ -113,7 +113,8 @@ class tx_version_tcemain {
                                                $this->version_setStage($table, $elementId, $value['stageId'],
                                                        (isset($value['comment']) && $value['comment'] ? $value['comment'] : $this->generalComment),
                                                        TRUE,
-                                                       $tcemainObj
+                                                       $tcemainObj,
+                                                       $value['notificationAlternativeRecipients']
                                                );
                                        }
                                break;
@@ -130,7 +131,7 @@ class tx_version_tcemain {
        public function processCmdmap_afterFinish(&$tcemainObj) {
                        // Empty accumulation array:
                foreach ($this->notificationEmailInfo as $notifItem) {
-                       $this->notifyStageChange($notifItem['shared'][0], $notifItem['shared'][1], implode(', ', $notifItem['elements']), 0, $notifItem['shared'][2], $tcemainObj);
+                       $this->notifyStageChange($notifItem['shared'][0], $notifItem['shared'][1], implode(', ', $notifItem['elements']), 0, $notifItem['shared'][2], $tcemainObj, $notifItem['alternativeRecipients']);
                }
 
                        // Reset notification array
@@ -286,93 +287,108 @@ class tx_version_tcemain {
         * @param       string          Table name of element (or list of element names if $id is zero)
         * @param       integer         Record uid of element (if zero, then $table is used as reference to element(s) alone)
         * @param       string          User comment sent along with action
+        * @param       object          TCEmain object
+        * @param       string          comma separated list of recipients to notificate instead of be_users selected by sys_workspace, list is generated by workspace extension module
         * @return      void
         */
-       protected function notifyStageChange($stat, $stageId, $table, $id, $comment, $tcemainObj) {
+       protected function notifyStageChange($stat, $stageId, $table, $id, $comment, $tcemainObj, $notificationAlternativeRecipients = FALSE) {
                $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $stat['uid']);
                        // So, if $id is not set, then $table is taken to be the complete element name!
                $elementName = $id ? $table . ':' . $id : $table;
 
                if (is_array($workspaceRec)) {
 
-                               // TODO: CONSTANTS SHOULD BE USED - tx_service_workspace_workspaces
-                               // TODO: use localized labels
-                               // Compile label:
-                       switch ((int)$stageId) {
-                               case 1:
-                                       $newStage = 'Ready for review';
-                               break;
-                               case 10:
-                                       $newStage = 'Ready for publishing';
-                               break;
-                               case -1:
-                                       $newStage = 'Element was rejected!';
-                               break;
-                               case 0:
-                                       $newStage = 'Rejected element was noticed and edited';
-                               break;
-                               default:
-                                       $newStage = 'Unknown state change!?';
-                               break;
+                                // Get the new stage title from workspaces library, if workspaces extension is installed
+                       if (t3lib_extMgm::isLoaded('workspaces')) {
+                               $stageService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
+                               $newStage = $stageService->getStageTitle((int)$stageId);
+                       } else {
+                                       // TODO: CONSTANTS SHOULD BE USED - tx_service_workspace_workspaces
+                                       // TODO: use localized labels
+                                       // Compile label:
+                               switch ((int)$stageId) {
+                                       case 1:
+                                               $newStage = 'Ready for review';
+                                       break;
+                                       case 10:
+                                               $newStage = 'Ready for publishing';
+                                       break;
+                                       case -1:
+                                               $newStage = 'Element was rejected!';
+                                       break;
+                                       case 0:
+                                               $newStage = 'Rejected element was noticed and edited';
+                                       break;
+                                       default:
+                                               $newStage = 'Unknown state change!?';
+                                       break;
+                               }
                        }
 
-                               // Compile list of recipients:
-                       $emails = array();
-                       switch((int)$stat['stagechg_notification'])     {
-                               case 1:
-                                       switch((int)$stageId)   {
-                                               case 1:
-                                                       $emails = $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']);
-                                               break;
-                                               case 10:
-                                                       $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
-                                               break;
-                                               case -1:
-#                                                      $emails = $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']);
-#                                                      $emails = array_merge($emails,$this->getEmailsForStageChangeNotification($workspaceRec['members']));
-
-                                                               // List of elements to reject:
-                                                       $allElements = explode(',', $elementName);
-                                                               // Traverse them, and find the history of each
-                                                       foreach ($allElements as $elRef) {
-                                                               list($eTable, $eUid) = explode(':', $elRef);
-
-                                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                                               'log_data,tstamp,userid',
-                                                                               'sys_log',
-                                                                               'action=6 and details_nr=30
-                                                                               AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($eTable, 'sys_log') . '
-                                                                               AND recuid=' . intval($eUid),
-                                                                               '',
-                                                                               'uid DESC'
-                                                               );
-                                                                       // Find all implicated since the last stage-raise from editing to review:
-                                                               foreach ($rows as $dat) {
-                                                                       $data = unserialize($dat['log_data']);
-
-                                                                       $emails = t3lib_div::array_merge($emails, $this->getEmailsForStageChangeNotification($dat['userid'], TRUE));
-
-                                                                       if ($data['stage'] == 1) {
-                                                                               break;
+                       if ($notificationAlternativeRecipients == false) {
+                                       // Compile list of recipients:
+                               $emails = array();
+                               switch((int)$stat['stagechg_notification'])     {
+                                       case 1:
+                                               switch((int)$stageId)   {
+                                                       case 1:
+                                                               $emails = $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']);
+                                                       break;
+                                                       case 10:
+                                                               $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
+                                                       break;
+                                                       case -1:
+#                                                              $emails = $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']);
+#                                                              $emails = array_merge($emails,$this->getEmailsForStageChangeNotification($workspaceRec['members']));
+
+                                                                       // List of elements to reject:
+                                                               $allElements = explode(',', $elementName);
+                                                                       // Traverse them, and find the history of each
+                                                               foreach ($allElements as $elRef) {
+                                                                       list($eTable, $eUid) = explode(':', $elRef);
+
+                                                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                                                                       'log_data,tstamp,userid',
+                                                                                       'sys_log',
+                                                                                       'action=6 and details_nr=30
+                                                                                       AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($eTable, 'sys_log') . '
+                                                                                       AND recuid=' . intval($eUid),
+                                                                                       '',
+                                                                                       'uid DESC'
+                                                                       );
+                                                                               // Find all implicated since the last stage-raise from editing to review:
+                                                                       foreach ($rows as $dat) {
+                                                                               $data = unserialize($dat['log_data']);
+
+                                                                               $emails = t3lib_div::array_merge($emails, $this->getEmailsForStageChangeNotification($dat['userid'], TRUE));
+
+                                                                               if ($data['stage'] == 1) {
+                                                                                       break;
+                                                                               }
                                                                        }
                                                                }
-                                                       }
-                                               break;
+                                                       break;
 
-                                               case 0:
-                                                       $emails = $this->getEmailsForStageChangeNotification($workspaceRec['members']);
-                                               break;
+                                                       case 0:
+                                                               $emails = $this->getEmailsForStageChangeNotification($workspaceRec['members']);
+                                                       break;
 
-                                               default:
-                                                       $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
-                                               break;
-                                       }
-                               break;
-                               case 10:
-                                       $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
-                                       $emails = t3lib_div::array_merge($emails, $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']));
-                                       $emails = t3lib_div::array_merge($emails, $this->getEmailsForStageChangeNotification($workspaceRec['members']));
-                               break;
+                                                       default:
+                                                               $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
+                                                       break;
+                                               }
+                                       break;
+                                       case 10:
+                                               $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
+                                               $emails = t3lib_div::array_merge($emails, $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']));
+                                               $emails = t3lib_div::array_merge($emails, $this->getEmailsForStageChangeNotification($workspaceRec['members']));
+                                       break;
+                               }
+                       } else {
+                               $emails = array();
+                               foreach ($notificationAlternativeRecipients as $emailAddress) {
+                                       $emails[] = array('email' => $emailAddress);
+                               }
                        }
 
                                // prepare and then send the emails
@@ -560,9 +576,11 @@ class tx_version_tcemain {
         * @param       integer         Stage ID to set
         * @param       string          Comment that goes into log
         * @param       boolean         Accumulate state changes in memory for compiled notification email?
+        * @param       object          TCEmain object
+        * @param       string          comma separated list of recipients to notificate instead of normal be_users
         * @return      void
         */
-       protected function version_setStage($table, $id, $stageId, $comment = '', $notificationEmailInfo = FALSE, $tcemainObj) {
+       protected function version_setStage($table, $id, $stageId, $comment = '', $notificationEmailInfo = FALSE, $tcemainObj, $notificationAlternativeRecipients = FALSE) {
                if ($errorCode = $tcemainObj->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) {
                        $tcemainObj->newlog('Attempt to set stage for record failed: ' . $errorCode, 1);
                } elseif ($tcemainObj->checkRecordUpdateAccess($table, $id)) {
@@ -585,8 +603,9 @@ class tx_version_tcemain {
                                        if ($notificationEmailInfo) {
                                                $this->notificationEmailInfo[$stat['uid'] . ':' . $stageId . ':' . $comment]['shared'] = array($stat, $stageId, $comment);
                                                $this->notificationEmailInfo[$stat['uid'] . ':' . $stageId . ':' . $comment]['elements'][] = $table . ':' . $id;
+                                               $this->notificationEmailInfo[$stat['uid'] . ':' . $stageId . ':' . $comment]['alternativeRecipients'] = $notificationAlternativeRecipients;
                                        } else {
-                                               $this->notifyStageChange($stat, $stageId, $table, $id, $comment, $tcemainObj);
+                                               $this->notifyStageChange($stat, $stageId, $table, $id, $comment, $tcemainObj, $notificationAlternativeRecipients);
                                        }
                                }
                        } else $tcemainObj->newlog('The member user tried to set a stage value "' . $stageId . '" that was not allowed', 1);