diff options
Diffstat (limited to 'lib/evaluation/classes/db')
| -rw-r--r-- | lib/evaluation/classes/db/EvaluationAnswerDB.class.php | 284 | ||||
| -rw-r--r-- | lib/evaluation/classes/db/EvaluationDB.class.php | 291 | ||||
| -rw-r--r-- | lib/evaluation/classes/db/EvaluationGroupDB.class.php | 225 | ||||
| -rw-r--r-- | lib/evaluation/classes/db/EvaluationObjectDB.class.php | 365 | ||||
| -rw-r--r-- | lib/evaluation/classes/db/EvaluationQuestionDB.class.php | 298 |
5 files changed, 0 insertions, 1463 deletions
diff --git a/lib/evaluation/classes/db/EvaluationAnswerDB.class.php b/lib/evaluation/classes/db/EvaluationAnswerDB.class.php deleted file mode 100644 index 54bdb7d..0000000 --- a/lib/evaluation/classes/db/EvaluationAnswerDB.class.php +++ /dev/null @@ -1,284 +0,0 @@ -<?php -# Lifter002: TODO -# Lifter007: TODO -# Lifter003: TODO -# Lifter010: TODO -/** - * Beschreibung - * - * @author Alexander Willner <mail@AlexanderWillner.de> - * @copyright 2004 Stud.IP-Project - * @access public - * @package evaluation - * @modulegroup evaluation_modules - * - */ - -// +--------------------------------------------------------------------------+ -// This file is part of Stud.IP -// Copyright (C) 2001-2004 Stud.IP -// +--------------------------------------------------------------------------+ -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or any later version. -// +--------------------------------------------------------------------------+ -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// +--------------------------------------------------------------------------+ - -require_once 'lib/evaluation/evaluation.config.php'; -require_once EVAL_FILE_OBJECTDB; - - -class EvaluationAnswerDB extends EvaluationObjectDB -{ - /** - * Constructor - * @access public - */ - public function __construct() - { - parent::__construct(); - $this->instanceof = 'EvalANSWERDB'; - } - - /** - * Loads answers of a group from the DB - * @access public - * @param EvaluationAnswer &&$answerObject The answer object - */ - public function load(&$answerObject) - { - /* load answer --------------------------------------------------------- */ - $row = DBManager::get()->fetchOne( - "SELECT * FROM evalanswer WHERE evalanswer_id= ?", [$answerObject->getObjectID()] - ); - if (!count($row)) { - return $this->throwError(2, _("Keine Antwort mit dieser ID gefunden.")); - } - - $answerObject->setObjectID($row['evalanswer_id']); - $answerObject->setParentID($row['parent_id']); - $answerObject->setPosition($row['position']); - $answerObject->setText($row['text']); - $answerObject->setValue($row['value']); - $answerObject->setRows($row['rows']); - $answerObject->setResidual($row['residual']); - } - - - /** - * Loads the votes from the users for this answer - * @access public - * @param EvaluationAnswer &$answerObject The answer object - */ - function loadVotes(&$answerObject) - { - /* load users -------------------------------------------------------- */ - $result = DBManager::get()->fetchFirst("SELECT user_id FROM evalanswer_user - WHERE evalanswer_id= ?", [$answerObject->getObjectID()]); - foreach ($result as $row) { - $answerObject->addUserID($row, NO); - } - } - /* ----------------------------------------------------------- end: users */ - - /** - * Writes answers into the DB - * @access public - * @param EvaluationAnswer &$answerObject The answerobject - * @throws error - */ - function save(&$answerObject) - { - /* save answers -------------------------------------------------------- */ - DBManager::get()->execute( - "REPLACE INTO evalanswer SET - `evalanswer_id` = ?, - `parent_id` = ?, - `position` = ?, - `text` = ?, - `value` = ?, - `rows` = ?, - `residual` = ? - ", - [$answerObject->getObjectID(), - $answerObject->getParentID(), - $answerObject->getPosition(), - $answerObject->getText(), - $answerObject->getValue(), - $answerObject->getRows(), - $answerObject->isResidual()]); - /* ----------------------------------------------------- end: answersave */ - - /* connect answer to users --------------------------------------------- */ - while ($userID = $answerObject->getNextUserID()) { - DBManager::get()->execute( - "INSERT INTO evalanswer_user SET - evalanswer_id = ?, - user_id = ?, - evaldate = UNIX_TIMESTAMP()", - [$answerObject->getObjectID(), $userID]); - } - /* ----------------------------------------------------- end: connecting */ - - } // saved - - /** - * Deletes all votes from the users for this answers - * @access public - * @param EvaluationAnswer &$answerObject The answer object - */ - function resetVotes(&$answerObject) - { - /* delete userconnects ------------------------------------------------- */ - DBManager::get()->execute(" - DELETE FROM evalanswer_user - WHERE evalanswer_id = ?", - [$answerObject->getObjectID()]); - /* ------------------------------------------------------- end: deleting */ - } - - /** - * Deletes a answer - * @access public - * @param EvaluationAnswer &$answerObject The answer to delete - * @throws error - */ - function delete(&$answerObject) - { - /* delete answer ----------------------------------------------------- */ - DBManager::get()->execute(" - DELETE FROM evalanswer - WHERE evalanswer_id = ?", - [$answerObject->getObjectID()]); - /* ------------------------------------------------------- end: deleting */ - $this->resetVotes($answerObject); - } // deleted - - - /** - * Checks if answer with this ID exists - * @access public - * @param string $answerID The answerID - * @return bool YES if exists - */ - function exists($answerID) - { - $result = DBManager::get()->fetchOne("SELECT 1 FROM evalanswer - WHERE evalanswer_id= ?", [$answerID]); - if (count($result) > 0) - return true; - return false; - } - - - /** - * Adds the children to a parent object - * @access public - * @param EvaluationObject &$parentObject The parent object - */ - public static function addChildren(&$parentObject) - { - $result = DBManager::get()->fetchFirst("SELECT evalanswer_id FROM evalanswer - WHERE parent_id= ? ORDER by position", - [$parentObject->getObjectID()]); - - $loadChildren = - $parentObject->loadChildren == EVAL_LOAD_ALL_CHILDREN ? EVAL_LOAD_ALL_CHILDREN : EVAL_LOAD_NO_CHILDREN; - - foreach ($result as $row) { - $child = new EvaluationAnswer($row, $parentObject, $loadChildren); - $parentObject->addChild($child); - } - } - - /** - * Returns the type of an objectID - * @access public - * @param string $objectID The objectID - * @return string INSTANCEOF_x, else NO - */ - function getType($objectID) - { - if ($this->exists($objectID)) { - return INSTANCEOF_EVALANSWER; - } else { - return NO; - } - } - - /** - * Returns the id from the parent object - * @access public - * @param string $objectID The object id - * @return string The id from the parent object - */ - public static function getParentID($objectID) - { - return DBManager::get()->fetchColumn("SELECT parent_id FROM evalanswer - WHERE evalanswer_id = ?", - [$objectID]); - } - - /** - * Give all textanswers for a user and question for the export - * @access public - * @param string $questionID The question id - * @param string $userID The user id - */ - function getUserAnwerIDs($questionID, $userID) - { - /* ask database ------------------------------------------------------- */ - $sql = "SELECT a.evalanswer_id as ttt FROM evalanswer a, evalanswer_user b - WHERE a.parent_id = ? AND a.evalanswer_id = b.evalanswer_id"; - if (empty ($userID)) - $answer_ids = DBManager::get()->fetchFirst($sql, [$questionID]); - else - $answer_ids = DBManager::get()->fetchFirst($sql . " AND b.user_id = ?", [$questionID, $userID]); - /* -------------------------------------------------------- end: asking */ - return $answer_ids; - } - - /** - * Checks whether a user has voted for an answer - * @access public - * @param string $answerID The answer id - * @param string $userID The user id - * @return boolean YES if user has voted for the answer - */ - function hasVoted($answerID, $userID) - { - $result = DBManager::get()->fetchOne("SELECT 1 FROM evalanswer_user - WHERE evalanswer_id= ? AND user_id", [$answerID, $userID]); - if (count($result) > 0) - return true; - return false; - } - - function getAllAnswers($question_id, $userID, $only_user_answered = false) - { - if ($only_user_answered) - return DBManager::get()->fetchAll(" - SELECT evalanswer.*, COUNT(IF(user_id=?,1,NULL)) AS has_voted - FROM evalanswer LEFT JOIN evalanswer_user USING(evalanswer_id) - WHERE parent_id = ? AND user_id = ? - GROUP BY evalanswer.evalanswer_id ORDER BY position", - [$userID, $question_id, $userID]); - else - return DBManager::get()->fetchAll(" - SELECT evalanswer.*, COUNT(IF(user_id=?,1,NULL)) AS has_voted - FROM evalanswer LEFT JOIN evalanswer_user USING(evalanswer_id) - WHERE parent_id = ? - GROUP BY evalanswer.evalanswer_id ORDER BY position", - [$userID, $question_id]); - } -} - -?> diff --git a/lib/evaluation/classes/db/EvaluationDB.class.php b/lib/evaluation/classes/db/EvaluationDB.class.php deleted file mode 100644 index fd1c2b6..0000000 --- a/lib/evaluation/classes/db/EvaluationDB.class.php +++ /dev/null @@ -1,291 +0,0 @@ -<?php -# Lifter002: TODO -# Lifter007: TODO -# Lifter003: TODO -# Lifter010: TODO -// +--------------------------------------------------------------------------+ -// This file is part of Stud.IP -// Copyright (C) 2001-2004 Stud.IP -// +--------------------------------------------------------------------------+ -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or any later version. -// +--------------------------------------------------------------------------+ -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// +--------------------------------------------------------------------------+ - - -require_once 'lib/evaluation/evaluation.config.php'; -require_once EVAL_FILE_OBJECTDB; -require_once EVAL_FILE_GROUPDB; - - -/** - * @const EVAL_STATE_NEW Beschreibung - * @access public - */ -define("EVAL_STATE_NEW", "new"); - -/** - * @const EVAL_STATE_ACTIVE Beschreibung - * @access public - */ -define("EVAL_STATE_ACTIVE", "active"); - -/** - * @const EVAL_STATE_STOPPED Beschreibung - * @access public - */ -define("EVAL_STATE_STOPPED", "stopped"); -# =========================================================================== # - - -/** - * Databaseclass for all evaluations - * - * @author Alexander Willner <mail@AlexanderWillner.de> - * - * @copyright 2004 Stud.IP-Project - * @access public - * @package evaluation - * - */ -class EvaluationDB extends EvaluationObjectDB -{ - - public function __construct() - { - parent::__construct(); - $this->instanceof = 'EvalDB'; - } - - /** - * Loads an evaluation from DB into an object - * - * @access public - * @param object EvaluationObject &$evalObject The evaluation to load - * @throws error - */ - public function load(&$evalObject) - { - $row = DBManager::get()->fetchOne("SELECT * FROM eval WHERE eval_id = ?", [$evalObject->getObjectID()]); - - if (!count($row)) { - return $this->throwError(1, _("Keine Evaluation mit dieser ID gefunden.")); - } - - $evalObject->setAuthorID($row['author_id']); - $evalObject->setTitle($row['title']); - $evalObject->setText($row['text']); - $evalObject->setStartdate($row['startdate']); - $evalObject->setStopdate($row['stopdate']); - $evalObject->setTimespan($row['timespan']); - $evalObject->setCreationdate($row['mkdate']); - $evalObject->setChangedate($row['chdate']); - $evalObject->setAnonymous($row['anonymous']); - $evalObject->setVisible($row['visible']); - $evalObject->setShared($row['shared']); - - $range_ids = DBManager::get()->fetchFirst("SELECT range_id FROM eval_range WHERE eval_id = ?", - [$evalObject->getObjectID()]); - - foreach ($range_ids as $range_id) { - $evalObject->addRangeID($range_id); - } - if ($evalObject->loadChildren != EVAL_LOAD_NO_CHILDREN) { - EvaluationGroupDB::addChildren($evalObject); - } - } - - /** - * Saves an evaluation - * @access public - * @param object Evaluation &$evalObject The evaluation to save - * @throws error - */ - public function save(&$evalObject) - { - $startdate = $evalObject->getStartdate(); - $stopdate = $evalObject->getStopdate(); - $timespan = $evalObject->getTimespan(); - - $evalObject->setChangedate(time()); - if ($this->exists($evalObject->getObjectID())) { - DBManager::get()->execute( - "UPDATE eval SET title = ?, text = ?, startdate = ?, - stopdate = ?, timespan = ?, mkdate = ?, - chdate = ?, anonymous = ?, visible = ?, shared = ? - WHERE eval_id = ?", - [$evalObject->getTitle(), $evalObject->getText(), - $startdate, $stopdate, $timespan, $evalObject->getCreationdate(), - $evalObject->getChangedate(), $evalObject->isAnonymous(), - $evalObject->isVisible(), $evalObject->isShared(), $evalObject->getObjectID()]); - } else { - DBManager::get()->execute( - "INSERT INTO eval SET eval_id = ?, - author_id = ?, title = ?, text = ?, startdate = ?, - stopdate = ?, timespan = ?, mkdate = ?, chdate = ?, - anonymous = ?, visible = ?, shared = ?", - [$evalObject->getObjectID(), $evalObject->getAuthorID(), - $evalObject->getTitle(), $evalObject->getText(), - $startdate, $stopdate, $timespan, $evalObject->getCreationdate(), - $evalObject->getChangedate(), $evalObject->isAnonymous(), - $evalObject->isVisible(), $evalObject->isShared()]); - } - DBManager::get()->execute("DELETE FROM eval_range WHERE eval_id = ?", [$evalObject->getObjectID()]); - - while ($rangeID = $evalObject->getNextRangeID()) { - DBManager::get()->execute("INSERT INTO eval_range SET eval_id = ?, range_id = ?", - [$evalObject->getObjectID(), $rangeID]); - } - } - - /** - * Deletes an evaluation - * @access public - * @param object Evaluation &$evalObject The evaluation to delete - * @throws error - */ - public function delete(&$evalObject) - { - DBManager::get()->execute("DELETE FROM eval WHERE eval_id = ?", [$evalObject->getObjectID()]); - - DBManager::get()->execute("DELETE FROM eval_range WHERE eval_id = ?", [$evalObject->getObjectID()]); - DBManager::get()->execute("DELETE FROM eval_user WHERE eval_id = ?", [$evalObject->getObjectID()]); - - } - - /** - * Checks if evaluation with this ID exists - * @access public - * @param string $evalID The evalID - * @return bool YES if exists - */ - public function exists($evalID) - { - $entry = DBManager::get()->fetchOne("SELECT 1 FROM eval WHERE eval_id = ?", [$evalID]); - if (count($entry) > 0) - return true; - return false; - } - - /** - * Checks if someone used the evaluation - * @access public - * @param string $evalID The eval id - * @param string $userID The user id - * @return bool YES if evaluation was used - */ - public function hasVoted($evalID, $userID = "") - { - /* ask database ------------------------------------------------------- */ - $sql = "SELECT 1 FROM eval_user WHERE eval_id = ?"; - if (empty($userID)) - $entry = DBManager::get()->fetchOne($sql, [$evalID]); - else - $entry = DBManager::get()->fetchOne($sql . " AND user_id = ?", [$evalID, $userID]); - /* --------------------------------------------------------- end: asking */ - if (count($entry) > 0) - return true; - return false; - } - - /** - * Returns the type of an objectID - * @access public - * @param string $objectID The objectID - * @return string INSTANCEOF_x, else NO - */ - public function getType($objectID) - { - if ($this->exists($objectID)) { - return INSTANCEOF_EVAL; - } else { - $dbObject = new EvaluationGroupDB(); - return $dbObject->getType($objectID); - } - } - - /** - * Connect a user with an evaluation - * @access public - * @param string $evalID The evaluation id - * @param string $userID The user id - */ - public function connectWithUser($evalID, $userID) - { - if (empty($userID)) - die ("EvaluationDB::connectWithUser: UserID leer!!"); - DBManager::get()->execute("INSERT IGNORE INTO eval_user SET eval_id = ?, user_id = ?", [$evalID, $userID]); - } - - /** - * Removes the connection of an evaluation with a user or all users - * @access public - * @param string $evalID The evaluation id - * @param string $userID The user id - */ - public function removeUser($evalID, $userID = "") - { - $sql = "DELETE FROM eval_user WHERE eval_id = ?"; - - if (empty($userID)) - DBManager::get()->execute($sql, [$evalID]); - else - DBManager::get()->execute($sql . " AND user_id = ?", [$evalID, $userID]); - } - - /** - * Get number of users who participated in the eval - * @access public - * @param string $evalID The eval id - * @return integer The number of users - */ - public static function getNumberOfVotes($evalID) - { - return DBManager::get()->fetchColumn("SELECT count(DISTINCT user_id) AS number FROM eval_user WHERE eval_id = ?", [$evalID]); - } - - /** - * Get users who participated in the eval - * @access public - * @param string $evalID The eval id - * @param array $answerIDs The answerIDs to get the pseudonym users - * @return string[] Ids of the users who voted - */ - public static function getUserVoted($evalID, $answerIDs = [], $questionIDs = []) - { - $sql = "SELECT DISTINCT user_id FROM "; - - if (empty($answerIDs) && empty($questionIDs)) { - $sql .= "eval_user WHERE eval_id = ?"; - $search_criteria = $evalID; - } elseif (empty ($questionIDs)) { - $sql .= "evalanswer_user WHERE evalanswer_id IN (?)"; - $search_criteria = $answerIDs; - } else { - $sql .= "evalanswer INNER JOIN evalanswer_user USING(evalanswer_id) WHERE parent_id IN (?)"; - $search_criteria = $questionIDs; - } - - return DBManager::get()->fetchFirst($sql, [$search_criteria]); - } - - /** - * - * @access public - * @param string $search_str - * @return array - */ - public function search_range($search_str) - { - return search_range($search_str, true); - } -} diff --git a/lib/evaluation/classes/db/EvaluationGroupDB.class.php b/lib/evaluation/classes/db/EvaluationGroupDB.class.php deleted file mode 100644 index 60842ad..0000000 --- a/lib/evaluation/classes/db/EvaluationGroupDB.class.php +++ /dev/null @@ -1,225 +0,0 @@ -<?php -# Lifter002: TODO -# Lifter007: TODO -# Lifter003: TODO -# Lifter010: TODO -// +--------------------------------------------------------------------------+ -// This file is part of Stud.IP -// Copyright (C) 2001-2004 Stud.IP -// +--------------------------------------------------------------------------+ -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or any later version. -// +--------------------------------------------------------------------------+ -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// +--------------------------------------------------------------------------+ - - -# Include all required files ================================================ # -require_once 'lib/evaluation/evaluation.config.php'; -require_once EVAL_FILE_OBJECTDB; -require_once EVAL_FILE_ANSWERDB; - -/** - * Databaseclass for all evaluationgroups - * - * @author Alexander Willner <mail@AlexanderWillner.de> - * @copyright 2004 Stud.IP-Project - * @access public - * @package evaluation - * - */ -class EvaluationGroupDB extends EvaluationObjectDB -{ - - /** - * Constructor - * @access public - */ - public function __construct() - { - parent::__construct(); - $this->instanceof = 'EvalGroupDB'; - } - - /** - * Loads an evaluationgroup from DB into an object - * - * @access private - * @param object EvaluationGroup &$groupObject The group to load - * @throws error - */ - public function load(&$groupObject) - { - /* load group ---------------------------------------------------------- */ - $row = DBManager::get()->fetchOne(" - SELECT * FROM evalgroup - WHERE evalgroup_id = ? - ORDER BY position ", [$groupObject->getObjectID()]); - - if (count($row) === 0) { - return $this->throwError(1, _("Keine Gruppe mit dieser ID gefunden.")); - } - - $groupObject->setParentID($row['parent_id']); - $groupObject->setTitle($row['title']); - $groupObject->setText($row['text']); - $groupObject->setPosition($row['position']); - $groupObject->setChildType($row['child_type']); - $groupObject->setMandatory($row['mandatory']); - $groupObject->setTemplateID($row['template_id']); - if ($groupObject->loadChildren != EVAL_LOAD_NO_CHILDREN) { - if ($groupObject->loadChildren == EVAL_LOAD_ONLY_EVALGROUP) { - EvaluationGroupDB::addChildren($groupObject); - } else { - EvaluationGroupDB::addChildren($groupObject); - EvaluationQuestionDB::addChildren($groupObject); - } - } - } - - - /** - * Saves a group - * @access public - * @param object EvaluationGroup &$groupObject The group to save - * @throws error - */ - public function save(&$groupObject) - { - if ($this->exists($groupObject->getObjectID())) { - DBManager::get()->execute(" - UPDATE evalgroup SET - title = ?, - text = ?, - child_type = ?, - position = ?, - template_id = ?, - mandatory = ? - WHERE - evalgroup_id = ? - ", [(string)$groupObject->getTitle(), - (string)$groupObject->getText(), - (string)$groupObject->getChildType(), - (int)$groupObject->getPosition(), - (string)$groupObject->getTemplateID(), - (int)$groupObject->isMandatory(), - (string)$groupObject->getObjectID() - ]); - } else { - DBManager::get()->execute(" - INSERT INTO evalgroup SET - evalgroup_id = ?, - parent_id = ?, - title = ?, - text = ?, - child_type = ?, - mandatory = ?, - template_id = ?, - position = ? - ", [ - (string)$groupObject->getObjectID(), - (string)$groupObject->getParentID(), - (string)$groupObject->getTitle(), - (string)$groupObject->getText(), - (string)$groupObject->getChildType(), - (int)$groupObject->isMandatory(), - (string)$groupObject->getTemplateID(), - (int)$groupObject->getPosition() - ]); - } - } - - /** - * Deletes a group - * @access public - * @param object EvaluationGroup &$groupObject The group to delete - * @throws error - */ - public function delete(&$groupObject) - { - DBManager::get()->execute("DELETE FROM evalgroup WHERE evalgroup_id = ?", [$groupObject->getObjectID()]); - } - - /** - * Checks if group with this ID exists - * @access public - * @param string $groupID The groupID - * @return bool YES if exists - */ - public function exists($groupID) - { - $result = DBManager::get()->fetchColumn("SELECT 1 FROM evalgroup WHERE evalgroup_id = ?", [$groupID]); - return (bool)$result; - } - - /** - * Adds the children to a parent object - * @access public - * @param EvaluationObject &$parentObject The parent object - */ - public static function addChildren(&$parentObject) - { - $result = DBManager::get()->fetchFirst(" - SELECT evalgroup_id FROM evalgroup - WHERE parent_id = ? - ORDER BY position", [$parentObject->getObjectID()]); - - if (($loadChildren = $parentObject->loadChildren) == EVAL_LOAD_NO_CHILDREN) - $loadChildren = EVAL_LOAD_NO_CHILDREN; - - foreach ($result as $groupID) { - $child = new EvaluationGroup ($groupID, $parentObject, $loadChildren); - $parentObject->addChild($child); - } - } - - /** - * Returns the type of an objectID - * @access public - * @param string $objectID The objectID - * @return string INSTANCEOF_x, else NO - */ - public function getType($objectID) - { - if ($this->exists($objectID)) { - return INSTANCEOF_EVALGROUP; - } else { - $dbObject = new EvaluationQuestionDB (); - return $dbObject->getType($objectID); - } - } - - - /** - * Returns whether the childs are groups or questions - * @access public - * @param string $objectID The object id - */ - public function getChildType($objectID) - { - $result = DBManager::get()->fetchColumn(" - SELECT child_type FROM evalgroup WHERE evalgroup_id = ?", [$objectID]); - if ($result) return $result; - return NULL; - } - - /** - * Returns the id from the parent object - * @access public - * @param string $objectID The object id - * @return string The id from the parent object - */ - public static function getParentID($objectID) - { - return DBManager::get()->fetchColumn(" - SELECT parent_id FROM evalgroup WHERE evalgroup_id = ?", [$objectID]); - } -} diff --git a/lib/evaluation/classes/db/EvaluationObjectDB.class.php b/lib/evaluation/classes/db/EvaluationObjectDB.class.php deleted file mode 100644 index fd5728d..0000000 --- a/lib/evaluation/classes/db/EvaluationObjectDB.class.php +++ /dev/null @@ -1,365 +0,0 @@ -<?php -# Lifter002: TODO -# Lifter007: TODO -# Lifter003: TODO -# Lifter010: TODO -// +--------------------------------------------------------------------------+ -// This file is part of Stud.IP -// Copyright (C) 2001-2004 Stud.IP -// +--------------------------------------------------------------------------+ -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or any later version. -// +--------------------------------------------------------------------------+ -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -require_once 'lib/evaluation/evaluation.config.php'; - -/** - * Databaseclass for all evaluationobjects - * - * @author Alexander Willner <mail@AlexanderWillner.de> - * - * @copyright 2004 Stud.IP-Project - * @access public - * @package evaluation - * - */ -class EvaluationObjectDB extends DatabaseObject -{ - /** - * Constructor - * @access public - */ - public function __construct() - { - parent::__construct(); - $this->instanceof = 'EvalDBObject'; - } - - /** - * Gets the name of the range. Copied somewhere from Stud.IP... - * @access public - * @param string $rangeID the rangeID - * @param boolean $html_decode (optional) - * @return string The name of the range - */ - public function getRangename($rangeID, $html_decode = true) - { - if ($rangeID == "studip") { - return _('Systemweite Evaluationen'); - } - $o_type = get_object_type($rangeID, ['sem', 'user', 'inst']); - if (in_array($o_type, ['sem','inst','fak'])) { - $range = get_object_by_range_id($rangeID); - if ($range) { - $rangename = $range->getFullName('number-name-semester'); - } else { - $rangename = _('Kein Titel gefunden.'); - } - return $rangename; - } - if ($o_type != 'user') { - $user_id = get_userid($rangeID); - } else { - $user_id = $rangeID; - } - - if ($user_id != $GLOBALS['user']->id) { - $rangename = _('Profil') . ': ' - . get_fullname($user_id, 'full', true) - . ' (' . get_username($user_id) . ')'; - } else { - $rangename = _('Profil'); - } - return $rangename; - } - - /** - * Gets the global Studi.IP perm - * @access public - * @param boolean $as_value If YES return as value - * @return string the perm or NULL - */ - public static function getGlobalPerm($as_value = false) - { - if ($GLOBALS['perm']->have_perm("root")) { - return $as_value ? 63 : "root"; - } elseif ($GLOBALS['perm']->have_perm("admin")) { - return $as_value ? 31 : "admin"; - } elseif ($GLOBALS['perm']->have_perm("dozent")) { - return $as_value ? 15 : "dozent"; - } elseif ($GLOBALS['perm']->have_perm("tutor")) { - return $as_value ? 7 : "dozent"; - } elseif ($GLOBALS['perm']->have_perm("autor")) { - return $as_value ? 3 : "autor"; - } elseif ($GLOBALS['perm']->have_perm("user")) { - return $as_value ? 1 : "user"; - } else { - return $as_value ? 0 : NULL; - } - } - - /** - * Get the Stud.IP-Perm for a range - * @param string $rangeID The range id - * @param string $userID The user id - * @param boolean $as_value If YES return as value - * @access public - * @return string - */ - public static function getRangePerm($rangeID, $userID = NULL, $as_value = false) - { - if (!$rangeID) { - print "no rangeID!<br>"; - return NULL; - } - $userID = ($userID) ? $userID : $GLOBALS['user']->id; - $range_perm = $GLOBALS['perm']->get_studip_perm($rangeID, $userID); - - if ($rangeID == $userID) { - return ($as_value) ? 63 : "root"; - } - - if (($rangeID == "studip") && ($GLOBALS['perm']->have_perm("root"))) { - return ($as_value) ? 63 : "root"; - } - - switch ($range_perm) { - case "root": - return ($as_value) ? 63 : "root"; - case "admin": - return ($as_value) ? 31 : "admin"; - case "dozent": - return ($as_value) ? 15 : "dozent"; - case "tutor": - return ($as_value) ? 7 : "dozent"; - case "autor": - return ($as_value) ? 3 : "autor"; - case "user": - return ($as_value) ? 1 : "user"; - default: - return 0; - } - - } - - /** - * Look for all rangeIDs for my permissions - * @param object Perm &$permObj PHP-LIB-Perm-Object - * @param object User &$userObj PHP-LIB-User-Object - * @param string $rangeID RangeID of actual page - */ - public function getValidRangeIDs(&$permObj, &$userObj, $rangeID) - { - $range_ids = []; - $username = $userObj->username; - - $range_ids += [ - $username => ["name" => _("Profil")] - ]; - - if ($permObj->have_perm("root")) { - $range_ids += ["studip" => ["name" => _("Stud.IP-System")]]; - if (($adminRange = $this->getRangename($rangeID)) && - $rangeID != $userObj->id) - $range_ids += [$rangeID => ["name" => - $adminRange]]; - } else if ($permObj->have_perm("admin")) { - if (($adminRange = $this->getRangename($rangeID)) && - $rangeID != $userObj->id) { - $range_ids += [$rangeID => ["name" => - $adminRange]]; - } - } else if ($permObj->have_perm("dozent") || $permObj->have_perm("tutor")) { - if ($ranges = search_range("")) { - $range_ids += $ranges; - } - } - return $range_ids; - } - - /** - * Returns the number of ranges with no permission - * @access public - * @param EvaluationObject &$eval The evaluation - * @param boolean $return_ids If YES return the ids - * @return array|integer Number of ranges with no permission or array of ids - */ - public static function getEvalUserRangesWithNoPermission(&$eval, $return_ids = false) - { - $no_permisson = 0; - $rangeIDs = $eval->getRangeIDs(); - $no_permisson_ranges = []; - if (!is_array($rangeIDs)) { - $rangeIDs = [$rangeIDs]; - } - - foreach ($eval->getRangeIDs() as $rangeID) { - $user_perm = EvaluationObjectDB::getRangePerm($rangeID, $GLOBALS['user']->id, YES); - // every range with a lower perm than Tutor - if ($user_perm < 7) { - $no_permisson++; - $no_permisson_ranges[] = $rangeID; - } - } - if ($return_ids == YES) { - return $no_permisson_ranges; - } - return ($no_permisson > 0) ? $no_permisson : NO; - } - - /** - * Gets the public template ids - * @access public - * @param string $searchString The name of the template - * @return array The public template ids - */ - public function getPublicTemplateIDs($searchString) - { - $sql = " - SELECT eval_id FROM eval - LEFT JOIN auth_user_md5 ON user_id = author_id - WHERE shared = 1 - AND author_id <> :current_user - AND (title LIKE :search_string - OR text LIKE :search_string - OR Vorname LIKE :search_string - OR Nachname LIKE :search_string - OR username LIKE :search_string - ) - ORDER BY title"; - - return DBManager::get()->fetchFirst( - $sql, [':current_user' => $GLOBALS['user']->id, ':search_string' => '%' . $searchString . '%'] - ); - } - - /** - * Return all evaluationIDs in a specific range - * - * @access public - * @param string $rangeID Specific rangeID or it is a template - * @param string $state Specific state - * @return array All evaluations in this range and this state - */ - public function getEvaluationIDs($rangeID = "", $state = "") - { - if (!empty ($rangeID) && !is_scalar($rangeID)) { - return $this->throwError(1, _("Übergebene RangeID ist ungültig.")); - } - if ($state != "" && - $state != EVAL_STATE_NEW && - $state != EVAL_STATE_ACTIVE && - $state != EVAL_STATE_STOPPED) { - return $this->throwError(2, _("Übergebener Status ist ungültig.")); - } - - if (get_userid($rangeID) != NULL && $rangeID != NULL) { - $rangeID = get_userid($rangeID); - } - - if (!empty ($rangeID)) { - $sql = - "SELECT" . - " a.eval_id " . - "FROM" . - " eval_range a, eval b " . - "WHERE" . - " a.eval_id = b.eval_id" . - " AND " . - " a.range_id = ?"; - $param = $rangeID; - } else { - $sql = - "SELECT" . - " b.eval_id " . - "FROM" . - " eval b " . - "LEFT JOIN" . - " eval_range " . - "ON" . - " b.eval_id = eval_range.eval_id " . - "WHERE" . - " eval_range.eval_id IS NULL" . - " AND" . - " b.author_id = ?"; - $param = $GLOBALS['user']->id; - } - - if ($state == EVAL_STATE_NEW) - $sql .= " AND (b.startdate IS NULL OR b.startdate > " . time() . ")"; - - elseif ($state == EVAL_STATE_ACTIVE) - $sql .= - " AND b.startdate < " . time() . "" . - " AND (" . - " (b.timespan IS NULL AND b.stopdate > " . time() . ")" . - " OR" . - " (b.stopdate IS NULL AND (b.startdate+b.timespan) > " . time() . ")" . - " OR" . - " (b.timespan IS NULL AND b.stopdate IS NULL)" . - " )"; - - elseif ($state == EVAL_STATE_STOPPED) - $sql .= - " AND b.startdate < " . time() . "" . - " AND (" . - " (b.timespan IS NULL AND b.stopdate <= " . time() . ")" . - " OR" . - " (b.stopdate IS NULL AND (b.startdate+b.timespan) <= " . time() . ")" . - " )"; - - $sql .= " ORDER BY chdate DESC"; - - return DBManager::get()->fetchFirst($sql, [$param]); - } - - /** - * Gets the evaluation id for a object id - * @access public - * @param string $objectID The object id - * @return string The evaluation id or nothing - */ - public function getEvalID($objectID) - { - if (empty ($objectID)) { - throw new Exception("FATAL ERROR in getEvalID ;)"); - } - - $type = EvaluationObjectDB::getType($objectID); - - switch ($type) { - case INSTANCEOF_EVALANSWER: - $parentID = EvaluationAnswerDB::getParentID($objectID); - break; - case INSTANCEOF_EVALQUESTION: - $parentID = EvaluationQuestionDB::getParentID($objectID); - break; - case INSTANCEOF_EVALGROUP: - $parentID = EvaluationGroupDB::getParentID($objectID); - break; - default: - return $objectID; - } - return EvaluationObjectDB::getEvalID($parentID); - } - - /** - * Returns the type of an objectID - * @access public - * @param string $objectID The objectID - * @return string INSTANCEOF_x, else NO - */ - public function getType($objectID) - { - return (new EvaluationDB ())->getType($objectID); - } -} diff --git a/lib/evaluation/classes/db/EvaluationQuestionDB.class.php b/lib/evaluation/classes/db/EvaluationQuestionDB.class.php deleted file mode 100644 index b6cea24..0000000 --- a/lib/evaluation/classes/db/EvaluationQuestionDB.class.php +++ /dev/null @@ -1,298 +0,0 @@ -<?php -# Lifter002: TODO -# Lifter007: TODO -# Lifter003: TODO -# Lifter010: TODO -/** - * Beschreibung - * - * @author Alexander Willner <mail@AlexanderWillner.de> - * @copyright 2004 Stud.IP-Project - * @access public - * @package evaluation - * @modulegroup evaluation_modules - * - */ - - -// +--------------------------------------------------------------------------+ -// This file is part of Stud.IP -// Copyright (C) 2001-2004 Stud.IP -// +--------------------------------------------------------------------------+ -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or any later version. -// +--------------------------------------------------------------------------+ -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// +--------------------------------------------------------------------------+ - -# Include all required files ================================================ # -require_once 'lib/evaluation/evaluation.config.php'; -require_once EVAL_FILE_OBJECTDB; -require_once EVAL_FILE_ANSWERDB; -# ====================================================== end: including files # - -# Define all required constants ============================================= # -/** - * @const INSTANCEOF_EVALQUESTIONDB Instance of an evaluationQuestionDB object - * @access public - */ -define("INSTANCEOF_EVALQUESTIONDB", "EvalQuestionDB"); - -# =========================================================================== # - - -class EvaluationQuestionDB extends EvaluationObjectDB -{ - - /** - * Constructor - * @access public - */ - public function __construct() - { - parent::__construct(); - $this->instanceof = 'EvalQuestionDB'; - } - - /** - * Loads a question from the DB - * @access public - * @param EvaluationQuestion &$questionObject The question object - */ - public function load(&$questionObject) - { - $db = DBManager::get(); - $query = - "SELECT" . - " * " . - "FROM" . - " evalquestion " . - "WHERE" . - " evalquestion_id = ? " . - "ORDER BY" . - " position "; - $row = $db->fetchOne($query, [$questionObject->getObjectID()]); - - if (!count($row)) { - return $this->throwError(1, _("Keine Frage mit dieser ID gefunden.")); - } - - $questionObject->setParentID($row['parent_id']); - $questionObject->setType($row['type']); - $questionObject->setPosition($row['position']); - $questionObject->setText($row['text']); - $questionObject->setMultiplechoice($row['multiplechoice']); - - if ($questionObject->loadChildren != EVAL_LOAD_NO_CHILDREN) { - EvaluationAnswerDB::addChildren($questionObject); - } - } - - - /** - * Writes or updates a question into the DB - * @access public - * @param EvaluationQuestion &$questionObject The question object - */ - public function save(&$questionObject) - { - $db = DBManager::get(); - - if ($this->exists($questionObject->getObjectID())) { - $sql = - "UPDATE" . - " evalquestion " . - "SET" . - " parent_id = ?," . - " type = ?," . - " position = ?," . - " text = ?," . - " multiplechoice = ? " . - "WHERE" . - " evalquestion_id = ?"; - } else { - $sql = - "INSERT INTO" . - " evalquestion " . - "SET" . - " parent_id = ?," . - " type = ?," . - " position = ?," . - " text = ?," . - " multiplechoice = ?," . - " evalquestion_id = ?";; - } - $db->execute($sql, [ - (string)$questionObject->getParentID(), - (string)$questionObject->getType(), - (int)$questionObject->getPosition(), - (string)$questionObject->getText(), - (int)$questionObject->isMultiplechoice(), - $questionObject->getObjectID() - ]); - } - - /** - * Deletes a question - * @access public - * @param object EvaluationQuestion &$questionObject The question to delete - * @throws error - */ - public function delete(&$questionObject) - { - $db = DBManager::get(); - - $sql = "DELETE FROM evalquestion WHERE evalquestion_id = ?"; - $db->execute($sql, [$questionObject->getObjectID()]); - } - - /** - * Checks if question with this ID exists - * @access public - * @param string $questionID The questionID - * @return bool YES if exists - */ - public function exists($questionID) - { - $db = DBManager::get(); - - $sql = - "SELECT" . - " 1 " . - "FROM" . - " evalquestion " . - "WHERE" . - " evalquestion_id = ?"; - $result = $db->fetchColumn($sql, [$questionID]); - - return (bool)$result; - } - - /** - * Checks if a template exists with this title - * @access public - * @param string $questionTitle The title of the question - * @param string $userID The user id - * @return bool YES if exists - */ - public function titleExists($questionTitle, $userID) - { - $db = DBManager::get(); - - $sql = - "SELECT" . - " 1 " . - "FROM" . - " evalquestion " . - "WHERE" . - " text = ? " . - " AND " . - " parent_id = ?"; - - $result = $db->fetchColumn($sql, [$questionTitle, $userID]); - - return (bool)$result; - } - - - /** - * Adds the children to a parent object - * @access public - * @param EvaluationObject &$parentObject The parent object - */ - public static function addChildren(&$parentObject) - { - $db = DBManager::get(); - - $sql = - "SELECT" . - " evalquestion_id " . - "FROM" . - " evalquestion " . - "WHERE" . - " parent_id = ? " . - "ORDER BY" . - " position"; - $result = $db->fetchFirst($sql, [$parentObject->getObjectID()]); - - $loadChildren = $parentObject->loadChildren == EVAL_LOAD_ALL_CHILDREN - ? EVAL_LOAD_ALL_CHILDREN - : EVAL_LOAD_NO_CHILDREN; - - foreach ($result as $evalquestion_id) { - $child = new EvaluationQuestion($evalquestion_id, $parentObject, $loadChildren); - $parentObject->addChild($child); - } - } - - /** - * Returns the type of an objectID - * @access public - * @param string $objectID The objectID - * @return string INSTANCEOF_x, else NO - */ - public function getType($objectID) - { - if ($this->exists($objectID)) { - return INSTANCEOF_EVALQUESTION; - } else { - $dbObject = new EvaluationAnswerDB (); - return $dbObject->getType($objectID); - } - } - - /** - * Returns the id from the parent object - * @access public - * @param string $objectID The object id - * @return string The id from the parent object - */ - public static function getParentID($objectID) - { - $db = DBManager::get(); - - $sql = - "SELECT" . - " parent_id " . - "FROM" . - " evalquestion " . - "WHERE" . - " evalquestion_id = ?"; - $result = $db->fetchColumn($sql, [$objectID]); - return $result; - } - - /** - * Returns the ids of the Answertemplates of a user - * @access public - * @param string $userID The user id - * @return array The ids of the answertemplates - */ - public function getTemplateID($userID) - { - $db = DBManager::get(); - - if (EvaluationObjectDB::getGlobalPerm() === 'root') { - $sql = "SELECT evalquestion_id - FROM evalquestion - WHERE parent_id = '0' - ORDER BY text"; - return $db->fetchFirst($sql); - } else { - $sql = "SELECT evalquestion_id - FROM evalquestion - WHERE parent_id = ? - OR parent_id = '0' - ORDER BY text"; - return $db->fetchFirst($sql, [$userID]); - } - } -} |
