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/Courseware/Bookmark.php | |
current code from svn, revision 62608
Diffstat (limited to 'lib/models/Courseware/Bookmark.php')
| -rwxr-xr-x | lib/models/Courseware/Bookmark.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/models/Courseware/Bookmark.php b/lib/models/Courseware/Bookmark.php new file mode 100755 index 0000000..d6e5910 --- /dev/null +++ b/lib/models/Courseware/Bookmark.php @@ -0,0 +1,65 @@ +<?php + +namespace Courseware; + +/** + * Courseware's bookmarks. + * + * @author Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> + * @author Till Glöggler <gloeggler@elan-ev.de> + * @author Ron Lucke <lucke@elan-ev.de> + * @license GPL2 or any later version + * + * @since Stud.IP 5.0 + * + * @property array $id computed column read/write + * @property string $user_id database column + * @property int $element_id database column + * @property int $mkdate database column + * @property int $chdate database column + * @property \User $user belongs_to User + * @property \Courseware\StructuralElement $element belongs_to Courseware\StructuralElement + */ +class Bookmark extends \SimpleORMap +{ + protected static function configure($config = []) + { + $config['db_table'] = 'cw_bookmarks'; + + $config['belongs_to']['user'] = [ + 'class_name' => \User::class, + 'foreign_key' => 'user_id', + ]; + + $config['belongs_to']['element'] = [ + 'class_name' => StructuralElement::class, + 'foreign_key' => 'element_id', + ]; + + parent::configure($config); + } + + /** + * Returns the range object this bookmark belongs to. + * + * @return \Range the range object of this object + */ + public function getRange(): \Range + { + $rangeType = $this->element['range_type']; + + return $this->element->$rangeType; + } + + /** + * Returns all bookmarks of a user. + * + * @param string $userId the user's ID for whom to search for bookmarks + * + * @return Bookmark[] the list of bookmarks + */ + public function findUsersBookmarks(string $userId): array + { + return self::findBySQL('user_id = ?', [$userId]); + } +} |
