Debug search on dolistore

This commit is contained in:
Laurent Destailleur 2017-09-12 21:02:18 +02:00
parent d340ce6380
commit 1a056d29d2
4 changed files with 173 additions and 160 deletions

View File

@ -20,145 +20,10 @@ include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
include_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/PSWebServiceLibrary.class.php';
/**
* Class DolistoreModel
*/
class DolistoreModel
{
function get_categories($parent = 0)
{
if (!isset($this->categories)) die('not possible');
if ($parent != 0) {
$html = '<ul>';
} else {
$html = '';
}
$nbofcateg = count($this->categories);
for ($i = 0; $i < $nbofcateg; $i++)
{
$cat = $this->categories[$i];
if ($cat->is_root_category == 1 && $parent == 0) {
$html .= '<li class="root"><h3 class="nomargesupinf"><a class="nomargesupinf link2cat" href="?mode=marketplace&categorie='.$cat->id.'" '
.'title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang])).'"'
.'>'.$cat->name->language[$this->lang].' <sup>'.$cat->nb_products_recursive.'</sup></a></h3>';
$html .= self::get_categories($cat->id);
$html .= "</li>\n";
} elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau
$select = ($cat->id == $this->categorie) ? ' selected' : '';
$html .= '<li><a class="link2cat'.$select.'" href="?mode=marketplace&categorie='.$cat->id.'"'
.' title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang])).'" '
.'>'.$cat->name->language[$this->lang].' <sup>'.$cat->nb_products_recursive.'</sup></a>';
$html .= self::get_categories($cat->id);
$html .= "</li>\n";
} else {
}
}
if ($html == '<ul>') {
return '';
}
if ($parent != 0) {
return $html.'</ul>';
} else {
return $html;
}
}
function get_products()
{
global $langs, $conf;
$html = "";
$parity = "pair";
$last_month = time() - (30 * 24 * 60 * 60);
foreach ($this->products as $product) {
$parity = ($parity == "impair") ? 'pair' : 'impair';
// check new product ?
$newapp = '';
if ($last_month < strtotime($product->date_add)) {
$newapp .= '<span class="newApp">'.$langs->trans('New').'</span> ';
}
// check updated ?
if ($last_month < strtotime($product->date_upd) && $newapp == '') {
$newapp .= '<span class="updatedApp">'.$langs->trans('Updated').'</span> ';
}
// add image or default ?
if ($product->id_default_image != '') {
$image_url = dol_buildPath('/dolistore/ajax/image.php?id_product=', 2).$product->id.'&id_image='.$product->id_default_image;
$images = '<a href="'.$image_url.'" class="fancybox" rel="gallery'.$product->id.'" title="'.$product->name->language[$this->lang].', '.$langs->trans('Version').' '.$product->module_version.'">'.
'<img src="'.$image_url.'&quality=home_default" style="max-height:250px;max-width: 210px;" alt="" /></a>';
} else {
$images = '<img src="'.dol_buildPath('/dolistore/img/NoImageAvailable.png', 2).'" />';
}
// free or pay ?
if ($product->price > 0) {
$price = '<h3>'.price(round((float) $product->price * $this->vat_rate, 2)).'&nbsp;&euro;</h3>';
$download_link = '<a target="_blank" href="'.$this->shop_url.$product->id.'"><img width="32" src="'.dol_buildPath('/dolistore/img/follow.png',
2).'" /></a>';
} else {
$price = $langs->trans('Free');
$download_link = '<a target="_blank" href="'.$this->shop_url.$product->id.'"><img width="32" src="'.dol_buildPath('/dolistore/img/Download-128.png',
2).'" /></a>';
}
//checking versions
if ($this->version_compare($product->dolibarr_min, DOL_VERSION) <= 0) {
if ($this->version_compare($product->dolibarr_max, DOL_VERSION) >= 0) {
//compatible
$version = '<span class="compatible">'.$langs->trans('CompatibleUpTo', $product->dolibarr_max,
$product->dolibarr_min, $product->dolibarr_max).'</span>';
$compatible = '';
} else {
//never compatible, module expired
$version = '<span class="notcompatible">'.$langs->trans('NotCompatible', DOL_VERSION,
$product->dolibarr_min, $product->dolibarr_max).'</span>';
$compatible = 'NotCompatible';
}
} else {
//need update
$version = '<span class="compatibleafterupdate">'.$langs->trans('CompatibleAfterUpdate', DOL_VERSION,
$product->dolibarr_min, $product->dolibarr_max).'</span>';
$compatible = 'NotCompatible';
}
//output template
$html .= '<tr class="app '.$parity.' '.$compatible.'">
<td align="center" width="210"><div class="newAppParent">'.$newapp.$images.'</div></td>
<td class="margeCote"><h2 class="appTitle"><a target="_blank" href="'.$this->shop_url.$product->id.'">'.$product->name->language[$this->lang].'</a><span class="details button">Details</span>'
.'<br/><small>'.$version.'</small></h2>
<small> '.dol_print_date(strtotime($product->date_upd)).' - '.$langs->trans('Référence').': '.$product->reference.' - '.$langs->trans('Id').': '.$product->id.'</small><br><br>'.$product->description_short->language[$this->lang].'</td>
<td style="display:none;" class="long_description">'.$product->description->language[$this->lang].'</td>
<td class="margeCote" align="right">'.$price.'</td>
<td class="margeCote">'.$download_link.'</td>
</tr>';
}
return $html;
}
function get_previous_link($text = '<<')
{
return '<a href="'.$this->get_previous_url().'" class="button">'.$text.'</a>';
}
function get_next_link($text = '>>')
{
return '<a href="'.$this->get_next_url().'" class="button">'.$text.'</a>';
}
}
/**
* Class Dolistore
*/
class Dolistore extends DolistoreModel
class Dolistore
{
// params
public $start // beginning of pagination
@ -173,6 +38,11 @@ class Dolistore extends DolistoreModel
, $lang // the integer representing the lang in the store
, $debug_api; // usefull if no dialog
/**
* Constructor
*
* @param array $options
*/
function __construct($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0))
{
global $conf, $langs;
@ -254,6 +124,139 @@ class Dolistore extends DolistoreModel
}
}
function get_categories($parent = 0)
{
if (!isset($this->categories)) die('not possible');
if ($parent != 0) {
$html = '<ul>';
} else {
$html = '';
}
$nbofcateg = count($this->categories);
for ($i = 0; $i < $nbofcateg; $i++)
{
$cat = $this->categories[$i];
if ($cat->is_root_category == 1 && $parent == 0) {
$html .= '<li class="root"><h3 class="nomargesupinf"><a class="nomargesupinf link2cat" href="?mode=marketplace&categorie='.$cat->id.'" '
.'title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang])).'"'
.'>'.$cat->name->language[$this->lang].' <sup>'.$cat->nb_products_recursive.'</sup></a></h3>';
$html .= self::get_categories($cat->id);
$html .= "</li>\n";
} elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau
$select = ($cat->id == $this->categorie) ? ' selected' : '';
$html .= '<li><a class="link2cat'.$select.'" href="?mode=marketplace&categorie='.$cat->id.'"'
.' title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang])).'" '
.'>'.$cat->name->language[$this->lang].' <sup>'.$cat->nb_products_recursive.'</sup></a>';
$html .= self::get_categories($cat->id);
$html .= "</li>\n";
} else {
}
}
if ($html == '<ul>') {
return '';
}
if ($parent != 0) {
return $html.'</ul>';
} else {
return $html;
}
}
/**
* Return list of product formated for output
*
* @return string HTML output
*/
function get_products()
{
global $langs, $conf;
$html = "";
$parity = "pair";
$last_month = time() - (30 * 24 * 60 * 60);
foreach ($this->products as $product) {
$parity = ($parity == "impair") ? 'pair' : 'impair';
// check new product ?
$newapp = '';
if ($last_month < strtotime($product->date_add)) {
$newapp .= '<span class="newApp">'.$langs->trans('New').'</span> ';
}
// check updated ?
if ($last_month < strtotime($product->date_upd) && $newapp == '') {
$newapp .= '<span class="updatedApp">'.$langs->trans('Updated').'</span> ';
}
// add image or default ?
if ($product->id_default_image != '') {
$image_url = DOL_URL_ROOT.'/dolistore/ajax/image.php?id_product='.$product->id.'&id_image='.$product->id_default_image;
$images = '<a href="'.$image_url.'" class="fancybox" rel="gallery'.$product->id.'" title="'.$product->name->language[$this->lang].', '.$langs->trans('Version').' '.$product->module_version.'">'.
'<img src="'.$image_url.'&quality=home_default" style="max-height:250px;max-width: 210px;" alt="" /></a>';
} else {
$images = '<img src="'.DOL_URL_ROOT.'/dolistore/img/NoImageAvailable.png" />';
}
// free or pay ?
if ($product->price > 0) {
$price = '<h3>'.price(round((float) $product->price * $this->vat_rate, 2)).'&nbsp;&euro;</h3>';
$download_link = '<a target="_blank" href="'.$this->shop_url.$product->id.'"><img width="32" src="'.DOL_URL_ROOT.'/admin/dolistore/img/follow.png" /></a>';
} else {
$price = '<h3>'.$langs->trans('Free').'</h3>';
$download_link = '<a target="_blank" href="'.$this->shop_url.$product->id.'"><img width="32" src="'.DOL_URL_ROOT.'/admin/dolistore/img/Download-128.png" /></a>';
$download_link.= '<br><br><a target="_blank" href="'.$this->shop_url.$product->id.'"><img width="32" src="'.DOL_URL_ROOT.'/admin/dolistore/img/follow.png" /></a>';
}
//checking versions
if ($this->version_compare($product->dolibarr_min, DOL_VERSION) <= 0) {
if ($this->version_compare($product->dolibarr_max, DOL_VERSION) >= 0) {
//compatible
$version = '<span class="compatible">'.$langs->trans('CompatibleUpTo', $product->dolibarr_max,
$product->dolibarr_min, $product->dolibarr_max).'</span>';
$compatible = '';
} else {
//never compatible, module expired
$version = '<span class="notcompatible">'.$langs->trans('NotCompatible', DOL_VERSION,
$product->dolibarr_min, $product->dolibarr_max).'</span>';
$compatible = 'NotCompatible';
}
} else {
//need update
$version = '<span class="compatibleafterupdate">'.$langs->trans('CompatibleAfterUpdate', DOL_VERSION,
$product->dolibarr_min, $product->dolibarr_max).'</span>';
$compatible = 'NotCompatible';
}
//.'<br><a class="inline-block valignmiddle" target="_blank" href="'.$this->shop_url.$product->id.'"><span class="details button">'.$langs->trans("SeeInMarkerPlace").'</span></a>
//output template
$html .= '<tr class="app '.$parity.' '.$compatible.'">
<td align="center" width="210"><div class="newAppParent">'.$newapp.$images.'</div></td>
<td class="margeCote"><h2 class="appTitle">'.$product->name->language[$this->lang]
.'<br/><small>'.$version.'</small></h2>
<small> '.dol_print_date(dol_stringtotime($product->date_upd), 'dayhour').' - '.$langs->trans('Ref').': '.$product->reference.' - '.$langs->trans('Id').': '.$product->id.'</small><br><br>'.$product->description_short->language[$this->lang].'</td>
<td style="display:none;" class="long_description">'.$product->description->language[$this->lang].'</td>
<td class="margeCote" align="center">'.$price.'
</td>
<td class="margeCote">'.$download_link.'</td>
</tr>';
}
return $html;
}
function get_previous_link($text = '<<')
{
return '<a href="'.$this->get_previous_url().'" class="button">'.$text.'</a>';
}
function get_next_link($text = '>>')
{
return '<a href="'.$this->get_next_url().'" class="button">'.$text.'</a>';
}
function get_previous_url()
{
$param_array = array();

View File

@ -115,7 +115,9 @@ div.divsearchfield {
tr.app {
height:250px;
}
tr.app td {
border-bottom: 1px solid #888;
}
div#newsDoli.tabBar {
margin-top: 50px;
margin-right: 30px;
@ -225,6 +227,7 @@ tr.NotCompatible:hover{
}
#listing-content{
width: 75%;
float: right;
}
}
span.details{

View File

@ -832,44 +832,50 @@ if ($mode == 'marketplace')
if (empty($conf->global->MAIN_DISABLE_DOLISTORE_SEARCH) && $conf->global->MAIN_FEATURES_LEVEL >= 1)
{
print '<span class="opacitymedium">'.$langs->trans('DOLISTOREdescriptionLong').'</span>';
print '<span class="opacitymedium">'.$langs->trans('DOLISTOREdescriptionLong').'</span><br><br>';
$previouslink = $dolistore->get_previous_link();
$nextlink = $dolistore->get_next_link();
print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">'
?>
<br><br>
<div class="tabBar">
<form method="POST" id="searchFormList" action="<?php echo $dolistore->url ?>">
<form method="POST" class="centpercent" id="searchFormList" action="<?php echo $dolistore->url ?>">
<input type="hidden" name="mode" value="marketplace" />
<div class="divsearchfield"><?php echo $langs->trans('Mot-cle') ?>:
<div class="divsearchfield"><?php echo $langs->trans('Keyword') ?>:
<input name="search_keyword" placeholder="<?php echo $langs->trans('Chercher un module') ?>" id="search_keyword" type="text" size="50" value="<?php echo $options['search'] ?>"><br>
</div>
<div class="divsearchfield">
<input class="button butAction searchDolistore" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
<a class="button butActionDelete" href="<?php echo $dolistore->url ?>"><?php echo $langs->trans('Tout afficher') ?></a>
</div><br><br><br style="clear: both">
<input class="button" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
<a class="button" href="<?php echo $dolistore->url ?>"><?php echo $langs->trans('Reset') ?></a>
&nbsp;
</div>
<div class="divsearchfield right">
<?php
print $previouslink;
print $nextlink;
?>
</div>
</form>
</div>
<?php
print '</div></div>';
print '<div class="clearboth"></div>';
?>
<div id="category-tree-left">
<ul class="tree">
<?php echo $dolistore->get_categories(); ?>
</ul>
</div>
<div id="listing-content">
<table summary="list_of_modules" id="list_of_modules" class="liste" width="100%">
<thead>
<tr class="liste_titre">
<td colspan="100%"><?php echo $dolistore->get_previous_link() ?> <?php echo $dolistore->get_next_link() ?> <span style="float:right"><?php echo $langs->trans('AchatTelechargement') ?></span></td>
</tr>
</thead>
<table summary="list_of_modules" id="list_of_modules" class="productlist centpercent">
<tbody id="listOfModules">
<?php echo $dolistore->get_products($categorie); ?>
</tbody>
<tfoot>
<tr class="liste_titre">
<td colspan="100%"><?php echo $dolistore->get_previous_link() ?> <?php echo $dolistore->get_next_link() ?> <span style="float:right"><?php echo $langs->trans('AchatTelechargement') ?></span></td>
</tr>
</tfoot>
</table>
</div>

View File

@ -201,8 +201,9 @@ DOLISTOREdescriptionLong=Instead of switching on <a href="https://www.dolistore.
NewModule=New
FreeModule=Free
CompatibleUpTo=Compatible with version %s
NotCompatible=This module does not seem compatible with your Dolibarr %s, contact its editor (%s - %s).
CompatibleAfterUpdate=This module requires an update to your Dolibarr %s, installed dolibarr %s - %s.
NotCompatible=This module does not seem compatible with your Dolibarr %s (Min %s - Max %s).
CompatibleAfterUpdate=This module requires an update to your Dolibarr %s (Min %s - Max %s).
SeeInMarkerPlace=See in Market place
Updated=Updated
Nouveauté=Novelty
AchatTelechargement=Buy / Download