Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Merge branch '5.6' into 5.7
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	plugin.xml
  • Loading branch information
rmiddle committed Jan 8, 2012
2 parents 731b4ea + 39edf44 commit 7708441
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 40 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ Installation using Git
* Change directory to **/cerb5/storage/plugins/**
* `git clone git://github.com/rmiddle/cerb5blog.required_watcher.git`
* `cd cerb5blog.required_watcher`
<<<<<<< HEAD
* `git checkout --track -b 5.7 origin/5.7`
=======
* `git checkout --track -b 5.6 origin/5.6`
>>>>>>> 5.6
* In your helpdesk, enable the plugin from **Setup->Features & Plugins**.
Installation using zip / tar.gz
Expand Down
154 changes: 114 additions & 40 deletions api/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ function handleEvent(Model_DevblocksEvent $event) {
case 'context_link.set':
$this->_handleContextLink($event);
break;
case 'dao.ticket.update':
$this->_workerOwned($event);
break;
case 'cerb5blog.context_link.watcher':
$this->_workerAssigned($event);
$this->_workerWatched($event);
break;
}
}
Expand All @@ -37,28 +40,28 @@ private function _handleContextLink($event) {
}
}

private function _workerAssigned($event) {
private function _workerWatched($event) {
$context = $event->params['context'];

switch($context) {
case CerberusContexts::CONTEXT_TICKET:
$this->_workerAssignedTicket($event);
$this->_workerWatchedTicket($event);
break;
case CerberusContexts::CONTEXT_TASK:
$this->_workerAssignedTask($event);
$this->_workerWatchedTask($event);
break;
}
}

private function _workerAssignedTicket($event) {
private function _workerWatchedTicket($event) {
$translate = DevblocksPlatform::getTranslationService();
$events = DevblocksPlatform::getEventService();

$worker_id = $event->params['worker_id'];
$context = $event->params['context'];
$ticket_id = $event->params['context_id'];

$ticket = DAO_Ticket::get($ticket_id);
Context_Ticket::getContext($ticket_id, $token_labels, $values);

$address = DAO_AddressOutgoing::getDefault();
$default_from = $address->email;
Expand All @@ -71,37 +74,42 @@ private function _workerAssignedTicket($event) {
if(empty($to))
return;

$ticket = DAO_Ticket::get($ticket_id);
$messages = DAO_Message::getMessagesByTicket($ticket_id);
$message = end($messages); // last message
unset($messages);

$subject = sprintf("[Ticket Assignment #%s]: %s\r\n",
$ticket->mask,
$ticket->subject
$params = array(
'action' => 'relay_email',
'to' => array( '0' => $to ),
'subject' => "[Ticket Watcher #{{mask}}]: {{subject}}",
'content' =>
"## Relayed from {{url}}
## Your reply to this message will be broadcast to the requesters.
## Instructions: http://wiki.cerb5.com/wiki/Email_Relay
##
{{initial_message_content}}
",
'include_attachments' => 1,
);
DevblocksEventHelper::runActionRelayEmail(
$params,
$values,
CerberusContexts::CONTEXT_TICKET,
$ticket_id,
$values['group_id'],
@$values['bucket_id'] or 0,
$values['initial_message_id'],
@$values['owner_id'] or 0,
$values['initial_message_sender_address'],
$values['initial_message_sender_full_name'],
$values['subject']
);

$url_writer = DevblocksPlatform::getUrlService();
$url = $url_writer->write(sprintf("c=display&mask=%s", $ticket->mask), true);

$body = "## " . $url;
$body .= "\r\n" . $message->getContent();

CerberusMail::quickSend(
$to,
$subject,
$body
);
}

private function _workerAssignedTask($event) {
private function _workerWatchedTask($event) {
$translate = DevblocksPlatform::getTranslationService();
$events = DevblocksPlatform::getEventService();

$worker_id = $event->params['worker_id'];
$context = $event->params['context'];
$task_id = $event->params['context_id'];
$task = DAO_Task::get($task_id);

// Sanitize and combine all the destination addresses
Expand All @@ -110,32 +118,98 @@ private function _workerAssignedTask($event) {

if(empty($to))
return;
$subject = sprintf("[Task Assignment #%d]: %s",
$subject = sprintf("[Task Watcher #%d]: %s",
$task->id,
$task->title
);

$body = sprintf("[Task Assignment #%d]: %s",
$task->id,
$task->title
);

$url_writer = DevblocksPlatform::getUrlService();
$url = $url_writer->write(sprintf("c=tasks&tab=display&id=%d", $task_id), true);

$body = "\r\n## " . $url;
$body .= "\r\nTitle: " . $task->title;
$body .= "\r\nLast Update: " . $task->updated_date;
$body .= "\r\nDue Date: " . $task->due_date;
$body .= "\r\nIs Completed: " . $task->is_completed ? "Open" : "Closed";
$body .= "\r\nCompleted Date: " . $task->completed_date;
$body .= "\r\nLast Update: " . date("F j, Y, g:i a T", intval($task->updated_date));
$body .= "\r\nDue Date: " . date("F j, Y, g:i a T", intval($task->due_date));
$body .= "\r\nIs Completed: ";
$body .= $task->is_completed ? "Closed" : "Open";
if ($task->is_completed) {
$body .= "\r\nCompleted Date: " . date("F j, Y, g:i a T", intval($task->completed_date));
}

CerberusMail::quickSend(
$to,
$subject,
$body
);
);
}

private function _workerOwned($event) {
$translate = DevblocksPlatform::getTranslationService();
$events = DevblocksPlatform::getEventService();

$objects = $event->params['objects'];
if(is_array($objects)) {
foreach($objects as $object_id => $object) {
@$model = $object['model'];
@$changes = $object['changes'];

if(empty($model) || empty($changes))
continue;

/*
* Owner changed
*/
if(isset($changes[DAO_Ticket::OWNER_ID])) {
@$owner = $changes[DAO_Ticket::OWNER_ID];

if ( (!empty($owner['to'])) && ($owner['to'] !== 0) ) {
@$owner_id = $changes[DAO_Ticket::OWNER_ID]['to'];
@$ticket_id = $model[DAO_Ticket::ID];

Context_Ticket::getContext($ticket_id, $token_labels, $values);

$address = DAO_AddressOutgoing::getDefault();
$default_from = $address->email;
$default_personal = $address->reply_personal;

// Sanitize and combine all the destination addresses
$next_worker = DAO_Worker::get($owner_id);
$to = $next_worker->email;

if(empty($to))
return;

$params = array(
'action' => 'relay_email',
'to' => array( '0' => $to ),
'subject' => "[Ticket Owner #{{mask}}]: {{subject}}",
'content' =>
"## Relayed from {{url}}
## Your reply to this message will be broadcast to the requesters.
## Instructions: http://wiki.cerb5.com/wiki/Email_Relay
##
{{initial_message_content}}
",
'include_attachments' => 1,
);
DevblocksEventHelper::runActionRelayEmail(
$params,
$values,
CerberusContexts::CONTEXT_TICKET,
$ticket_id,
$values['group_id'],
@$values['bucket_id'] or 0,
$values['initial_message_id'],
@$values['owner_id'] or 0,
$values['initial_message_sender_address'],
$values['initial_message_sender_full_name'],
$values['subject']
);
}
}
}
}
}
};

5 changes: 5 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<!-- Requirements -->

<requires>
<<<<<<< HEAD
<app_version min="5.6" max="5.7" />
=======
<app_version min="5.6" max="5.7.99" />
>>>>>>> 5.6
</requires>

<!-- Plugin Dependencies -->
Expand Down Expand Up @@ -77,6 +81,7 @@
<param key="events">
<value>
<data key="context_link.set" />
<data key="dao.ticket.update" />
<data key="cerb5blog.context_link.watcher" />
</value>
</param>
Expand Down

0 comments on commit 7708441

Please sign in to comment.