Skip to content

Commit

Permalink
Fixing admin: model and view
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiljevski committed Dec 30, 2021
1 parent 722c083 commit e5733c0
Show file tree
Hide file tree
Showing 20 changed files with 1,486 additions and 906 deletions.
6 changes: 3 additions & 3 deletions com_admirorgallery/admin/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function display($cachable = false, $urlparams = false)
}

AdmirorGalleryHelper::addSubmenu(
$this->input->get('view', 'control_panel'), $this->input->get('AG_resourceType', '')
$this->input->get('view', 'control_panel'), $this->input->get('resourceType', '')
);

$doc = JFactory::getDocument();
Expand All @@ -63,8 +63,8 @@ public function display($cachable = false, $urlparams = false)

if ($viewName == 'resourcemanager')
{
JToolbarHelper::custom('ag_install', 'ag_install', 'ag_install', 'JTOOLBAR_INSTALL', false, false);
JToolbarHelper::deleteList('COM_ADMIRORGALLERY_ARE_YOU_SURE', 'ag_uninstall', 'JTOOLBAR_UNINSTALL');
JToolbarHelper::custom('installResource', 'installResource', 'installResource', 'JTOOLBAR_INSTALL', false, false);
JToolbarHelper::deleteList('COM_ADMIRORGALLERY_ARE_YOU_SURE', 'uninstallResource', 'JTOOLBAR_UNINSTALL');
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion com_admirorgallery/admin/controllers/admirorgallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function agApply(): void
$model = $this->getModel('admirorgallery');

// UPDATE
$model->_update();
$model->update();

parent::display();
}
Expand Down
9 changes: 0 additions & 9 deletions com_admirorgallery/admin/controllers/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,4 @@
*/
class AdmirorgalleryControllerButton extends AdmirorgalleryController
{
/**
* __construct
*
* @since 1.0.0
*/
public function __construct()
{
parent::__construct();
}
}
43 changes: 21 additions & 22 deletions com_admirorgallery/admin/controllers/imagemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,69 +59,68 @@ public function agApply(): void
{
// FOLDER MODELS
// BOOKMARK REMOVE
$cbBookmarkRemove = $this->input->getVar('cbBookmarkRemove');
$bookmarksToRemove = $this->input->getVar('bookmarksToRemove');

if (!empty($cbBookmarkRemove))
if (!empty($bookmarksToRemove))
{
$model->_bookmarkRemove($cbBookmarkRemove);
$model->removeBookmark($bookmarksToRemove, $model->bookmarkPath);
}

// PRIORITY
$cbPriority = $this->input->getVar('cbPriority');

if (!empty($cbPriority))
{
$model->_cbox_priority($cbPriority);
$model->updatePriority($cbPriority);
}

// UPLOAD
$file = $this->input->getVar('AG_fileUpload', null, 'files');

if (isset($file) && !empty($file['name']))
{
$model->_fileUpload($itemURL, $file);
$model->uploadFile($itemURL, $file);
}

// ADD FOLDERS
$addFolders = $this->input->getVar('addFolders');

if (!empty($addFolders))
{
$model->_addFolders($itemURL, $addFolders);
$model->addFolders($itemURL, $addFolders);
}

// REMOVE // BOOKMARK ADD
$cbSelectItem = $this->input->getVar('cbSelectItem');
$selectItem = $this->input->getVar('selectItem');
$operationsTargetFolder = $this->input->getVar('operationsTargetFolder');

if (!empty($cbSelectItem))
if (!empty($selectItem))
{
switch ($this->input->getVar('AG_operations'))
{
case "move":
$model->_move($cbSelectItem, $operationsTargetFolder);
break;
$model->moveItems($selectItem, $operationsTargetFolder);
break;
case "copy":
$model->_copy($cbSelectItem, $operationsTargetFolder);
break;
$model->copyItems($selectItem, $operationsTargetFolder);
break;
case "bookmark":
$model->_bookmarkAdd($cbSelectItem);
$model->bookmarkAdd($selectItem);
break;
case "delete":
$model->_remove($cbSelectItem);
$model->removeItems($selectItem);
break;
case "hide":
$model->_set_visible($cbSelectItem, $itemURL, "hide");
$model->setVisible($selectItem, $itemURL, "hide");
break;
case "show":
$model->_set_visible($cbSelectItem, $itemURL, "show");
$model->setVisible($selectItem, $itemURL, "show");
break;
}
}

// RENAME
$rename = $this->input->getVar('rename');
$webSafe = array("/", " ", ":", ".", "+", "&");

if (!empty($rename))
{
Expand All @@ -130,14 +129,14 @@ public function agApply(): void
$originalName = JFile::stripExt(basename($renameKey));

// CREATE WEBSAFE TITLES
foreach ($webSafe as $key => $value)
foreach ($this->model->webSafe as $key => $value)
{
$newName = str_replace($value, "-", $renameValue);
$newName = str_replace($value, "-", $renameValue);
}

if ($originalName != $newName && !empty($renameValue))
{
$model->_rename($itemURL, $renameKey, $newName);
$model->renameItem($itemURL, $renameKey, $newName);
}
}
}
Expand All @@ -149,7 +148,7 @@ public function agApply(): void

if ($this->input->getVar('AG_folderSettings_status') == "edit")
{
$model->_folder_desc_content($itemURL, $descContent, $descTags, $folderThumb);
$model->setFolderDescription($itemURL, $descContent, $descTags, $folderThumb);
}
}
else
Expand All @@ -161,7 +160,7 @@ public function agApply(): void

if (!empty($descContent))
{
$model->_desc_content($itemURL, $descContent, $descTags);
$model->setDescriptionContent($itemURL, $descContent, $descTags);
}
}

Expand Down
67 changes: 55 additions & 12 deletions com_admirorgallery/admin/controllers/resourcemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,58 @@
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Language\Text as JText;

/**
* AdmirorgalleryControllerResourcemanager
*
* @since 1.0.0
*/
class AdmirorgalleryControllerResourcemanager extends AdmirorgalleryController
{
var $model;
/**
* model
*
* @var mixed
*
* @since 1.0.0
*/
public $model;

function __construct()
/**
* __construct
*
* @since 1.0.0
*/
public function __construct()
{
parent::__construct();

// Register Extra tasks
$this->registerTask('ag_install', 'ag_install');
$this->registerTask('ag_uninstall', 'ag_uninstall');
$this->registerTask('ag_reset', 'ag_reset');
$this->registerTask('installResource', 'installResource');
$this->registerTask('uninstallResource', 'uninstallResource');
$this->registerTask('resetResource', 'resetResource');

$this->model = $this->getModel('resourcemanager');
}

function ag_install()
/**
* installResource
*
* @return void
*
* @since 1.0.0
*/
public function installResource(): void
{
$file = $this->input->getVar('AG_fileUpload', null, 'files');

if (isset($file) && !empty($file['name']))
{
$this->model->_install($file);
$resourceType = $this->model->input->getVar('resourceType');

// Trim trailing directory separator
$resourceType = substr($resourceType, 0, strlen($resourceType) - 1);

$this->model->installResource($file, $resourceType, "zip", JFactory::getConfig()->get('tmp_path'));
}
else
{
Expand All @@ -46,19 +75,33 @@ function ag_install()
parent::display();
}

function ag_uninstall()
/**
* uninstallResource
*
* @return void
*
* @since 1.0.0
*/
public function uninstallResource(): void
{
$ag_cidArray = $this->input->getVar('cid');
$idsToRemove = $this->input->getVar('cid');

if (!empty($ag_cidArray))
if (!empty($idsToRemove))
{
$this->model->_uninstall($ag_cidArray);
$this->model->uninstallResource($idsToRemove, $this->model->input->getVar('resourceType'));
}

parent::display();
}

function ag_reset()
/**
* resetResource
*
* @return void
*
* @since 1.0.0
*/
public function resetResource(): void
{
parent::display();
}
Expand Down
18 changes: 10 additions & 8 deletions com_admirorgallery/admin/helpers/admirorgallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ abstract class AdmirorGalleryHelper
/**
* Configure the Linkbar
*
* @param string $submenu
* @param string $type
* @param string $submenu Submenu
* @param string $type Type
*
* @return void
*
* @since 5.5.0
*/
public static function addSubmenu(string $submenu, string $type)
public static function addSubmenu(string $submenu, string $type): void
{
JHtmlSidebar::addEntry(JText::_('COM_ADMIRORGALLERY_CONTROL_PANEL'),
'index.php?option=com_admirorgallery&controller=admirorgallery', $submenu == 'control_panel'
);
JHtmlSidebar::addEntry(JText::_('COM_ADMIRORGALLERY_TEMPLATES'),
'index.php?option=com_admirorgallery&view=resourcemanager&AG_resourceType=templates',
'index.php?option=com_admirorgallery&view=resourcemanager&resourceType=templates',
$type == 'templates'
);
JHtmlSidebar::addEntry(JText::_('COM_ADMIRORGALLERY_POPUPS'),
'index.php?option=com_admirorgallery&view=resourcemanager&AG_resourceType=popups',
'index.php?option=com_admirorgallery&view=resourcemanager&resourceType=popups',
$type == 'popups'
);
JHtmlSidebar::addEntry(JText::_('COM_ADMIRORGALLERY_IMAGE_MANAGER'),
Expand All @@ -53,14 +55,14 @@ public static function addSubmenu(string $submenu, string $type)
/**
* Read JInput values
*
* @param string $name
* @param $default
* @param string $name Name of the fieald we need walue from
* @param mixed $default Default value in case none is found
*
* @return string|null
*
* @since 5.5.0
*/
public static function getCmd(string $name, $default): ?string
public static function getCmd(string $name, mixed $default): ?string
{
try
{
Expand Down
22 changes: 17 additions & 5 deletions com_admirorgallery/admin/models/admirorgallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@
use Joomla\CMS\Language\Text as JText;
use Joomla\CMS\MVC\Model\BaseDatabaseModel as JModelLegacy;

/**
* AdmirorgalleryModelAdmirorgallery
*
* @since 1.0.0
*/
class AdmirorgalleryModelAdmirorgallery extends JModelLegacy
{
function _update()
/**
* update
*
* @return void
*
* @since 1.0.0
*/
public function update(): void
{
$AG_DB_input = '{';
$dbInput = '{';

foreach ($_POST['params'] as $key => $value)
{
$AG_DB_input .= '"' . $key . '":"' . $value . '",';
$dbInput .= '"' . $key . '":"' . $value . '",';
}

$AG_DB_input = substr_replace($AG_DB_input, '}', -1, 1);
$dbInput = substr_replace($dbInput, '}', -1, 1);

$db = JFactory::getDBO();
$query = "UPDATE #__extensions SET params='" . $AG_DB_input . "' WHERE (element = 'admirorgallery') AND (type = 'plugin')";
$query = "UPDATE #__extensions SET params='" . $dbInput . "' WHERE (element = 'admirorgallery') AND (type = 'plugin')";
$db->setQuery($query);

if ($db->execute())
Expand Down
5 changes: 5 additions & 0 deletions com_admirorgallery/admin/models/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

use Joomla\CMS\MVC\Model\BaseDatabaseModel as JModelLegacy;

/**
* AdmirorgalleryModelButton
*
* @since 1.0.0
*/
class AdmirorgalleryModelButton extends JModelLegacy
{
}
Loading

0 comments on commit e5733c0

Please sign in to comment.