Passed
Push — master ( 005d4f...8b5e26 )
by Michael
06:49
created

Picture::getSearchString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace XoopsModules\Pedigree;
3
4
/*
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 */
13
14
/**
15
 * @package         XoopsModules\Pedigree
16
 * @copyright       {@link https://xoops.org/ XOOPS Project}
17
 * @license         {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author          XOOPS Module Dev Team
19
 */
20
21
use XoopsModules\Pedigree\{
22
    Animal,
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Animal. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
23
    Field,
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Field. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
    Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Helper. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
};
26
27
/**
28
 * Class Picture
29
 */
30
class Picture extends HtmlInputAbstract
31
{
32
    /** @TODO: make file size a module Preferences config setting */
33
    private const MAXFILESIZE = 1024000;
34
35
    protected $fieldnumber  = 0;
36
    protected $fieldname    = '';
37
    protected $value        = null;
38
    protected $defaultvalue = '';
39
    protected $lookuptable  = 0;
40
    private $helper = null;
41
42
/**
43
     * @param Field  $parentObject
44
     * @param Animal $animalObject
45
     */
46
    public function __construct(Field $parentObject, Animal $animalObject)
47
    {
48
        $this->helper       = Helper::getInstance();
49
        $this->fieldnumber  = $parentObject->getId();
50
        $this->fieldname    = $parentObject->getSetting('fieldname');
51
        $this->value        = $animalObject->{'user' . (string) $this->fieldnumber};
52
        $this->defaultvalue = $parentObject->getSetting('defaultvalue');
53
        $this->lookuptable  = $parentObject->hasLookup();
54
55
        /** @TODO move hard coded language strings to language files */
56
        if ($this->lookuptable) {
57
            xoops_error('No lookuptable may be specified for userfield ' . $this->fieldnumber);
58
        }
59
        if ($parentObject->inAdvanced()) {
60
            xoops_error('userfield ' . $this->fieldnumber . ' cannot be shown in advanced info', get_class($this));
61
        }
62
        if ($parentObject->inPie()) {
63
            xoops_error('A Pie-chart cannot be specified for userfield ' . $this->fieldnumber, get_class($this));
64
        }
65
        if ('1' == $parentObject->viewinlist) {
0 ignored issues
show
Bug introduced by
The property viewinlist does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
66
            xoops_error('userfield ' . $this->fieldnumber . ' cannot be included in listview', get_class($this));
67
        }
68
        if ('1' == $parentObject->hassearch) {
0 ignored issues
show
Bug introduced by
The property hassearch does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
69
            xoops_error('Search cannot be defined for userfield ' . $this->fieldnumber, get_class($this));
70
        }
71
    }
72
73
    /**
74
     * @return \XoopsFormFile
75
     */
76
    public function editField(): \XoopsFormFile
77
    {
78
        $picturefield = new \XoopsFormFile($this->fieldname, 'user' . $this->fieldnumber, self::MAXFILESIZE);
79
        $picturefield->setExtra("size ='50'");
80
81
        return $picturefield;
82
    }
83
84
    /**
85
     * @param null|string $name
86
     *
87
     * @return \XoopsFormFile
88
     */
89
    public function newField($name = ''): \XoopsFormFile
90
    {
91
        $picturefield = new \XoopsFormFile($this->fieldname, $name . 'user' . $this->fieldnumber, self::MAXFILESIZE);
92
        $picturefield->setExtra("size ='50'");
93
94
        return $picturefield;
95
    }
96
97
    /**
98
     * @return \XoopsFormLabel
99
     */
100
    public function viewField(): \XoopsFormLabel
101
    {
102
        $view = new \XoopsFormLabel($this->fieldname, '<img src="' . $this->helper->uploadUrl('images/thumbnails/' . $this->value . '_400.jpeg') . '">');
103
104
        return $view;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function showField(): string
111
    {
112
        return '<img src="' . $this->helper->uploadUrl('images/thumbnails/' . $this->value . '_150.jpeg') . '">';
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function showValue(): string
119
    {
120
        return '<img src="' . $this->helper->uploadUrl('images/thumbnails/' . $this->value . '_400.jpeg') . '">';
121
    }
122
}
123