TreeData.php ➔ get_documents()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30
Metric Value
cc 5
eloc 22
nc 12
nop 3
dl 0
loc 29
ccs 0
cts 27
cp 0
crap 30
rs 8.439
1
<?php
2
 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
require_once('include/ytree/Node.php');
42
43
44
45
//function returns an array of objects of Node type.
46
function get_node_data($params,$get_array=false) {
47
    $ret=array();
48
    $click_level=$params['TREE']['depth'];
49
    $subcat_id=$params['NODES'][$click_level]['id'];
50
    $cat_id=$params['NODES'][$click_level-1]['id'];
51
    $href=true;
52
    if (isset($params['TREE']['caller']) and $params['TREE']['caller']=='Documents' ) {
53
        $href=false;
54
    }
55
	$nodes=get_documents($cat_id,$subcat_id,$href);
56
	foreach ($nodes as $node) {
57
		$ret['nodes'][]=$node->get_definition();
58
	}
59
	$json = new JSON(JSON_LOOSE_TYPE);
0 ignored issues
show
Unused Code introduced by
The call to JSON::__construct() has too many arguments starting with JSON_LOOSE_TYPE.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
	$str=$json->encode($ret);
61
	return $str;
62
}
63
64
/*
65
 *  
66
 *
67
 */
68
 function get_category_nodes($href_string){
69
    $nodes=array();
70
    global $mod_strings;
71
    global $app_list_strings;
72
    $query="select distinct category_id, subcategory_id from documents where deleted=0 order by category_id, subcategory_id";
73
    $result=$GLOBALS['db']->query($query);
74
    $current_cat_id=null;
75
    $cat_node=null;
76
    while (($row=$GLOBALS['db']->fetchByAssoc($result))!= null) {
77
78
        if (empty($row['category_id'])) {
79
            $cat_id='null';
80
            $cat_name=$mod_strings['LBL_CAT_OR_SUBCAT_UNSPEC'];
81
        } else {
82
            $cat_id=$row['category_id'];
83
            $cat_name=$app_list_strings['document_category_dom'][$row['category_id']];
84
        }            
85
        if (empty($current_cat_id) or $current_cat_id != $cat_id) {
86
            $current_cat_id = $cat_id;
87
            if (!empty($cat_node)) $nodes[]=$cat_node;
88
            
89
            $cat_node = new Node($cat_id, $cat_name);
90
            $cat_node->set_property("href", $href_string);
91
            $cat_node->expanded = true;
92
            $cat_node->dynamic_load = false;
93
        } 
94
95
        if (empty($row['subcategory_id'])) {
96
            $subcat_id='null';
97
            $subcat_name=$mod_strings['LBL_CAT_OR_SUBCAT_UNSPEC'];
98
        } else {
99
            $subcat_id=$row['subcategory_id'];
100
            $subcat_name=$app_list_strings['document_subcategory_dom'][$row['subcategory_id']];
101
        }            
102
        $subcat_node = new Node($subcat_id, $subcat_name);
103
        $subcat_node->set_property("href", $href_string);
104
        $subcat_node->expanded = false;
105
        $subcat_node->dynamic_load = true;
106
        
107
        $cat_node->add_node($subcat_node);
108
    }    
109
    if (!empty($cat_node)) $nodes[]=$cat_node;
110
111
    return $nodes;
112
 }
113
 
114
function get_documents($cat_id, $subcat_id,$href=true) {
115
    $nodes=array();
116
    $href_string = "javascript:select_document('doctree')";
117
    $query="select * from documents where deleted=0";
118
    if ($cat_id != 'null') {
119
        $query.=" and category_id='$cat_id'";
120
    } else {
121
        $query.=" and category_id is null";
122
    }
123
        
124
    if ($subcat_id != 'null') {
125
        $query.=" and subcategory_id='$subcat_id'";
126
    } else {
127
        $query.=" and subcategory_id is null";
128
    }
129
    $result=$GLOBALS['db']->query($query);
130
    $current_cat_id=null;
131
    while (($row=$GLOBALS['db']->fetchByAssoc($result))!= null) {
132
        $node = new Node($row['id'], $row['document_name']);
133
        if ($href) {
134
            $node->set_property("href", $href_string);
135
        }
136
        $node->expanded = true;
137
        $node->dynamic_load = false;
138
        
139
        $nodes[]=$node;
140
    }
141
    return $nodes;
142
}
143
?>
144