|
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
|
|
|
use XoopsModules\Oledrion; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Gestion des fichies attachés aux produits |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class FilesHandler |
|
31
|
|
|
*/ |
|
32
|
|
|
class FilesHandler extends OledrionPersistableObjectHandler |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* FilesHandler constructor. |
|
36
|
|
|
* @param \XoopsDatabase|null $db |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
39
|
|
|
{ |
|
40
|
|
|
// Table Classe Id Libellé |
|
41
|
|
|
parent::__construct($db, 'oledrion_files', Files::class, 'file_id', 'file_filename'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Supprime un fichier (son fichier joint ET l'enregistrement dans la base de données) |
|
46
|
|
|
* |
|
47
|
|
|
* @param Files $file |
|
48
|
|
|
* @return bool Le résultat de la suppression |
|
49
|
|
|
*/ |
|
50
|
|
|
public function deleteAttachedFile(Files $file) |
|
51
|
|
|
{ |
|
52
|
|
|
if ($file->fileExists()) { |
|
53
|
|
|
$file->deleteAttachedFile(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->delete($file, true); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Retourne les fichiers attachés à un produit |
|
61
|
|
|
* |
|
62
|
|
|
* @param int $file_product_id L'Id du produit |
|
63
|
|
|
* @param int $start Position de départ |
|
64
|
|
|
* @param int $limit Nombre maxi de produits à retourner |
|
65
|
|
|
* @return array tableau d'objets de type Files |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getProductFiles($file_product_id, $start = 0, $limit = 0) |
|
68
|
|
|
{ |
|
69
|
|
|
$criteria = new \Criteria('file_product_id', $file_product_id, '='); |
|
70
|
|
|
$criteria->setStart($start); |
|
71
|
|
|
$criteria->setLimit($limit); |
|
72
|
|
|
|
|
73
|
|
|
return $this->getObjects($criteria); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Retourne le nombre de fichiers attachés à un produit qui sont des MP3 |
|
78
|
|
|
* |
|
79
|
|
|
* @param int $file_product_id L'Id du produit |
|
80
|
|
|
* @return int le nombre de fichiers MP3 |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getProductMP3Count($file_product_id) |
|
83
|
|
|
{ |
|
84
|
|
|
$criteria = new \CriteriaCompo(); |
|
85
|
|
|
$criteria->add(new \Criteria('file_product_id', $file_product_id, '=')); |
|
86
|
|
|
$criteria->add(new \Criteria('file_mimetype', 'audio/mpeg', '=')); |
|
87
|
|
|
|
|
88
|
|
|
return $this->getCount($criteria); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Retourne le nombre de fichiers attachés à un produit |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $file_product_id L'Id du produit |
|
95
|
|
|
* @return int le nombre de fichiers |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getProductFilesCount($file_product_id) |
|
98
|
|
|
{ |
|
99
|
|
|
$criteria = new \Criteria('file_product_id', $file_product_id, '='); |
|
100
|
|
|
|
|
101
|
|
|
return $this->getCount($criteria); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Supprime les fichiers attachés à un produit |
|
106
|
|
|
* |
|
107
|
|
|
* @param int $file_product_id L'Id du produit |
|
108
|
|
|
*/ |
|
109
|
|
|
public function deleteProductFiles($file_product_id) |
|
110
|
|
|
{ |
|
111
|
|
|
$files = []; |
|
|
|
|
|
|
112
|
|
|
$criteria = new \Criteria('file_product_id', $file_product_id, '='); |
|
113
|
|
|
$files = $this->getObjects($criteria); |
|
114
|
|
|
if (count($files) > 0) { |
|
115
|
|
|
foreach ($files as $file) { |
|
116
|
|
|
$file->deleteAttachedFile(); |
|
117
|
|
|
$this->delete($file, true); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|