diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /lib/models/Degree.class.php | |
current code from svn, revision 62608
Diffstat (limited to 'lib/models/Degree.class.php')
| -rw-r--r-- | lib/models/Degree.class.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/models/Degree.class.php b/lib/models/Degree.class.php new file mode 100644 index 0000000..502e9f7 --- /dev/null +++ b/lib/models/Degree.class.php @@ -0,0 +1,71 @@ +<?php +/** + * Degree.class.php + * model class for table studiengang + * + * 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 (at your option) any later version. + * + * @author André Noack <noack@data-quest.de> + * @copyright 2013 Stud.IP Core-Group + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Stud.IP + * + * @property string abschluss_id database column + * @property string id alias column for abschluss_id + * @property string name database column + * @property string beschreibung database column + * @property string mkdate database column + * @property string chdate database column + */ +class Degree extends SimpleORMap +{ + protected static function configure($config = []) + { + $config['db_table'] = 'abschluss'; + + $config['has_and_belongs_to_many']['professions'] = [ + 'class_name' => 'StudyCourse', + 'thru_table' => 'user_studiengang', + 'thru_key' => 'abschluss_id', + 'thru_assoc_key' => 'fach_id', + 'order_by' => 'GROUP BY fach_id ORDER BY name' + ]; + + $config['additional_fields']['count_user']['get'] = 'countUser'; + + parent::configure($config); + } + + public function countUser() + { + $stmt = DBManager::get()->prepare('SELECT COUNT(DISTINCT user_id) ' + . 'FROM user_studiengang WHERE abschluss_id = ?'); + $stmt->execute([$this->id]); + return $stmt->fetchColumn(); + } + + public function countUserByStudycourse($studycourse_id) + { + $stmt = DBManager::get()->prepare('SELECT COUNT(DISTINCT user_id) ' + . 'FROM user_studiengang ' + . 'WHERE fach_id = ? AND abschluss_id = ?'); + $stmt->execute([$studycourse_id, $this->id]); + return $stmt->fetchColumn(); + } + + public function store() + { + if ($this->isNew() || $this->isDirty()) { + $this->editor_id = $GLOBALS['user']->id; + if (!$this->getPristineValue('author_id')) { + $this->author_id = $GLOBALS['user']->id; + } + } + + return parent::store(); + } + +} |
