Completed
Branch master (b4ab83)
by Mikołaj
03:16
created

DelModel::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Galleries\One\Admin;
4
5
use Rudolf\Framework\Model\AdminModel;
6
use Rudolf\Component\Modules\Module;
7
use Rudolf\Modules\Galleries\One;
8
9
class DelModel extends AdminModel
10
{
11
    /**
12
     * Delete gallery.
13
     *
14
     * @param int $id gallery ID
15
     */
16
    public function delete($id)
17
    {
18
        $query = $this->pdo->prepare("DELETE FROM {$this->prefix}galleries WHERE id = :id");
19
        $query->bindValue(':id', $id, \PDO::PARAM_INT);
20
21
        $f = (new One\Model())->getGalleryInfoById($id);
22
        $config = (new Module('galleries'))->getConfig();
23
        $directory = $config['path_root'].'/'.$f['slug'];
24
        array_map('unlink', glob($directory.'/*'));
25
        rmdir($directory);
26
27
        return $query->execute();
28
    }
29
}
30