Skip to content

Commit

Permalink
- fixed problem with display collections
Browse files Browse the repository at this point in the history
 - added search to index page
  • Loading branch information
ggoffy committed Feb 21, 2021
1 parent 873c95b commit 6bcdbaa
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 34 deletions.
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
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- 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
70 changes: 60 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,44 @@
$start = Request::getInt('start', 0);
$limit = Request::getInt('limit', $helper->getConfig('userpager'));

$form = $packagesHandler->getFormSearchPackages();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
//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:
$GLOBALS['xoopsTpl']->assign('isAdmin', is_object($xoopsUser) && $xoopsUser->isAdmin());
$count = 1;
$packagesCount = $packagesHandler->getCountPackages();
$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 Down Expand Up @@ -95,15 +120,24 @@
$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);
Expand All @@ -126,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 @@ -145,18 +185,28 @@
'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));
}
$GLOBALS['xoopsTpl']->assign('packagesList', $packagesList);
break;
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
40 changes: 34 additions & 6 deletions templates/wgtransifex_index.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<{include file='db:wgtransifex_header.tpl' }>

<{if $form|default:''}>
<{$form}>
<{/if}>
<script>
$(document).ready(function(){
$("#toggleFormFilter").click(function(){
$("#formFilter").toggle(1000);
if (document.getElementById("toggleFormFilter").innerText === "<{$smarty.const._MA_WGTRANSIFEX_FILTER_HIDE}>") {
document.getElementById("toggleFormFilter").innerText = "<{$smarty.const._MA_WGTRANSIFEX_FILTER_SHOW}>";
} else {
document.getElementById("toggleFormFilter").innerText = "<{$smarty.const._MA_WGTRANSIFEX_FILTER_HIDE}>";
}
});
});
</script>
<!-- Start index list -->
<table>
Expand Down Expand Up @@ -31,8 +40,28 @@
</table>
<!-- End index list -->
<{if $pagenav|default:'' != ''}>
<div class="row wgt-filter-row">
<div class="col-sm-12">
<a id="toggleFormFilter" class='btn btn-default pull-right' href='#' title='<{$btnFormFilterLabel}>'><{$btnFormFilterLabel}></a>
</div>
<{if $formFilter|default:''}>
<div id="formFilter" class="wgt-formFilter" style="display:<{$displayFormFilter}>">
<div class="col-sm-12"><{$formFilter}></div>
</div>
<{/if}>
</div>
<{/if}>
<div class='wgtransifex-linetitle'>
<{if $pkgFilterText|default:''}>
<{$smarty.const._MA_WGTRANSIFEX_FILTER_RESULT}>: <{$pkgFilterText}>
<{else}>
<{$smarty.const._MA_WGTRANSIFEX_INDEX_LATEST_LIST}>
<{/if}>
</div>
<{if $displaySingle|default:''}>
<div class='wgtransifex-linetitle'><{$smarty.const._MA_WGTRANSIFEX_INDEX_LATEST_LIST}></div>
<{if $packagesCount|default:0 > 0}>
<!-- Start show new packages in index -->
<table class='table table-<{$table_type}>'>
Expand All @@ -53,13 +82,12 @@
<{/if}>
<{if $displayCollection|default:''}>
<div class='wgtransifex-linetitle'><{$smarty.const._MA_WGTRANSIFEX_INDEX_LATEST_LIST}></div>
<{if $projectsCount|default:0 > 0}>
<table class='table table-<{$table_type}>'>
<tr>
<!-- Start new link loop -->
<{foreach item=packages from=$packagesList}>
<td class='col_width<{$numb_col}> top center'>
<td class='col_width<{$numb_col}> top'>
<{include file='db:wgtransifex_packages_prolist.tpl' packages=$packages}>
</td>
<{if $packages|@count is div by $divideby}>
Expand Down
27 changes: 14 additions & 13 deletions templates/wgtransifex_packages_prolist.tpl
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<div class='panel-body-'>
<div class='col-xs-12 col-sm-3 col-md-3 col-lg-3'>
<div class='panel-body'>
<div class='col-xs-12 col-sm-3 col-md-3 col-lg-3 wgt-package-img'>
<img class='img-responsive' src="<{$wgtransifex_upload_url}>/logos/<{$packages.logo}>" alt="<{$packages.name}>" title="<{$packages.name}>">
</div>
<div class='col-xs-12 col-sm-8 col-md-8 col-lg-8'>
<div class='package-line-'><{$smarty.const._MA_WGTRANSIFEX_PACKAGE_NAME}>: <{$packages.name}></div>
<{if $packages.desc|default:''}>
<div class='package-line-'><{$smarty.const._MA_WGTRANSIFEX_PACKAGE_DESC}>: <{$packages.desc}></div>
<{/if}>
<div class="row wgt-package-row">
<p><{$smarty.const._MA_WGTRANSIFEX_PACKAGE_NAME}>: <{$packages.name}></p>
<{if $packages.desc|default:''}>
<p><{$smarty.const._MA_WGTRANSIFEX_PACKAGE_DESC}>: <{$packages.desc}></p>
<{/if}>
</div>
<{foreach item=pkglang from=$packages.langs}>
<div class="row">
<div class="row wgt-package-row">
<div class="pull-left">
<img src="<{$modPathIconFlags}><{$pkglang.lang_flag}>" alt="<{$pkglang.lang_id}>" title="<{$pkglang.lang_id}>">
<{$pkglang.lang_id}>
<i class="fa fa-globe" title="<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_TRAPERC}>"></i><{$pkglang.traperc_text}>
<img src="<{$modPathIconFlags}><{$pkglang.lang_flag}>" alt="<{$pkglang.lang_id}>" title="<{$pkglang.lang_id}>"> <{$pkglang.lang_id}>
<i class="fa fa-globe" title="<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_TRAPERC}>"></i> <{$pkglang.traperc_text}>
<i class="fa fa-calendar" title="<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_DATE}>"></i>&nbsp;<{$pkglang.date}>
</div>
<div class="pull-right">
<a class='btn btn-default' href='packages.php?op=show_index&amp;pkg_id=<{$pkglang.pkg_id}>' title='<{$smarty.const._MA_WGTRANSIFEX_DETAILS}>'>
<a class='btn btn-primary' href='packages.php?op=show_index&amp;pkg_id=<{$pkglang.pkg_id}>' title='<{$smarty.const._MA_WGTRANSIFEX_DETAILS}>'>
<i class="fa fa-search" title="<{$smarty.const._MA_WGTRANSIFEX_DETAILS}>"></i>
</a>
<a class='btn btn-default' href='download.php?op=package&amp;pkg_id=<{$pkglang.pkg_id}>' title='<{$smarty.const._MA_WGTRANSIFEX_DOWNLOAD_PACKAGE}>'>
<i class="fa fa-download" title="<{$smarty.const._MA_WGTRANSIFEX_DOWNLOAD}>"></i>
<a class='btn btn-success' href='download.php?op=package&amp;pkg_id=<{$pkglang.pkg_id}>' title='<{$smarty.const._MA_WGTRANSIFEX_DOWNLOAD_PACKAGE}>'>
<i class="fa fa-download" title="<{$smarty.const._MA_WGTRANSIFEX_DOWNLOAD_PACKAGE}>"></i>
</a>
</div>
</div>
Expand Down

0 comments on commit 6bcdbaa

Please sign in to comment.