Completed
Push — master ( 88111b...b3fce7 )
by Michael
05:58
created

MlObject::getEditLanguageLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php namespace XoopsModules\Smartobject;
2
3
/**
4
 * Contains the basis classes for managing any objects derived from SmartObjects
5
 *
6
 * @license    GNU
7
 * @author     marcan <[email protected]>
8
 * @link       http://smartfactory.ca The SmartFactory
9
 * @package    SmartObject
10
 * @subpackage SmartObjectCore
11
 */
12
13
use XoopsModules\Smartobject;
14
15
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
16
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
17
18
/**
19
 * SmartObject base Multilanguage-enabled class
20
 *
21
 * Base class representing a single SmartObject with multilanguages capabilities
22
 *
23
 * @package SmartObject
24
 * @author  marcan <[email protected]>
25
 * @link    http://smartfactory.ca The SmartFactory
26
 */
27
class MlObject extends Smartobject\BaseSmartObject
28
{
29
    /**
30
     * SmartMlObject constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
35
        $this->setControl('language', 'language');
36
    }
37
38
    /**
39
     * If object is not new, change the control of the not-multilanguage fields
40
     *
41
     * We need to intercept this function from SmartObject because if the object is not new...
42
     */
43
    // function getForm() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
45
    //}
46
47
    /**
48
     * Strip Multilanguage Fields
49
     *
50
     * Get rid of all the multilanguage fields to have an object with only global fields.
51
     * This will be usefull when creating the ML object for the first time. Then we will be able
52
     * to create translations.
53
     */
54 View Code Duplication
    public function stripMultilanguageFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $objectVars    =& $this->getVars();
57
        $newObjectVars = [];
58
        foreach ($objectVars as $key => $var) {
59
            if (!$var['multilingual']) {
60
                $newObjectVars[$key] = $var;
61
            }
62
        }
63
        $this->vars = $newObjectVars;
64
    }
65
66 View Code Duplication
    public function stripNonMultilanguageFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $objectVars    =& $this->getVars();
69
        $newObjectVars = [];
70
        foreach ($objectVars as $key => $var) {
71
            if ($var['multilingual'] || $key == $this->handler->keyName) {
72
                $newObjectVars[$key] = $var;
73
            }
74
        }
75
        $this->vars = $newObjectVars;
76
    }
77
78
    /**
79
     * Make non multilanguage fields read only
80
     *
81
     * This is used when we are creating/editing a translation.
82
     * We only want to edit the multilanguag fields, not the global one.
83
     */
84
    public function makeNonMLFieldReadOnly()
85
    {
86
        foreach ($this->getVars() as $key => $var) {
87
            //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
            if (!$var['multilingual'] && $key != $this->handler->keyName) {
89
                $this->setControl($key, 'label');
90
            }
91
        }
92
    }
93
94
    /**
95
     * @param  bool $onlyUrl
96
     * @param  bool $withimage
97
     * @return string
98
     */
99
    public function getEditLanguageLink($onlyUrl = false, $withimage = true)
100
    {
101
        $controller = new ObjectController($this->handler);
102
103
        return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
104
    }
105
}
106