Passed
Push — master ( a42092...8afea9 )
by Goffy
03:23
created

Favorite   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getNewInsertedId() 0 3 1
A getValuesFavorite() 0 24 3
A __construct() 0 7 1
A getInstance() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace XoopsModules\Wgfilemanager;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
*/
17
18
/**
19
 * wgFileManager module for xoops
20
 *
21
 * @copyright    2021 XOOPS Project (https://xoops.org)
22
 * @license      GPL 2.0 or later
23
 * @package      wgfilemanager
24
 * @since        1.0
25
 * @min_xoops    2.5.9
26
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
27
 */
28
29
use XoopsModules\Wgfilemanager;
30
31
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
32
33
/**
34
 * Class Object Mimetype
35
 */
36
class Favorite extends \XoopsObject
37
{
38
    /**
39
     * Constructor
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->initVar('id', \XOBJ_DTYPE_INT);
45
        $this->initVar('directory_id', \XOBJ_DTYPE_INT);
46
        $this->initVar('file_id', \XOBJ_DTYPE_INT);
47
        $this->initVar('date_created', \XOBJ_DTYPE_INT);
48
        $this->initVar('submitter', \XOBJ_DTYPE_INT);
49
    }
50
51
    /**
52
     * @static function &getInstance
53
     *
54
     */
55
    public static function getInstance()
56
    {
57
        static $instance = false;
58
        if (!$instance) {
59
            $instance = new self();
60
        }
61
    }
62
63
    /**
64
     * The new inserted $Id
65
     * @return integer
66
     */
67
    public function getNewInsertedId()
68
    {
69
        return $GLOBALS['xoopsDB']->getInsertId();
70
    }
71
72
    /**
73
     * Get Values
74
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
75
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
76
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
77
     * @return array
78
     */
79
    public function getValuesFavorite($keys = null, $format = null, $maxDepth = null)
80
    {
81
        $helper  = \XoopsModules\Wgfilemanager\Helper::getInstance();
82
83
        $ret = $this->getValues($keys, $format, $maxDepth);
84
        $directoryHandler = $helper->getHandler('Directory');
85
        $directoryObj = $directoryHandler->get($this->getVar('directory_id'));
86
        $ret['dir_name'] = '';
87
        if (\is_object($directoryObj)) {
88
            $ret['dir_name'] = $directoryObj->getVar('name');
89
        } else {
90
            $ret['dir_name'] = 'error get dir name';
91
        }
92
        $fileHandler = $helper->getHandler('File');
93
        $fileObj = $fileHandler->get($this->getVar('file_id'));
94
        $ret['file_name'] = '';
95
        if (\is_object($fileObj)) {
96
            $ret['file_name'] = $fileObj->getVar('name');
97
        } else {
98
            $ret['file_name'] = 'error get file name';
99
        }
100
        $ret['date_created_text'] = \formatTimestamp($this->getVar('date_created'), 's');
101
        $ret['submitter_text']    = \XoopsUser::getUnameFromId($this->getVar('submitter'));
102
        return $ret;
103
    }
104
}
105