|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Oledrion; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* oledrion |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
19
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
20
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Gestion des listes utilisateurs |
|
25
|
|
|
* |
|
26
|
|
|
* @since 2.3.2009.06.13 |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
use XoopsModules\Oledrion; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class Lists |
|
33
|
|
|
*/ |
|
34
|
|
|
class Lists extends OledrionObject |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* constructor |
|
38
|
|
|
* |
|
39
|
|
|
* normally, this is called from child classes only |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->initVar('list_id', XOBJ_DTYPE_INT, null, false); |
|
44
|
|
|
$this->initVar('list_uid', XOBJ_DTYPE_INT, null, false); |
|
45
|
|
|
$this->initVar('list_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
46
|
|
|
$this->initVar('list_date', XOBJ_DTYPE_INT, null, false); |
|
47
|
|
|
$this->initVar('list_productscount', XOBJ_DTYPE_INT, null, false); |
|
48
|
|
|
$this->initVar('list_views', XOBJ_DTYPE_INT, null, false); |
|
49
|
|
|
$this->initVar('list_password', XOBJ_DTYPE_TXTBOX, null, false); |
|
50
|
|
|
$this->initVar('list_type', XOBJ_DTYPE_INT, null, false); |
|
51
|
|
|
$this->initVar('list_description', XOBJ_DTYPE_OTHER, null, false); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Indique si la liste courante est accessible de l'utilisateur courant |
|
56
|
|
|
* |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function isSuitableForCurrentUser() |
|
60
|
|
|
{ |
|
61
|
|
|
$uid = Oledrion\Utility::getCurrentUserID(); |
|
62
|
|
|
if (Constants::OLEDRION_LISTS_PRIVATE == $this->getVar('list_type')) { |
|
63
|
|
|
if (0 == $uid || $uid != $this->getVar('list_uid')) { |
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return true; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Retourne un tableau associatif qui pour chaque type de liste indique son type sous forme de texte |
|
73
|
|
|
* |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function getTypesArray() |
|
77
|
|
|
{ |
|
78
|
|
|
return [ |
|
79
|
|
|
Constants::OLEDRION_LISTS_PRIVATE => _OLEDRION_LIST_PRIVATE, |
|
80
|
|
|
Constants::OLEDRION_LISTS_WISH => _OLEDRION_LIST_PUBLIC_WISH_LIST, |
|
81
|
|
|
Constants::OLEDRION_LISTS_RECOMMEND => _OLEDRION_LIST_PUBLIC_RECOMMENDED_LIST, |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Retourne la description de la liste courante |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getListTypeDescription() |
|
91
|
|
|
{ |
|
92
|
|
|
$description = static::getTypesArray(); |
|
93
|
|
|
|
|
94
|
|
|
return $description[$this->list_type]; |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Retourne l'url à utiliser pour accéder à la liste en tenant compte des préférences du module |
|
99
|
|
|
* |
|
100
|
|
|
* @return string L'url à utiliser |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getLink() |
|
103
|
|
|
{ |
|
104
|
|
|
$url = ''; |
|
105
|
|
|
if (1 == Oledrion\Utility::getModuleOption('urlrewriting')) { |
|
106
|
|
|
// On utilise l'url rewriting |
|
107
|
|
|
$url = OLEDRION_URL . 'list-' . $this->getVar('list_id') . Oledrion\Utility::makeSeoUrl($this->getVar('list_title', 'n')) . '.html'; |
|
|
|
|
|
|
108
|
|
|
} else { |
|
109
|
|
|
// Pas d'utilisation de l'url rewriting |
|
110
|
|
|
$url = OLEDRION_URL . 'list.php?list_id=' . $this->getVar('list_id'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $url; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Retourne la date de création de la liste formatée |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $format |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getFormatedDate($format = 's') |
|
123
|
|
|
{ |
|
124
|
|
|
return formatTimestamp($this->list_date, $format); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Rentourne la chaine à utiliser dans une balise <a> pour l'attribut href |
|
129
|
|
|
* |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getHrefTitle() |
|
133
|
|
|
{ |
|
134
|
|
|
return Oledrion\Utility::makeHrefTitle($this->getVar('list_title')); |
|
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Retourne le nom de l'auteur de la liste courante |
|
139
|
|
|
* |
|
140
|
|
|
* @return string |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getListAuthorName() |
|
143
|
|
|
{ |
|
144
|
|
|
return \XoopsUser::getUnameFromId($this->getVar('list_uid', true)); |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Retourne les éléments formatés pour affichage (en général) |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $format |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
|
|
public function toArray($format = 's') |
|
154
|
|
|
{ |
|
155
|
|
|
$ret = []; |
|
|
|
|
|
|
156
|
|
|
$ret = parent::toArray($format); |
|
157
|
|
|
$ret['list_type_description'] = $this->getListTypeDescription(); |
|
158
|
|
|
$ret['list_href_title'] = $this->getHrefTitle(); |
|
159
|
|
|
$ret['list_url_rewrited'] = $this->getLink(); |
|
160
|
|
|
$ret['list_formated_date'] = $this->getFormatedDate(); |
|
161
|
|
|
$ret['list_username'] = $this->getListAuthorName(); |
|
162
|
|
|
$ret['list_formated_count'] = sprintf(_OLEDRION_PRODUCTS_COUNT, $this->getVar('list_productscount')); |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
return $ret; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|