diff options
| author | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
|---|---|---|
| committer | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
| commit | 4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch) | |
| tree | 5c07151ae61276d334e88f6309c30d439a85c12e /lib/models/ClipboardItem.php | |
| parent | da0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff) | |
| parent | 97a188592c679890a25c37ab78463add76a52ff7 (diff) | |
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/models/ClipboardItem.php')
| -rw-r--r-- | lib/models/ClipboardItem.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/models/ClipboardItem.php b/lib/models/ClipboardItem.php new file mode 100644 index 0000000..a19eeaf --- /dev/null +++ b/lib/models/ClipboardItem.php @@ -0,0 +1,69 @@ +<?php +/** + * ClipboardItem.php - model class for clipboard items + * (Merkzettel-Einträge) + * + * The ClipboardItem class holds single items of a clipboard. + * + * 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 Moritz Strohm <strohm@data-quest.de> + * @copyright 2018-2019 + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Stud.IP + * @since 4.5 + * + * @property int $id database column + * @property int $clipboard_id database column + * @property string $range_id database column + * @property string $range_type database column + * @property int $mkdate database column + * @property int $chdate database column + * @property Clipboard $clipboard belongs_to Clipboard + * + * @property-read string $name + */ +class ClipboardItem extends SimpleORMap +{ + protected static function configure($config = []) + { + $config['db_table'] = 'clipboard_items'; + + $config['belongs_to']['clipboard'] = [ + 'class_name' => Clipboard::class, + 'foreign_key' => 'clipboard_id', + 'assoc_func' => 'find' + ]; + + $config['additional_fields']['name'] = [ + 'get' => fn(ClipboardItem $item) => $item->__toString(), + ]; + + parent::configure($config); + } + + /** + * @returns string representation of this clipboard item. + */ + public function __toString() + { + // Get the class $range_type and the object with ID $range_id, + // if $range_type is a StudipItem: + if (is_subclass_of($this->range_type, StudipItem::class)) { + $range_class_name = $this->range_type; + $object = $range_class_name::find($this->range_id); + if ($object) { + return $object->getItemName(false); + } + } + + // $range_type is not a class name of a StudipItem class + // or no object of a StudipItem class could be found: + // We cannot determine the name and must therefore use + // a generic name: + return $this->range_type . '_' . $this->range_id; + } +} |
