private function _sendNotifications($filters, $url, $msg) { if (is_array($filters)) { foreach ($filters as $idx => $filter) { /* @var $filter Model_WatcherMailFilter */ if (isset($filter->actions['notify'])) { $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $filter->worker_id, DAO_WorkerEvent::URL => $url, DAO_WorkerEvent::TITLE => 'Watcher: ' . $filter->name, DAO_WorkerEvent::CONTENT => $msg, DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } } }
private function _postCreateAction($path) { $xmlstr = $this->getPayload(); $xml_in = simplexml_load_string($xmlstr); $fields = array(); $flds = DAO_WorkerEvent::getFields(); unset($flds[DAO_WorkerEvent::ID]); foreach ($flds as $idx => $f) { $idx_name = $this->translate($idx, true); if ($idx_name == null) { continue; } @($value = DevblocksPlatform::importGPC($xml_in->{$idx_name}, 'string')); if ($this->isValid($idx_name, $value)) { $fields[$idx] = $value; } } if (empty($fields[DAO_WorkerEvent::TITLE]) || empty($fields[DAO_WorkerEvent::WORKER_ID]) || empty($fields[DAO_WorkerEvent::CREATED_DATE]) || empty($fields[DAO_WorkerEvent::CONTENT]) || empty($fields[DAO_WorkerEvent::URL])) { $this->_error("All required fields were not provided."); } $id = DAO_WorkerEvent::create($fields); // Render $this->_getIdAction(array($id)); }
function saveCommentAction() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer')); @($comment = DevblocksPlatform::importGPC($_REQUEST['comment'], 'string', '')); // Worker is logged in if (null === ($active_worker = CerberusApplication::getActiveWorker())) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket_id))); } $worker_email = $active_worker->email; // Worker address exists if (null === ($address = CerberusApplication::hashLookupAddress($active_worker->email, true))) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket_id))); } // Form was filled in if (empty($ticket_id) || empty($comment)) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket_id))); } $fields = array(DAO_TicketComment::CREATED => time(), DAO_TicketComment::TICKET_ID => $ticket_id, DAO_TicketComment::ADDRESS_ID => $address->id, DAO_TicketComment::COMMENT => $comment); $comment_id = DAO_TicketComment::create($fields); @($ticket = DAO_Ticket::getTicket($ticket_id)); // Notifications $url_writer = DevblocksPlatform::getUrlService(); @($notify_worker_ids = DevblocksPlatform::importGPC($_REQUEST['notify_worker_ids'], 'array', array())); if (is_array($notify_worker_ids) && !empty($notify_worker_ids)) { foreach ($notify_worker_ids as $notify_worker_id) { $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $notify_worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=display&id=' . $ticket->mask, true), DAO_WorkerEvent::TITLE => 'New Ticket Comment', DAO_WorkerEvent::CONTENT => sprintf("#%s: %s\n%s comments: %s", $ticket->mask, $ticket->subject, $active_worker->getName(), $comment), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket->mask, 'comments'))); }
function saveOppNoteAction() { @($opp_id = DevblocksPlatform::importGPC($_REQUEST['opp_id'], 'integer', 0)); @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', '')); $active_worker = CerberusApplication::getActiveWorker(); if (!empty($opp_id) && 0 != strlen(trim($content))) { $fields = array(DAO_Note::SOURCE_EXTENSION_ID => CrmNotesSource_Opportunity::ID, DAO_Note::SOURCE_ID => $opp_id, DAO_Note::WORKER_ID => $active_worker->id, DAO_Note::CREATED => time(), DAO_Note::CONTENT => $content); $note_id = DAO_Note::create($fields); } $opp = DAO_CrmOpportunity::get($opp_id); // Worker notifications $url_writer = DevblocksPlatform::getUrlService(); @($notify_worker_ids = DevblocksPlatform::importGPC($_REQUEST['notify_worker_ids'], 'array', array())); if (is_array($notify_worker_ids) && !empty($notify_worker_ids)) { foreach ($notify_worker_ids as $notify_worker_id) { $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $notify_worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=crm&a=opps&id=' . $opp_id, true), DAO_WorkerEvent::TITLE => 'New Opportunity Note', DAO_WorkerEvent::CONTENT => sprintf("%s\n%s notes: %s", $opp->name, $active_worker->getName(), $content), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('crm', 'opp', $opp_id))); }
function saveTaskPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', '')); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); @($link_namespace = DevblocksPlatform::importGPC($_REQUEST['link_namespace'], 'string', '')); @($link_object_id = DevblocksPlatform::importGPC($_REQUEST['link_object_id'], 'integer', 0)); @($do_delete = DevblocksPlatform::importGPC($_REQUEST['do_delete'], 'integer', 0)); $active_worker = CerberusApplication::getActiveWorker(); if (!empty($id) && !empty($do_delete)) { // delete $task = DAO_Task::get($id); // Check privs if ($active_worker->hasPriv('core.tasks.actions.create') && $active_worker->id == $task->worker_id || $active_worker->hasPriv('core.tasks.actions.update_nobody') && empty($task->worker_id) || $active_worker->hasPriv('core.tasks.actions.update_all')) { DAO_Task::delete($id); } } else { // create|update $fields = array(); // Title @($title = DevblocksPlatform::importGPC($_REQUEST['title'], 'string', '')); if (!empty($title)) { $fields[DAO_Task::TITLE] = $title; } // Completed @($completed = DevblocksPlatform::importGPC($_REQUEST['completed'], 'integer', 0)); $fields[DAO_Task::IS_COMPLETED] = intval($completed); // [TODO] This shouldn't constantly update the completed date (it should compare) if ($completed) { $fields[DAO_Task::COMPLETED_DATE] = time(); } else { $fields[DAO_Task::COMPLETED_DATE] = 0; } // Due Date @($due_date = DevblocksPlatform::importGPC($_REQUEST['due_date'], 'string', '')); @($fields[DAO_Task::DUE_DATE] = empty($due_date) ? 0 : intval(strtotime($due_date))); // Worker @($worker_id = DevblocksPlatform::importGPC($_REQUEST['worker_id'], 'integer', 0)); @($fields[DAO_Task::WORKER_ID] = intval($worker_id)); // Content @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', '')); @($fields[DAO_Task::CONTENT] = $content); // Link to object (optional) if (!empty($link_namespace) && !empty($link_object_id)) { @($fields[DAO_Task::SOURCE_EXTENSION] = $link_namespace); @($fields[DAO_Task::SOURCE_ID] = $link_object_id); } // Save if (!empty($id)) { DAO_Task::update($id, $fields); } else { $id = DAO_Task::create($fields); // Write a notification (if not assigned to ourselves) // $url_writer = DevblocksPlatform::getUrlService(); $source_extensions = DevblocksPlatform::getExtensions('cerberusweb.task.source', true); if (!empty($worker_id)) { // && $active_worker->id != $worker_id (Temporarily allow self notifications) if (null != @($source_renderer = $source_extensions[$link_namespace])) { /* @var $source_renderer Extension_TaskSource */ $source_info = $source_renderer->getSourceInfo($link_object_id); $source_name = $source_info['name']; $source_url = $source_info['url']; if (empty($source_name) || empty($source_url)) { break; } $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $worker_id, DAO_WorkerEvent::URL => $source_url, DAO_WorkerEvent::TITLE => 'New Task Assignment', DAO_WorkerEvent::CONTENT => sprintf("%s\n%s says: %s", $source_name, $active_worker->getName(), $title), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } } // Custom field saves @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array())); DAO_CustomFieldValue::handleFormPost(ChCustomFieldSource_Task::ID, $id, $field_ids); } if (!empty($view_id) && null != ($view = C4_AbstractViewLoader::getView('', $view_id))) { $view->render(); } exit; }
function viewAssignThreadsAction() { @($row_ids = DevblocksPlatform::importGPC($_POST['row_id'], 'array', array())); @($worker_id = DevblocksPlatform::importGPC($_REQUEST['assign_worker_id'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $active_worker = CerberusApplication::getActiveWorker(); if (is_array($row_ids) && !empty($row_ids)) { // Do assignments $fields = array(DAO_ForumsThread::WORKER_ID => $worker_id); DAO_ForumsThread::update($row_ids, $fields); // Only send notifications if not assigning to self (or unassigning) if (!empty($worker_id) && $active_worker->id != $worker_id) { $url_writer = DevblocksPlatform::getUrlService(); // Load threads for notifications $forum_threads = DAO_ForumsThread::getWhere(sprintf("%s IN (%s)", DAO_ForumsThread::ID, implode(',', $row_ids))); // Send notifications about assigned forum threads if (is_array($forum_threads) && !empty($forum_threads)) { foreach ($forum_threads as $forum_thread) { /* @var $forum_thread Model_ForumsThread */ $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=forums&a=explorer', true) . '?start=' . $forum_thread->id, DAO_WorkerEvent::TITLE => 'New Forum Assignment', DAO_WorkerEvent::CONTENT => sprintf("%s assigned: %s", $active_worker->getName(), $forum_thread->title), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } } } if (!empty($view_id) && null != ($view = C4_AbstractViewLoader::getView($view_id))) { $view->render(); } }
private function _workerAssigned($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); if (empty($ticket_ids) || empty($changed_fields)) { return; } @($next_worker_id = $changed_fields[DAO_Ticket::NEXT_WORKER_ID]); // Make sure a next worker was assigned if (empty($next_worker_id)) { return; } @($active_worker = CerberusApplication::getActiveWorker()); // Make sure we're not assigning work to ourselves, if so then bail if (null != $active_worker && $active_worker->id == $next_worker_id) { return; } $tickets = DAO_Ticket::getTickets($ticket_ids); // Write a notification (if not assigned to ourselves) $url_writer = DevblocksPlatform::getUrlService(); foreach ($ticket_ids as $ticket_id) { if (null == ($ticket = $tickets[$ticket_id])) { /* @var $ticket CerberusTicket */ continue; } $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $next_worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=display&id=' . $ticket->mask, true), DAO_WorkerEvent::TITLE => 'New Ticket Assignment', DAO_WorkerEvent::CONTENT => sprintf("#%s: %s", $ticket->mask, $ticket->subject), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } }