Merge branch 'maint/7.0'
[ninja.git] / modules / orm / models / downtime.php
blob769d6d3e317925787f490fa9ec32f45732238006
1 <?php
3 require_once( dirname(__FILE__).'/base/basedowntime.php' );
5 /**
6 * Describes a single object from livestatus
7 */
8 class Downtime_Model extends BaseDowntime_Model {
9 /**
10 * A list of column dependencies for custom columns
12 static public $rewrite_columns = array(
13 'triggered_by_text' => array('triggered_by')
16 /**
17 * Get triggered by object, as a text.
19 public function get_triggered_by_text() {
20 // TODO: Don't nest queries... Preformance!!! (Do this in livestatus?)
21 $trig_id = $this->get_triggered_by();
22 if( !$trig_id ) return 'N/A';
23 $trig = DowntimePool_Model::all()->reduce_by('id', $trig_id, '=')->it(array('host.name', 'service.description'), array(), 1, 0)->current();
24 if( !$trig ) return 'Unknown';
25 $host = $trig->get_host()->get_name();
26 $svc = $trig->get_service()->get_description();
27 if( $svc ) return $host.';'.$svc;
28 return $host;