public function afterStoreCallback() { if ($this->isDirty()) { //add notification to writer of review if (!$this->review['host_id'] && $this->review['user_id'] !== $this['user_id']) { PersonalNotifications::add($this->review['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat einen Kommentar zu Ihrem Review geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable")); } //add notification to all users of this servers who discussed this review but are neither the new //commentor nor the writer of the review $statement = DBManager::get()->prepare("\n SELECT user_id\n FROM lernmarktplatz_comments\n WHERE review_id = :review_id\n AND host_id IS NULL\n GROUP BY user_id\n "); $statement->execute(array('review_id' => $this->review->getId())); foreach ($statement->fetchAll(PDO::FETCH_COLUMN, 0) as $user_id) { if (!in_array($user_id, array($this->review['user_id'], $this['user_id']))) { PersonalNotifications::add($user_id, URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat auch einen Kommentar geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable")); } } //only push if the comment is from this server and the material-server is different if (!$this['host_id']) { $myHost = LernmarktplatzHost::thisOne(); $data = array(); $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']); $data['data'] = $this->toArray(); $data['data']['foreign_comment_id'] = $data['data']['comment_id']; unset($data['data']['comment_id']); unset($data['data']['id']); unset($data['data']['user_id']); unset($data['data']['host_id']); $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($this['user_id'], $user_description_datafield->getId())); } $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null); $statement = DBManager::get()->prepare("\n SELECT host_id\n FROM lernmarktplatz_comments\n WHERE review_id = :review_id\n AND host_id IS NOT NULL\n GROUP BY host_id\n "); $statement->execute(array('review_id' => $this->review->getId())); $hosts = $statement->fetchAll(PDO::FETCH_COLUMN, 0); if ($this->review['host_id'] && !in_array($this->review['host_id'], $hosts)) { $hosts[] = $this->review['host_id']; } if ($this->review->material['host_id'] && !in_array($this->review->material['host_id'], $hosts)) { $hosts[] = $this->review->material['host_id']; } foreach ($hosts as $host_id) { $remote = new LernmarktplatzHost($host_id); if (!$remote->isMe()) { $review_id = $this->review['foreign_review_id'] ?: $this->review->getId(); if ($this->review['foreign_review_id']) { if ($this->review->host_id === $remote->getId()) { $host_hash = null; } else { $host_hash = md5($this->review->host['public_key']); } } else { $host_hash = md5($myHost['public_key']); } $remote->pushDataToEndpoint("add_comment/" . $review_id . "/" . $host_hash, $data); } } } } }
public function afterStoreCallback() { if (!$this->material['host_id'] && $this->material['user_id'] !== $GLOBALS['user']->id) { PersonalNotifications::add($this->material['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/details/" . $this->material->getId() . "#review_" . $this->getId()), $this->isNew() ? sprintf(_("%s hat ein Review zu '%s' geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']) : sprintf(_("%s hat ein Review zu '%s' verändert."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']), "review_" . $this->getId(), Icon::create("support", "clickable")); } //only push if the comment is from this server and the material-server is different if ($this->material['host_id'] && !$this['host_id'] && $this->isDirty()) { $remote = new LernmarktplatzHost($this->material['host_id']); $myHost = LernmarktplatzHost::thisOne(); $data = array(); $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']); $data['data'] = $this->toArray(); $data['data']['foreign_review_id'] = $data['data']['review_id']; unset($data['data']['review_id']); unset($data['data']['id']); unset($data['data']['user_id']); unset($data['data']['host_id']); $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($this['user_id'], $user_description_datafield->getId())); } $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null); if (!$remote->isMe()) { $remote->pushDataToEndpoint("add_review/" . $this->material['foreign_material_id'], $data); } } }
<div class="author_name"> <a href="<?php echo URLHelper::getLink("dispatch.php/profile", array('username' => $user['username'])); ?> "> <?php echo htmlReady($user->getFullName()); ?> </a> </div> <div class="author_host">(<?php echo htmlReady($GLOBALS['UNI_NAME_CLEAN']); ?> )</div> <div class="description"><? $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($user['user_id'], $user_description_datafield->getId())); echo $datafield_entry && $datafield_entry['content'] ? formatReady($datafield_entry['content']) : ""; if ($material['user_id'] === $GLOBALS['user']->id) : ?> <a href="<?php echo URLHelper::getLink("dispatch.php/settings/details#datafields_" . $user_description_datafield->getId()); ?> " title="<?php echo _("Text bearbeiten"); ?> "> <?php echo Icon::create("edit", "clickable")->asImg(20, array('class' => "text-bottom")); ?>
public function pushDataToIndexServers($delete = false) { $myHost = LernmarktplatzHost::thisOne(); $data = array(); $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']); $data['data'] = $this->toArray(); $data['data']['foreign_material_id'] = $data['data']['material_id']; unset($data['data']['material_id']); unset($data['data']['id']); unset($data['data']['user_id']); unset($data['data']['host_id']); $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($this['user_id'], $user_description_datafield->getId())); } $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null); $data['topics'] = array(); foreach ($this->getTopics() as $tag) { if ($tag['name']) { $data['topics'][] = $tag['name']; } } if ($delete) { $data['delete_material'] = 1; } foreach (LernmarktplatzHost::findBySQL("index_server = '1' AND allowed_as_index_server = '1' ") as $index_server) { if (!$index_server->isMe()) { echo " push "; $index_server->pushDataToEndpoint("push_data", $data); } } }
/** * 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; } }