Commit fa50fb027371571f48c8fbceb14f99e0974de701
1 parent
e436bae2
Modfied function to create standard subscription notifications
Committed By: Kevin Cyster Reviewed By: Megan Watson
Showing
1 changed file
with
170 additions
and
5 deletions
lib/subscriptions/subscriptions.inc.php
| ... | ... | @@ -431,10 +431,171 @@ class SubscriptionContent { |
| 431 | 431 | ); |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | + /** | |
| 435 | + * This function generates the email that will be sent for subscription notifications | |
| 436 | + * | |
| 437 | + * @author KnowledgeTree Team | |
| 438 | + * @access public | |
| 439 | + * @param object $oKTNotification: The notification object | |
| 440 | + * @return string $str: The html string that will be sent via email | |
| 441 | + */ | |
| 434 | 442 | function getEmailAlertContent($oKTNotification) { |
| 435 | - // we can re-use the normal template. | |
| 443 | + // set up logo and title | |
| 444 | + $rootUrl = KTUtil::kt_url(); | |
| 445 | + | |
| 446 | + $info = $this->_getSubscriptionData($oKTNotification); | |
| 447 | + | |
| 448 | + // set up email text | |
| 449 | + $addFolderText = _kt('The folder "').$info['object_name']._kt('" was added'); | |
| 450 | + $removeSubscribedFolderText = _kt('The folder "').$info['object_name']._kt('" to which you were subscribed, has been removed'); | |
| 451 | + $removeChildFolderText = _kt('The folder "').$info['object_name']._kt('" has been removed'); | |
| 452 | + $addDocumentText = _kt('The document "').$info['object_name']._kt('" was added'); | |
| 453 | + $removeSubscribedDocumentText = _kt('The document "').$info['object_name']._kt('" to which you were subscribed, has been removed'); | |
| 454 | + $removeChildDocumentText = _kt('The document "').$info['object_name']._kt('" has been removed'); | |
| 455 | + $modifyDocumentText = _kt('The document "').$info['object_name']._kt('" has been changed'); | |
| 456 | + $checkInDocumentText = _kt('The document "').$info['object_name']._kt('" has been checked in'); | |
| 457 | + $checkOutDocumentText = _kt('The document "').$info['object_name']._kt('" has been checked out'); | |
| 458 | + $moveDocumentText = _kt('The document "').$info['object_name']._kt('" has been moved'); | |
| 459 | + $copiedDocumentText = _kt('The document "').$info['object_name']._kt('" has been copied'); | |
| 460 | + $archivedDocumentText = _kt('The document "').$info['object_name']._kt('"'); | |
| 461 | + $restoreArchivedDocumentText = _kt('The document "').$info['object_name']._kt('" has been restored by an administrator'); | |
| 462 | + $downloadDocumentText = _kt('The document "').$info['object_name']._kt('"'); | |
| 463 | + $documentAlertText = _kt('An alert on the document "').$info['object_name']._kt('" has been added or modified'); | |
| 464 | + | |
| 465 | + if($info['location_name'] !== NULL){ | |
| 466 | + $addFolderText .= _kt(' to "').$info['location_name']._kt('"'); | |
| 467 | + $removeChildFolderText .= _kt(' from the folder "').$info['location_name']._kt('"'); | |
| 468 | + $addDocumentText .= _kt(' to "').$info['location_name']._kt('"'); | |
| 469 | + $removeChildDocumentText .= _kt(' from the folder "').$info['location_name']._kt('" to which you are subscribed'); | |
| 470 | + $modifyDocumentText .= _kt(' in the folder "').$info['location_name']._kt('"'); | |
| 471 | + $checkInDocumentText .= _kt(', in the folder "').$info['location_name']._kt('"'); | |
| 472 | + $checkOutDocumentText .= _kt(', from the folder "').$info['location_name']._kt('"'); | |
| 473 | + $moveDocumentText .= _kt(' to the folder "').$info['location_name']._kt('"'); | |
| 474 | + $copiedDocumentText .= _kt(' to the folder "').$info['location_name']._kt('"'); | |
| 475 | + $archivedDocumentText .= _kt(' in the folder "').$info['location_name']._kt('" has been archived'); | |
| 476 | + $downloadDocumentText .= _kt(' in the folder "').$info['location_name']._kt('" has been downloaded'); | |
| 477 | + $documentAlertText .= _kt(' in the folder "').$info['location_name']._kt('"'); | |
| 478 | + } | |
| 479 | + | |
| 480 | + // set up links | |
| 481 | + switch($info['event_type']){ | |
| 482 | + case 'AddFolder': | |
| 483 | + $text = $addFolderText; | |
| 484 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 485 | + $links = '<a href="'.$url.'">'._kt('View New Folder').'</a>'; | |
| 486 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 487 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 488 | + break; | |
| 489 | + case 'RemoveSubscribedFolder': | |
| 490 | + $text = $removeSubscribedFolderText; | |
| 491 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 492 | + $links = '<a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 493 | + break; | |
| 494 | + case 'RemoveChildFolder': | |
| 495 | + $text = $removeChildFolderText; | |
| 496 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 497 | + $links = '<a href="'.$url.'">'._kt('View Folder').'</a>'; | |
| 498 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 499 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 500 | + break; | |
| 501 | + case 'AddDocument': | |
| 502 | + $text = $addDocumentText; | |
| 503 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 504 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 505 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 506 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 507 | + break; | |
| 508 | + case 'RemoveSubscribedDocument': | |
| 509 | + $text = $removeSubscribedDocumentText; | |
| 510 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 511 | + $links = '<a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 512 | + break; | |
| 513 | + case 'RemoveChildDocument': | |
| 514 | + $text = $removeChildDocumentText; | |
| 515 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 516 | + $links = '<a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 517 | + break; | |
| 518 | + case 'ModifyDocument': | |
| 519 | + $text = $modifyDocumentText; | |
| 520 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 521 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 522 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 523 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 524 | + break; | |
| 525 | + case 'CheckInDocument': | |
| 526 | + $text = $checkInDocumentText; | |
| 527 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 528 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 529 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 530 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 531 | + break; | |
| 532 | + case 'CheckOutDocument': | |
| 533 | + $text = $checkOutDocumentText; | |
| 534 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 535 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 536 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 537 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 538 | + break; | |
| 539 | + case 'MovedDocument': | |
| 540 | + $text = $modifyDocumentText; | |
| 541 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 542 | + $links = '<a href="'.$url.'">'._kt('View New Location').'</a>'; | |
| 543 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 544 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 545 | + break; | |
| 546 | + case 'CopiedDocument': | |
| 547 | + $text = $copiedDocumentText; | |
| 548 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 549 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 550 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 551 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 552 | + break; | |
| 553 | + case 'ArchivedDocument': | |
| 554 | + $text = $archivedDocumentText; | |
| 555 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 556 | + $links = '<a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 557 | + break; | |
| 558 | + case 'RestoreArchivedDocument': | |
| 559 | + $text = $restoreArchivedDocumentText; | |
| 560 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 561 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 562 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 563 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 564 | + break; | |
| 565 | + case 'DownloadDocument': | |
| 566 | + $text = $downloadDocumentText; | |
| 567 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 568 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 569 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 570 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 571 | + break; | |
| 572 | + case 'ModifyDocumentAlert': | |
| 573 | + $text = $documentAlertText; | |
| 574 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id']; | |
| 575 | + $links = '<a href="'.$url.'">'._kt('View Document').'</a>'; | |
| 576 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=clear'; | |
| 577 | + $links .= ' | <a href="'.$url.'">'._kt('Clear Alert').'</a>'; | |
| 578 | + $url = $rootUrl.'/notify.php?id='.$info['notify_id'].'¬ify_action=viewall'; | |
| 579 | + $links .= ' | <a href="'.$url.'">'._kt('View all alerts on this document').'</a>'; | |
| 580 | + } | |
| 581 | + | |
| 582 | + if($info['actor_name'] !== NULL && $info['event_type'] != 'RestoredArchivedDocument'){ | |
| 583 | + $text .= _kt(', by ').$info['actor_name']; | |
| 584 | + } | |
| 585 | + | |
| 586 | + // we can re-use the normal template. | |
| 436 | 587 | // however, we need to wrap it - no need for a second template here. |
| 437 | - $str = '<html><body>' . $this->getNotificationAlertContent($oKTNotification) . '</body></html>'; | |
| 588 | + //$str = '<html><body>' . $this->getNotificationAlertContent($oKTNotification) . '</body></html>'; | |
| 589 | + $str = '<br /> | |
| 590 | +     <b>'._kt('Subscription notification').': '.$this->_eventTypeNames[$info['event_type']].'</b> | |
| 591 | + <br /> | |
| 592 | + <br /> | |
| 593 | +     '.$text.' | |
| 594 | + <br /> | |
| 595 | + <br /> | |
| 596 | +     '.$links.' | |
| 597 | + <br /> | |
| 598 | + <br />'; | |
| 438 | 599 | return $str; |
| 439 | 600 | } |
| 440 | 601 | |
| ... | ... | @@ -450,7 +611,7 @@ class SubscriptionContent { |
| 450 | 611 | $oTemplate = $oTemplating->loadTemplate("kt3/notifications/subscriptions." . $info['event_type']); |
| 451 | 612 | // if, for some reason, this doesn't actually work, use the "generic" title. |
| 452 | 613 | if (PEAR::isError($oTemplate)) { |
| 453 | - $oTemplate = $oTemplating->loadTemplate("kt3/notifications/subscriptions.generic"); | |
| 614 | + $oTemplate = $oTemplating->loadTemplate("kt3/notifications/subscriptions.generic"); | |
| 454 | 615 | } |
| 455 | 616 | // FIXME we need to specify the i18n by user. |
| 456 | 617 | |
| ... | ... | @@ -487,7 +648,9 @@ class SubscriptionContent { |
| 487 | 648 | |
| 488 | 649 | |
| 489 | 650 | function _getSubscriptionData($oKTNotification) { |
| 490 | - $info = array( | |
| 651 | + $appName = APP_NAME; | |
| 652 | + | |
| 653 | + $info = array( | |
| 491 | 654 | 'object_name' => $oKTNotification->getLabel(), |
| 492 | 655 | 'event_type' => $oKTNotification->getStrData1(), |
| 493 | 656 | 'location_name' => $oKTNotification->getStrData2(), |
| ... | ... | @@ -497,7 +660,9 @@ class SubscriptionContent { |
| 497 | 660 | 'notify_id' => $oKTNotification->getId(), |
| 498 | 661 | ); |
| 499 | 662 | |
| 500 | - $info['title'] = KTUtil::arrayGet($this->_eventTypeNames, $info['event_type'], 'Subscription alert:') .': ' . $info['object_name']; | |
| 663 | +// $info['title'] = KTUtil::arrayGet($this->_eventTypeNames, $info['event_type'], 'Subscription alert:') .': ' . $info['object_name']; | |
| 664 | + $info['title'] = $appName.': '._kt('Subscription notification for').' "'.$info['object_name'].'" - '.$this->_eventTypeNames[$info['event_type']]; | |
| 665 | + | |
| 501 | 666 | |
| 502 | 667 | if ($info['actor_id'] !== null) { |
| 503 | 668 | $oTempUser = User::get($info['actor_id']); | ... | ... |