示例#1
0
 /**
  * Returns a koala_* instance matching the given steam_* object.
  * You can use this function if you don't know which type a steam object
  * is, e.g. to be able to call specialized functions like get_display_name().
  * 
  * Note that this function will at least query the object's type and its
  * OBJ_TYPE attribute. Extensions may also query additional attributes,
  * so this function might be costly regarding server requests. Only use it
  * when you need a matching koala object (e.g. for get_display_name()) and
  * you cannot determine the matching class yourself.
  *
  * @param Object $steam_object the steam_* object for which to return a
  *   matching koala_* wrapper object
  * @return Object a koala_* wrapper object that matches the given steam_*
  *   object in class
  */
 public static final function get_koala_object($steam_object, $vars = array())
 {
     if (!is_object($steam_object)) {
         return FALSE;
     }
     if ($steam_object instanceof koala_object) {
         return $steam_object;
     }
     if (isset($vars[OBJ_TYPE])) {
         $obj_type = $vars[OBJ_TYPE];
     } else {
         $obj_type = $steam_object->get_attribute(OBJ_TYPE);
     }
     $type = $steam_object->get_type();
     //TODO: rewrite old extensionmanager
     /*    
     		foreach ( lms_steam::get_extensionmanager()->get_installed_extensions() as $extension ) {
     			$obj = $extension->get_koala_object_for( $steam_object, $type, $obj_type );
     			if ( is_object( $obj ) ) {
     				return $obj;
           }
     		}*/
     switch (TRUE) {
         case $steam_object instanceof steam_user:
             return new koala_user($steam_object);
         case $steam_object instanceof steam_group:
             $course_group = koala_group_course::get_course_group($steam_object);
             if (is_object($course_group)) {
                 return new koala_group_course($course_group);
             } else {
                 return new koala_group_default($steam_object);
             }
         case $steam_object instanceof steam_container:
             // check for a wiki container first
             if ($obj_type === "container_wiki_koala" || $obj_type === "room_wiki_koala" || $obj_type === "KOALA_WIKI") {
                 return new lms_wiki($steam_object);
             }
             // check for workroom
             if (is_object($creator = $steam_object->get_creator()) && is_object($workroom = $creator->get_workroom()) && $workroom->get_id() == $steam_object->get_id()) {
                 return new koala_container_workroom($steam_object);
             }
             // ok, its just a container
             return new koala_container($steam_object);
         default:
             // forum:
             if ($steam_object instanceof steam_messageboard) {
                 return new lms_forum($steam_object);
             }
             // weblog:
             if ($obj_type === "calendar_weblog_koala") {
                 return new lms_weblog($steam_object);
             }
             // wiki:
             if ($obj_type === "container_wiki_koala" || $obj_type === "room_wiki_koala" || $obj_type === "KOALA_WIKI") {
                 return new lms_wiki($steam_object);
             }
             return new koala_object($steam_object);
     }
 }