Skip to content
Snippets Groups Projects
Commit 641b69f4 authored by Jared Hancock's avatar Jared Hancock
Browse files

Fixup thread counts for edited threads on ticket queue

parent c161b596
Branches
Tags
No related merge requests found
...@@ -535,14 +535,20 @@ class SqlFunction { ...@@ -535,14 +535,20 @@ class SqlFunction {
$this->args = array_slice(func_get_args(), 1); $this->args = array_slice(func_get_args(), 1);
} }
function input($what, $compiler, $model) {
if ($what instanceof SqlFunction)
$A = $what->toSql($compiler, $model);
elseif ($what instanceof Q)
$A = $compiler->compileQ($what, $model);
else
$A = $compiler->input($what);
return $A;
}
function toSql($compiler, $model=false, $alias=false) { function toSql($compiler, $model=false, $alias=false) {
$args = array(); $args = array();
foreach ($this->args as $A) { foreach ($this->args as $A) {
if ($A instanceof SqlFunction) $args[] = $this->input($A, $compiler, $model);
$A = $A->toSql($compiler, $model);
else
$A = $compiler->input($A);
$args[] = $A;
} }
return sprintf('%s(%s)%s', $this->func, implode(',', $args), return sprintf('%s(%s)%s', $this->func, implode(',', $args),
$alias && $this->alias ? ' AS '.$compiler->quote($this->alias) : ''); $alias && $this->alias ? ' AS '.$compiler->quote($this->alias) : '');
...@@ -562,6 +568,40 @@ class SqlFunction { ...@@ -562,6 +568,40 @@ class SqlFunction {
} }
} }
class SqlCase extends SqlFunction {
var $cases = array();
var $else = false;
static function N() {
return new static('CASE');
}
function when($expr, $result) {
$this->cases[] = array($expr, $result);
return $this;
}
function otherwise($result) {
$this->else = $result;
return $this;
}
function toSql($compiler, $model=false, $alias=false) {
$cases = array();
foreach ($this->cases as $A) {
list($expr, $result) = $A;
$expr = $this->input($expr, $compiler, $model);
$result = $this->input($result, $compiler, $model);
$cases[] = "WHEN {$expr} THEN {$result}";
}
if ($this->else) {
$else = $this->input($this->else, $compiler, $model);
$cases[] = "ELSE {$else}";
}
return sprintf('CASE %s END%s', implode(' ', $cases),
$alias && $this->alias ? ' AS '.$compiler->quote($this->alias) : '');
}
}
class SqlExpr extends SqlFunction { class SqlExpr extends SqlFunction {
function __construct($args) { function __construct($args) {
$this->args = $args; $this->args = $args;
...@@ -687,7 +727,12 @@ class SqlAggregate extends SqlFunction { ...@@ -687,7 +727,12 @@ class SqlAggregate extends SqlFunction {
// For DISTINCT, require a field specification — not a relationship // For DISTINCT, require a field specification — not a relationship
// specification. // specification.
list($field, $rmodel) = $compiler->getField($this->expr, $model, $options); $E = $this->expr;
if ($E instanceof SqlFunction) {
$field = $E->toSql($compiler, $model, $alias);
}
else {
list($field, $rmodel) = $compiler->getField($E, $model, $options);
if ($this->distinct) { if ($this->distinct) {
$pk = false; $pk = false;
foreach ($rmodel::$meta['pk'] as $f) { foreach ($rmodel::$meta['pk'] as $f) {
...@@ -708,6 +753,7 @@ class SqlAggregate extends SqlFunction { ...@@ -708,6 +753,7 @@ class SqlAggregate extends SqlFunction {
} }
} }
} }
}
return sprintf('%s(%s%s)%s', $this->func, return sprintf('%s(%s%s)%s', $this->func,
$this->distinct ? 'DISTINCT ' : '', $field, $this->distinct ? 'DISTINCT ' : '', $field,
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
?></textarea> ?></textarea>
<?php if ($this->entry->type == 'R') { ?> <?php if ($this->entry->type == 'R') { ?>
<div style="margin:10px 0;"><?php echo __('Signature'); ?>: <div style="margin:10px 0;"><strong><?php echo __('Signature'); ?>:</strong>
<label><input type="radio" name="signature" value="none" checked="checked"> <?php echo __('None');?></label> <label><input type="radio" name="signature" value="none" checked="checked"> <?php echo __('None');?></label>
<?php <?php
if ($thisstaff->getSignature()) {?> if ($thisstaff->getSignature()) {?>
......
...@@ -9,14 +9,15 @@ $E = $entry; ...@@ -9,14 +9,15 @@ $E = $entry;
do { ?> do { ?>
<dt> <dt>
<a href="#"><i class="icon-copy"></i> <a href="#"><i class="icon-copy"></i>
<strong><?php echo Format::htmlchars($E->title); ?></strong> <strong><?php if ($E->title)
echo Format::htmlchars($E->title).' — '; ?></strong>
<em><?php if (strpos($E->updated, '0000-') === false) <em><?php if (strpos($E->updated, '0000-') === false)
echo sprintf(__('Edited on %s'), Format::datetime($E->updated)); echo sprintf(__('Edited on %s'), Format::datetime($E->updated));
else else
echo __('Original'); ?></em> echo __('Original'); ?></em>
</a> </a>
</dt> </dt>
<dd class="hidden"> <dd class="hidden" style="background-color:transparent">
<div class="thread-body" style="background-color:transparent"> <div class="thread-body" style="background-color:transparent">
<?php echo $E->getBody()->toHtml(); ?> <?php echo $E->getBody()->toHtml(); ?>
</div> </div>
......
...@@ -150,12 +150,14 @@ if (!$view_all_tickets) { ...@@ -150,12 +150,14 @@ if (!$view_all_tickets) {
if ($teams = array_filter($thisstaff->getTeams())) if ($teams = array_filter($thisstaff->getTeams()))
$assigned->add(array('team_id__in' => $teams)); $assigned->add(array('team_id__in' => $teams));
$visibility = array( if ($status)
new Q(array('status__state'=>'open', $assigned)) $visibility = Q::any(array($assigned));
); else
$visibility = Q::any(array('status__state'=>'open', $assigned));
// -- Routed to a department of mine // -- Routed to a department of mine
if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts())) if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts()))
$visibility[] = new Q(array('dept_id__in' => $depts)); $visibility->add(array('dept_id__in' => $depts));
$tickets->filter(Q::any($visibility)); $tickets->filter(Q::any($visibility));
} }
...@@ -268,7 +270,12 @@ $tickets->values('lock__staff_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_i ...@@ -268,7 +270,12 @@ $tickets->values('lock__staff_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_i
$tickets->annotate(array( $tickets->annotate(array(
'collab_count' => SqlAggregate::COUNT('thread__collaborators'), 'collab_count' => SqlAggregate::COUNT('thread__collaborators'),
'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'), 'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'),
'thread_count' => SqlAggregate::COUNT('thread__entries'), 'thread_count' => SqlAggregate::COUNT(SqlCase::N()
->when(
new Q(array('thread__entries__flags__hasbit'=>ThreadEntry::FLAG_HIDDEN)),
null)
->otherwise(1)
),
)); ));
// Save the query to the session for exporting // Save the query to the session for exporting
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment