whereAdd(" metric_name ILIKE '%{$this->escape($q['search']['name'])}%' "); } } function beforeInsert($q, $roo) { if($this->isNameExist()){ $roo->jerr("{$this->metric_name} already exists!"); } } function beforeUpdate($old, $q, $roo) { if($this->isNameExist()){ $roo->jerr("{$this->metric_name} already exists!"); } } function isNameExist() { $metric = DB_DataObject::factory('metric'); $metric->metric_name = $this->metric_name; if(!empty($this->metric_id)){ $metric->whereAdd(" metric_id != {$this->metric_id} "); } return ($metric->count()) ? true : false; } }