diff --git a/assets/pluginmarket.js b/assets/pluginmarket.js index f441a88497bdb7c697452611115156f08e545e4b..c5da3be1ebdc921e272a85ec73c3be1c2e107fee 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 5c1b643ce43415d15f3ffd3b507e06dde44ba11e..4946912ab733449677708b4d21925f1f387eb577 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 f3e963550bc7ccfd4c71c608a6ee087d426e490a..8aebeb2a902f559e705602dced9fd509cd851530 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 f8d17849c5dbe6f2c0dbd2d2f980a7d003b934d2..e6a7f13c35b4117651e2b77bd4e1b6185a1a9caa 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 0000000000000000000000000000000000000000..6b2c28568a1ead2d6dfff68ed5423090dee82747 --- /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 412961fbc9c19fac202c617fc9bbfe088b2d99e5..d6dd0eeb9d2afc7bf92d9267a0574788536e4b39 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">