|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* **************************************************************************** |
|
4
|
|
|
* bookshop - MODULE FOR XOOPS |
|
5
|
|
|
* Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
|
6
|
|
|
* **************************************************************************** |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Shows last recommended books |
|
11
|
|
|
* |
|
12
|
|
|
* @param $options |
|
13
|
|
|
* |
|
14
|
|
|
* @return array|bool |
|
15
|
|
|
*/ |
|
16
|
|
|
function b_bookshop_recomm_show($options) |
|
17
|
|
|
{ |
|
18
|
|
|
// '10|0'; // See 10 books, for all categories or a particular category |
|
19
|
|
|
global $xoopsConfig, $xoopsTpl; |
|
|
|
|
|
|
20
|
|
|
include XOOPS_ROOT_PATH . '/modules/bookshop/include/common.php'; |
|
21
|
|
|
$tblLivres = $tblCategories = $tblTmp = $tbl_tmp_vat = $tbl_vat = $tbl_tmp_lang = $block = $tbl_books_id = array(); |
|
|
|
|
|
|
22
|
|
|
$tblLivres = $h_bookshop_books->getRecentRecommendedBooks(0, $options[0], $options[1]); |
|
|
|
|
|
|
23
|
|
|
if ($h_bookshop_books->getRecommendedCount() > $options[0]) { // Il y a plus de livres recommand�s dans la BDD que dans le bloc, on affiche donc un lien vers la page des livres recommand�s |
|
24
|
|
|
$block['showMore'] = true; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
if (count($tblLivres) > 0) { |
|
28
|
|
|
$url = BOOKSHOP_URL . 'assets/css/bookshop.css'; |
|
29
|
|
|
$block['nostock_msg'] = bookshop_getmoduleoption('nostock_msg'); |
|
30
|
|
|
$xoopsTpl->assign('xoops_module_header', "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\" />"); |
|
31
|
|
|
$tblTmp = array(); |
|
32
|
|
|
foreach ($tblLivres as $item) { |
|
33
|
|
|
$tblTmp[] = $item->getVar('book_cid'); |
|
34
|
|
|
$tbl_tmp_vat[] = $item->getVar('book_vat_id'); |
|
35
|
|
|
$tbl_tmp_lang[] = $item->getVar('book_lang_id'); |
|
36
|
|
|
$tbl_books_id[] = $item->getVar('book_id'); |
|
37
|
|
|
} |
|
38
|
|
|
$tblTmp = array_unique($tblTmp); |
|
39
|
|
|
$tbl_tmp_vat = array_unique($tbl_tmp_vat); |
|
40
|
|
|
$tbl_tmp_lang = array_unique($tbl_tmp_lang); |
|
41
|
|
|
|
|
42
|
|
|
sort($tbl_tmp_lang); |
|
43
|
|
|
sort($tblTmp); |
|
44
|
|
|
sort($tbl_tmp_vat); |
|
45
|
|
|
sort($tbl_books_id); |
|
46
|
|
|
|
|
47
|
|
|
// Get languages ******************************************* |
|
48
|
|
|
if (count($tbl_tmp_lang) > 0) { |
|
49
|
|
|
$tbl_lang = $h_bookshop_lang->getObjects(new Criteria('lang_id', '(' . implode(',', $tbl_tmp_lang) . ')', 'IN'), true); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// Get the list of categories **************************** |
|
53
|
|
|
$tblCategories = $h_bookshop_cat->getObjects(new Criteria('cat_cid', '(' . implode(',', $tblTmp) . ')', 'IN'), true); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
// Get VAT *********************************************** |
|
56
|
|
|
if (count($tbl_tmp_vat) > 0) { |
|
57
|
|
|
$tbl_vat = $h_bookshop_vat->getObjects(new Criteria('vat_id', '(' . implode(',', $tbl_tmp_vat) . ')', 'IN'), true); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// Get the authors, deuxi�me partie ************************** |
|
61
|
|
|
$tbl_books_auteurs = array(); |
|
62
|
|
|
$tbl_auteurs = $h_bookshop_booksauthors->getObjects(new Criteria('ba_book_id', '(' . implode(',', $tbl_books_id) . ')', 'IN'), true); |
|
|
|
|
|
|
63
|
|
|
if (count($tbl_auteurs) > 0) { |
|
64
|
|
|
foreach ($tbl_auteurs as $item) { |
|
65
|
|
|
$tbl_tmp_auteurs[] = $item->getVar('ba_auth_id'); |
|
|
|
|
|
|
66
|
|
|
// Grouping data by book |
|
67
|
|
|
$tbl_books_auteurs[$item->getVar('ba_book_id')][] = $item; |
|
68
|
|
|
} |
|
69
|
|
|
$tbl_tmp_auteurs = array_unique($tbl_tmp_auteurs); |
|
|
|
|
|
|
70
|
|
|
sort($tbl_tmp_auteurs); |
|
71
|
|
|
// Then recovered the information from these authors / translators |
|
72
|
|
|
$tbl_infos_auteurs = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tbl_tmp_auteurs) . ')', 'IN'), true); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
foreach ($tblLivres as $item) { |
|
75
|
|
|
$tbl_tmp = array(); |
|
|
|
|
|
|
76
|
|
|
$tbl_tmp = $item->toArray(); |
|
77
|
|
|
$tbl_tmp['book_category'] = $tblCategories[$item->getVar('book_cid')]; |
|
78
|
|
|
$tbl_tmp['book_language'] = $tbl_lang[$item->getVar('book_lang_id')]; |
|
|
|
|
|
|
79
|
|
|
$tbl_tmp['book_vat_rate'] = $tbl_vat[$item->getVar('book_vat_id')]; |
|
80
|
|
|
$tbl_tmp['book_price_ttc'] = bookshop_getTTC($item->getVar('book_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
|
81
|
|
|
$tbl_tmp['book_discount_price_ttc'] = bookshop_getTTC($item->getVar('book_discount_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
|
82
|
|
|
|
|
83
|
|
|
// Search for authors / translators |
|
84
|
|
|
$tbl_join1 = $tbl_join2 = array(); |
|
85
|
|
|
$tbl_tmp2 = $tbl_books_auteurs[$item->getVar('book_id')]; // Returns a list of all authors / translators of a book |
|
86
|
|
|
$tbl_livre_auteurs = $tbl_livre_traducteurs = array(); |
|
87
|
|
|
foreach ($tbl_tmp2 as $oneauthor) { |
|
88
|
|
|
$auteur = $tbl_infos_auteurs[$oneauthor->getVar('ba_auth_id')]; |
|
|
|
|
|
|
89
|
|
|
if ($oneauthor->getVar('ba_type') == 1) { |
|
90
|
|
|
$tbl_livre_auteurs[] = $auteur->toArray(); |
|
91
|
|
|
$tbl_join1[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
|
92
|
|
|
} else { |
|
93
|
|
|
$tbl_livre_traducteurs[] = $auteur->toArray(); |
|
94
|
|
|
$tbl_join2[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
if (count($tbl_join1) > 0) { |
|
98
|
|
|
$tbl_tmp['book_joined_authors'] = implode(', ', $tbl_join1); |
|
99
|
|
|
} |
|
100
|
|
|
if (count($tbl_join2) > 0) { |
|
101
|
|
|
$tbl_tmp['book_joined_translators'] = implode(',', $tbl_join2); |
|
102
|
|
|
} |
|
103
|
|
|
$tbl_tmp['book_authors'] = $tbl_livre_auteurs; |
|
104
|
|
|
$tbl_tmp['book_translators'] = $tbl_livre_traducteurs; |
|
105
|
|
|
// Et on place le tout dans le template |
|
106
|
|
|
$block['block_books'][] = $tbl_tmp; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $block; |
|
110
|
|
|
} else { // The list of books is not found (it is not books sold in the stock books) |
|
111
|
|
|
|
|
112
|
|
|
return false; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Block settings |
|
118
|
|
|
* @param $options |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
function b_bookshop_recomm_edit($options) |
|
122
|
|
|
{ |
|
123
|
|
|
// '10|0'; // See 10 books, for all categories |
|
124
|
|
|
global $xoopsConfig; |
|
|
|
|
|
|
125
|
|
|
include XOOPS_ROOT_PATH . '/modules/bookshop/include/common.php'; |
|
126
|
|
|
include_once BOOKSHOP_PATH . 'class/tree.php'; |
|
127
|
|
|
$tblCategories = array(); |
|
|
|
|
|
|
128
|
|
|
$tblCategories = $h_bookshop_cat->GetAllCategories(); |
|
|
|
|
|
|
129
|
|
|
$mytree = new Bookshop_XoopsObjectTree($tblCategories, 'cat_cid', 'cat_pid'); |
|
130
|
|
|
$form = ''; |
|
131
|
|
|
$checkeds = array('', ''); |
|
132
|
|
|
if (!isset($options[1])) { |
|
133
|
|
|
$options[1] = 0; |
|
134
|
|
|
} |
|
135
|
|
|
$checkeds[$options[1]] = 'checked'; |
|
136
|
|
|
$form .= "<table border='0'>"; |
|
137
|
|
|
$form .= '<tr><td>' . _MB_BOOKSHOP_BOOKS_CNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>"; |
|
138
|
|
|
//$form .= '<tr><td>'._MB_BOOKSHOP_SORT_ORDER."</td><td><input type='radio' name='options[]' id='options[]' value='0' ".$checkeds[0]." />"._MB_BOOKSHOP_SORT_1." <input type='radio' name='options[]' id='options[]' value='1' ".$checkeds[1]." />"._MB_BOOKSHOP_SORT_2.'</td></tr>'; |
|
|
|
|
|
|
139
|
|
|
$select = $mytree->makeSelBox('options[]', 'cat_title', '-', $options[1], _MB_BOOKSHOP_ALL_CATEGORIES); |
|
140
|
|
|
$form .= '<tr><td>' . _MB_BOOKSHOP_CATEGORY . '</td><td>' . $select . '</td></tr>'; |
|
141
|
|
|
$form .= '</table>'; |
|
142
|
|
|
|
|
143
|
|
|
return $form; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Ad hoc Block |
|
148
|
|
|
* @param $options |
|
149
|
|
|
*/ |
|
150
|
|
View Code Duplication |
function b_bookshop_recomm_duplicatable($options) |
|
|
|
|
|
|
151
|
|
|
{ |
|
152
|
|
|
$options = explode('|', $options); |
|
153
|
|
|
$block = &b_bookshop_recomm_show($options); |
|
154
|
|
|
|
|
155
|
|
|
$tpl = new XoopsTpl(); |
|
156
|
|
|
$tpl->assign('block', $block); |
|
157
|
|
|
$tpl->display('db:bookshop_block_recommended.tpl'); |
|
158
|
|
|
} |
|
159
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state