Skip to content

Commit

Permalink
added share multiple drafts button and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
prozb committed Aug 26, 2021
1 parent 4c65ddc commit 5dec5a6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 24 deletions.
Expand Up @@ -189,4 +189,32 @@ public function unshareDrafts()

$this->setRedirect(Route::_($redirectUrl, false), $message);
}

public function shareDrafts()
{
// Check for request forgeries
$this->checkToken();

// Get the input
$task = $this->getTask();
$pks = $this->input->post->get('cid', array(), 'array');
$value = 1;
$redirectUrl = 'index.php?option=com_content&view=' . $this->view_list;
$message = '';

/** @var \Joomla\Component\Content\Administrator\Model\DraftModel $model */
$model = $this->getModel();

// Publish the items.
if (!$model->share($pks, $value))
{
$this->setRedirect(Route::_($redirectUrl, false), $model->getError(), 'error');

return;
}
// TODO: HERE properly messages
$message = Text::plural('COM_CONTENT_N_ITEMS_SHARED', count($pks));

$this->setRedirect(Route::_($redirectUrl, false), $message);
}
}
64 changes: 45 additions & 19 deletions administrator/components/com_content/src/Model/DraftModel.php
Expand Up @@ -12,6 +12,7 @@

\defined('_JEXEC') or die;

use \Datetime;
use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
Expand Down Expand Up @@ -266,8 +267,10 @@ public function unshare($pks)
$query = $db->getQuery(true)
->update($db->quoteName('#__draft'))
->set($db->quoteName('state') . ' = :state')
->set($db->quoteName('share_date') . ' = :date')
->whereIn($db->quoteName('article_id'), $pks)
->bind(':state', $value, ParameterType::INTEGER);
->bind(':state', $value, ParameterType::INTEGER)
->bind(':share_date', NULL, ParameterType::NULL);

$db->setQuery($query);
$db->execute();
Expand All @@ -279,25 +282,48 @@ public function unshare($pks)
return false;
}

// $table->reorder();

// // Trigger the change state event.
// Factory::getApplication()->getDispatcher()->dispatch(
// $this->event_after_change_featured,
// AbstractEvent::create(
// $this->event_after_change_featured,
// [
// 'eventClass' => 'Joomla\Component\Content\Administrator\Event\Model\FeatureEvent',
// 'subject' => $this,
// 'extension' => $context,
// 'pks' => $pks,
// 'value' => $value,
// ]
// )
// );

// $this->cleanCache();
return true;
}

public function share($pks)
{
// Sanitize the ids.
$pks = (array) $pks;
$pks = ArrayHelper::toInteger($pks);
$context = $this->option . '.' . $this->name;

if (empty($pks))
{
$this->setError(Text::_('COM_CONTENT_NO_ITEM_SELECTED'));

return false;
}

try
{
$value = 1;
// Adjust the mapping table.
// Clear the existing features settings.
$now = new DateTime();
$date_sql = $now->format('Y-m-d H:i:s');
$db = $this->getDbo();
$query = $db->getQuery(true)
->update($db->quoteName('#__draft'))
->set($db->quoteName('state') . ' = :state')
->set($db->quoteName('shared_date') . ' = :date')
->whereIn($db->quoteName('article_id'), $pks)
->bind(':state', $value, ParameterType::INTEGER)
->bind(':date', $date_sql, ParameterType::STRING);

$db->setQuery($query);
$db->execute();
}
catch (\Exception $e)
{
$this->setError($e->getMessage());

return false;
}
return true;
}
}
Expand Up @@ -171,6 +171,12 @@ protected function addToolbar()
->task('drafts.unshareDrafts')
->listCheck(true);

$toolbar->unshare('com_content')
->text('JTOOLBAR_SHARE')
->icon('icon-eye')
->task('drafts.shareDrafts')
->listCheck(true);

if (!$this->isEmptyState && $this->state->get('filter.published') == ContentComponent::CONDITION_TRASHED && $canDo->get('core.delete'))
{
$toolbar->delete('articles.delete')
Expand Down
5 changes: 1 addition & 4 deletions administrator/components/com_content/tmpl/drafts/default.php
Expand Up @@ -139,10 +139,7 @@


<td class="d-none d-lg-table-cell">
<?php
$it = $item->hashval;
echo '/joomla-cms/index.php?draft=' . $it;
?>
<a target="_blank" href="<?php echo str_replace('/administrator', '', Route::_('index.php?view=draft&draft_hash=' . $item->hashval)) ?>"><?php echo "index.php?draft=" . $item->hashval ?></a>;
</td>

<th scope="row" class="has-context">
Expand Down
3 changes: 2 additions & 1 deletion administrator/language/en-GB/com_content.ini
Expand Up @@ -127,7 +127,8 @@ COM_CONTENT_N_ITEMS_DRAFTED_1="Article drafted."
COM_CONTENT_N_ITEMS_FEATURED="%s articles featured."
COM_CONTENT_N_ITEMS_FEATURED_1="Article featured."
COM_CONTENT_N_ITEMS_UNSHARED="%s drafts unshared."
COM_CONTENT_N_ITEMS_UNSHARED_1="Draft unshared."
COM_CONTENT_N_ITEMS_SHARED="%s drafts shared."
COM_CONTENT_N_ITEMS_SHARED_1="Draft shared."
COM_CONTENT_N_ITEMS_PUBLISHED="%s articles published."
COM_CONTENT_N_ITEMS_PUBLISHED_1="Article published."
COM_CONTENT_N_ITEMS_TRASHED="%s articles trashed."
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/joomla.ini
Expand Up @@ -1002,6 +1002,7 @@ JTOOLBAR_CHANGE_STATUS="Actions"
JTOOLBAR_CHECKIN="Check-in"
JTOOLBAR_CLOSE="Close"
JTOOLBAR_UNSHARE="Unshare"
JTOOLBAR_SHARE="Share"
JTOOLBAR_DEFAULT="Default"
JTOOLBAR_DELETE="Delete"
JTOOLBAR_DELETE_ALL="Delete All"
Expand Down
1 change: 1 addition & 0 deletions api/language/en-GB/joomla.ini
Expand Up @@ -998,6 +998,7 @@ JTOOLBAR_EDIT_CSS="Edit CSS"
JTOOLBAR_EDIT_HTML="Edit HTML"
JTOOLBAR_EMPTY_TRASH="Empty Trash"
JTOOLBAR_UNSHARE="Unshare"
JTOOLBAR_SHARE="Share"
JTOOLBAR_ENABLE="Enable"
JTOOLBAR_EXPORT="Export"
JTOOLBAR_DRAFT="Draft"
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/joomla.ini
Expand Up @@ -79,6 +79,7 @@ JEXPIRED="Expired"
JFALSE="False"
JFEATURED="Featured"
JTOOLBAR_UNSHARE="Unshare"
JTOOLBAR_SHARE="Share"
JFEATURED_ASC="Featured ascending"
JFEATURED_DESC="Featured descending"
JHIDE="Hide"
Expand Down

0 comments on commit 5dec5a6

Please sign in to comment.