/** * This method will move current period down in sorting order. */ public function move_down() { if (isset($this->id) && intval($this->id) > 0) { $down_period = new Period(); $down_period->order_by('sorting', 'asc')->limit(1); $down_period->where('sorting >', $this->sorting); $down_period->get(); if ($down_period->exists()) { $upsort = $down_period->sorting; $down_period->sorting = $this->sorting; if ($down_period->save()) { $my_period = new Period(); $my_period->get_where(array('id' => $this->id)); $my_period->sorting = $upsort; if ($my_period->save()) { $this->sorting = $upsort; } } } } }
public function _is_unique_name_not_in($str, $id) { $period = new Period(); $period->where('name', $str); $period->where('id !=', intval($id)); $period->get(); return (bool) (!$period->exists()); }