Skip to content

Commit

Permalink
variable: Complete Thread ASC or DESC
Browse files Browse the repository at this point in the history
This pull adds the ability to choose between ASC or DESC order for the
complete thread variable. If `complete_asc` is chosen the system will order
the thread in ASC order, if `complete_desc` is chosen the system will order
the thread in DESC order. This keeps backwards compatibility with just
`complete` as some people might forget to update this for a while.
  • Loading branch information
JediKev committed Mar 27, 2019
1 parent 89838c0 commit 84d05c6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 40 additions & 10 deletions include/class.thread.php
Expand Up @@ -2989,7 +2989,7 @@ function __toString() {
}

function asVar() {
return $this->getVar('complete');
return new ThreadEntries($this);
}

function getVar($name) {
Expand All @@ -3013,21 +3013,14 @@ function getVar($name) {

break;
case 'complete':
$content = '';
$thread = $this;
ob_start();
include INCLUDE_DIR.'client/templates/thread-export.tmpl.php';
$content = ob_get_contents();
ob_end_clean();
return $content;

return $this->asVar();
break;
}
}

static function getVarScope() {
return array(
'complete' => __('Thread Correspondence'),
'complete' =>array('class' => 'ThreadEntries', 'desc' => __('Thread Correspondence')),
'original' => array('class' => 'MessageThreadEntry', 'desc' => __('Original Message')),
'lastmessage' => array('class' => 'MessageThreadEntry', 'desc' => __('Last Message')),
);
Expand All @@ -3047,6 +3040,43 @@ static function lookup($criteria, $type=false) {
}
}

class ThreadEntries {
var $thread;

function __construct($thread) {
$this->thread = $thread;
}

function asVar() {
return $this->getVar();
}

function getVar($name='') {

$order = '';
switch ($name) {
case 'reversed':
$order = '-';
default:
$content = '';
$thread = $this->thread;
ob_start();
include INCLUDE_DIR.'client/templates/thread-export.tmpl.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
break;
}
}

static function getVarScope() {
return array(
'reversed' => sprintf('%s %s', __('Thread Correspondence'),
__('in reversed order')),
);
}
}

// Ticket thread class
class TicketThread extends ObjectThread {
static function create($ticket=false) {
Expand Down
2 changes: 1 addition & 1 deletion include/client/templates/thread-export.tmpl.php
Expand Up @@ -12,7 +12,7 @@
))->all();

$entries = $thread->getEntries();
$entries->filter(array('type__in' => array_keys($entryTypes)));
$entries->filter(array('type__in' => array_keys($entryTypes)))->order_by("{$order}id");;
?>
<style type="text/css">
div {font-family: sans-serif;}
Expand Down

0 comments on commit 84d05c6

Please sign in to comment.