1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rudolf\Modules\Galleries\One\Admin; |
4
|
|
|
|
5
|
|
|
use Rudolf\Framework\Model\AdminModel; |
6
|
|
|
use Rudolf\Component\Modules\Module; |
7
|
|
|
|
8
|
|
|
class AddModel extends AdminModel |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Add article. |
12
|
|
|
* |
13
|
|
|
* @param array $data |
|
|
|
|
14
|
|
|
* |
15
|
|
|
* @return int |
16
|
|
|
*/ |
17
|
|
|
public function add($f) |
18
|
|
|
{ |
19
|
|
|
$userInfo = self::$auth->getUser(); |
20
|
|
|
$f['added'] = date('Y-m-d H:i:s'); |
21
|
|
|
$f['adder_ID'] = $userInfo['id']; |
22
|
|
|
|
23
|
|
|
$stmt = $this->pdo->prepare(" |
24
|
|
|
INSERT INTO {$this->prefix}galleries |
25
|
|
|
(title |
26
|
|
|
, added |
27
|
|
|
, adder_ID |
28
|
|
|
, slug |
29
|
|
|
, thumb_width |
30
|
|
|
, thumb_height) |
31
|
|
|
VALUES |
32
|
|
|
(:title |
33
|
|
|
, :added |
34
|
|
|
, :adder_ID |
35
|
|
|
, :slug |
36
|
|
|
, :thumb_width |
37
|
|
|
, :thumb_height) |
38
|
|
|
"); |
39
|
|
|
$stmt->bindValue(':title', $f['title'], \PDO::PARAM_STR); |
40
|
|
|
$stmt->bindValue(':added', $f['added'], \PDO::PARAM_STR); |
41
|
|
|
$stmt->bindValue(':adder_ID', $f['adder_ID'], \PDO::PARAM_INT); |
42
|
|
|
$stmt->bindValue(':slug', $f['slug'], \PDO::PARAM_STR); |
43
|
|
|
$stmt->bindValue(':thumb_width', $f['thumb_width'] ? $f['thumb_width'] : 209, \PDO::PARAM_INT); |
44
|
|
|
$stmt->bindValue(':thumb_height', $f['thumb_height'] ? $f['thumb_height'] : 157, \PDO::PARAM_INT); |
45
|
|
|
|
46
|
|
|
if (!$stmt->execute()) { |
47
|
|
|
return false; |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$id = $this->pdo->lastInsertId(); |
51
|
|
|
$config = (new Module('galleries'))->getConfig(); |
52
|
|
|
$directory = $config['path_root'].'/'.$f['slug']; |
53
|
|
|
|
54
|
|
|
if (file_exists($directory)) { |
55
|
|
|
$directory = $directory.'-'.$id; |
56
|
|
|
$stmt = $this->pdo->prepare("UPDATE {$this->prefix}galleries SET slug = :slug WHERE id = :id"); |
57
|
|
|
$stmt->bindValue(':slug', $f['slug'].'-'.$id, \PDO::PARAM_STR); |
58
|
|
|
$stmt->bindValue(':id', $id, \PDO::PARAM_INT); |
59
|
|
|
$stmt->execute(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
mkdir($directory); |
63
|
|
|
|
64
|
|
|
return $id; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.