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

Support custom statuses deletion

Statuses with tickets cannot be deleted
Fix orm to class gracefully when joins are not inspected
Add create date to new statuses
parent fafc884e
No related branches found
No related tags found
No related merge requests found
......@@ -748,6 +748,11 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
'table' => TICKET_STATUS_TABLE,
'ordering' => array('name'),
'pk' => array('id'),
'joins' => array(
'tickets' => array(
'reverse' => 'TicketModel.status',
)
)
);
var $_list;
......@@ -831,11 +836,19 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
function isDeletable() {
return !($this->isInternal() || $this->isDefault());
return !($this->isInternal()
|| $this->isDefault()
|| $this->getNumTickets());
}
function isInternal() {
return ($this->hasFlag('mode', self::INTERNAL));
return ($this->isDefault()
|| $this->hasFlag('mode', self::INTERNAL));
}
function getNumTickets() {
return $this->tickets->count();
}
function getId() {
......@@ -961,11 +974,11 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
function delete() {
// Statuses with tickets are not deletable
if (!$this->isDeletable())
return false;
// TODO: Delete and do house cleaning (move tickets..etc)
return parent::delete();
}
function toString() {
......@@ -976,6 +989,15 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
return $this->toString();
}
static function create($ht) {
if (!isset($ht['mode']))
$ht['mode'] = 1;
$ht['created'] = new SqlFunction('NOW');
return parent::create($ht);
}
static function lookup($var, $list= false) {
......@@ -993,7 +1015,6 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
$properties = JsonDataEncoder::encode($ht['properties']);
unset($ht['properties']);
$ht['created'] = new SqlFunction('NOW');
if ($status = TicketStatus::create($ht)) {
$status->save(true);
$status->_config = new Config('TS.'.$status->getId());
......@@ -1007,4 +1028,6 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
include(STAFFINC_DIR . 'templates/status-options.tmpl.php');
}
}
TicketStatus::_inspect();
?>
......@@ -42,10 +42,14 @@ class VerySimpleModel {
elseif (isset(static::$meta['joins'][$field])) {
// TODO: Support instrumented lists and such
$j = static::$meta['joins'][$field];
$class = $j['fkey'][0];
$v = $this->ht[$field] = $class::lookup(
array($j['fkey'][1] => $this->ht[$j['local']]));
return $v;
// Make sure joins were inspected
if (isset($j['fkey'])
&& ($class = $j['fkey'][0])
&& class_exists($class)) {
$v = $this->ht[$field] = $class::lookup(
array($j['fkey'][1] => $this->ht[$j['local']]));
return $v;
}
}
if (isset($default))
return $default;
......
......@@ -39,6 +39,9 @@ class TicketModel extends VerySimpleModel {
'joins' => array(
'user' => array(
'constraint' => array('user_id' => 'UserModel.id')
),
'status' => array(
'constraint' => array('status_id' => 'TicketStatus.id')
)
)
);
......
......@@ -44,7 +44,7 @@ foreach($actions as $k => $v) {
<a class="no-pjax tickets-action"
href="#tickets/status/<?php echo $k; ?>/<?php
echo $s->getId(); ?>"> <i
class="icon-tag"></i> <?php echo $s->getName(); ?></a> </li>
class="icon-tag"></i> <?php echo __($s->getName()); ?></a> </li>
<?php
} ?>
</ul>
......
......@@ -95,9 +95,11 @@ if($_POST) {
if ($errors)
$errors['err'] = $errors['err'] ?: sprintf(__('Unable to update %s. Correct error(s) below and try again!'),
__('custom list items'));
else
else {
$list->_items = null;
$msg = sprintf(__('Successfully updated %s'),
__('this custom list'));
}
} elseif ($errors)
$errors['err'] = $errors['err'] ?: sprintf(__('Unable to update %s. Correct error(s) below and try again!'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment