Skip to content

Commit

Permalink
Merge pull request #38 from ggoffy/master
Browse files Browse the repository at this point in the history
preparation for php8; added search
  • Loading branch information
ggoffy authored Feb 21, 2021
2 parents b3d0589 + 6bcdbaa commit 21b96ba
Show file tree
Hide file tree
Showing 37 changed files with 304 additions and 137 deletions.
5 changes: 5 additions & 0 deletions _TODO.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
add style bootstrap

add search function

$indexDisplay ==

collection
16 changes: 16 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ ul.menu > li + li:before {
.wgt-icon24 {
height:24px;
}
.wgt-filter-row {
padding: 10px 0;
}
#formFilterIndex {
margin-bottom:50px;
}
.wgt-package-img {
padding: 0 10px 0 0 !important;
}
.wgt-package-img img{
margin-top: 15px !important;
}
.wgt-package-row {
border-bottom: 1px solid #cccccc;
padding: 10px 0 5px 0;
}
34 changes: 33 additions & 1 deletion class/PackagesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public function getFormAllPackages($action = false)
$form = new \XoopsThemeForm(\_AM_WGTRANSIFEX_PACKAGES_AUTOCREATE, 'form', $action, 'post', true);
$form->setExtra('enctype="multipart/form-data"');


// Form Table projects
$pkgProjectsSelect = new \XoopsFormSelect(\_AM_WGTRANSIFEX_PACKAGE_PRO_ID, 'pkgProIds', 0, 10, true);
$crProjects = new \CriteriaCompo();
Expand Down Expand Up @@ -174,6 +173,39 @@ public function getFormAllPackages($action = false)
return $form;
}

/**
* @public function getForm
* @param bool|string $action
* @param string $pkgFilterText
* @return \XoopsThemeForm
*/
public function getFormFilterPackages($action = false, $pkgFilterText = '')
{
$helper = Helper::getInstance();
$projectsHandler = $helper->getHandler('Projects');
//$resourcesHandler = $helper->getHandler('Resources');
$languagesHandler = $helper->getHandler('Languages');
if (!$action) {
$action = $_SERVER['REQUEST_URI'];
}

// Get Theme Form
\xoops_load('XoopsFormLoader');
$form = new \XoopsSimpleForm('', 'formFilterIndex', $action, 'post', true);
$form->setExtra('enctype="multipart/form-data"');
$searchTray = new \XoopsFormElementTray(\_AM_WGTRANSIFEX_PACKAGE_SEARCH . ': ', ' ');
// Form Table projects
$searchTray->addElement(new \XoopsFormText('', 'pkgFilterText', 50, 255, $pkgFilterText), true);
$searchTray->addElement(new \XoopsFormButton('', 'submit', \_SEARCH, 'submit'));
$searchTray->addElement(new \XoopsFormButton('', 'cancel', \_CANCEL, 'submit'));
$form->addElement($searchTray);
// To Save
$form->addElement(new \XoopsFormHidden('op', 'search'));


return $form;
}

/**
* @param string $dir
* @param string $pattern
Expand Down
4 changes: 2 additions & 2 deletions class/Transifex.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ public function readResources($resId, $proId)
$resourcesObj->setVar('res_i18n_type', $item['i18n_type']);
$resourcesObj->setVar('res_priority', $item['priority']);
$resourcesObj->setVar('res_slug', $item['slug']);
$resourcesObj->setVar('res_categories', $item['categories']);
$resourcesObj->setVar('res_metadata', $item['metadata']);
$resourcesObj->setVar('res_categories', serialize($item['categories']));
$resourcesObj->setVar('res_metadata', serialize($item['metadata']));
$resourcesObj->setVar('res_pro_id', $proId);
$resourcesObj->setVar('res_status', Constants::STATUS_READTX);
$resourcesObj->setVar('res_date', \time());
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- added download of module images from GitHub (goffy)
- fixed problem with strict_types (goffy)
- added image size (goffy)
- fixed smarty default problem (goffy)
- fixed data type bug (array/string) (goffy)
- fixed problem with display collections (goffy)
- added search to index page (goffy)

===================================================================
2020/12/13 Version 1.05 alpha
Expand Down
88 changes: 70 additions & 18 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,48 @@
$GLOBALS['xoopsTpl']->assign('wgtransifex_url', WGTRANSIFEX_URL);
$GLOBALS['xoopsTpl']->assign('modPathIconFlags', WGTRANSIFEX_IMAGE_URL . '/flags/');

$count = 1;


$indexDisplay = $helper->getConfig('index_display');
$start = Request::getInt('start', 0);
$limit = Request::getInt('limit', $helper->getConfig('userpager'));

//handle filter
if (Request::hasVar('cancel', '')) {
$pkgFilterText = '';
} else {
$pkgFilterText = Request::getString('pkgFilterText', '');
}
$form = $packagesHandler->getFormFilterPackages(false, $pkgFilterText);
$GLOBALS['xoopsTpl']->assign('formFilter', $form->render());
$GLOBALS['xoopsTpl']->assign('pkgFilterText', $pkgFilterText);
if ('' === $pkgFilterText) {
$GLOBALS['xoopsTpl']->assign('displayFormFilter', 'none');
$GLOBALS['xoopsTpl']->assign('btnFormFilterLabel', \_MA_WGTRANSIFEX_FILTER_SHOW);
} else {
$GLOBALS['xoopsTpl']->assign('displayFormFilter', 'block');
$GLOBALS['xoopsTpl']->assign('btnFormFilterLabel', \_MA_WGTRANSIFEX_FILTER_HIDE);
}

switch ($indexDisplay) {
case 'single':
default:
$packagesCount = $packagesHandler->getCountPackages();
$GLOBALS['xoopsTpl']->assign('isAdmin', is_object($xoopsUser) && $xoopsUser->isAdmin());
$count = 1;
$crPackages = new \CriteriaCompo();
if ('' !== $pkgFilterText) {
$crPkgFilter = new \CriteriaCompo();
$crPkgFilter->add(new \Criteria('pkg_name', '*' . $pkgFilterText . '*', 'LIKE'));
$crPkgFilter->add(new \Criteria('pkg_desc', '*' . $pkgFilterText . '*', 'LIKE'), 'OR');
$crPackages->add($crPkgFilter);
}
$packagesCount = $packagesHandler->getCount($crPackages);
$GLOBALS['xoopsTpl']->assign('packagesCount', $packagesCount);
if ($packagesCount > 0) {
$GLOBALS['xoopsTpl']->assign('displaySingle', true);
$packagesAll = $packagesHandler->getAllPackages($start, $limit, 'pkg_date', 'DESC');
$crPackages->setStart($start);
$crPackages->setLimit($limit);
$crPackages->setSort('pkg_date');
$crPackages->setOrder('DESC');
$packagesAll = $packagesHandler->getAll($crPackages);
// Get All Packages
$packages = [];
foreach (\array_keys($packagesAll) as $i) {
Expand All @@ -75,9 +103,8 @@
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
}
$GLOBALS['xoopsTpl']->assign('lang_thereare', \sprintf(\_MA_WGTRANSIFEX_INDEX_THEREARE, $packagesCount));
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
}
unset($count);
break;
case 'collection':
$GLOBALS['xoopsTpl']->assign('displayCollection', true);
Expand All @@ -93,19 +120,31 @@
$projectsAll = $projectsHandler->getAll($crProjects);
if ($projectsCount > 0) {
$packagesList = [];
// Get All Projects
if ('' !== $pkgFilterText) {
$crPkgFilter = new \CriteriaCompo();
$crPkgFilter->add(new \Criteria('pkg_name', '%' . $pkgFilterText . '%', 'LIKE'));
$crPkgFilter->add(new \Criteria('pkg_desc', '%' . $pkgFilterText . '%', 'LIKE'), 'OR');
}
// Get All Project
foreach (\array_keys($projectsAll) as $i) {
$pkgCounter = 0;
$languagesList = [];
//$projects[$i] = $projectsAll[$i]->getValuesProjects();
$proId = $projectsAll[$i]->getVar('pro_id');
//get list of packages
//get list of packages of primary language
$crPackages = new \CriteriaCompo();
$crPackages->add(new \Criteria('pkg_pro_id', $proId));
$crPackages->add(new \Criteria('pkg_lang_id', $langPrimary));
if ('' !== $pkgFilterText) {
$crPackages->add($crPkgFilter);
}
$packagesCount = $packagesHandler->getCount($crPackages);
$GLOBALS['xoopsTpl']->assign('packagesCount', $packagesCount);
$crPackages->setStart(0);
$crPackages->setLimit(1);
$pkgName = '';
$pkgLogo = '';
$pkgDesc = '';
$packagesAll = $packagesHandler->getAll($crPackages);
foreach (\array_keys($packagesAll) as $j) {
$package = $packagesAll[$j]->getValuesPackages();
Expand All @@ -121,11 +160,17 @@
'traperc_text' => $package['traperc_text'],
'date' => $package['date'],
];
$pkgCounter++;
}
unset($crPackages);

//get list of packages of other languages
$crPackages = new \CriteriaCompo();
$crPackages->add(new \Criteria('pkg_pro_id', $proId));
$crPackages->add(new \Criteria('pkg_lang_id', $langPrimary, '<>'));
if ('' !== $pkgFilterText) {
$crPackages->add($crPkgFilter);
}
$packagesCount = $packagesHandler->getCount($crPackages);
$GLOBALS['xoopsTpl']->assign('packagesCount', $packagesCount);
$packagesAll = $packagesHandler->getAll($crPackages);
Expand All @@ -140,29 +185,36 @@
'traperc_text' => $package['traperc_text'],
'date' => $package['date'],
];
$pkgCounter++;
}
$primary = array_column($languagesList, 'lang_primary');
$percentage = array_column($languagesList, 'traperc');
array_multisort($primary, SORT_DESC, $percentage, SORT_DESC, $languagesList);
if($pkgCounter > 0) {
$primary = array_column($languagesList, 'lang_primary');
$percentage = array_column($languagesList, 'traperc');
array_multisort($primary, SORT_DESC, $percentage, SORT_DESC, $languagesList);

$packagesList[$proId] = [
$packagesList[$proId] = [
'name' => $pkgName,
'logo' => $pkgLogo,
'desc' => $pkgDesc,
'langs' => $languagesList
];
}
}
// Display Navigation
if ($projectsCount > $limit) {
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
$pagenav = new \XoopsPageNav($projectsCount, $limit, $start, 'start', 'op=list&limit=' . $limit);
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
}
$GLOBALS['xoopsTpl']->assign('lang_thereare', \sprintf(\_MA_WGTRANSIFEX_INDEX_THEREARE, $packagesCount));
}
var_dump($packagesList);
$GLOBALS['xoopsTpl']->assign('packagesList', $packagesList);
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));

break;
}

unset($count);
$GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_MA_WGTRANSIFEX_INDEX];
// Keywords
Expand Down
5 changes: 5 additions & 0 deletions language/english/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
\define('_MA_WGTRANSIFEX_NOPERM', 'You do not have the necessary permissions');
\define('_MA_WGTRANSIFEX_FORM_OK', 'Successfully saved');
\define('_MA_WGTRANSIFEX_FORM_SURE_BROKEN', "Are you sure to notify as broken: <b><span style='color : Red;'>%s </span></b>");
\define('_MA_WGTRANSIFEX_FILTER_HIDE', 'Hide filter');
\define('_MA_WGTRANSIFEX_FILTER_SHOW', 'Show filter');
\define('_MA_WGTRANSIFEX_FILTER_RESULT', 'Result for filter');
// ---------------- Contents ----------------
// Project
\define('_MA_WGTRANSIFEX_PROJECT', 'Project');
Expand All @@ -59,6 +62,8 @@
\define('_MA_WGTRANSIFEX_PACKAGES_TITLE', 'List of available packages');
\define('_MA_WGTRANSIFEX_PACKAGES_DESC', 'Packages description');
\define('_MA_WGTRANSIFEX_PACKAGES_LIST', 'List of Packages');
\define('_MA_WGTRANSIFEX_PACKAGE_DETAILS', 'Details of Package');
\define('_AM_WGTRANSIFEX_PACKAGE_SEARCH', 'Search for Package');
// Caption of Package
\define('_MA_WGTRANSIFEX_PACKAGE_ID', 'Id');
\define('_MA_WGTRANSIFEX_PACKAGE_NAME', 'Language Package Name');
Expand Down
4 changes: 2 additions & 2 deletions language/english/modinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
\define('_MI_WGTRANSIFEX_PANEL_TYPE_DESC', 'Panel Type is the bootstrap html div.');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY', 'Index Display Type');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_DESC', 'Define how you want to display translations on index page.');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Each translation as single item');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Create for each resource a collection of all available translations');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Each packages as single item');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Create for each project a collection of all available language packages');
\define('_MI_WGTRANSIFEX_IDPAYPAL', 'Paypal ID');
\define('_MI_WGTRANSIFEX_IDPAYPAL_DESC', 'Insert here your PayPal ID for donactions.');
\define('_MI_WGTRANSIFEX_ADVERTISE', 'Advertisement Code');
Expand Down
5 changes: 5 additions & 0 deletions language/german/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
\define('_MA_WGTRANSIFEX_NOPERM', 'Du hast nicht die erforderlichen Berechtigungen');
\define('_MA_WGTRANSIFEX_FORM_OK', 'Erfolgreich gespeichert');
\define('_MA_WGTRANSIFEX_FORM_SURE_BROKEN', "Willst du wirklich als fehlerhaft melden: <b><span style='color : Red;'>%s </span></b>");
\define('_MA_WGTRANSIFEX_FILTER_HIDE', 'Filter ausblenden');
\define('_MA_WGTRANSIFEX_FILTER_SHOW', 'Filter anzeigen');
\define('_MA_WGTRANSIFEX_FILTER_RESULT', 'Ergebnis für Filter');
// ---------------- Contents ----------------
// Project
\define('_MA_WGTRANSIFEX_PROJECT', 'Projekt');
Expand All @@ -59,6 +62,8 @@
\define('_MA_WGTRANSIFEX_PACKAGES_TITLE', 'Liste der Pakete');
\define('_MA_WGTRANSIFEX_PACKAGES_DESC', 'Beschreibung des Pakets');
\define('_MA_WGTRANSIFEX_PACKAGES_LIST', 'Liste der Pakete');
\define('_MA_WGTRANSIFEX_PACKAGE_DETAILS', 'Details zu Paket');
\define('_AM_WGTRANSIFEX_PACKAGE_SEARCH', 'Suche nach Sprachpaket');
// Caption of Package
\define('_MA_WGTRANSIFEX_PACKAGE_ID', 'Id');
\define('_MA_WGTRANSIFEX_PACKAGE_NAME', 'Name Sprachpaket');
Expand Down
4 changes: 2 additions & 2 deletions language/german/modinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
\define('_MI_WGTRANSIFEX_PANEL_TYPE_DESC', 'Panel Type is the bootstrap html div.');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY', 'Anzeige Indexseite');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_DESC', 'Definiere wie die Übersetzungen auf der Indexseite angezeigt werden sollen.');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Jede Übersetzung als eigender Eintrag');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Erstelle eine Zusammenstellung aller Übersetzungen je Sprachressource');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Jedes Sprachpakete als eigender Eintrag');
\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Erstelle eine Zusammenstellung aller Sprachpakete je Projekt');
\define('_MI_WGTRANSIFEX_IDPAYPAL', 'Paypal ID');
\define('_MI_WGTRANSIFEX_IDPAYPAL_DESC', 'Deinen PayPal IDfür Spenden hier angeben.');
\define('_MI_WGTRANSIFEX_ADVERTISE', 'Code Werbung');
Expand Down
2 changes: 2 additions & 0 deletions languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
}
$GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('panel_type', $helper->getConfig('panel_type'));
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
}
Expand Down
3 changes: 3 additions & 0 deletions packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
} else {
$GLOBALS['xoopsTpl']->assign('link_list', 'packages.php');
}
$GLOBALS['xoopsTpl']->assign('isAdmin', is_object($xoopsUser) && $xoopsUser->isAdmin());

// Checking permissions
$request_allowed = false;
Expand Down Expand Up @@ -107,6 +108,8 @@
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
}
$GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('panel_type', $helper->getConfig('panel_type'));
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
}
Expand Down
2 changes: 2 additions & 0 deletions projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
}
$GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('panel_type', $helper->getConfig('panel_type'));
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
}
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/wgtransifex_admin_about.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<{includeq file='db:wgtransifex_admin_header.tpl' }>

<!-- About Page -->
<div class="top"><{$about}></div>
<div class="top"><{$about|default:''}></div>

<!-- Footer -->
<{includeq file='db:wgtransifex_admin_footer.tpl' }>
Loading

0 comments on commit 21b96ba

Please sign in to comment.