Skip to content
Snippets Groups Projects
Commit ba7b77fe authored by Peter Rotich's avatar Peter Rotich
Browse files

Tasks Export

Add ability to export tasks
parent 56091291
Branches
Tags
No related merge requests found
......@@ -99,7 +99,7 @@ class Export {
);
}
/* static */ function saveTickets($sql, $filename, $how='csv') {
static function saveTickets($sql, $filename, $how='csv') {
ob_start();
self::dumpTickets($sql, $how);
$stuff = ob_get_contents();
......@@ -110,7 +110,64 @@ class Export {
return false;
}
static function dumpTasks($sql, $how='csv') {
// Add custom fields to the $sql statement
$cdata = $fields = array();
foreach (TaskForm::getInstance()->getFields() as $f) {
// Ignore non-data fields
if (!$f->hasData() || $f->isPresentationOnly())
continue;
$name = $f->get('name') ?: 'field_'.$f->get('id');
$key = 'cdata.'.$name;
$fields[$key] = $f;
$cdata[$key] = $f->getLocal('label');
}
// Reset the $sql query
$tasks = $sql->models()
->select_related('dept', 'staff', 'team', 'cdata')
->annotate(array(
'collab_count' => SqlAggregate::COUNT('thread__collaborators'),
'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'),
'thread_count' => SqlAggregate::COUNT('thread__entries'),
));
return self::dumpQuery($tasks,
array(
'number' => __('Task Number'),
'created' => __('Date Created'),
'cdata.title' => __('Title'),
'dept::getLocalName' => __('Department'),
'flags' => __('Current Status'), //FIXME: self:getStatus()?
'duedate' => __('Due Date'),
'staff::getName' => __('Agent Assigned'),
'team::getName' => __('Team Assigned'),
'thread_count' => __('Thread Count'),
'attachment_count' => __('Attachment Count'),
) + $cdata,
$how,
array('modify' => function(&$record, $keys) use ($fields) {
foreach ($fields as $k=>$f) {
if (($i = array_search($k, $keys)) !== false) {
$record[$i] = $f->export($f->to_php($record[$i]));
}
}
return $record;
})
);
}
static function saveTasks($sql, $filename, $how='csv') {
ob_start();
self::dumpTasks($sql, $how);
$stuff = ob_get_contents();
ob_end_clean();
if ($stuff)
Http::download($filename, "text/$how", $stuff);
return false;
}
......
#
# This is popup help messages for the Agents Panel -> Tasks
#
# Fields:
# title - Shown in bold at the top of the popover window
# content - The body of the help popover
# links - List of links shows below the content
# title - Link title
# href - href of link (links starting with / are translated to the
# helpdesk installation path)
#
# The key names such as 'helpdesk_name' should not be translated as they
# must match the HTML #ids put into the page template.
#
---
advanced:
title: Advanced
content: >
Narrow down your search parameters. Once you have selected your advanced
search criteria and run the search, you can <span class="doc-desc-title">Export
</span> the data at the bottom of the page.
export:
title: Export
content: >
Export your data currently in view in a CSV file.
CSV files may be opened with any spreadsheet software
(i.e., Microsoft Excel, Apple Pages, OpenOffice, etc.).
......@@ -13,6 +13,7 @@
require('staff.inc.php');
require_once(INCLUDE_DIR.'class.task.php');
require_once(INCLUDE_DIR.'class.export.php');
$page = '';
$task = null; //clean start.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment