Sync variant publication with parent set
This commit is contained in:
@@ -9,6 +9,26 @@ use Joomla\CMS\MVC\Model\AdminModel;
|
||||
|
||||
class SetModel extends AdminModel
|
||||
{
|
||||
public function publish(&$pks, $value = 1)
|
||||
{
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', (array) $pks))));
|
||||
if (!parent::publish($pks, $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($ids) {
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->update($db->quoteName('#__testquestions_sets'))
|
||||
->set($db->quoteName('published') . ' = ' . (int) $value)
|
||||
->where($db->quoteName('parent_id') . ' IN (' . implode(',', $ids) . ')')
|
||||
)->execute();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTable($name = 'Set', $prefix = 'Administrator', $config = [])
|
||||
{
|
||||
return $this->getMVCFactory()->createTable($name, $prefix, $config);
|
||||
@@ -136,6 +156,7 @@ class SetModel extends AdminModel
|
||||
$parent = $this->getItem($parentId);
|
||||
if ($parent) {
|
||||
$data['duration'] = (int) $parent->duration;
|
||||
$data['published'] = (int) $parent->published;
|
||||
}
|
||||
} elseif (!in_array(($data['set_type'] ?? 'ordinary'), ['ordinary', 'multi'], true)) {
|
||||
$data['set_type'] = 'ordinary';
|
||||
@@ -151,6 +172,15 @@ class SetModel extends AdminModel
|
||||
|
||||
$setId = (int) $this->getState($this->getName() . '.id');
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
if ($parentId === 0) {
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->update($db->quoteName('#__testquestions_sets'))
|
||||
->set($db->quoteName('published') . ' = ' . (int) ($data['published'] ?? 1))
|
||||
->where($db->quoteName('parent_id') . ' = ' . $setId)
|
||||
)->execute();
|
||||
}
|
||||
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete($db->quoteName('#__testquestions_set_questions'))
|
||||
|
||||
Reference in New Issue
Block a user