* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class ObjectdisplayHelper {
/**
* Produces the name with a link to the given object
* @param User/Course The given object
* @return string html code
*/
public static function link($object) {
return '' . self::map($object, 'name') . '';
}
/**
* Produces the avatar and the name with a link to the given object
* @param User/Course The given object
* @return string html code
*/
public static function avatarlink($object) {
return '' . self::map($object, 'avatar') . " " . self::map($object, 'name') . '';
}
/**
* Mapping function where to find what
* @param type $object the object
* @param type $function the called function
* @return string output
*/
private static function map($object, $function) {
/**
* If you want to add an object to the helper simply add to this array
*/
$mapping = [
'User' => [
'link' => function($obj) {
return URLHelper::getLink('dispatch.php/profile', ['username' => $obj->username]);
},
'name' => function($obj) {
return htmlReady($obj->getFullname());
},
'avatar' => function($obj) {
return Avatar::getAvatar($obj->id, $obj->username)->getImageTag(Avatar::SMALL,['title' => $obj->getFullname('no_title')]);
}
],
'Course' => [
'link' => function($obj) {
return URLHelper::getLink('seminar_main.php', ['auswahl' => $obj->id]);
},
'name' => function($obj) {
return htmlReady($obj->name);
},
'avatar' => function($obj) {
return CourseAvatar::getAvatar($obj->id)->getImageTag($size = CourseAvatar::SMALL,['title' => $obj->name]);
}
]
];
/*
* Some php magic to call the right function if it exists
*/
if ($object && $mapping[get_class($object)]) {
return $mapping[get_class($object)][$function]($object);
}
return "";
}
}