Skip to content

Commit 28010b8

Browse files
committed
update outdated child of a master item
This adds a new edit view for updating a child item when it is oudated with the master item. There it is just possible to save the target and update his masters modified date. When versions are enabled for this itemtype then there is a compare view displayed for the reference/master otherwise the edit view is displayed.
1 parent dbe7494 commit 28010b8

File tree

12 files changed

+502
-17
lines changed

12 files changed

+502
-17
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* @package Joomla.Administrator
4+
* @subpackage com_associations
5+
*
6+
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\Component\Associations\Administrator\Controller;
11+
12+
defined('_JEXEC') or die;
13+
14+
use Joomla\CMS\MVC\Controller\BaseController;
15+
use Joomla\CMS\Router\Route;
16+
17+
/**
18+
* Association edit controller class.
19+
*
20+
* @since 4.0
21+
*/
22+
class AssociationMasterController extends BaseController
23+
{
24+
/**
25+
* Method to update the childs modified date of the master item in the associations table.
26+
*
27+
* @return void
28+
*
29+
* @since 4.0
30+
*/
31+
public function update()
32+
{
33+
$targetId = $this->input->get('targetId', '', 'int');
34+
$masterId = $this->input->get('id', '' , 'int');
35+
$itemtype = $this->input->get('itemtype', '', 'string');
36+
37+
$this->getModel('associationmaster')->update($targetId, $masterId, $itemtype);
38+
39+
$this->setRedirect(Route::_('index.php?option=com_associations&view=associations', false));
40+
}
41+
}

administrator/components/com_associations/Helper/AssociationsHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId
244244
// Create associated items list.
245245
foreach ($languages as $langCode => $language)
246246
{
247+
$update = false;
248+
247249
// Don't do for the reference language, when there is no master language set
248250
if ($langCode == $itemLanguage && !$globalMasterLanguage)
249251
{
@@ -415,7 +417,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId
415417
$options = array(
416418
'option' => 'com_associations',
417419
'view' => 'association',
418-
'layout' => 'edit',
420+
'layout' => $update ? 'update' : 'edit',
419421
'itemtype' => $extensionName . '.' . $typeName,
420422
'task' => 'association.edit',
421423
'id' => $masterId ?? $itemId,

administrator/components/com_associations/Helper/MasterAssociationsHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
class MasterAssociationsHelper extends ContentHelper
2727
{
2828
/**
29-
* @param $globalMasterLanguage
29+
* Method to create a link for a child item that has no master item
30+
*
31+
* @param string $globalMasterLanguage The global master language
3032
*
3133
* @return string
3234
*/
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* @package Joomla.Administrator
4+
* @subpackage com_associations
5+
*
6+
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\Component\Associations\Administrator\Model;
11+
12+
defined('_JEXEC') or die;
13+
14+
use Joomla\CMS\Factory;
15+
use Joomla\CMS\MVC\Model\BaseModel;
16+
17+
/**
18+
* Methods supporting a list of article records.
19+
*
20+
* @since 4.0
21+
*/
22+
class AssociationMasterModel extends BaseModel
23+
{
24+
25+
/**
26+
* Update the childs modified date of the master item from #__associations table.
27+
*
28+
* @param integer $childId The id of the item that gets updated
29+
* @param integer $masterId The associated master item of the child item
30+
* @param string $itemtype The component item type
31+
*
32+
* @return boolean True on success.
33+
*
34+
* @since 4.0
35+
*/
36+
public function update($childId, $masterId, $itemtype) {
37+
38+
list($extensionName, $typeName) = explode('.', $itemtype, 2);
39+
40+
$context = ($typeName ==='category')
41+
? 'com_categories.item'
42+
: $extensionName . '.item';
43+
$db = Factory::getDbo();
44+
45+
$subQuery = $db->getQuery(true)
46+
->select($db->quoteName('assocParams'))
47+
->from($db->quoteName('#__associations'))
48+
->where($db->quoteName('id') . ' = ' . $db->quote($masterId))
49+
->where($db->quoteName('parent_id') . ' = ' . $db->quote(0))
50+
->where($db->quoteName('context') . ' = ' . $db->quote($context));
51+
$masterModified = $db->setQuery($subQuery)->loadResult();
52+
53+
$query = $db->getQuery(true)
54+
->update($db->quoteName('#__associations'))
55+
->set($db->quoteName('assocParams') . ' = ' . $db->quote($masterModified))
56+
->where($db->quoteName('id') . ' = ' . $db->quote($childId))
57+
->where($db->quoteName('parent_id') . ' = ' . $db->quote($masterId))
58+
->where($db->quoteName('context') . ' = ' . $db->quote($context));
59+
$db->setQuery($query);
60+
61+
try
62+
{
63+
$db->execute();
64+
}
65+
catch (ExecutionFailureException $e)
66+
{
67+
return false;
68+
}
69+
70+
return true;
71+
}
72+
}

administrator/components/com_associations/Model/AssociationModel.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
defined('_JEXEC') or die;
1313

14+
use Joomla\CMS\Factory;
1415
use Joomla\CMS\MVC\Model\ListModel;
1516

1617
/**
@@ -37,4 +38,56 @@ public function getForm($data = array(), $loadData = true)
3738

3839
return !empty($form) ? $form : false;
3940
}
41+
42+
/**
43+
* Method to get the history version ids of a master item.
44+
*
45+
* @param integer $masterId Id of the master item
46+
* @param integer $targetId Id of an child item
47+
* @param string $extensionName The extension name with com_
48+
* @param string $typeName The item type
49+
* @param integer $typeId the content type id
50+
*
51+
* @return array of version history ids
52+
*/
53+
public function getMasterCompareValues($masterId, $targetId, $extensionName, $typeName, $typeId){
54+
55+
$context = ($typeName === 'category')
56+
? 'com_categories.item'
57+
: $extensionName . '.item';
58+
59+
$db = Factory::getDbo();
60+
$masterQuery = $db->getQuery(true)
61+
->select($db->quoteName('assocParams'))
62+
->from($db->quoteName('#__associations'))
63+
->where($db->quoteName('id') . ' = ' . $db->quote($masterId))
64+
->where($db->quoteName('context') . ' = ' . $db->quote($context));
65+
$latestMasterDate = $db->setQuery($masterQuery)->loadResult();
66+
67+
$latestVersionQuery = $db->getQuery(true)
68+
->select($db->quoteName('version_id'))
69+
->from($db->quoteName('#__ucm_history'))
70+
->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($masterId))
71+
->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId))
72+
->where($db->quoteName('save_date') . ' = ' . $db->quote($latestMasterDate));
73+
$latestVersionId = $db->setQuery($latestVersionQuery)->loadResult();
74+
75+
$childQuery = $db->getQuery(true)
76+
->select($db->quoteName('assocParams'))
77+
->from($db->quoteName('#__associations'))
78+
->where($db->quoteName('id') . ' = ' . $db->quote($targetId))
79+
->where($db->quoteName('parent_id') . ' = ' . $db->quote($masterId))
80+
->where($db->quoteName('context') . ' = ' . $db->quote($context));
81+
$childMasterDate = $db->setQuery($childQuery)->loadResult();
82+
83+
$olderVersionQuery = $db->getQuery(true)
84+
->select($db->quoteName('version_id'))
85+
->from($db->quoteName('#__ucm_history'))
86+
->where($db->quoteName('ucm_item_id') . ' = ' . $db->quote($masterId))
87+
->where($db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId))
88+
->where($db->quoteName('save_date') . ' = ' . $db->quote($childMasterDate));
89+
$olderVersionId = $db->setQuery($olderVersionQuery)->loadResult();
90+
91+
return [$latestVersionId, $olderVersionId];
92+
}
4093
}

administrator/components/com_associations/View/Association/HtmlView.php

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
defined('_JEXEC') or die;
1313

14+
use Joomla\CMS\Component\ComponentHelper;
1415
use Joomla\CMS\Factory;
1516
use Joomla\CMS\Language\Text;
1617
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
1718
use Joomla\CMS\Router\Route;
19+
use Joomla\CMS\Table\Table;
1820
use Joomla\CMS\Toolbar\Toolbar;
1921
use Joomla\CMS\Toolbar\ToolbarHelper;
2022
use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
@@ -206,24 +208,42 @@ protected function addToolbar()
206208

207209
ToolbarHelper::title(Text::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', Text::_($this->extensionName), Text::_($languageKey)), 'contract assoc');
208210

209-
$bar = Toolbar::getInstance('toolbar');
211+
$toolbar = Toolbar::getInstance('toolbar');
210212

211-
$bar->appendButton(
212-
'Custom', '<button onclick="Joomla.submitbutton(\'reference\')" '
213-
. 'class="btn btn-sm btn-success"><span class="icon-apply" aria-hidden="true"></span>'
214-
. Text::_('COM_ASSOCIATIONS_SAVE_REFERENCE') . '</button>', 'reference'
215-
);
216-
217-
$bar->appendButton(
218-
'Custom', '<button onclick="Joomla.submitbutton(\'target\')" '
219-
. 'class="btn btn-sm btn-success"><span class="icon-apply" aria-hidden="true"></span>'
220-
. Text::_('COM_ASSOCIATIONS_SAVE_TARGET') . '</button>', 'target'
221-
);
222-
223-
if ($this->typeName === 'category' || $this->extensionName === 'com_menus' || $this->save2copy === true)
213+
// In the update view we can just save the target and when saving the other button gets activated via js to update master information for the child
214+
if($this->getLayout() === 'update')
224215
{
225-
ToolbarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false);
216+
$toolbar->appendButton(
217+
'Custom', '<button onclick="Joomla.submitbutton(\'target\')" '
218+
. 'class="btn btn-sm btn-success"><span class="icon-apply" aria-hidden="true"></span>'
219+
. Text::_('COM_ASSOCIATIONS_SAVE_AND_UPDATE_TARGET') . '</button>', 'target'
220+
);
221+
222+
$toolbar->appendButton(
223+
'Custom', '<button class="btn btn-sm btn-success hidden" id="updateChild" onclick="Joomla.submitbutton(\'associationmaster.update\')"></button>', 'target'
224+
);
226225
}
226+
else
227+
{
228+
$toolbar->appendButton(
229+
'Custom', '<button onclick="Joomla.submitbutton(\'reference\')" '
230+
. 'class="btn btn-sm btn-success"><span class="icon-apply" aria-hidden="true"></span>'
231+
. Text::_('COM_ASSOCIATIONS_SAVE_REFERENCE') . '</button>',
232+
'reference'
233+
);
234+
235+
$toolbar->appendButton(
236+
'Custom', '<button onclick="Joomla.submitbutton(\'target\')" '
237+
. 'class="btn btn-sm btn-success"><span class="icon-apply" aria-hidden="true"></span>'
238+
. Text::_('COM_ASSOCIATIONS_SAVE_TARGET') . '</button>', 'target'
239+
);
240+
241+
if ($this->typeName === 'category' || $this->extensionName === 'com_menus' || $this->save2copy === true)
242+
{
243+
ToolbarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false);
244+
}
245+
}
246+
227247

228248
ToolbarHelper::cancel('association.cancel', 'JTOOLBAR_CLOSE');
229249
ToolbarHelper::help('JHELP_COMPONENTS_ASSOCIATIONS_EDIT');
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* @package Joomla.Administrator
4+
* @subpackage com_associations
5+
*
6+
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
defined('_JEXEC') or die;
11+
12+
use Joomla\CMS\HTML\HTMLHelper;
13+
use Joomla\CMS\Language\Text;
14+
use Joomla\CMS\Router\Route;
15+
use Joomla\CMS\Session\Session;
16+
17+
HTMLHelper::_('behavior.formvalidator');
18+
HTMLHelper::_('behavior.keepalive');
19+
HTMLHelper::_('jquery.framework');
20+
21+
HTMLHelper::_('script', 'com_associations/sidebysideupdate.js', ['version' => 'auto', 'relative' => true]);
22+
//HTMLHelper::_('script', 'com_associations/sidebyside.js', ['version' => 'auto', 'relative' => true]);
23+
HTMLHelper::_('stylesheet', 'com_associations/sidebyside.css', ['version' => 'auto', 'relative' => true]);
24+
25+
$options = array(
26+
'layout' => $this->app->input->get('layout', '', 'string'),
27+
'itemtype' => $this->itemtype,
28+
'id' => $this->referenceId,
29+
'targetId' => $this->targetId
30+
);
31+
?>
32+
<form action="<?php echo Route::_('index.php?option=com_associations&view=association&' . http_build_query($options)); ?>" method="post" name="adminForm" id="adminForm" data-associatedview="<?php echo $this->typeName; ?>">
33+
<div class="sidebyside">
34+
<div class="outer-panel" id="left-panel">
35+
<div class="inner-panel">
36+
<?php if (isset($this->referenceVersionIdNew)) : ?>
37+
<h3><?php echo Text::_('COM_ASSOCIATIONS_REFERENCE_ITEM_COMPARE_VIEW'); ?></h3>
38+
<iframe id="reference-association" name="reference-association" title="reference-association"
39+
src="<?php echo Route::_('index.php?option=com_contenthistory&view=compare&layout=compareMaster&tmpl=component&' . Session::getFormToken() . '=1&id1=' . $this->referenceVersionIdNew . '&id2=' . $this->referenceVersionIdOld); ?>"
40+
height="400" width="400" >
41+
</iframe>
42+
<?php else : ?>
43+
<h3><?php echo Text::_('COM_ASSOCIATIONS_REFERENCE_ITEM'); ?></h3>
44+
<iframe id="reference-association" name="reference-association" title="reference-association"
45+
src="<?php echo Route::_($this->editUri . '&task=' . $this->typeName . '.edit&id=' . (int) $this->referenceId); ?>"
46+
height="400" width="400"
47+
data-action="edit"
48+
data-item="<?php echo $this->typeName; ?>"
49+
data-id="<?php echo $this->referenceId; ?>"
50+
data-title="<?php echo $this->referenceTitle; ?>"
51+
data-language="<?php echo $this->referenceLanguage; ?>"
52+
data-editurl="<?php echo Route::_($this->editUri); ?>">
53+
</iframe>
54+
<?php endif; ?>
55+
</div>
56+
</div>
57+
<div class="outer-panel" id="right-panel">
58+
<div class="inner-panel">
59+
<h3 class="target-text"><?php echo Text::_('COM_ASSOCIATIONS_ASSOCIATED_ITEM'); ?></h3>
60+
<iframe id="target-association" name="target-association" title="target-association"
61+
src="<?php echo Route::_($this->editUri . '&task=' . $this->typeName . '.edit&id=' . (int) $this->targetId); ?>"
62+
height="400" width="400"
63+
data-action="<?php echo $this->targetAction; ?>"
64+
data-item="<?php echo $this->typeName; ?>"
65+
data-id="<?php echo $this->targetId; ?>"
66+
data-title="<?php echo $this->targetTitle; ?>"
67+
data-language="<?php echo $this->targetLanguage; ?>"
68+
data-editurl="<?php echo Route::_($this->editUri); ?>">
69+
</iframe>
70+
</div>
71+
</div>
72+
</div>
73+
<input type="hidden" name="task" value="">
74+
<?php echo HTMLHelper::_('form.token'); ?>
75+
</form>

0 commit comments

Comments
 (0)