MyiframeBase::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Myiframe;
4
5
/**
6
 * ****************************************************************************
7
 * MYIFRAME - MODULE FOR XOOPS
8
 * Copyright (c) Hervé Thouzard of Instant Zero (https://www.instant-zero.com)
9
 * ****************************************************************************
10
 */
11
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
12
13
/**
14
 * Class Myiframe
15
 */
16
class MyiframeBase extends \XoopsObject
17
{
18
    //    /** @var \XoopsMySQLDatabase */
19
    public $db;
20
21
    /**
22
     * myiframe constructor.
23
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
24
     */
25
    public function __construct($id = null)
26
    {
27
        $this->db = \XoopsDatabaseFactory::getDatabaseConnection();
28
        $this->initVar('frame_frameid', \XOBJ_DTYPE_INT, null, false, 10);
29
        $this->initVar('frame_created', \XOBJ_DTYPE_INT, null, false, 10);
30
        $this->initVar('frame_uid', \XOBJ_DTYPE_INT, null, false, 10);
31
        $this->initVar('frame_description', \XOBJ_DTYPE_TXTBOX, null, false, 255);
32
        $this->initVar('frame_width', \XOBJ_DTYPE_TXTBOX, null, false, 15);
33
        $this->initVar('frame_height', \XOBJ_DTYPE_TXTBOX, null, false, 15);
34
        $this->initVar('frame_align', \XOBJ_DTYPE_INT, null, false, 10);
35
        $this->initVar('frame_frameborder', \XOBJ_DTYPE_INT, null, false, 10);
36
        $this->initVar('frame_marginwidth', \XOBJ_DTYPE_INT, null, false, 10);
37
        $this->initVar('frame_marginheight', \XOBJ_DTYPE_INT, null, false, 10);
38
        $this->initVar('frame_scrolling', \XOBJ_DTYPE_INT, null, false, 10);
39
        $this->initVar('frame_hits', \XOBJ_DTYPE_INT, null, false, 10);
40
        $this->initVar('frame_url', \XOBJ_DTYPE_TXTBOX, null, false, 255);
41
        if (!empty($id)) {
42
            if (\is_array($id)) {
43
                $this->assignVars($id);
44
            } else {
45
                $this->load((int)$id);
46
            }
47
        } else {
48
            $this->setNew();
49
        }
50
    }
51
52
    /**
53
     * @param $id
54
     */
55
    public function load($id): void
56
    {
57
        $sql   = 'SELECT * FROM ' . $this->db->prefix('myiframe') . ' WHERE frame_frameid=' . (int)$id;
58
        $myrow = $this->db->fetchArray($this->db->query($sql));
59
        $this->assignVars($myrow);
60
        if (!$myrow) {
61
            $this->setNew();
62
        }
63
    }
64
}
65