/** * Sets the position of a subject in the timeboard schedule * This function automatically reschedules all subs to properly fit in the timeboard after setting the new position * @param integer $id The id of the subject to set position to * @param integer $position The position(in timestamp format) to set to the subject * @param integer $type The position type set by who(user or manager) * @return boolean true on success false on failure */ public function set_position($id, $position, $type = 'manager') { if ($position < SiteLibrary::utc_time()) { return false; } //Position to be set can't be smaller than the current available timeboard positions //if(Subject::model()->find('id=:id AND position=:position',array(':id'=>$id,':position'=>$position))) return false; //Nothing to do, already set //If there is a fixed sub occupying the requested position, then move it forward if ($occupied_pos = Subject::model()->find('(user_position > 0 OR manager_position > 0) AND position = ' . $position . ' AND id<>' . $id)) { Subject::move_position_forward($occupied_pos->id, false); } if ($type == 'manager') { Subject::model()->updateByPk($id, array('position' => $position, 'manager_position' => $position)); } else { Subject::model()->updateByPk($id, array('position' => $position, 'user_position' => $position)); } Subject::reschedule_positions(); return true; }