From bffffe725b009ad36d7cbf0df01a233bb7ac3d50 Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <fuhse@data-quest.de> Date: Tue, 20 Jun 2017 18:17:06 +0200 Subject: [PATCH] re #78 --- assets/pluginmarket.js | 17 ++++++++- assets/pluginmarket.less | 7 ++++ classes/MarketPlugin.class.php | 5 +-- controllers/myplugins.php | 57 ++++++++++++++++++++++++++++++- views/myplugins/_collaborator.php | 15 ++++++++ views/myplugins/edit.php | 11 ++++++ 6 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 views/myplugins/_collaborator.php diff --git a/assets/pluginmarket.js b/assets/pluginmarket.js index f441a88..c5da3be 100755 --- a/assets/pluginmarket.js +++ b/assets/pluginmarket.js @@ -7,4 +7,19 @@ $(document).ready(function () { $('input#used_at').val($.trim(e.target.text)); }); }); -}); \ No newline at end of file +}); + +STUDIP.PluginMarket = { + addCollaborator: function (user_id, name) { + jQuery.ajax({ + url: STUDIP.ABSOLUTE_URI_STUDIP + "plugins.php/pluginmarket/myplugins/add_user", + data: { + "user_id": user_id + }, + success: function (html) { + jQuery(html).hide().appendTo("#plugincollaborators").fadeIn(); + } + }); + return false; + } +}; \ No newline at end of file diff --git a/assets/pluginmarket.less b/assets/pluginmarket.less index 5c1b643..4946912 100755 --- a/assets/pluginmarket.less +++ b/assets/pluginmarket.less @@ -194,3 +194,10 @@ article.contentbox { transform: scale(1,1) rotate(0deg); } } + +#plugincollaborators { + input[type=checkbox]:checked + span { + opacity: 0.5; + text-decoration: line-through; + } +} \ No newline at end of file diff --git a/classes/MarketPlugin.class.php b/classes/MarketPlugin.class.php index f3e9635..8aebeb2 100755 --- a/classes/MarketPlugin.class.php +++ b/classes/MarketPlugin.class.php @@ -66,7 +66,9 @@ class MarketPlugin extends SimpleORMap { public function isWritable($user_id = null) { $user_id || $user_id = $GLOBALS['user']->id; - return ($this['user_id'] === $user_id) || $this->isRootable($user_id); + return ($this['user_id'] === $user_id) + || $this->isRootable($user_id) + || in_array($user_id, $this->more_users->pluck("user_id")); } public function isRootable($user_id = null) { @@ -166,5 +168,4 @@ class MarketPlugin extends SimpleORMap { return $rating; } - } \ No newline at end of file diff --git a/controllers/myplugins.php b/controllers/myplugins.php index f8d1784..e6a7f13 100755 --- a/controllers/myplugins.php +++ b/controllers/myplugins.php @@ -13,7 +13,11 @@ class MypluginsController extends MarketController public function overview_action() { - $this->plugins = MarketPlugin::findBySQL("user_id = ? ORDER BY mkdate DESC", array($GLOBALS['user']->id)); + $this->plugins = MarketPlugin::findBySQL("LEFT JOIN pluginmarket_user_plugins USING (plugin_id) + WHERE pluginmarket_plugins.user_id = :user_id + OR pluginmarket_user_plugins.user_id = :user_id + ORDER BY mkdate DESC", array('user_id' => $GLOBALS['user']->id) + ); } public function addfromzip_action() @@ -166,6 +170,51 @@ class MypluginsController extends MarketController } } + + foreach (Request::getArray("collaborator") as $user_id) { + if ($this->marketplugin['user_id'] !== $user_id) { + $statement = DBManager::get()->prepare(" + INSERT IGNORE INTO pluginmarket_user_plugins + SET user_id = :user_id, + plugin_id = :plugin_id + "); + $statement->execute(array( + 'user_id' => $user_id, + 'plugin_id' => $this->marketplugin->getId() + )); + } + } + $this->marketplugin->store(); + foreach (Request::getArray("drop_collaborator") as $user_id) { + if ($this->marketplugin['user_id'] === $user_id) { + if (count($this->marketplugin->more_users)) { + $new_boss = $this->marketplugin->more_users[0]; + $this->marketplugin['user_id'] = $new_boss->getId(); + $this->marketplugin->store(); + $statement = DBManager::get()->prepare(" + DELETE FROM pluginmarket_user_plugins + WHERE user_id = :user_id + AND plugin_id = :plugin_id + "); + $statement->execute(array( + 'user_id' => $new_boss->getId(), + 'plugin_id' => $this->marketplugin->getId() + )); + } + } else { + $statement = DBManager::get()->prepare(" + DELETE FROM pluginmarket_user_plugins + WHERE user_id = :user_id + AND plugin_id = :plugin_id + "); + $statement->execute(array( + 'user_id' => $user_id, + 'plugin_id' => $this->marketplugin->getId() + )); + } + } + + PageLayout::postMessage(MessageBox::success(_("Plugin wurde gespeichert."))); $this->redirect('presenting/details/' . $this->marketplugin->getId()); } @@ -209,5 +258,11 @@ class MypluginsController extends MarketController } } + public function add_user_action() + { + $this->user = User::find(Request::option("user_id")); + $this->render_template("myplugins/_collaborator.php"); + } + } \ No newline at end of file diff --git a/views/myplugins/_collaborator.php b/views/myplugins/_collaborator.php new file mode 100644 index 0000000..6b2c285 --- /dev/null +++ b/views/myplugins/_collaborator.php @@ -0,0 +1,15 @@ +<li> + <input type="checkbox" + id="drop_collaborator_<?= htmlReady($user->getId()) ?>" + name="drop_collaborator[]" + value="<?= htmlReady($user->getId()) ?>" + style="display: none;"> + <span> + <?= Avatar::getAvatar($user->getId())->getImageTag(Avatar::SMALL) ?> + <?= htmlReady($user->getFullName()) ?> + </span> + <input type="hidden" name="collaborator[]" value="<?= htmlReady($user->getId()) ?>"> + <label for="drop_collaborator_<?= htmlReady($user->getId()) ?>" style="cursor: pointer; display: inline;"> + <?= Icon::create("trash", "clickable")->asImg(20, array('class' => "text-bottom")) ?> + </label> +</li> \ No newline at end of file diff --git a/views/myplugins/edit.php b/views/myplugins/edit.php index 412961f..d6dd0ee 100755 --- a/views/myplugins/edit.php +++ b/views/myplugins/edit.php @@ -46,6 +46,17 @@ <input type="text" name="tags" value="<?= htmlReady(ucwords(implode(", ", $marketplugin->getTags()))) ?>"> </label> + <div style="margin-bottom: 10px; margin-top: 10px;"> + <?= _("Mitarbeiter") ?> + <ul class="clean" style="margin-bottom: 5px;" id="plugincollaborators"> + <?= $this->render_partial("myplugins/_collaborator.php", array('user' => $marketplugin->user)) ?> + <? foreach ($marketplugin->more_users as $user) : ?> + <?= $this->render_partial("myplugins/_collaborator.php", array('user' => $user)) ?> + <? endforeach ?> + </ul> + <?= QuickSearch::get("user_id", new StandardSearch("user_id"))->fireJSFunctionOnSelect("STUDIP.PluginMarket.addCollaborator")->render() ?> + </div> + <div> <?= _("Lizenz") ?> <input type="hidden" name="data[license]" value="GPL 2 or later"> -- GitLab