diff --git a/include/class.list.php b/include/class.list.php index d1eae41603555072de0559069d384a39e4615a4f..a88040d8b57fd1ce770bf4e63bdab432338d1447 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -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(); ?> diff --git a/include/class.orm.php b/include/class.orm.php index f46fd8ea5a37972e032d89ae52ce8198e46f95f7..264582fb6885c4dd636aaa09f9777f5c421e652d 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -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; diff --git a/include/class.user.php b/include/class.user.php index 127a078d5067d1acf43ff136ec6d0f0d27e804b1..8130551a96b1fb7ceda79bc9c2ebf1607b7caf6c 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -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') ) ) ); diff --git a/include/staff/templates/status-options.tmpl.php b/include/staff/templates/status-options.tmpl.php index 5d056a659e62de3f91448db78b3c54970a01d513..5fc39f32ad99c9f6c52b129291545a8f8d7f336d 100644 --- a/include/staff/templates/status-options.tmpl.php +++ b/include/staff/templates/status-options.tmpl.php @@ -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> diff --git a/scp/lists.php b/scp/lists.php index 02b41d117988466a5a58f92ff31be4d409541e08..b3c424de7e15af1ecd0bbfe7428b57c013776330 100644 --- a/scp/lists.php +++ b/scp/lists.php @@ -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!'),