/** * adds step to the tour and rearranges existing steps */ function addStep($data, $position = 0) { $step = new HelpTourStep(); $step->setData($data, true); if ($position) { $step->step = $position; } else { $step->step = count($this->steps) + 1; } $step->tour_id = $this->tour_id; if ($step->validate()) { if ($position and $position <= count($this->steps)) { $query = "UPDATE help_tour_steps \n SET step = step+1 \n WHERE tour_id = ? AND step >= ? \n ORDER BY step DESC"; $statement = DBManager::get()->prepare($query); $statement->execute(array($this->tour_id, $position)); } $step->store(); $this->restore(); return true; } return false; }