From a9b8826d4a4e4547840127e97a1fe98af36ad53f Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <krassmus@gmail.com> Date: Thu, 18 Sep 2014 14:54:16 +0200 Subject: [PATCH] add tags --- classes/MarketPlugin.class.php | 40 +++++++++++++++++++++++++++++++++ classes/MarketRelease.class.php | 2 +- controllers/myplugins.php | 3 ++- install.sql | 11 +++++---- views/myplugins/edit.php | 5 +++++ views/presenting/details.php | 8 +++++++ 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/classes/MarketPlugin.class.php b/classes/MarketPlugin.class.php index 176a9a0..163a238 100644 --- a/classes/MarketPlugin.class.php +++ b/classes/MarketPlugin.class.php @@ -54,4 +54,44 @@ class MarketPlugin extends SimpleORMap { $firstimage = $this->images->first(); return $firstimage ? $firstimage->getURL() : null; } + + public function setTags($tags) { + if (!$this->getId()) { + return false; + } + $tags = array_map("strtolower", $tags); + $old_tags = $this->getTags(); + $insert = DBManager::get()->prepare(" + INSERT IGNORE INTO pluginmarket_tags + SET plugin_id = :plugin_id, + tag = :tag, + user_id = :user_id + "); + $delete = DBManager::get()->prepare(" + DELETE FROM pluginmarket_tags + WHERE plugin_id = :plugin_id, + AND tag = :tag + "); + foreach (array_diff($old_tags, $tags) as $tag_to_delete) { + $delete->execute(array( + 'plugin_id' => $this->getId(), + 'tag' => $tag_to_delete + )); + } + foreach ($tags as $tag) { + $insert->execute(array( + 'plugin_id' => $this->getId(), + 'tag' => $tag, + 'user_id' => $GLOBALS['user']->id + )); + } + } + + public function getTags() { + $statement = DBManager::get()->prepare(" + SELECT tag FROM pluginmarket_tags WHERE plugin_id = ? ORDER BY tag ASC + "); + $statement->execute(array($this->getId())); + return $statement->fetchAll(PDO::FETCH_COLUMN, 0); + } } \ No newline at end of file diff --git a/classes/MarketRelease.class.php b/classes/MarketRelease.class.php index 1b7e035..f832ad9 100644 --- a/classes/MarketRelease.class.php +++ b/classes/MarketRelease.class.php @@ -100,7 +100,7 @@ class MarketRelease extends SimpleORMap { } if ($readme) { $html = Parsedown::instance()->text($readme); - $this->plugin['description'] = "<div>".$html."</div>"; + $this->plugin['description'] = "<div>".studip_utf8decode($html)."</div>"; $this->plugin->store(); } } diff --git a/controllers/myplugins.php b/controllers/myplugins.php index 6ace500..b3a5ecf 100644 --- a/controllers/myplugins.php +++ b/controllers/myplugins.php @@ -14,7 +14,7 @@ class MypluginsController extends PluginController { public function overview_action() { - $this->plugins = MarketPlugin::findBySQL("1=1"); + $this->plugins = MarketPlugin::findBySQL("user_id = ?", array($GLOBALS['user']->id)); } public function add_action() { @@ -83,6 +83,7 @@ class MypluginsController extends PluginController { } $this->marketplugin->store(); + $this->marketplugin->setTags(array_map("trim", explode(",", Request::get("tags")))); if (Request::submitted("image_order")) { $order = array_flip(Request::getArray("image_order")); diff --git a/install.sql b/install.sql index 36defb4..764d7da 100644 --- a/install.sql +++ b/install.sql @@ -56,10 +56,13 @@ CREATE TABLE IF NOT EXISTS `pluginmarket_rezension` ( CREATE TABLE IF NOT EXISTS `pluginmarket_tags` ( - `plugin_id` varchar(32) NOT NULL, - `tag` varchar(255) NOT NULL, - KEY (`tag_id`), - KEY `plugin_id` (`plugin_id`) + `tag` varchar(64) NOT NULL, + `plugin_id` varchar(32) NOT NULL, + `proposal` tinyint(4) NOT NULL DEFAULT '0', + `user_id` varchar(32) NOT NULL, + PRIMARY KEY (`tag`,`plugin_id`), + KEY `plugin_id` (`plugin_id`), + KEY `user_id` (`user_id`) ) ENGINE=MyISAM; CREATE TABLE IF NOT EXISTS `pluginmarket_rezension` ( diff --git a/views/myplugins/edit.php b/views/myplugins/edit.php index af0f171..d156b2b 100644 --- a/views/myplugins/edit.php +++ b/views/myplugins/edit.php @@ -43,6 +43,11 @@ <input type="text" name="data[url]" value="<?= htmlReady($marketplugin['url']) ?>"> </label> + <label> + <?= _("Schlagworte") ?> + <input type="text" name="tags" value="<?= htmlReady(ucwords(implode(", ", $marketplugin->getTags()))) ?>"> + </label> + <div> <?= _("Lizenz") ?> <input type="hidden" name="data[license]" value="GPL 2 or later"> diff --git a/views/presenting/details.php b/views/presenting/details.php index 3b42917..33c22a3 100644 --- a/views/presenting/details.php +++ b/views/presenting/details.php @@ -44,6 +44,14 @@ if ($icon) { <div><?= formatLinks($marketplugin['url']) ?></div> <? endif ?> +<? $tags = $marketplugin->getTags() ?> +<? if (count($tags)) : ?> + <h2><?= _("Schlagworte") ?></h2> + <div> + <?= htmlReady(ucwords(implode(", ", $tags))) ?> + </div> +<? endif ?> + <h2><?= _("Zum Autor") ?></h2> <ul class="clean"> <li> -- GitLab