id = $id; } $this->load($this->id); } function load($id = NULL) { if (is_numeric($id)) { $this->id = $id; } $ret = false; if (is_numeric($this->id)) { $q = "SELECT * FROM " . DB_PREFIX . "training_plan_days WHERE id=".$this->id; $ret = query_row($q); } if ( $ret) { $this->id = $ret->id; $this->muscle_group = $ret->muscle_group; $this->exercise = $ret->exercise; $this->series = $ret->series; $this->repetitions = $ret->repetitions; $this->break_length = $ret->break_length; $this->break_unit = $ret->break_unit; } } function getId() { return $this->id; } function create() { //$this->setCreator(get_logged_in_user()->getId()); $q = "INSERT INTO " . DB_PREFIX . "training_plan_days (training_plan, day, position, muscle_group, exercise, series, repetitions, break_length, break_unit) values (".$this->getTrainingplan().", ".$this->getDay().", ".$this->getPosition().", '".$this->getMuscleGroup()."', '".mysql_real_escape_string($this->getExercise())."', ".$this->getSeries().", '".mysql_real_escape_string($this->getRepetitions())."', ".$this->getBreakLength().", '".$this->getBreakUnit()."')"; $uid = query_insert($q); if ($uid) return $uid; return false; } function save() { $update_query = "UPDATE " . DB_PREFIX . "training_plan_days SET"; $update_query .= " muscle_group=".$this->getMuscleGroup().","; $update_query .= " exercise='".mysql_real_escape_string($this->getExercise())."',"; $update_query .= " series='".$this->getSeries()."',"; $update_query .= " repetitions='".mysql_real_escape_string($this->getRepetitions())."',"; $update_query .= " break_length='".$this->getBreakLength()."',"; $update_query .= " break_unit='".$this->getBreakUnit()."',"; $update_query .= " position='".$this->getPosition()."'"; $update_query .= " WHERE id=".$this->getId(); $update = query_update($update_query); return $this->getId(); } function build($data) { if ($this->isBuildValuesEmpty($data)) { return false; } $this->setMuscleGroup($data["muscle_group"]); $this->setExercise($data["exercise"]); $this->setSeries($data["series"]); $this->setRepetitions($data["repetitions"]); $this->setBreakLength($data["break_length"]); $this->setBreakUnit($data["break_unit"]); if ($this->getId() > 0) { $id = $this->save(); } else { $id = $this->create(); } return $id; } function isBuildValuesEmpty($data) { if (empty($data["exercise"])) { return true; } return false; } function delete() { global $TeKe; if (is_numeric($this->getId()) && $this->getId() > 0) { if ($TeKe->is_logged_in() && ($TeKe->is_admin() || get_logged_in_user()->getId() == $this->getCreator())) { return query("DELETE FROM " . DB_PREFIX . "training_plan_days WHERE id=".$this->getId()); } } return false; } function getTrainingplan() { return $this->trainingplan; } function setTrainingplan($trainingplan) { $this->trainingplan = $trainingplan; } function getDay() { return $this->day; } function setDay($day) { $this->day = $day; } function getPosition() { return $this->position; } function setPosition($position) { $this->position = $position; } function getMuscleGroup() { return $this->muscle_group; } function setMuscleGroup($muscle_group) { $this->muscle_group = $muscle_group; } function getExercise() { return $this->exercise; } function setExercise($exercise) { $this->exercise = $exercise; } function getSeries() { return $this->series; } function setSeries($series) { if (!$series) $series = 0; $this->series = $series; } function getRepetitions() { return $this->repetitions; } function setRepetitions($repetitions) { $this->repetitions = $repetitions; } function getBreakLength() { return $this->break_length; } function setBreakLength($break_length) { if (!$break_length) $break_length = 0; $this->break_length = $break_length; } function getBreakUnit() { return $this->break_unit; } function setBreakUnit($break_unit) { $this->break_unit = $break_unit; } } ?>