Skip to content

Commit

Permalink
move editFile() to Utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mambax7 committed Dec 27, 2020
1 parent 145b01f commit 8475bac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
47 changes: 1 addition & 46 deletions admin/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,6 @@

$op = Request::getString('op');

/**
* @param bool $showmenu
* @param int $fileid
* @param int $itemId
*/
function publisher_editFile($showmenu = false, $fileid = 0, $itemId = 0)
{
$helper = Helper::getInstance();
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');

// if there is a parameter, and the id exists, retrieve data: we're editing a file
if (0 != $fileid) {
// Creating the File object
/** @var \XoopsModules\Publisher\File $fileObj */
$fileObj = $helper->getHandler('File')->get($fileid);

if ($fileObj->notLoaded()) {
redirect_header('<script>javascript:history.go(-1)</script>', 1, _AM_PUBLISHER_NOFILESELECTED);
}

echo "<br>\n";
echo "<span style='color: #2F5376; font-weight: bold; font-size: 16px; margin: 6px 6px 0 0; '>" . _AM_PUBLISHER_FILE_EDITING . '</span>';
echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_PUBLISHER_FILE_EDITING_DSC . '</span>';
Utility::openCollapsableBar('editfile', 'editfileicon', _AM_PUBLISHER_FILE_INFORMATIONS);
} else {
// there's no parameter, so we're adding an item
$fileObj = $helper->getHandler('File')->create();
$fileObj->setVar('itemid', $itemId);
echo "<span style='color: #2F5376; font-weight: bold; font-size: 16px; margin: 6px 6px 0 0; '>" . _AM_PUBLISHER_FILE_ADDING . '</span>';
echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_PUBLISHER_FILE_ADDING_DSC . '</span>';
Utility::openCollapsableBar('addfile', 'addfileicon', _AM_PUBLISHER_FILE_INFORMATIONS);
}

// FILES UPLOAD FORM
/** @var File $fileObj */
$uploadForm = $fileObj->getForm();
$uploadForm->display();

if (0 != $fileid) {
Utility::closeCollapsableBar('editfile', 'editfileicon');
} else {
Utility::closeCollapsableBar('addfile', 'addfileicon');
}
}

//$itemObj = null;
/* -- Available operations -- */
switch ($op) {
Expand All @@ -93,7 +48,7 @@ function publisher_editFile($showmenu = false, $fileid = 0, $itemId = 0)
Utility::cpHeader();
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');

publisher_editFile(true, $fileid, $itemId);
Utility::editFile(true, $fileid, $itemId);
break;
case 'modify':
$fileid = Request::getInt('fileid', 0, 'POST');
Expand Down
46 changes: 46 additions & 0 deletions class/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,52 @@ public static function displayCategory(Category $categoryObj, $level = 0)
// unset($categoryObj);
}


/**
* @param bool $showmenu
* @param int $fileid
* @param int $itemId
*/
public static function editFile($showmenu = false, $fileid = 0, $itemId = 0)
{
$helper = Helper::getInstance();
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');

// if there is a parameter, and the id exists, retrieve data: we're editing a file
if (0 != $fileid) {
// Creating the File object
/** @var \XoopsModules\Publisher\File $fileObj */
$fileObj = $helper->getHandler('File')->get($fileid);

if ($fileObj->notLoaded()) {
redirect_header('<script>javascript:history.go(-1)</script>', 1, _AM_PUBLISHER_NOFILESELECTED);
}

echo "<br>\n";
echo "<span style='color: #2F5376; font-weight: bold; font-size: 16px; margin: 6px 6px 0 0; '>" . _AM_PUBLISHER_FILE_EDITING . '</span>';
echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_PUBLISHER_FILE_EDITING_DSC . '</span>';
static::openCollapsableBar('editfile', 'editfileicon', _AM_PUBLISHER_FILE_INFORMATIONS);
} else {
// there's no parameter, so we're adding an item
$fileObj = $helper->getHandler('File')->create();
$fileObj->setVar('itemid', $itemId);
echo "<span style='color: #2F5376; font-weight: bold; font-size: 16px; margin: 6px 6px 0 0; '>" . _AM_PUBLISHER_FILE_ADDING . '</span>';
echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_PUBLISHER_FILE_ADDING_DSC . '</span>';
static::openCollapsableBar('addfile', 'addfileicon', _AM_PUBLISHER_FILE_INFORMATIONS);
}

// FILES UPLOAD FORM
/** @var File $fileObj */
$uploadForm = $fileObj->getForm();
$uploadForm->display();

if (0 != $fileid) {
static::closeCollapsableBar('editfile', 'editfileicon');
} else {
static::closeCollapsableBar('addfile', 'addfileicon');
}
}

/**
* @param bool $showmenu
* @param int $categoryId
Expand Down

0 comments on commit 8475bac

Please sign in to comment.