/**
  * Deletes the admission rule and all associated data.
  */
 public function delete()
 {
     if ($this->prio_exists) {
         $set_id = DBManager::get()->fetchColumn("SELECT set_id FROM courseset_rule WHERE rule_id = ? LIMIT 1", array($this->id));
         //Delete priorities
         AdmissionPriority::unsetAllPriorities($set_id);
     }
     parent::delete();
     // Delete rule data.
     $stmt = DBManager::get()->prepare("DELETE FROM `participantrestrictedadmissions`\n            WHERE `rule_id`=?");
     $stmt->execute(array($this->id));
 }
Beispiel #2
0
 public function store()
 {
     // Generate new ID if course set doesn't exist in DB yet.
     if (!$this->id) {
         do {
             $newid = md5(uniqid(get_class($this), true));
             $db = DBManager::get()->query("SELECT `set_id`\n                    FROM `coursesets` WHERE `set_id`='{$newid}'");
         } while ($db->fetch());
         $this->id = $newid;
     }
     if (!$this->user_id) {
         $this->user_id = $GLOBALS['user']->id;
     }
     if ($this->isSeatDistributionEnabled()) {
         if (!$this->getAlgorithm()) {
             $algorithm = new RandomAlgorithm();
             $this->setAlgorithm($algorithm);
         }
         if (!$this->getSeatDistributionTime()) {
             $this->setAlgorithmRun(true);
             //Delete priorities
             AdmissionPriority::unsetAllPriorities($this->getId());
         }
         if ($this->getSeatDistributionTime() > time()) {
             $this->setAlgorithmRun(false);
         }
     }
     // Store basic data.
     $stmt = DBManager::get()->prepare("INSERT INTO `coursesets`\n            (`set_id`, `user_id`, `name`, `infotext`, `algorithm`, `algorithm_run`,\n            `private`, `mkdate`, `chdate`)\n            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE\n            `name`=VALUES(`name`), `infotext`=VALUES(`infotext`),\n            `algorithm`=VALUES(`algorithm`), `algorithm_run`=VALUES(`algorithm_run`), `private`=VALUES(`private`),\n            `chdate`=VALUES(`chdate`)");
     $stmt->execute(array($this->id, $this->user_id, $this->name, $this->infoText, get_class($this->algorithm), $this->hasAlgorithmRun(), intval($this->private), time(), time()));
     // Delete removed institute assignments from database.
     DBManager::get()->exec("DELETE FROM `courseset_institute`\n            WHERE `set_id`='" . $this->id . "' AND `institute_id` NOT IN ('" . implode("', '", array_keys($this->institutes)) . "')");
     // Store associated institute IDs.
     foreach ($this->institutes as $institute => $associated) {
         $stmt = DBManager::get()->prepare("INSERT IGNORE INTO `courseset_institute`\n                (`set_id`, `institute_id`, `mkdate`)\n                VALUES (?, ?, ?)");
         $stmt->execute(array($this->id, $institute, time()));
     }
     // log removed course assignments.
     DBManager::get()->fetchAll("SELECT seminar_id,set_id FROM `seminar_courseset`\n            WHERE `set_id` = ? AND `seminar_id` NOT IN (?)", array($this->id, count($this->courses) ? array_keys($this->courses) : ''), function ($row) {
         StudipLog::log('SEM_CHANGED_ACCESS', $row['seminar_id'], null, 'Entfernung von Anmeldeset', sprintf('Anmeldeset: %s', $row['set_id']));
         //Delete priorities
         AdmissionPriority::unsetAllPrioritiesForCourse($row['seminar_id']);
     });
     //removed course assignments
     DBManager::get()->execute("DELETE FROM `seminar_courseset`\n            WHERE `set_id` = ? AND `seminar_id` NOT IN (?)", array($this->id, count($this->courses) ? array_keys($this->courses) : ''));
     //log removing other associations
     DBManager::get()->execute("SELECT seminar_id,set_id FROM `seminar_courseset`\n            WHERE `set_id` <> ? AND `seminar_id` IN (?)", array($this->id, array_keys($this->courses)), function ($row) {
         StudipLog::log('SEM_CHANGED_ACCESS', $row['seminar_id'], null, 'Entfernung von Anmeldeset', sprintf('Anmeldeset: %s', $row['set_id']));
         //Delete priorities
         AdmissionPriority::unsetAllPrioritiesForCourse($row['seminar_id']);
     });
     //Delete other associations, only one set possible
     DBManager::get()->execute("DELETE FROM `seminar_courseset`\n            WHERE `set_id` <> ? AND `seminar_id` IN (?)", array($this->id, array_keys($this->courses)));
     // Store associated course IDs.
     foreach ($this->courses as $course => $associated) {
         $stmt = DBManager::get()->prepare("INSERT IGNORE INTO `seminar_courseset`\n                (`set_id`, `seminar_id`, `mkdate`)\n                VALUES (?, ?, ?)");
         $stmt->execute(array($this->id, $course, time()));
         if ($stmt->rowCount()) {
             StudipLog::log('SEM_CHANGED_ACCESS', $course, null, 'Zuordnung zu Anmeldeset', sprintf('Anmeldeset: %s', $this->id));
         }
     }
     // Delete removed user list assignments from database.
     DBManager::get()->exec("DELETE FROM `courseset_factorlist`\n            WHERE `set_id`='" . $this->id . "' AND `factorlist_id` NOT IN ('" . implode("', '", array_keys($this->userlists)) . "')");
     // Store associated user list IDs.
     foreach ($this->userlists as $list => $associated) {
         $stmt = DBManager::get()->prepare("INSERT IGNORE INTO `courseset_factorlist`\n                (`set_id`, `factorlist_id`, `mkdate`)\n                VALUES (?, ?, ?)");
         $stmt->execute(array($this->id, $list, time()));
     }
     // Delete removed admission rules from database.
     $stmt = DBManager::get()->query("SELECT `rule_id`, `type` FROM `courseset_rule`\n            WHERE `set_id`='" . $this->id . "' AND `rule_id` NOT IN ('" . implode("', '", array_keys($this->admissionRules)) . "')");
     $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($data as $ruleData) {
         $rule = new $ruleData['type']($ruleData['rule_id']);
         $rule->delete();
     }
     // Store all rules.
     foreach ($this->admissionRules as $rule) {
         // Store each rule...
         $rule->store();
         // ... and its connection to the current course set.
         $stmt = DBManager::get()->prepare("INSERT INTO `courseset_rule`\n                (`set_id`, `rule_id`, `type`, `mkdate`)\n                VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE\n                `type`=VALUES(`type`)");
         $stmt->execute(array($this->id, $rule->getId(), get_class($rule), time()));
     }
     //fix free access courses
     if (count($this->courses)) {
         DBManager::get()->execute("UPDATE seminare SET Lesezugriff=1,Schreibzugriff=1 WHERE seminar_id IN(?)", array(array_keys($this->courses)));
     }
 }