GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

documentModel   F
last analyzed

Complexity

Total Complexity 308

Size/Duplication

Total Lines 1628
Duplicated Lines 17.26 %

Coupling/Cohesion

Components 2
Dependencies 10

Importance

Changes 0
Metric Value
dl 281
loc 1628
rs 0.8
c 0
b 0
f 0
wmc 308
lcom 2
cbo 10

42 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A isGranted() 0 4 1
A getDocumentExtraVarsFromDB() 0 12 3
D setToAllDocumentExtraVars() 0 76 22
A getDocument() 0 18 6
C getDocuments() 16 52 11
F getDocumentList() 0 127 28
B getNoticeList() 14 31 7
C getExtraKeys() 0 83 13
A getExtraVars() 0 12 3
C getDocumentMenu() 37 85 11
A getDocumentCount() 0 10 2
A getDocumentCountByGroupStatus() 0 7 2
A getDocumentExtraVarsCount() 0 16 1
B getDocumentPage() 21 50 7
A getCategory() 0 22 3
A getCategoryChlidCount() 0 8 2
A getCategoryList() 0 20 3
C _arrangeCategory() 0 54 11
A getCategoryDocumentCount() 0 8 1
A getCategoryXmlFile() 10 10 2
A getCategoryPhpFile() 10 10 2
B getMonthlyArchivedList() 20 20 6
A getDailyArchivedList() 21 21 5
A getDocumentCategories() 0 17 4
A getDocumentConfig() 0 15 3
A getExtraVarsHTML() 0 12 1
A getCategoryHTML() 20 20 1
A getDocumentCategoryTplInfo() 0 20 3
A getDocumentSrlByAlias() 0 12 4
A getDocumentSrlByTitle() 0 14 5
A getAlias() 0 10 3
A getHistories() 0 9 1
A getHistory() 0 7 1
F getTrashList() 19 76 37
B getDocumentVotedMemberList() 18 45 10
A getStatusNameList() 0 7 2
B _setSortIndex() 0 36 7
F _setSearchOption() 62 255 67
A getDocumentCountByMemberSrl() 0 7 1
A getDocumentListByMemberSrl() 13 13 3
A getDocumentExtraImagePath() 0 15 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like documentModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use documentModel, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* Copyright (C) XEHub <https://www.xehub.io> */
3
/**
4
 * documentModel class
5
 * model class of the module document
6
 *
7
 * @author XEHub ([email protected])
8
 * @package /modules/document
9
 * @version 0.1
10
 */
11
class documentModel extends document
12
{
13
	private $documentConfig = NULL;
14
15
	/**
16
	 * Initialization
17
	 * @return void
18
	 */
19
	function init()
20
	{
21
	}
22
23
	/**
24
	 * document checked the permissions on the session values
25
	 * @param int $document_srl
26
	 * @return void
27
	 */
28
	function isGranted($document_srl)
29
	{
30
		return $_SESSION['own_document'][$document_srl];
31
	}
32
33
	/**
34
	 * Return document extra information from database
35
	 * @param array $documentSrls
36
	 * @return object
37
	 */
38
	function getDocumentExtraVarsFromDB($documentSrls)
39
	{
40
		if(!is_array($documentSrls) || count($documentSrls) == 0)
41
		{
42
			return new BaseObject(-1, 'msg_invalid_request');
43
		}
44
45
		$args = new stdClass();
46
		$args->document_srl = $documentSrls;
47
		$output = executeQueryArray('document.getDocumentExtraVars', $args);
48
		return $output;
49
	}
50
51
	/**
52
	 * Extra variables for each article will not be processed bulk select and apply the macro city
53
	 * @return void
54
	 */
55
	function setToAllDocumentExtraVars()
56
	{
57
		static $checked_documents = array();
58
		$_document_list = &$GLOBALS['XE_DOCUMENT_LIST'];
59
60
		// XE XE_DOCUMENT_LIST all documents that the object referred to the global variable settings
61
		if(count($_document_list) <= 0) return;
62
63
		// Find all called the document object variable has been set extension
64
		$document_srls = array();
65
		foreach($_document_list as $key => $val)
66
		{
67
			if(!$val->document_srl || $checked_documents[$val->document_srl]) continue;
68
			$checked_documents[$val->document_srl] = true;
69
			$document_srls[] = $val->document_srl;
70
		}
71
		// If the document number, return detected
72
		if(!count($document_srls)) return;
73
		// Expand variables mijijeongdoen article about a current visitor to the extension of the language code, the search variable
74
		//$obj->document_srl = implode(',',$document_srls);
75
		$output = $this->getDocumentExtraVarsFromDB($document_srls);
76
		if($output->toBool() && $output->data)
77
		{
78
			foreach($output->data as $key => $val)
79
			{
80
				if(!isset($val->value)) continue;
81
				if(!$extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0]) $extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0] = trim($val->value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$extra_vars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $extra_vars = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $extra_vars does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
82
				$extra_vars[$val->document_srl][$val->var_idx][$val->lang_code] = trim($val->value);
83
			}
84
		}
85
86
		$user_lang_code = Context::getLangType();
87
		for($i=0,$c=count($document_srls);$i<$c;$i++)
88
		{
89
			$document_srl = $document_srls[$i];
90
			unset($vars);
91
92
			if(!$_document_list[$document_srl] || !is_object($_document_list[$document_srl]) || !$_document_list[$document_srl]->isExists()) continue;
93
			$module_srl = $_document_list[$document_srl]->get('module_srl');
94
			$extra_keys = $this->getExtraKeys($module_srl);
95
			$vars = $extra_vars[$document_srl];
96
			$document_lang_code = $_document_list[$document_srl]->get('lang_code');
97
			// Expand the variable processing
98
			if(count($extra_keys))
99
			{
100
				foreach($extra_keys as $idx => $key)
101
				{
102
					$extra_keys[$idx] = clone($key);
103
					$val = $vars[$idx];
104
					if(isset($val[$user_lang_code])) $v = $val[$user_lang_code];
105
					else if(isset($val[$document_lang_code])) $v = $val[$document_lang_code];
106
					else if(isset($val[0])) $v = $val[0];
107
					else $v = null;
108
					$extra_keys[$idx]->value = $v;
109
				}
110
			}
111
112
			unset($evars);
113
			$evars = new ExtraVar($module_srl);
114
			$evars->setExtraVarKeys($extra_keys);
115
			// Title Processing
116
			if($vars[-1][$user_lang_code]) $_document_list[$document_srl]->add('title',$vars[-1][$user_lang_code]);
117
			// Information processing
118
			if($vars[-2][$user_lang_code]) $_document_list[$document_srl]->add('content',$vars[-2][$user_lang_code]);
119
			
120
			// static 데이터를 갱신해주기 위해 들어간 코드같으나 어차피 언어 변경 자체는 페이지 전환이 일어나면서 발생하는게 대부분이라 효용이 없음. 또한 예기치않게 권한이 없는 다국어 문서 내용을 보여주는 부효과가 일어남		
121
			/*		
122
			if($vars[-1][$user_lang_code] || $vars[-2][$user_lang_code])
123
			{
124
				unset($checked_documents[$document_srl]);
125
			}
126
			*/
127
128
			$GLOBALS['XE_EXTRA_VARS'][$document_srl] = $evars->getExtraVars();
129
		}
130
	}
131
132
	/**
133
	 * Import Document
134
	 * @param int $document_srl
135
	 * @param bool $is_admin
136
	 * @param bool $load_extra_vars
137
	 * @param array $columnList
138
	 * @return documentItem
139
	 */
140
	function getDocument($document_srl=0, $is_admin = false, $load_extra_vars=true, $columnList = array())
141
	{
142
		if(!$document_srl) return new documentItem();
143
144
		if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
145
		{
146
			$oDocument = new documentItem($document_srl, $load_extra_vars, $columnList);
147
			if(!$oDocument->isExists())
148
			{
149
				return $oDocument;
150
			}
151
			$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
152
			if($load_extra_vars) $this->setToAllDocumentExtraVars();
153
		}
154
		if($is_admin) $GLOBALS['XE_DOCUMENT_LIST'][$document_srl]->setGrant();
155
156
		return $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
157
	}
158
159
	/**
160
	 * Bringing multiple documents (or paging)
161
	 * @param array|string $document_srls
162
	 * @param bool $is_admin
163
	 * @param bool $load_extra_vars
164
	 * @param array $columnList
165
	 * @return array value type is documentItem
166
	 */
167
	function getDocuments($document_srls, $is_admin = false, $load_extra_vars=true, $columnList = array())
168
	{
169
		if(is_array($document_srls))
170
		{
171
			$list_count = count($document_srls);
172
			$document_srls = implode(',',$document_srls);
173
		}
174
		else
175
		{
176
			$list_count = 1;
177
		}
178
		$args = new stdClass();
179
		$args->document_srls = $document_srls;
180
		$args->list_count = $list_count;
181
		$args->order_type = 'asc';
182
183
		$output = executeQuery('document.getDocuments', $args, $columnList);
184
		$document_list = $output->data;
185
		if(!$document_list) return;
186
		if(!is_array($document_list)) $document_list = array($document_list);
187
188
		$document_count = count($document_list);
0 ignored issues
show
Unused Code introduced by
$document_count is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
189 View Code Duplication
		foreach($document_list as $key => $attribute)
190
		{
191
			$document_srl = $attribute->document_srl;
192
			if(!$document_srl) continue;
193
194
			if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
195
			{
196
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
197
				$oDocument = new documentItem();
198
				$oDocument->setAttribute($attribute, false);
199
				if($is_admin) $oDocument->setGrant();
200
				$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
201
			}
202
203
			$result[$attribute->document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
204
		}
205
206
		if($load_extra_vars) $this->setToAllDocumentExtraVars();
207
208
		$output = null;
209
		if(count($result))
210
		{
211
			foreach($result as $document_srl => $val)
0 ignored issues
show
Bug introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
212
			{
213
				$output[$document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
214
			}
215
		}
216
217
		return $output;
218
	}
219
220
	/**
221
	 * Module_srl value, bringing the list of documents
222
	 * @param object $obj
223
	 * @param bool $except_notice
224
	 * @param bool $load_extra_vars
225
	 * @param array $columnList
226
	 * @return BaseObject
227
	 */
228
	function getDocumentList($obj, $except_notice = false, $load_extra_vars=true, $columnList = array())
229
	{
230
		$sort_check = $this->_setSortIndex($obj, $load_extra_vars);
231
		$obj->sort_index = $sort_check->sort_index;
232
		$obj->isExtraVars = $sort_check->isExtraVars;
233
		unset($obj->use_alternate_output);
234
		$obj->columnList = $columnList;
235
		// Call trigger (before)
236
		// This trigger can be used to set an alternative output using a different search method
237
		$output = ModuleHandler::triggerCall('document.getDocumentList', 'before', $obj);
238
		if($output instanceof BaseObject && !$output->toBool())
239
		{
240
			return $output;
241
		}
242
243
		// If an alternate output is set, use it instead of running the default queries
244
		$use_alternate_output = (isset($obj->use_alternate_output) && $obj->use_alternate_output instanceof BaseObject);
245
		if (!$use_alternate_output)
246
		{
247
			$this->_setSearchOption($obj, $args, $query_id, $use_division);
248
		}
249
250
		if ($use_alternate_output)
251
		{
252
			$output = $obj->use_alternate_output;
253
			unset($obj->use_alternate_output);
254
		}
255
		elseif ($sort_check->isExtraVars && substr_count($obj->search_target,'extra_vars'))
256
		{
257
			$query_id = 'document.getDocumentListWithinExtraVarsExtraSort';
258
			$args->sort_index = str_replace('documents.','',$args->sort_index);
0 ignored issues
show
Bug introduced by
The variable $args does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
259
			$output = executeQueryArray($query_id, $args);
260
		}
261
		elseif ($sort_check->isExtraVars)
262
		{
263
			$output = executeQueryArray($query_id, $args);
0 ignored issues
show
Bug introduced by
The variable $query_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
264
		}
265
		else
266
		{
267
			// document.getDocumentList query execution
268
			// Query_id if you have a group by clause getDocumentListWithinTag getDocumentListWithinComment or used again to perform the query because
269
			$groupByQuery = array('document.getDocumentListWithinComment' => 1, 'document.getDocumentListWithinTag' => 1, 'document.getDocumentListWithinExtraVars' => 1);
270
			if(isset($groupByQuery[$query_id]))
271
			{
272
				$group_args = clone($args);
273
				$group_args->sort_index = 'documents.'.$args->sort_index;
274
				$output = executeQueryArray($query_id, $group_args);
275
				if(!$output->toBool()||!count($output->data)) return $output;
276
277
				foreach($output->data as $key => $val)
278
				{
279
					if($val->document_srl) $target_srls[] = $val->document_srl;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$target_srls was never initialized. Although not strictly required by PHP, it is generally a good practice to add $target_srls = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
280
				}
281
282
				$page_navigation = $output->page_navigation;
283
				$keys = array_keys($output->data);
284
				$virtual_number = $keys[0];
285
286
				$target_args = new stdClass();
287
				$target_args->document_srls = implode(',',$target_srls);
0 ignored issues
show
Bug introduced by
The variable $target_srls does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
288
				$target_args->list_order = $args->sort_index;
289
				$target_args->order_type = $args->order_type;
290
				$target_args->list_count = $args->list_count;
291
				$target_args->page = 1;
292
				$output = executeQueryArray('document.getDocuments', $target_args);
293
				$output->page_navigation = $page_navigation;
294
				$output->total_count = $page_navigation->total_count;
295
				$output->total_page = $page_navigation->total_page;
296
				$output->page = $page_navigation->cur_page;
297
			}
298
			else
299
			{
300
				$output = executeQueryArray($query_id, $args, $columnList);
301
			}
302
		}
303
		// Return if no result or an error occurs
304
		if(!$output->toBool()||!count($output->data)) return $output;
305
		$idx = 0;
0 ignored issues
show
Unused Code introduced by
$idx is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
306
		$data = $output->data;
307
		unset($output->data);
308
309
		if(!isset($virtual_number))
310
		{
311
			$keys = array_keys($data);
312
			$virtual_number = $keys[0];
313
		}
314
315
		if($except_notice)
316
		{
317
			foreach($data as $key => $attribute)
318
			{
319
				if($attribute->is_notice == 'Y') $virtual_number --;
320
			}
321
		}
322
323
		foreach($data as $key => $attribute)
324
		{
325
			if($except_notice && $attribute->is_notice == 'Y') continue;
326
			$document_srl = $attribute->document_srl;
327
			if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
328
			{
329
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
330
				$oDocument = new documentItem();
331
				$oDocument->setAttribute($attribute, false);
332
				if($is_admin) $oDocument->setGrant();
0 ignored issues
show
Bug introduced by
The variable $is_admin does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
333
				$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
334
			}
335
336
			$output->data[$virtual_number] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
337
			$virtual_number--;
338
		}
339
340
		if($load_extra_vars) $this->setToAllDocumentExtraVars();
341
342
		if(count($output->data))
343
		{
344
			foreach($output->data as $number => $document)
345
			{
346
				$output->data[$number] = $GLOBALS['XE_DOCUMENT_LIST'][$document->document_srl];
347
			}
348
		}
349
350
		// Call trigger (after)
351
		// This trigger can be used to modify search results
352
		ModuleHandler::triggerCall('document.getDocumentList', 'after', $output);
353
		return $output;
354
	}
355
356
	/**
357
	 * Module_srl value, bringing the document's gongjisa Port
358
	 * @param object $obj
359
	 * @param array $columnList
360
	 * @return object|void
361
	 */
362
	function getNoticeList($obj, $columnList = array())
363
	{
364
		$args = new stdClass();
365
		$args->module_srl = $obj->module_srl;
366
		$args->category_srl= $obj->category_srl;
367
		$output = executeQueryArray('document.getNoticeList', $args, $columnList);
368
		if(!$output->toBool()||!$output->data) return;
369
370 View Code Duplication
		foreach($output->data as $key => $val)
371
		{
372
			$document_srl = $val->document_srl;
373
			if(!$document_srl) continue;
374
375
			if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
376
			{
377
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
378
				$oDocument = new documentItem();
379
				$oDocument->setAttribute($val, false);
380
				$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
381
			}
382
			$result->data[$document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
0 ignored issues
show
Bug introduced by
The variable $result does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
383
		}
384
		$this->setToAllDocumentExtraVars();
385
386
		foreach($result->data as $document_srl => $val)
387
		{
388
			$result->data[$document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
389
		}
390
391
		return $result;
392
	}
393
394
	/**
395
	 * Function to retrieve the key values of the extended variable document
396
	 * $Form_include: writing articles whether to add the necessary extensions of the variable input form
397
	 * @param int $module_srl
398
	 * @return array
399
	 */
400
	function getExtraKeys($module_srl)
401
	{
402
		if(!isset($GLOBALS['XE_EXTRA_KEYS'][$module_srl]))
403
		{
404
			$keys = false;
405
			$oCacheHandler = CacheHandler::getInstance('object', null, true);
406
			if($oCacheHandler->isSupport())
407
			{
408
				$object_key = 'module_document_extra_keys:' . $module_srl;
409
				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
410
				$keys = $oCacheHandler->get($cache_key);
411
			}
412
413
			$oExtraVar = ExtraVar::getInstance($module_srl);
414
415
			if($keys === false)
416
			{
417
				$obj = new stdClass();
418
				$obj->module_srl = $module_srl;
419
				$obj->sort_index = 'var_idx';
420
				$obj->order = 'asc';
421
				$output = executeQueryArray('document.getDocumentExtraKeys', $obj);
422
423
				// correcting index order
424
				$isFixed = FALSE;
425
				if(is_array($output->data))
426
				{
427
					$prevIdx = 0;
428
					foreach($output->data as $no => $value)
429
					{
430
						// case first
431
						if($prevIdx == 0 && $value->idx != 1)
432
						{
433
							$args = new stdClass();
434
							$args->module_srl = $module_srl;
435
							$args->var_idx = $value->idx;
436
							$args->new_idx = 1;
437
							executeQuery('document.updateDocumentExtraKeyIdx', $args);
438
							executeQuery('document.updateDocumentExtraVarIdx', $args);
439
							$prevIdx = 1;
440
							$isFixed = TRUE;
441
							continue;
442
						}
443
444
						// case others
445
						if($prevIdx > 0 && $prevIdx + 1 != $value->idx)
446
						{
447
							$args = new stdClass();
448
							$args->module_srl = $module_srl;
449
							$args->var_idx = $value->idx;
450
							$args->new_idx = $prevIdx + 1;
451
							executeQuery('document.updateDocumentExtraKeyIdx', $args);
452
							executeQuery('document.updateDocumentExtraVarIdx', $args);
453
							$prevIdx += 1;
454
							$isFixed = TRUE;
455
							continue;
456
						}
457
458
						$prevIdx = $value->idx;
459
					}
460
				}
461
462
				if($isFixed)
463
				{
464
					$output = executeQueryArray('document.getDocumentExtraKeys', $obj);
465
				}
466
467
				$oExtraVar->setExtraVarKeys($output->data);
468
				$keys = $oExtraVar->getExtraVars();
469
				if(!$keys) $keys = array();
0 ignored issues
show
Bug Best Practice introduced by
The expression $keys of type ExtraItem[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
470
471
				if($oCacheHandler->isSupport())
472
				{
473
					$oCacheHandler->put($cache_key, $keys);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
474
				}
475
			}
476
477
478
			$GLOBALS['XE_EXTRA_KEYS'][$module_srl] = $keys;
479
		}
480
481
		return $GLOBALS['XE_EXTRA_KEYS'][$module_srl];
482
	}
483
484
	/**
485
	 * A particular document to get the value of the extra variable function
486
	 * @param int $module_srl
487
	 * @param int $document_srl
488
	 * @return array
489
	 */
490
	function getExtraVars($module_srl, $document_srl)
0 ignored issues
show
Unused Code introduced by
The parameter $module_srl is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
491
	{
492
		if(!isset($GLOBALS['XE_EXTRA_VARS'][$document_srl]))
493
		{
494
			// Extended to extract the values of variables set
495
			$oDocument = $this->getDocument($document_srl, false);
496
			$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
497
			$this->setToAllDocumentExtraVars();
498
		}
499
		if(is_array($GLOBALS['XE_EXTRA_VARS'][$document_srl])) ksort($GLOBALS['XE_EXTRA_VARS'][$document_srl]);
500
		return $GLOBALS['XE_EXTRA_VARS'][$document_srl];
501
	}
502
503
	/**
504
	 * Show pop-up menu of the selected posts
505
	 * Printing, scrap, recommendations and negative, reported the Add Features
506
	 * @return void
507
	 */
508
	function getDocumentMenu()
509
	{
510
		// Post number and the current login information requested Wanted
511
		$document_srl = Context::get('target_srl');
512
		$mid = Context::get('cur_mid');
0 ignored issues
show
Unused Code introduced by
$mid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
513
		$logged_info = Context::get('logged_info');
514
		$act = Context::get('cur_act');
0 ignored issues
show
Unused Code introduced by
$act is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
515
		// to menu_list "pyosihalgeul, target, url" put into an array
516
		$menu_list = array();
517
		// call trigger
518
		ModuleHandler::triggerCall('document.getDocumentMenu', 'before', $menu_list);
0 ignored issues
show
Documentation introduced by
$menu_list is of type array, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
519
520
		$oDocumentController = getController('document');
521
		// Members must be a possible feature
522
		if($logged_info->member_srl)
523
		{
524
			$oDocumentModel = getModel('document');
525
			$columnList = array('document_srl', 'module_srl', 'member_srl', 'ipaddress');
526
			$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
527
			$module_srl = $oDocument->get('module_srl');
528
			$member_srl = $oDocument->get('member_srl');
529
			if(!$module_srl) return new BaseObject(-1, 'msg_invalid_request');
530
531
			$oModuleModel = getModel('module');
532
			$document_config = $oModuleModel->getModulePartConfig('document',$module_srl);
533 View Code Duplication
			if($document_config->use_vote_up!='N' && $member_srl!=$logged_info->member_srl)
534
			{
535
				// Add a Referral Button
536
				$url = sprintf("doCallModuleAction('document','procDocumentVoteUp','%s')", $document_srl);
537
				$oDocumentController->addDocumentPopupMenu($url,'cmd_vote','','javascript');
538
			}
539
540 View Code Duplication
			if($document_config->use_vote_down!='N' && $member_srl!=$logged_info->member_srl)
541
			{
542
				// Add button to negative
543
				$url= sprintf("doCallModuleAction('document','procDocumentVoteDown','%s')", $document_srl);
544
				$oDocumentController->addDocumentPopupMenu($url,'cmd_vote_down','','javascript');
545
			}
546
547
			// Adding Report
548
			$url = sprintf("doCallModuleAction('document','procDocumentDeclare','%s')", $document_srl);
549
			$oDocumentController->addDocumentPopupMenu($url,'cmd_declare','','javascript');
550
551
			// Add Bookmark button
552
			$url = sprintf("doCallModuleAction('member','procMemberScrapDocument','%s')", $document_srl);
553
			$oDocumentController->addDocumentPopupMenu($url,'cmd_scrap','','javascript');
554
		}
555
		// Add print button
556
		$url = getUrl('','module','document','act','dispDocumentPrint','document_srl',$document_srl);
557
		$oDocumentController->addDocumentPopupMenu($url,'cmd_print','','printDocument');
558
		// Call a trigger (after)
559
		ModuleHandler::triggerCall('document.getDocumentMenu', 'after', $menu_list);
560 View Code Duplication
		if($this->grant->manager)
0 ignored issues
show
Bug introduced by
The property grant does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
561
		{
562
			$str_confirm = Context::getLang('confirm_move');
563
			$url = sprintf("if(!confirm('%s')) return; var params = new Array(); params['document_srl']='%s'; params['mid']=current_mid;params['cur_url']=current_url; exec_xml('document', 'procDocumentAdminMoveToTrash', params)", $str_confirm, $document_srl);
564
			$oDocumentController->addDocumentPopupMenu($url,'cmd_trash','','javascript');
565
		}
566
567
		// If you are managing to find posts by ip
568 View Code Duplication
		if($logged_info->is_admin == 'Y')
569
		{
570
			$oDocumentModel = getModel('document');
571
			$oDocument = $oDocumentModel->getDocument($document_srl);	//before setting document recycle
572
573
			if($oDocument->isExists())
574
			{
575
				// Find a post equivalent to ip address
576
				$url = getUrl('','module','admin','act','dispDocumentAdminList','search_target','ipaddress','search_keyword',$oDocument->getIpAddress());
577
				$oDocumentController->addDocumentPopupMenu($url,'cmd_search_by_ipaddress',$icon_path,'TraceByIpaddress');
0 ignored issues
show
Bug introduced by
The variable $icon_path does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
578
579
				$url = sprintf("var params = new Array(); params['ipaddress_list']='%s'; exec_xml('spamfilter', 'procSpamfilterAdminInsertDeniedIP', params, completeCallModuleAction)", $oDocument->getIpAddress());
580
				$oDocumentController->addDocumentPopupMenu($url,'cmd_add_ip_to_spamfilter','','javascript');
581
			}
582
		}
583
		// Changing the language of pop-up menu
584
		$menus = Context::get('document_popup_menu_list');
585
		$menus_count = count($menus);
586 View Code Duplication
		for($i=0;$i<$menus_count;$i++)
587
		{
588
			$menus[$i]->str = Context::getLang($menus[$i]->str);
589
		}
590
		// Wanted to finally clean pop-up menu list
591
		$this->add('menus', $menus);
592
	}
593
594
	/**
595
	 * The total number of documents that are bringing
596
	 * @param int $module_srl
597
	 * @param object $search_obj
598
	 * @return int
599
	 */
600
	function getDocumentCount($module_srl, $search_obj = NULL)
601
	{
602
		if(is_null($search_obj)) $search_obj = new stdClass();
603
		$search_obj->module_srl = $module_srl;
604
605
		$output = executeQuery('document.getDocumentCount', $search_obj);
606
		// Return total number of
607
		$total_count = $output->data->count;
608
		return (int)$total_count;
609
	}
610
611
	/**
612
	 * the total number of documents that are bringing
613
	 * @param object $search_obj
614
	 * @return array
615
	 */
616
	function getDocumentCountByGroupStatus($search_obj = NULL)
617
	{
618
		$output = executeQuery('document.getDocumentCountByGroupStatus', $search_obj);
619
		if(!$output->toBool()) return array();
620
621
		return $output->data;
622
	}
623
624
	function getDocumentExtraVarsCount($module_srl, $search_obj = NULL)
625
	{
626
		// Additional search options
627
		$args->module_srl = $module_srl;
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
628
629
		$args->category_srl = $search_obj->category_srl;
630
		$args->var_idx = $search_obj->s_var_idx;
631
		$args->var_eid = $search_obj->s_var_eid;
632
		$args->var_value = $search_obj->s_var_value;
633
		$args->var_lang_code = Context::getLangType();
634
635
		$output = executeQuery('document.getDocumentExtraVarsCount', $args);
636
		// Return total number of
637
		$total_count = $output->data->count;
638
		return (int)$total_count;
639
	}
640
641
	/**
642
	 * Import page of the document, module_srl Without throughout ..
643
	 * @param documentItem $oDocument
644
	 * @param object $opt
645
	 * @return int
646
	 */
647
	function getDocumentPage($oDocument, $opt)
648
	{
649
		$sort_check = $this->_setSortIndex($opt, TRUE);
650
		$opt->sort_index = $sort_check->sort_index;
651
		$opt->isExtraVars = $sort_check->isExtraVars;
652
653
		$this->_setSearchOption($opt, $args, $query_id, $use_division);
654
655
		if($sort_check->isExtraVars)
656
		{
657
			return 1;
658
		}
659
		else
660
		{
661
			if($sort_check->sort_index === 'list_order' || $sort_check->sort_index === 'update_order')
662
			{
663 View Code Duplication
				if($args->order_type === 'desc')
664
				{
665
					$args->{'rev_' . $sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
666
				}
667
				else
668
				{
669
					$args->{$sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
670
				}
671
			}
672 View Code Duplication
			elseif($sort_check->sort_index === 'regdate')
673
			{
674
675
				if($args->order_type === 'asc')
676
				{
677
					$args->{'rev_' . $sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
678
				}
679
				else
680
				{
681
					$args->{$sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
682
				}
683
684
			}
685
			else
686
			{
687
				return 1;
688
			}
689
		}
690
691
		// Guhanhu total number of the article search page
692
		$output = executeQuery($query_id . 'Page', $args);
693
		$count = $output->data->count;
694
		$page = (int)(($count-1)/$opt->list_count)+1;
695
		return $page;
696
	}
697
698
	/**
699
	 * Imported Category of information
700
	 * @param int $category_srl
701
	 * @param array $columnList
702
	 * @return object
703
	 */
704
	function getCategory($category_srl, $columnList = array())
705
	{
706
		$args =new stdClass();
707
		$args->category_srl = $category_srl;
708
		$output = executeQuery('document.getCategory', $args, $columnList);
709
710
		$node = $output->data;
711
		if(!$node) return;
712
713
		if($node->group_srls)
714
		{
715
			$group_srls = explode(',',$node->group_srls);
716
			unset($node->group_srls);
717
			$node->group_srls = $group_srls;
718
		}
719
		else
720
		{
721
			unset($node->group_srls);
722
			$node->group_srls = array();
723
		}
724
		return $node;
725
	}
726
727
	/**
728
	 * Check whether the child has a specific category
729
	 * @param int $category_srl
730
	 * @return bool
731
	 */
732
	function getCategoryChlidCount($category_srl)
733
	{
734
		$args = new stdClass();
735
		$args->category_srl = $category_srl;
736
		$output = executeQuery('document.getChildCategoryCount',$args);
737
		if($output->data->count > 0) return true;
738
		return false;
739
	}
740
741
	/**
742
	 * Bringing the Categories list the specific module
743
	 * Speed and variety of categories, considering the situation created by the php script to include a list of the must, in principle, to use
744
	 * @param int $module_srl
745
	 * @param array $columnList
746
	 * @return array
747
	 */
748
	function getCategoryList($module_srl, $columnList = array())
749
	{
750
		$module_srl = (int)$module_srl;
751
752
		// Category of the target module file swollen
753
		$filename = sprintf("%sfiles/cache/document_category/%s.php", _XE_PATH_, $module_srl);
754
		// If the target file to the cache file regeneration category
755
		if(!file_exists($filename))
756
		{
757
			$oDocumentController = getController('document');
758
			if(!$oDocumentController->makeCategoryFile($module_srl)) return array();
759
		}
760
761
		include($filename);
762
763
		// Cleanup of category
764
		$document_category = array();
765
		$this->_arrangeCategory($document_category, $menu->list, 0);
0 ignored issues
show
Bug introduced by
The variable $menu does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
766
		return $document_category;
767
	}
768
769
	/**
770
	 * Category within a primary method to change the array type
771
	 * @param array $document_category
772
	 * @param array $list
773
	 * @param int $depth
774
	 * @return void
775
	 */
776
	function _arrangeCategory(&$document_category, $list, $depth)
777
	{
778
		if(!count($list)) return;
779
		$idx = 0;
780
		$list_order = array();
781
		foreach($list as $key => $val)
782
		{
783
			$obj = new stdClass;
784
			$obj->mid = $val['mid'];
785
			$obj->module_srl = $val['module_srl'];
786
			$obj->category_srl = $val['category_srl'];
787
			$obj->parent_srl = $val['parent_srl'];
788
			$obj->title = $obj->text = $val['text'];
789
			$obj->description = $val['description'];
790
			$obj->expand = $val['expand']=='Y'?true:false;
791
			$obj->color = $val['color'];
792
			$obj->document_count = $val['document_count'];
793
			$obj->depth = $depth;
794
			$obj->child_count = 0;
795
			$obj->childs = array();
796
			$obj->grant = $val['grant'];
797
798
			if(Context::get('mid') == $obj->mid && Context::get('category') == $obj->category_srl) $selected = true;
799
			else $selected = false;
800
801
			$obj->selected = $selected;
802
803
			$list_order[$idx++] = $obj->category_srl;
804
			// If you have a parent category of child nodes apply data
805
			if($obj->parent_srl)
806
			{
807
				$parent_srl = $obj->parent_srl;
808
				$document_count = $obj->document_count;
809
				$expand = $obj->expand;
810
				if($selected) $expand = true;
811
812
				while($parent_srl)
813
				{
814
					$document_category[$parent_srl]->document_count += $document_count;
815
					$document_category[$parent_srl]->childs[] = $obj->category_srl;
816
					$document_category[$parent_srl]->child_count = count($document_category[$parent_srl]->childs);
817
					if($expand) $document_category[$parent_srl]->expand = $expand;
818
819
					$parent_srl = $document_category[$parent_srl]->parent_srl;
820
				}
821
			}
822
823
			$document_category[$key] = $obj;
824
825
			if(count($val['list'])) $this->_arrangeCategory($document_category, $val['list'], $depth+1);
826
		}
827
		$document_category[$list_order[0]]->first = true;
828
		$document_category[$list_order[count($list_order)-1]]->last = true;
829
	}
830
831
	/**
832
	 * Wanted number of documents belonging to category
833
	 * @param int $module_srl
834
	 * @param int $category_srl
835
	 * @return int
836
	 */
837
	function getCategoryDocumentCount($module_srl, $category_srl)
838
	{
839
		$args = new stdClass;
840
		$args->module_srl = $module_srl;
841
		$args->category_srl = $category_srl;
842
		$output = executeQuery('document.getCategoryDocumentCount', $args);
843
		return (int)$output->data->count;
844
	}
845
846
	/**
847
	 * Xml cache file of the document category return information
848
	 * @param int $module_srl
849
	 * @return string
850
	 */
851 View Code Duplication
	function getCategoryXmlFile($module_srl)
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...
852
	{
853
		$xml_file = sprintf('files/cache/document_category/%s.xml.php',$module_srl);
854
		if(!file_exists($xml_file))
855
		{
856
			$oDocumentController = getController('document');
857
			$oDocumentController->makeCategoryFile($module_srl);
858
		}
859
		return $xml_file;
860
	}
861
862
	/**
863
	 * Php cache files in the document category return information
864
	 * @param int $module_srl
865
	 * @return string
866
	 */
867 View Code Duplication
	function getCategoryPhpFile($module_srl)
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...
868
	{
869
		$php_file = sprintf('files/cache/document_category/%s.php',$module_srl);
870
		if(!file_exists($php_file))
871
		{
872
			$oDocumentController = getController('document');
873
			$oDocumentController->makeCategoryFile($module_srl);
874
		}
875
		return $php_file;
876
	}
877
878
	/**
879
	 * Imported post monthly archive status
880
	 * @param object $obj
881
	 * @return object
882
	 */
883 View Code Duplication
	function getMonthlyArchivedList($obj)
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...
884
	{
885
		if($obj->mid)
886
		{
887
			$oModuleModel = getModel('module');
888
			$obj->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
889
			unset($obj->mid);
890
		}
891
		// Module_srl passed the array may be a check whether the array
892
		$args = new stdClass;
893
		if(is_array($obj->module_srl)) $args->module_srl = implode(',', $obj->module_srl);
894
		else $args->module_srl = $obj->module_srl;
895
896
		$output = executeQuery('document.getMonthlyArchivedList', $args);
897
		if(!$output->toBool()||!$output->data) return $output;
898
899
		if(!is_array($output->data)) $output->data = array($output->data);
900
901
		return $output;
902
	}
903
904
	/**
905
	 * Bringing a month on the status of the daily posts
906
	 * @param object $obj
907
	 * @return object
908
	 */
909 View Code Duplication
	function getDailyArchivedList($obj)
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...
910
	{
911
		if($obj->mid)
912
		{
913
			$oModuleModel = getModel('module');
914
			$obj->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
915
			unset($obj->mid);
916
		}
917
		// Module_srl passed the array may be a check whether the array
918
		$args = new stdClass;
919
		if(is_array($obj->module_srl)) $args->module_srl = implode(',', $obj->module_srl);
920
		else $args->module_srl = $obj->module_srl;
921
		$args->regdate = $obj->regdate;
922
923
		$output = executeQuery('document.getDailyArchivedList', $args);
924
		if(!$output->toBool()) return $output;
925
926
		if(!is_array($output->data)) $output->data = array($output->data);
927
928
		return $output;
929
	}
930
931
	/**
932
	 * Get a list for a particular module
933
	 * @return void|BaseObject
934
	 */
935
	function getDocumentCategories()
936
	{
937
		if(!Context::get('is_logged')) return new BaseObject(-1,'msg_not_permitted');
938
		$module_srl = Context::get('module_srl');
939
		$categories= $this->getCategoryList($module_srl);
940
		$lang = Context::get('lang');
941
		// No additional category
942
		$output = "0,0,{$lang->none_category}\n";
943
		if($categories)
0 ignored issues
show
Bug Best Practice introduced by
The expression $categories of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
944
		{
945
			foreach($categories as $category_srl => $category)
946
			{
947
				$output .= sprintf("%d,%d,%s\n",$category_srl, $category->depth,$category->title);
948
			}
949
		}
950
		$this->add('categories', $output);
951
	}
952
953
	/**
954
	 * Wanted to set document information
955
	 * @return object
956
	 */
957
	function getDocumentConfig()
958
	{
959
		if($this->documentConfig === NULL)
960
		{
961
			$oModuleModel = getModel('module');
962
			$config = $oModuleModel->getModuleConfig('document');
963
964
			if (!$config)
965
			{
966
				$config = new stdClass();
967
			}
968
			$this->documentConfig = $config;
969
		}
970
		return $this->documentConfig;
971
	}
972
973
	/**
974
	 * Common:: Module extensions of variable management
975
	 * Expansion parameter management module in the document module instance, when using all the modules available
976
	 * @param int $module_srl
977
	 * @return string
978
	 */
979
	function getExtraVarsHTML($module_srl)
980
	{
981
		// Bringing existing extra_keys
982
		$extra_keys = $this->getExtraKeys($module_srl);
983
		Context::set('extra_keys', $extra_keys);
984
		$security = new Security();
985
		$security->encodeHTML('extra_keys..', 'selected_var_idx');
986
987
		// Get information of module_grants
988
		$oTemplate = &TemplateHandler::getInstance();
989
		return $oTemplate->compile($this->module_path.'tpl', 'extra_keys');
990
	}
991
992
	/**
993
	 * Common:: Category parameter management module
994
	 * @param int $module_srl
995
	 * @return string
996
	 */
997 View Code Duplication
	function getCategoryHTML($module_srl)
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...
998
	{
999
		$category_xml_file = $this->getCategoryXmlFile($module_srl);
1000
1001
		Context::set('category_xml_file', $category_xml_file);
1002
1003
		Context::loadJavascriptPlugin('ui.tree');
1004
1005
		// Get a list of member groups
1006
		$oMemberModel = getModel('member');
1007
		$group_list = $oMemberModel->getGroups($module_info->site_srl);
0 ignored issues
show
Bug introduced by
The variable $module_info does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1008
		Context::set('group_list', $group_list);
1009
1010
		$security = new Security();
1011
		$security->encodeHTML('group_list..title');
1012
1013
		// Get information of module_grants
1014
		$oTemplate = &TemplateHandler::getInstance();
1015
		return $oTemplate->compile($this->module_path.'tpl', 'category_list');
1016
	}
1017
1018
	/**
1019
	 * Certain categories of information, return the template guhanhu
1020
	 * Manager on the page to add information about a particular menu from the server after compiling tpl compiled a direct return html
1021
	 * @return void|BaseObject
1022
	 */
1023
	function getDocumentCategoryTplInfo()
1024
	{
1025
		$oModuleModel = getModel('module');
1026
		$oMemberModel = getModel('member');
0 ignored issues
show
Unused Code introduced by
$oMemberModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1027
		// Get information on the menu for the parameter settings
1028
		$module_srl = Context::get('module_srl');
1029
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
1030
		// Check permissions
1031
		$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info'));
1032
		if(!$grant->manager) return new BaseObject(-1,'msg_not_permitted');
1033
1034
		$category_srl = Context::get('category_srl');
1035
		$category_info = $this->getCategory($category_srl);
1036
		if(!$category_info)
1037
		{
1038
			return new BaseObject(-1, 'msg_invalid_request');
1039
		}
1040
1041
		$this->add('category_info', $category_info);
1042
	}
1043
1044
	/**
1045
	 * Return docuent data by alias
1046
	 * @param string $mid
1047
	 * @param string $alias
1048
	 * @return int|void
1049
	 */
1050
	function getDocumentSrlByAlias($mid, $alias)
1051
	{
1052
		if(!$mid || !$alias) return null;
1053
		$site_module_info = Context::get('site_module_info');
1054
		$args = new stdClass;
1055
		$args->mid = $mid;
1056
		$args->alias_title = $alias;
1057
		$args->site_srl = $site_module_info->site_srl;
1058
		$output = executeQuery('document.getDocumentSrlByAlias', $args);
1059
		if(!$output->data) return null;
1060
		else return $output->data->document_srl;
1061
	}
1062
1063
	/**
1064
	 * Return docuent number by document title
1065
	 * @param int $module_srl
1066
	 * @param string $title
1067
	 * @return int|void
1068
	 */
1069
	function getDocumentSrlByTitle($module_srl, $title)
1070
	{
1071
		if(!$module_srl || !$title) return null;
1072
		$args = new stdClass;
1073
		$args->module_srl = $module_srl;
1074
		$args->title = $title;
1075
		$output = executeQuery('document.getDocumentSrlByTitle', $args);
1076
		if(!$output->data) return null;
1077
		else
1078
		{
1079
			if(is_array($output->data)) return $output->data[0]->document_srl;
1080
			return $output->data->document_srl;
1081
		}
1082
	}
1083
1084
	/**
1085
	 * Return docuent's alias
1086
	 * @param int $document_srl
1087
	 * @return string|void
1088
	 */
1089
	function getAlias($document_srl)
1090
	{
1091
		if(!$document_srl) return null;
1092
		$args = new stdClass;
1093
		$args->document_srl = $document_srl;
1094
		$output = executeQueryArray('document.getAliases', $args);
1095
1096
		if(!$output->data) return null;
1097
		else return $output->data[0]->alias_title;
1098
	}
1099
1100
	/**
1101
	 * Return document's history list
1102
	 * @param int $document_srl
1103
	 * @param int $list_count
1104
	 * @param int $page
1105
	 * @return object
1106
	 */
1107
	function getHistories($document_srl, $list_count, $page)
1108
	{
1109
		$args = new stdClass;
1110
		$args->list_count = $list_count;
1111
		$args->page = $page;
1112
		$args->document_srl = $document_srl;
1113
		$output = executeQueryArray('document.getHistories', $args);
1114
		return $output;
1115
	}
1116
1117
	/**
1118
	 * Return document's history
1119
	 * @param int $history_srl
1120
	 * @return object
1121
	 */
1122
	function getHistory($history_srl)
1123
	{
1124
		$args = new stdClass;
1125
		$args->history_srl = $history_srl;
1126
		$output = executeQuery('document.getHistory', $args);
1127
		return $output->data;
1128
	}
1129
1130
	/**
1131
	 * Module_srl value, bringing the list of documents
1132
	 * @param object $obj
1133
	 * @return object
1134
	 */
1135
	function getTrashList($obj)
1136
	{
1137
		// Variable check
1138
		$args = new stdClass;
1139
		$args->category_srl = $obj->category_srl?$obj->category_srl:null;
1140
		$args->sort_index = $obj->sort_index;
1141
		$args->order_type = $obj->order_type?$obj->order_type:'desc';
1142
		$args->page = $obj->page?$obj->page:1;
1143
		$args->list_count = $obj->list_count?$obj->list_count:20;
1144
		$args->page_count = $obj->page_count?$obj->page_count:10;
1145
		// Search options
1146
		$search_target = $obj->search_target;
1147
		$search_keyword = $obj->search_keyword;
1148
		if($search_target && $search_keyword)
1149
		{
1150
			switch($search_target)
1151
			{
1152
				case 'title' :
1153 View Code Duplication
				case 'content' :
1154
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1155
					$args->{"s_".$search_target} = $search_keyword;
1156
					$use_division = true;
0 ignored issues
show
Unused Code introduced by
$use_division is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1157
					break;
1158 View Code Duplication
				case 'title_content' :
1159
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1160
					$args->s_title = $search_keyword;
1161
					$args->s_content = $search_keyword;
1162
					break;
1163 View Code Duplication
				case 'user_id' :
1164
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1165
					$args->s_user_id = $search_keyword;
1166
					$args->sort_index = 'documents.'.$args->sort_index;
1167
					break;
1168
				case 'user_name' :
1169
				case 'nick_name' :
1170
				case 'email_address' :
1171 View Code Duplication
				case 'homepage' :
1172
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1173
					$args->{"s_".$search_target} = $search_keyword;
1174
					break;
1175
				case 'is_notice' :
1176
				case 'is_secret' :
1177
					if($search_keyword=='N') $args->statusList = array($this->getConfigStatus('public'));
1178
					elseif($search_keyword=='Y') $args->statusList = array($this->getConfigStatus('secret'));
1179
					break;
1180
				case 'member_srl' :
1181
				case 'readed_count' :
1182
				case 'voted_count' :
1183
				case 'blamed_count' :
1184
				case 'comment_count' :
1185
				case 'trackback_count' :
1186
				case 'uploaded_count' :
1187
					$args->{"s_".$search_target} = (int)$search_keyword;
1188
					break;
1189
				case 'regdate' :
1190
				case 'last_update' :
1191
				case 'ipaddress' :
1192
				case 'tag' :
1193
					$args->{"s_".$search_target} = $search_keyword;
1194
					break;
1195
			}
1196
		}
1197
1198
		$output = executeQueryArray('document.getTrashList', $args);
1199
		if($output->data)
1200
		{
1201
			foreach($output->data as $key => $attribute)
1202
			{
1203
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1204
				$oDocument = new documentItem();
1205
				$oDocument->setAttribute($attribute, false);
1206
				$attribute = $oDocument;
1207
			}
1208
		}
1209
		return $output;
1210
	}
1211
1212
	/**
1213
	 * vote up, vote down member list in Document View page
1214
	 * @return void|BaseObject
1215
	 */
1216
	function getDocumentVotedMemberList()
1217
	{
1218
		$args = new stdClass;
1219
		$document_srl = Context::get('document_srl');
1220
		if(!$document_srl) return new BaseObject(-1,'msg_invalid_request');
1221
1222
		$point = Context::get('point');
1223
		if($point != -1) $point = 1;
1224
1225
		$oDocumentModel = getModel('document');
1226
		$columnList = array('document_srl', 'module_srl');
1227
		$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
1228
		$module_srl = $oDocument->get('module_srl');
1229
		if(!$module_srl) return new BaseObject(-1, 'msg_invalid_request');
1230
1231
		$oModuleModel = getModel('module');
1232
		$document_config = $oModuleModel->getModulePartConfig('document',$module_srl);
1233 View Code Duplication
		if($point == -1)
1234
		{
1235
			if($document_config->use_vote_down!='S') return new BaseObject(-1, 'msg_invalid_request');
1236
			$args->below_point = 0;
1237
		}
1238
		else
1239
		{
1240
			if($document_config->use_vote_up!='S') return new BaseObject(-1, 'msg_invalid_request');
1241
			$args->more_point = 0;
1242
		}
1243
1244
		$args->document_srl = $document_srl;
1245
1246
		$output = executeQueryArray('document.getVotedMemberList',$args);
1247
		if(!$output->toBool()) return $output;
1248
1249
		$oMemberModel = getModel('member');
1250 View Code Duplication
		if($output->data)
1251
		{
1252
			foreach($output->data as $k => $d)
1253
			{
1254
				$profile_image = $oMemberModel->getProfileImage($d->member_srl);
1255
				$output->data[$k]->src = $profile_image->src;
1256
			}
1257
		}
1258
1259
		$this->add('voted_member_list',$output->data);
1260
	}
1261
1262
	/**
1263
	 * Return status name list
1264
	 * @return array
1265
	 */
1266
	function getStatusNameList()
1267
	{
1268
		global $lang;
1269
		if(!isset($lang->status_name_list))
1270
			return array_flip($this->getStatusList());
1271
		else return $lang->status_name_list;
1272
	}
1273
1274
	/**
1275
	 * Setting sort index
1276
	 * @param object $obj
1277
	 * @param bool $load_extra_vars
1278
	 * @return object
1279
	 */
1280
	function _setSortIndex($obj, $load_extra_vars)
1281
	{
1282
		$sortIndex = $obj->sort_index;
1283
		$isExtraVars = false;
1284
		if(!in_array($sortIndex, array('list_order','regdate','last_update','update_order','readed_count','voted_count','blamed_count','comment_count','trackback_count','uploaded_count','title','category_srl')))
1285
		{
1286
			// get module_srl extra_vars list
1287
			if ($load_extra_vars)
1288
			{
1289
				$extra_args = new stdClass();
1290
				$extra_args->module_srl = $obj->module_srl;
1291
				$extra_output = executeQueryArray('document.getGroupsExtraVars', $extra_args);
1292
				if (!$extra_output->data || !$extra_output->toBool())
1293
				{
1294
					$sortIndex = 'list_order';
1295
				}
1296
				else
1297
				{
1298
					$check_array = array();
1299
					foreach($extra_output->data as $val)
1300
					{
1301
						$check_array[] = $val->eid;
1302
					}
1303
					if(!in_array($sortIndex, $check_array)) $sortIndex = 'list_order';
1304
					else $isExtraVars = true;
1305
				}
1306
			}
1307
			else
1308
				$sortIndex = 'list_order';
1309
		}
1310
		$returnObj = new stdClass();
1311
		$returnObj->sort_index = $sortIndex;
1312
		$returnObj->isExtraVars = $isExtraVars;
1313
1314
		return $returnObj;
1315
	}
1316
1317
	/**
1318
	 * 게시물 목록의 검색 옵션을 Setting함(2011.03.08 - cherryfilter)
1319
	 * page변수가 없는 상태에서 page 값을 알아오는 method(getDocumentPage)는 검색하지 않은 값을 return해서 검색한 값을 가져오도록 검색옵션이 추가 됨.
1320
	 * 검색옵션의 중복으로 인해 private method로 별도 분리
1321
	 * @param object $searchOpt
1322
	 * @param object $args
1323
	 * @param string $query_id
1324
	 * @param bool $use_division
1325
	 * @return void
1326
	 */
1327
	function _setSearchOption($searchOpt, &$args, &$query_id, &$use_division)
1328
	{
1329
		// Variable check
1330
		$args = new stdClass();
1331
		$args->category_srl = $searchOpt->category_srl?$searchOpt->category_srl:null;
1332
		$args->order_type = $searchOpt->order_type;
1333
		$args->page = $searchOpt->page?$searchOpt->page:1;
1334
		$args->list_count = $searchOpt->list_count?$searchOpt->list_count:20;
1335
		$args->page_count = $searchOpt->page_count?$searchOpt->page_count:10;
1336
		$args->start_date = $searchOpt->start_date?$searchOpt->start_date:null;
1337
		$args->end_date = $searchOpt->end_date?$searchOpt->end_date:null;
1338
		$args->member_srl = $searchOpt->member_srl;
1339
		$args->member_srls = $searchOpt->member_srls;
1340
1341
		$logged_info = Context::get('logged_info');
1342
1343
		$args->sort_index = $searchOpt->sort_index;
1344
1345
		// Check the target and sequence alignment
1346
		$orderType = array('desc' => 1, 'asc' => 1);
1347
		if(!isset($orderType[$args->order_type])) $args->order_type = 'asc';
1348
1349
		// If that came across mid module_srl instead of a direct module_srl guhaejum
1350
		if($searchOpt->mid)
1351
		{
1352
			$oModuleModel = getModel('module');
1353
			$args->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
0 ignored issues
show
Bug introduced by
The variable $obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1354
			unset($searchOpt->mid);
1355
		}
1356
1357
		// Module_srl passed the array may be a check whether the array
1358
		if(is_array($searchOpt->module_srl)) $args->module_srl = implode(',', $searchOpt->module_srl);
1359
		else $args->module_srl = $searchOpt->module_srl;
1360
1361
		// Except for the test module_srl
1362
		if(is_array($searchOpt->exclude_module_srl)) $args->exclude_module_srl = implode(',', $searchOpt->exclude_module_srl);
1363
		else $args->exclude_module_srl = $searchOpt->exclude_module_srl;
1364
1365
		// only admin document list, temp document showing
1366
		if($searchOpt->statusList) $args->statusList = $searchOpt->statusList;
1367
		else
1368
		{
1369
			if($logged_info->is_admin == 'Y' && !$searchOpt->module_srl)
1370
				$args->statusList = array($this->getConfigStatus('secret'), $this->getConfigStatus('public'), $this->getConfigStatus('temp'));
1371
			else
1372
				$args->statusList = array($this->getConfigStatus('secret'), $this->getConfigStatus('public'));
1373
		}
1374
1375
		// Category is selected, further sub-categories until all conditions
1376
		if($args->category_srl)
1377
		{
1378
			$category_list = $this->getCategoryList($args->module_srl);
1379
			$category_info = $category_list[$args->category_srl];
1380
			$category_info->childs[] = $args->category_srl;
1381
			$args->category_srl = implode(',',$category_info->childs);
1382
		}
1383
1384
		// Used to specify the default query id (based on several search options to query id modified)
1385
		$query_id = 'document.getDocumentList';
1386
1387
		// If the search by specifying the document division naeyonggeomsaekil processed for
1388
		$use_division = false;
1389
1390
		// Search options
1391
		$search_target = $searchOpt->search_target;
1392
		$search_keyword = $searchOpt->search_keyword;
1393
1394
		if($search_target && $search_keyword)
1395
		{
1396
			switch($search_target)
1397
			{
1398
				case 'title' :
1399 View Code Duplication
				case 'content' :
1400
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1401
					$args->{"s_".$search_target} = $search_keyword;
1402
					$use_division = true;
1403
					break;
1404 View Code Duplication
				case 'title_content' :
1405
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1406
					$args->s_title = $search_keyword;
1407
					$args->s_content = $search_keyword;
1408
					$use_division = true;
1409
					break;
1410 View Code Duplication
				case 'user_id' :
1411
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1412
					$args->s_user_id = $search_keyword;
1413
					$args->sort_index = 'documents.'.$args->sort_index;
1414
					break;
1415
				case 'user_name' :
1416
				case 'nick_name' :
1417
				case 'email_address' :
1418 View Code Duplication
				case 'homepage' :
1419
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1420
					$args->{"s_".$search_target} = $search_keyword;
1421
					break;
1422
				case 'is_notice' :
1423
					if($search_keyword=='N') $args->{"s_".$search_target} = 'N';
1424
					elseif($search_keyword=='Y') $args->{"s_".$search_target} = 'Y';
1425
					else $args->{"s_".$search_target} = '';
1426
					break;
1427
				case 'is_secret' :
1428
					if($search_keyword=='N') $args->statusList = array($this->getConfigStatus('public'));
1429
					elseif($search_keyword=='Y') $args->statusList = array($this->getConfigStatus('secret'));
1430
					elseif($search_keyword=='temp') $args->statusList = array($this->getConfigStatus('temp'));
1431
					break;
1432
				case 'member_srl' :
1433
				case 'readed_count' :
1434
				case 'voted_count' :
1435
				case 'comment_count' :
1436
				case 'trackback_count' :
1437
				case 'uploaded_count' :
1438
					$args->{"s_".$search_target} = (int)$search_keyword;
1439
					break;
1440
				case 'member_srls' :
1441
					$args->{"s_".$search_target} = (int)$search_keyword;
1442
1443
					if($logged_info->member_srl)
1444
					{
1445
						$srls = explode(',', $search_keyword);
1446
						foreach($srls as $srl)
1447
						{
1448
							if(abs($srl) != $logged_info->member_srl)
1449
							{
1450
								break; // foreach
1451
							}
1452
1453
							$args->{"s_".$search_target} = $search_keyword;
1454
							break; // foreach
1455
						}
1456
					}
1457
					break;
1458
				case 'blamed_count' :
1459
					$args->{"s_".$search_target} = (int)$search_keyword * -1;
1460
					break;
1461
				case 'regdate' :
1462
				case 'last_update' :
1463
				case 'ipaddress' :
1464
					$args->{"s_".$search_target} = $search_keyword;
1465
					break;
1466
				case 'comment' :
1467
					$args->s_comment = $search_keyword;
1468
					$query_id = 'document.getDocumentListWithinComment';
1469
					$use_division = true;
1470
					break;
1471
				case 'tag' :
1472
					$args->s_tags = str_replace(' ','%',$search_keyword);
1473
					$query_id = 'document.getDocumentListWithinTag';
1474
					break;
1475
				case 'extra_vars':
1476
					$args->var_value = str_replace(' ', '%', $search_keyword);
1477
					$query_id = 'document.getDocumentListWithinExtraVars';
1478
					break;
1479
				default :
1480 View Code Duplication
					if(strpos($search_target,'extra_vars')!==false) {
1481
						$args->var_idx = substr($search_target, strlen('extra_vars'));
1482
						$args->var_value = str_replace(' ','%',$search_keyword);
1483
						$args->sort_index = 'documents.'.$args->sort_index;
1484
						$query_id = 'document.getDocumentListWithExtraVars';
1485
					}
1486
					break;
1487
			}
1488
		}
1489
1490
		if ($searchOpt->isExtraVars)
1491
		{
1492
			$query_id = 'document.getDocumentListExtraSort';
1493
		}
1494
		else
1495
		{
1496
			/**
1497
			 * list_order asc sort of division that can be used only when
1498
			 */
1499
			if($args->sort_index != 'list_order' || $args->order_type != 'asc') $use_division = false;
1500
1501
			/**
1502
			 * If it is true, use_division changed to use the document division
1503
			 */
1504
			if($use_division)
1505
			{
1506
				// Division begins
1507
				$division = (int)Context::get('division');
1508
1509
				// order by list_order and (module_srl===0 or module_srl may count), therefore case table full scan
1510
				if($args->sort_index == 'list_order' && ($args->exclude_module_srl === '0' || count(explode(',', $args->module_srl)) > 5))
1511
				{
1512
					$listSqlID = 'document.getDocumentListUseIndex';
0 ignored issues
show
Unused Code introduced by
$listSqlID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1513
					$divisionSqlID = 'document.getDocumentDivisionUseIndex';
1514
				}
1515
				else
1516
				{
1517
					$listSqlID = 'document.getDocumentList';
0 ignored issues
show
Unused Code introduced by
$listSqlID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1518
					$divisionSqlID = 'document.getDocumentDivision';
1519
				}
1520
1521
				// If you do not value the best division top
1522 View Code Duplication
				if(!$division)
1523
				{
1524
					$division_args = new stdClass();
1525
					$division_args->module_srl = $args->module_srl;
1526
					$division_args->exclude_module_srl = $args->exclude_module_srl;
1527
					$division_args->list_count = 1;
1528
					$division_args->sort_index = $args->sort_index;
1529
					$division_args->order_type = $args->order_type;
1530
					$division_args->statusList = $args->statusList;
1531
1532
					$output = executeQuery($divisionSqlID, $division_args, array('list_order'));
1533
					if($output->data)
1534
					{
1535
						$item = array_pop($output->data);
1536
						$division = $item->list_order;
1537
					}
1538
					$division_args = null;
0 ignored issues
show
Unused Code introduced by
$division_args is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1539
				}
1540
1541
				// The last division
1542
				$last_division = (int)Context::get('last_division');
1543
1544
				// Division after division from the 5000 value of the specified Wanted
1545 View Code Duplication
				if(!$last_division)
1546
				{
1547
					$last_division_args = new stdClass();
1548
					$last_division_args->module_srl = $args->module_srl;
1549
					$last_division_args->exclude_module_srl = $args->exclude_module_srl;
1550
					$last_division_args->list_count = 1;
1551
					$last_division_args->sort_index = $args->sort_index;
1552
					$last_division_args->order_type = $args->order_type;
1553
					$last_division_args->list_order = $division;
1554
					$last_division_args->page = 5001;
1555
1556
					$output = executeQuery($divisionSqlID, $last_division_args, array('list_order'));
1557
					if($output->data)
1558
					{
1559
						$item = array_pop($output->data);
1560
						$last_division = $item->list_order;
1561
					}
1562
				}
1563
1564
				// Make sure that after last_division article
1565
				if($last_division)
1566
				{
1567
					$last_division_args = new stdClass();
1568
					$last_division_args->module_srl = $args->module_srl;
1569
					$last_division_args->exclude_module_srl = $args->exclude_module_srl;
1570
					$last_division_args->list_order = $last_division;
1571
					$output = executeQuery('document.getDocumentDivisionCount', $last_division_args);
1572
					if($output->data->count<1) $last_division = null;
1573
				}
1574
1575
				$args->division = $division;
1576
				$args->last_division = $last_division;
1577
				Context::set('division', $division);
1578
				Context::set('last_division', $last_division);
1579
			}
1580
		}
1581
	}
1582
1583
	/**
1584
	 * Get the total number of Document in corresponding with member_srl.
1585
	 * @param int $member_srl
1586
	 * @return int
1587
	 */
1588
	function getDocumentCountByMemberSrl($member_srl)
1589
	{
1590
		$args = new stdClass();
1591
		$args->member_srl = $member_srl;
1592
		$output = executeQuery('document.getDocumentCountByMemberSrl', $args);
1593
		return (int) $output->data->count;
1594
	}
1595
1596
	/**
1597
	 * Get document list of the doc in corresponding woth member_srl.
1598
	 * @param int $member_srl
1599
	 * @param array $columnList
1600
	 * @param int $page
1601
	 * @param bool $is_admin
1602
	 * @param int $count
1603
	 * @return object
1604
	 */
1605 View Code Duplication
	function getDocumentListByMemberSrl($member_srl, $columnList = array(), $page = 0, $is_admin = FALSE, $count = 0 )
0 ignored issues
show
Unused Code introduced by
The parameter $page is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $is_admin is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
1606
	{
1607
		$args = new stdClass();
1608
		$args->member_srl = $member_srl;
1609
		$args->list_count = $count;
1610
		$output = executeQuery('document.getDocumentListByMemberSrl', $args, $columnList);
1611
		$document_list = $output->data;
1612
1613
		if(!$document_list) return array();
1614
		if(!is_array($document_list)) $document_list = array($document_list);
1615
1616
		return $document_list;
1617
	}
1618
1619
	/**
1620
	 * get to the document extra image path.
1621
	 * @return string
1622
	 */
1623
	function getDocumentExtraImagePath()
1624
	{
1625
		$documentConfig = getModel('document')->getDocumentConfig();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class ModuleObject as the method getDocumentConfig() does only exist in the following sub-classes of ModuleObject: documentModel. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
1626
		if(Mobile::isFromMobilePhone())
1627
		{
1628
			$iconSkin = $documentConfig->micons;
1629
		}
1630
		else
1631
		{
1632
			$iconSkin = $documentConfig->icons;
1633
		}
1634
		$path = sprintf('%s%s',getUrl(), "modules/document/tpl/icons/$iconSkin/");
1635
1636
		return $path;
1637
	}
1638
}
1639
/* End of file document.model.php */
1640
/* Location: ./modules/document/document.model.php */
1641