public static function findByText($text) { self::fetchRemoteSearch($text); $statement = DBManager::get()->prepare("\n SELECT lernmarktplatz_material.*\n FROM lernmarktplatz_material\n LEFT JOIN lernmarktplatz_tags_material USING (material_id)\n LEFT JOIN lernmarktplatz_tags USING (tag_hash)\n WHERE lernmarktplatz_material.name LIKE :text\n OR description LIKE :text\n OR short_description LIKE :text\n OR lernmarktplatz_tags.name LIKE :text\n GROUP BY lernmarktplatz_material.material_id\n ORDER BY lernmarktplatz_material.mkdate DESC\n "); $statement->execute(array('text' => "%" . $text . "%")); $material_data = $statement->fetchAll(PDO::FETCH_ASSOC); $materials = array(); foreach ($material_data as $data) { $materials[] = LernmarktplatzMaterial::buildExisting($data); } return $materials; }
<td><?php echo _("Anzahl eigener Materialien"); ?> </td> <td><?php echo LernmarktplatzMaterial::countBySQL("host_id IS NULL"); ?> </td> </tr> <tr> <td><?php echo _("Anzahl Materialien von anderen Servern"); ?> </td> <td><?php echo LernmarktplatzMaterial::countBySQL("host_id IS NOT NULL"); ?> </td> </tr> </table> <h2><?php echo _("API-Endpoints"); ?> </h2> <ul class="clean"> <? foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) : ?> <? if (stripos($method->name, "_action") === strlen($method->name) - 7) : ?> <? $name = substr($method->name, 0, stripos($method->name, "_action")) ?> <? if (!in_array($name, array("render", "map", "index"))) : ?>
public function fetchRemoteSearch($text, $tag = false) { $endpoint_url = $this['url'] . "search_items"; if ($tag) { $endpoint_url .= "?tag=" . urlencode(studip_utf8encode($text)); } else { $endpoint_url .= "?text=" . urlencode(studip_utf8encode($text)); } $output = @file_get_contents($endpoint_url); if ($output) { $output = studip_utf8decode(json_decode($output, true)); foreach ((array) $output['results'] as $material_data) { $host = LernmarktplatzHost::findOneBySQL("public_key = ?", array($material_data['host']['public_key'])); if (!$host) { $host = new LernmarktplatzHost(); $host['url'] = $material_data['host']['url']; $host->fetchPublicKey(); $host->store(); } if (!$host->isMe()) { //set user: $user = LernmarktplatzUser::findOneBySQL("foreign_user_id", array($material_data['user']['user_id'], $host->getId())); if (!$user) { $user = new LernmarktplatzUser(); $user['foreign_user_id'] = $material_data['user']['user_id']; $user['host_id'] = $host->getId(); } $user['name'] = $material_data['user']['name']; $user['avatar'] = $material_data['user']['avatar'] ?: null; $user->store(); //set material: $material_data['data']['foreign_material_id'] = $material_data['data']['id']; $material = LernmarktplatzMaterial::findOneBySQL("foreign_material_id = ? AND host_id = ?", array($material_data['data']['foreign_material_id'], $host->getId())); if (!$material) { $material = new LernmarktplatzMaterial(); } unset($material_data['data']['id']); $material->setData($material_data['data']); $material['host_id'] = $host->getId(); $material['user_id'] = $user->getId(); $material->store(); //set topics: $material->setTopics($material_data['topics']); } } } }
public function profile_action($external_user_id) { $this->user = new LernmarktplatzUser($external_user_id); if ($this->user->isNew()) { throw new Exception(_("Nutzer ist nicht erfasst.")); } $this->materials = LernmarktplatzMaterial::findBySQL("user_id = ? AND host_id IS NOT NULL ORDER BY mkdate DESC", array($external_user_id)); }
public function overview_action() { Navigation::activateItem("/lernmarktplatz/mymaterial"); $this->materialien = LernmarktplatzMaterial::findMine(); }
/** * Adds or edits a review to the material on this server from a client of another server. * Use this request only as a POST request, the body must be a JSON-object that carries all the * necessary variables. * @param $material_id : ID of the item on this server. */ public function add_review_action($material_id) { if (Request::isPost()) { $public_key_hash = $_SERVER['HTTP_' . str_replace("-", "_", strtoupper($GLOBALS['LERNMARKTPLATZ_HEADER_PUBLIC_KEY_HASH']))]; $signature = base64_decode($_SERVER['HTTP_' . str_replace("-", "_", strtoupper($GLOBALS['LERNMARKTPLATZ_HEADER_SIGNATURE']))]); $host = LernmarktplatzHost::findOneBySQL("MD5(public_key) = ?", array($public_key_hash)); if ($host && !$host->isMe()) { $body = file_get_contents('php://input'); if ($host->verifySignature($body, $signature)) { $data = studip_utf8decode(json_decode($body, true)); $material = new LernmarktplatzMaterial($material_id); if ($material->isNew() || $material['host_id']) { throw new Exception("Unknown material."); } $user = LernmarktplatzUser::findOneBySQL("host_id = ? AND foreign_user_id = ?", array($host->getId(), $data['user']['user_id'])); if (!$user) { $user = new LernmarktplatzUser(); $user['host_id'] = $host->getId(); $user['foreign_user_id'] = $data['user']['user_id']; } $user['name'] = $data['user']['name']; $user['avatar'] = $data['user']['avatar']; $user['description'] = $data['user']['description'] ?: null; $user->store(); $review = LernmarktplatzReview::findOneBySQL("material_id = ? AND user_id = ? AND host_id = ?", array($material_id, $user->getId(), $host->getId())); if (!$review) { $review = new LernmarktplatzReview(); $review['user_id'] = $user->getId(); $review['foreign_review_id'] = $data['data']['foreign_review_id']; $review['host_id'] = $host->getId(); } $review['material_id'] = $material_id; $review['review'] = $data['data']['review']; $review['rating'] = $data['data']['rating']; $review['mkdate'] = $data['data']['mkdate']; $review['chdate'] = $data['data']['chdate']; $review->store(); echo "stored "; } else { throw new Exception("Wrong signature, sorry."); } } $this->render_text(""); } else { throw new Exception("USE POST TO PUSH."); } }
public function getHomepageTemplate($user_id) { $materialien = LernmarktplatzMaterial::findMine($user_id); if (count($materialien)) { $template_factory = new Flexi_TemplateFactory(__DIR__ . "/views"); $template = $template_factory->open("mymaterial/_material_list"); $template->set_attribute("plugin", $this); $template->set_attribute("materialien", $materialien); $template->set_attribute("title", _("Lernmaterialien")); $template->set_attribute("icon_url", Icon::create("service", "clickable")->asImagePath()); return $template; } else { return null; } }