Conditions | 16 |
Paths | 4096 |
Total Lines | 110 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 272 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
71 | function display(){ |
||
72 | |||
73 | /* valid entries for expected arguments array are as follow: |
||
74 | * args['left_header'] = value of left table header |
||
75 | * args['mid_header'] = value of middle table header |
||
76 | * args['right_header'] = value of right table header |
||
77 | * args['left_data'] = array to use in left data. |
||
78 | * args['mid_data'] = array to use in middle data. |
||
79 | * args['right_data'] =array to use in right data. |
||
80 | * args['title'] = title (if any) to be used. |
||
81 | * args['classname'] = name to be used as class. This helps when defining multiple templates on one screen. |
||
82 | * args['left_div_name'] = Name to be used for left div (should be unique) |
||
83 | * args['mid_div_name'] = Name to be used for middle div (should be unique) |
||
84 | * args['right_div_name'] = Name to be used for right div (should be unique) |
||
85 | * args['gridcount'] = Number of grids to show. Acceptable Values are 'one','two' and 'three' |
||
86 | * The string is converted to numeric values, so you could also set these directly |
||
87 | * The values are Zero Based, so to display one column, set to '0' |
||
88 | * To display two columns set to '1', to display three columns set to '2'. |
||
89 | * $this->args['return_array']= if this is set to true, then 'display()' function returns html and javascript |
||
90 | * in array format. This will allow granular control of html so that you can |
||
91 | * separate the tables and customize the grid |
||
92 | */ |
||
93 | |||
94 | |||
95 | //convert values for gridcount in case they are in string form |
||
96 | if($this->args['gridcount'] == 'one'){ |
||
97 | $this->args['gridcount'] = 0; |
||
98 | }elseif($this->args['gridcount'] == 'two'){ |
||
99 | $this->args['gridcount'] = 1; |
||
100 | }elseif( |
||
101 | $this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2; |
||
102 | } |
||
103 | |||
104 | if(!isset($this->args['classname']) || empty($this->args['classname'])){ |
||
105 | $this->args['classname'] = 'DragDropGrid'; |
||
106 | } |
||
107 | $json = getJSONobj(); |
||
108 | //use Json to encode the arrays of data, for passing to javascript. |
||
109 | //we will always display at least one column, so set left column |
||
110 | $this->args['left_data'][] = array(' ', ' '); |
||
111 | $data0_enc = $json->encode($this->args['left_data']); |
||
112 | $left_div_name = $this->args['left_div_name']; |
||
113 | |||
114 | //if count is set to 1, then we are displaying two columns, set the 2 column variables |
||
115 | if($this->args['gridcount']==1){ |
||
116 | $this->args['right_data'][] = array(' ', ' '); |
||
117 | $data1_enc = $json->encode($this->args['right_data']); |
||
118 | $right_div_name = $this->args['right_div_name']; |
||
119 | } |
||
120 | |||
121 | //if count is set to 2, then we are displaying three columns, set the 3 column variables |
||
122 | if($this->args['gridcount']==2){ |
||
123 | $this->args['mid_data'][] = array(' ', ' '); |
||
124 | $data1_enc = $json->encode($this->args['mid_data']); |
||
125 | $mid_div_name = $this->args['mid_div_name']; |
||
126 | $this->args['right_data'][] = array(' ', ' '); |
||
127 | $data2_enc = $json->encode($this->args['right_data']); |
||
128 | $right_div_name = $this->args['right_div_name']; |
||
129 | } |
||
130 | $html_str_arr = array(); |
||
131 | //create the table, with the divs that will get populated. Populate both the string and array version |
||
132 | $html_str = "<div id='" . $this->args['classname'] . "'><table align='left' width='180px' border='1' cellspacing='0' cellpadding='0'>"; |
||
133 | $html_str_arr['begin'] = $html_str; |
||
134 | $html_str .= "<tr><td width='180px' class='tabDetailViewDF'><div id='$left_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
||
135 | $html_str_arr['left'] = "<tr><td width='180px' class='tabDetailViewDF'><div id='$left_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
||
136 | //set the middle column only if we are displaying 3 columns |
||
137 | if($this->args['gridcount']==2){ |
||
138 | $html_str .= "<td width='180px' class='tabDetailViewDF'><div id='$mid_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
||
139 | $html_str_arr['middle'] = "<td width='180px' class='tabDetailViewDF'><div id='$mid_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
||
140 | } |
||
141 | //set the right column if we are not in 1 column only mode |
||
142 | if($this->args['gridcount']>0){ |
||
143 | $html_str .= "<td width='180px' class='tabDetailViewDF'><div id='$right_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
||
144 | $html_str_arr['right'] = "<td width='180px' class='tabDetailViewDF'><div id='$right_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
||
145 | } |
||
146 | $html_str .= "</tr></table></div>"; |
||
147 | $html_str_arr['end'] = "</tr></table></div>"; |
||
148 | |||
149 | //create the needed javascript to set the values and invoke listener |
||
150 | $j_str = "<script> "; |
||
151 | $j_str .= $this->args['classname'] . ".rows0 = {$data0_enc};\n"; |
||
152 | $j_str .= $this->args['classname'] . ".hdr0 = '{$this->args['left_header']}';\n"; |
||
153 | if($this->args['gridcount']==1){ |
||
154 | $j_str .= $this->args['classname'] . ".rows1 = {$data1_enc};\n"; |
||
155 | $j_str .= $this->args['classname'] . ".hdr1 = '{$this->args['right_header']}';\n"; |
||
156 | } |
||
157 | if($this->args['gridcount']==2){ |
||
158 | $j_str .= $this->args['classname'] . ".rows1 = {$data1_enc}; \n"; |
||
159 | $j_str .= $this->args['classname'] . ".rows2 = {$data2_enc}; \n"; |
||
160 | $j_str .= $this->args['classname'] . ".hdr1 = '{$this->args['mid_header']}'; \n"; |
||
161 | $j_str .= $this->args['classname'] . ".hdr2 = '{$this->args['right_header']}'; \n"; |
||
162 | } |
||
163 | $divs_str = "'".$left_div_name ."'"; |
||
164 | if($this->args['gridcount']==2){$divs_str .= ", '".$mid_div_name."'";} |
||
165 | if($this->args['gridcount']>0) {$divs_str .= ", '".$right_div_name."'";} |
||
166 | |||
167 | $j_str .= $this->args['classname'] . ".divs = [$divs_str]; "; |
||
168 | |||
169 | $j_str .= "YAHOO.util.Event.on(window, 'load', " . $this->args['classname'] . ".init); "; |
||
170 | $j_str .= "</script> "; |
||
171 | //return display string |
||
172 | $str = $j_str . ' ' . $html_str; |
||
173 | $html_str_arr['script'] = $j_str; |
||
174 | |||
175 | if(isset($this->args['return_array']) && $this->args['return_array']){ |
||
176 | return $html_str_arr; |
||
177 | }else{ |
||
178 | return $str; |
||
179 | } |
||
180 | } |
||
181 | |||
315 |