Beispiel #1
0
 /**
  * Preload rating data for list guis
  * 
  * @param array $a_obj_ids
  */
 public static function preloadListGUIData(array $a_obj_ids)
 {
     global $ilDB, $ilUser;
     $tmp = $res = $tmp_user = $res_user = array();
     // collapse by categories
     $q = "SELECT obj_id, obj_type, user_id, AVG(rating) av" . " FROM il_rating" . " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer") . " AND sub_obj_id = " . $ilDB->quote(0, "integer") . " GROUP BY obj_id, obj_type, user_id";
     $set = $ilDB->query($q);
     while ($rec = $ilDB->fetchAssoc($set)) {
         $tmp[$rec["obj_type"] . "/" . $rec["obj_id"]][$rec["user_id"]] = (double) $rec["av"];
         if ($rec["user_id"] == $ilUser->getId()) {
             // add final average to user result (no sub-objects)
             $res_user[$rec["obj_type"] . "/" . $rec["obj_id"]] = (double) $rec["av"];
         }
     }
     // average for main objects without sub-objects
     foreach ($tmp as $obj_id => $votes) {
         $res[$obj_id] = array("avg" => array_sum($votes) / sizeof($votes), "cnt" => sizeof($votes));
     }
     // file/wiki/lm rating toggles
     $set = $ilDB->query("SELECT file_id, rating" . " FROM file_data" . " WHERE " . $ilDB->in("file_id", $a_obj_ids, "", integer));
     while ($row = $ilDB->fetchAssoc($set)) {
         $id = "file/" . $row["file_id"];
         if ($row["rating"] && !isset($res[$id])) {
             $res[$id] = array("avg" => 0, "cnt" => 0);
         } else {
             if (!$row["rating"] && isset($res[$id])) {
                 unset($res[$id]);
             }
         }
     }
     $set = $ilDB->query("SELECT id, rating_overall" . " FROM il_wiki_data" . " WHERE " . $ilDB->in("id", $a_obj_ids, "", integer));
     while ($row = $ilDB->fetchAssoc($set)) {
         $id = "wiki/" . $row["id"];
         if ($row["rating_overall"] && !isset($res[$id])) {
             $res[$id] = array("avg" => 0, "cnt" => 0);
         } else {
             if (!$row["rating_overall"] && isset($res[$id])) {
                 unset($res[$id]);
             }
         }
     }
     $set = $ilDB->query("SELECT id, rating" . " FROM content_object" . " WHERE " . $ilDB->in("id", $a_obj_ids, "", integer));
     while ($row = $ilDB->fetchAssoc($set)) {
         $id = "lm/" . $row["id"];
         if ($row["rating"] && !isset($res[$id])) {
             $res[$id] = array("avg" => 0, "cnt" => 0);
         } else {
             if (!$row["rating"] && isset($res[$id])) {
                 unset($res[$id]);
             }
         }
     }
     self::$list_data = array("all" => $res, "user" => $res_user);
 }