Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

UrlField::newField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php namespace XoopsModules\Pedigree;
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * Pedigree module for XOOPS
13
 *
14
 * @copyright   {@link http://sourceforge.net/projects/thmod/ The TXMod XOOPS Project}
15
 * @copyright   {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
16
 * @license     GPL 2.0 or later
17
 * @package     pedigree
18
 * @subpackage  class
19
 * @author      XOOPS Mod Development Team
20
 */
21
22
use XoopsModules\Pedigree;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Pedigree. 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
24
25
/**
26
 * Class Pedigree\SelectBox
27
 */
28
class UrlField extends Pedigree\HtmlInputAbstract
29
{
30
    // Define class variables
31
    private $fieldnumber;
32
    private $fieldname;
33
    private $value;
34
    private $defaultvalue;
35
    private $lookuptable;
36
37
    /**
38
     * Constructor
39
     *
40
     * @param Field           $parentObject
41
     * @param Pedigree\Animal $animalObject
42
     */
43
    public function __construct($parentObject, $animalObject)
44
    {
45
        $this->fieldnumber  = $parentObject->getId();
46
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
47
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
48
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
49
        $this->lookuptable  = $parentObject->hasLookup();
50
        if ($this->lookuptable) {
51
            xoops_error('No lookuptable may be specified for userfield ' . $this->fieldnumber, get_class($this));
52
        }
53
        if ($parentObject->inAdvanced()) {
54
            xoops_error('userfield ' . $this->fieldnumber . ' cannot be shown in advanced info', get_class($this));
55
        }
56
        if ($parentObject->inPie()) {
57
            xoops_error('A Pie-chart cannot be specified for userfield ' . $this->fieldnumber, get_class($this));
58
        }
59
    }
60
61
    /**
62
     * @return \XoopsFormText
63
     */
64
    public function editField()
65
    {
66
        $textbox = new \XoopsFormText('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $size = 50, $maxsize = 255, $value = $this->value);
67
68
        return $textbox;
69
    }
70
71
    /**
72
     * @param string $name
73
     *
74
     * @return \XoopsFormText
75
     */
76
    public function newField($name = '')
77
    {
78
        $textbox = new \XoopsFormText('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $size = 50, $maxsize = 255, $value = $this->defaultvalue);
79
80
        return $textbox;
81
    }
82
83
    /**
84
     * @return \XoopsFormLabel
85
     */
86
    public function viewField()
87
    {
88
        $view = new \XoopsFormLabel($this->fieldname, '<a href="' . $this->value . '" target=\"_new\">' . $this->value . '</a>');
89
90
        return $view;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function showField()
97
    {
98
        return $this->fieldname . ' : <a href="' . $this->value . '" target="_new">' . $this->value . '</a>';
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function showValue()
105
    {
106
        return '<a href="' . $this->value . '" target="_new">' . $this->value . '</a>';
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function getSearchString()
113
    {
114
        return '&amp;o=naam&amp;l=1';
115
    }
116
117
    /**
118
     * @return mixed|void
119
     */
120
    public function searchField()
121
    {
122
        return null;
123
    }
124
}
125
126