예제 #1
0
 /**
  * Returns data of a given item including where to download it and the structure, decription, etc.
  * If item is not hosted on this server, just relocate the request to the real server.
  *
  * This endpoint should be called by a remote whenever a client wants to view the details of an item.
  *
  * @param $item_id : ID of the item on this server.
  */
 public function get_item_data_action($item_id)
 {
     $material = new LernmarktplatzMaterial($item_id);
     if ($material->isNew()) {
         $this->render_json(array('deleted' => 1));
     } elseif (!$material['foreign_material_id']) {
         $me = LernmarktplatzHost::thisOne();
         $topics = array();
         foreach ($material->getTopics() as $topic) {
             $topics[] = $topic['name'];
         }
         $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
         if ($user_description_datafield) {
             $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($material['user_id'], $user_description_datafield->getId()));
         }
         $reviews = array();
         foreach ($material->reviews as $review) {
             if ($review['host_id']) {
                 $user = LernmarktplatzUser::findOneBySQL("user_id = ?", array($review['user_id']));
                 $user = array('user_id' => $review['user_id'], 'name' => $user['name'], 'avatar' => $user['avatar'], 'description' => $user['description']);
             } else {
                 if ($user_description_datafield) {
                     $user_description = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($review['user_id'], $user_description_datafield->getId()));
                 }
                 $user = array('user_id' => $review['user_id'], 'name' => get_fullname($review['user_id']), 'avatar' => Avatar::getAvatar($review['user_id'])->getURL(Avatar::NORMAL), 'description' => $user_description['content'] ?: null);
             }
             $reviews[] = array('foreign_review_id' => $review['foreign_review_id'] ?: $review->getId(), 'review' => $review['review'], 'rating' => $review['rating'], 'user' => $user, 'host' => array('name' => $review['host_id'] ? $review->host['name'] : $me['name'], 'url' => $review['host_id'] ? $review->host['url'] : $me['url'], 'public_key' => $review['host_id'] ? $review->host['public_key'] : $me['public_key']), 'mkdate' => $review['mkdate'], 'chkdate' => $review['chdate']);
         }
         $this->render_json(array('data' => array('name' => $material['name'], 'short_description' => $material['short_description'], 'description' => $material['description'], 'content_type' => $material['content_type'], 'front_image_content_type' => $material['front_image_content_type'], 'url' => ($GLOBALS['LERNMARKTPLATZ_PREFERRED_URI'] ?: $GLOBALS['ABSOLUTE_URI_STUDIP']) . "/plugins.php/lernmarktplatz/market/download/" . $item_id, 'structure' => $material['structure'], 'license' => $material['license']), 'user' => array('user_id' => $material['user_id'], 'name' => User::find($material['user_id'])->getFullName(), 'avatar' => Avatar::getAvatar($material['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null), 'topics' => $topics, 'reviews' => $reviews));
     } else {
         $host = new LernmarktplatzHost($material['host_id']);
         header("Location: " . $host['url'] . "get_item_data/" . $item_id);
         return;
     }
 }