1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// ------------------------------------------------------------------------ // |
3
|
|
|
// BOOKSHOP - MODULE FOR XOOPS 2 // |
4
|
|
|
// Copyright (c) 2007, 2008 Instant Zero // |
5
|
|
|
// <http://www.instant-zero.com/> // |
6
|
|
|
// ------------------------------------------------------------------------- // |
7
|
|
|
// This program is free software; you can redistribute it and/or modify // |
8
|
|
|
// it under the terms of the GNU General Public License as published by // |
9
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
10
|
|
|
// (at your option) any later version. // |
11
|
|
|
// // |
12
|
|
|
// You may not change or alter any portion of this comment or credits // |
13
|
|
|
// of supporting developers from this source code or any supporting // |
14
|
|
|
// source code which is considered copyrighted (c) material of the // |
15
|
|
|
// original comment or credit authors. // |
16
|
|
|
// // |
17
|
|
|
// This program is distributed in the hope that it will be useful, // |
18
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20
|
|
|
// GNU General Public License for more details. // |
21
|
|
|
// // |
22
|
|
|
// You should have received a copy of the GNU General Public License // |
23
|
|
|
// along with this program; if not, write to the Free Software // |
24
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
25
|
|
|
// ------------------------------------------------------------------------ // |
26
|
|
|
|
27
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
28
|
|
|
|
29
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
30
|
|
|
if (!class_exists('Bookshop_XoopsPersistableObjectHandler')) { |
31
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/bookshop/class/PersistableObjectHandler.php'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class bookshop_cat |
36
|
|
|
*/ |
37
|
|
|
class bookshop_cat extends Bookshop_Object |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
$this->initVar('cat_cid', XOBJ_DTYPE_INT, null, false); |
42
|
|
|
$this->initVar('cat_pid', XOBJ_DTYPE_INT, null, false); |
43
|
|
|
$this->initVar('cat_title', XOBJ_DTYPE_TXTBOX, null, false); |
44
|
|
|
$this->initVar('cat_imgurl', XOBJ_DTYPE_TXTBOX, null, false); |
45
|
|
|
$this->initVar('cat_description', XOBJ_DTYPE_TXTAREA, null, false); |
46
|
|
|
$this->initVar('cat_advertisement', XOBJ_DTYPE_TXTAREA, null, false); |
47
|
|
|
$this->initVar('cat_metakeywords', XOBJ_DTYPE_TXTBOX, null, false); |
48
|
|
|
$this->initVar('cat_metadescription', XOBJ_DTYPE_TXTBOX, null, false); |
49
|
|
|
$this->initVar('cat_metatitle', XOBJ_DTYPE_TXTBOX, null, false); |
50
|
|
|
// Pour autoriser le html |
51
|
|
|
$this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Class BookshopBookshop_catHandler |
57
|
|
|
*/ |
58
|
|
|
class BookshopBookshop_catHandler extends Bookshop_XoopsPersistableObjectHandler |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
/** |
61
|
|
|
* @param $db |
62
|
|
|
*/ |
63
|
|
|
public function __construct($db) |
64
|
|
|
{ // Table Classe Id |
65
|
|
|
parent::__construct($db, 'bookshop_cat', 'bookshop_cat', 'cat_cid'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Renvoie (sous forme d'objet) la liste de toutes les catégories |
70
|
|
|
* |
71
|
|
|
* @param integer $start Indice de début de recherche |
72
|
|
|
* @param integer $limit Nombre maximum d'enregsitrements à renvoyer |
73
|
|
|
* @param string $sort Champ à utiliser pour le tri |
74
|
|
|
* @param string $order Ordre du tire (asc ou desc) |
75
|
|
|
* @param boolean $idaskey Indique s'il faut renvoyer un tableau dont la clé est l'identifiant de l'enregistrement |
76
|
|
|
* @return array Taleau d'objets (catégories) |
77
|
|
|
*/ |
78
|
|
|
public function GetAllCategories($start = 0, $limit = 0, $sort = 'cat_title', $order = 'ASC', $idaskey = true) |
79
|
|
|
{ |
80
|
|
|
$critere = new Criteria('cat_cid', 0, '<>'); |
81
|
|
|
$critere->setLimit($limit); |
82
|
|
|
$critere->setStart($start); |
83
|
|
|
$critere->setSort($sort); |
84
|
|
|
$critere->setOrder($order); |
85
|
|
|
$tbl_categs = array(); |
86
|
|
|
$tbl_categs =& $this->getObjects($critere, $idaskey); |
87
|
|
|
|
88
|
|
|
return $tbl_categs; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Renvoie le lien à utiliser pour aller vers une catégorie |
93
|
|
|
* |
94
|
|
|
* @param integer $cat_id Identifiant de la catégorie |
|
|
|
|
95
|
|
|
* @param string $cat_title Titre de la catégorie |
96
|
|
|
* |
97
|
|
|
* @internal param int $cat_id Identifiant de la cat�gorie |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function GetCategoryLink($cat_cid, $cat_title) |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$url = ''; |
|
|
|
|
103
|
|
|
if (bookshop_getmoduleoption('urlrewriting') == 1) { // On utilise l'url rewriting |
104
|
|
|
$url = BOOKSHOP_URL . 'category-' . (int)$cat_cid . bookshop_makeSEOurl($cat_title) . '.html'; |
105
|
|
|
} else { // Pas d'utilisation de l'url rewriting |
106
|
|
|
$url = BOOKSHOP_URL . 'category.php?cat_cid=' . (int)$cat_cid; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $url; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.