| Conditions | 6 |
| Paths | 9 |
| Total Lines | 68 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 namespace XoopsModules\Tdmcreate\Files\Includes; |
||
| 105 | public function getSearchFunction($moduleDirname) |
||
| 106 | { |
||
| 107 | $table = $this->getTable(); |
||
| 108 | $tableName = $table->getVar('table_name'); |
||
| 109 | $tableFieldname = $table->getVar('table_fieldname'); |
||
| 110 | $fieldId = ''; |
||
| 111 | $fieldSearch = null; |
||
| 112 | $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
||
| 113 | foreach (array_keys($fields) as $f) { |
||
| 114 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 115 | if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) { |
||
| 116 | $fieldId = $fieldName; |
||
| 117 | } |
||
| 118 | if (1 == $fields[$f]->getVar('field_main')) { |
||
| 119 | $fieldMain = $fieldName; |
||
| 120 | } |
||
| 121 | if (1 == $fields[$f]->getVar('field_search')) { |
||
| 122 | $fieldSearch = $fieldName; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | $img_search = 'blank.gif'; |
||
| 126 | $ret = <<<EOT |
||
| 127 | \n |
||
| 128 | /** |
||
| 129 | * search callback functions |
||
| 130 | * @param \$queryarray |
||
| 131 | * @param \$andor |
||
| 132 | * @param \$limit |
||
| 133 | * @param \$offset |
||
| 134 | * @param \$userid |
||
| 135 | */ |
||
| 136 | function {$moduleDirname}_search(\$queryarray, \$andor, \$limit, \$offset, \$userid) |
||
| 137 | { |
||
| 138 | global \$xoopsDB; |
||
| 139 | \$sql = "SELECT '{$fieldId}', '{$fieldMain}' FROM " . \$xoopsDB->prefix('{$moduleDirname}_{$tableName}') . ' WHERE {$fieldId} != 0'; |
||
| 140 | if ( \$userid != 0 ) { |
||
| 141 | \$sql .= ' AND {$tableFieldname}_submitter='.(int)\$userid; |
||
| 142 | } |
||
| 143 | if ( is_array(\$queryarray) && \$count = count(\$queryarray) ) |
||
| 144 | { |
||
| 145 | \$sql .= " AND ( |
||
| 146 | EOT; |
||
| 147 | $ret .= $this->getSearchField($fieldSearch, 0).'";'; |
||
| 148 | $ret .= <<<EOT |
||
| 149 | |||
| 150 | for(\$i = 1; \$i < \$count; ++\$i) |
||
| 151 | { |
||
| 152 | \$sql .= " \$andor "; |
||
| 153 | \$sql .= "{$this->getSearchField($fieldSearch, '$i')}"; |
||
| 154 | } |
||
| 155 | \$sql .= ')'; |
||
| 156 | } |
||
| 157 | \$sql .= " ORDER BY '{$fieldId}' DESC"; |
||
| 158 | \$result = \$xoopsDB->query(\$sql,\$limit,\$offset); |
||
| 159 | \$ret = array(); |
||
| 160 | \$i = 0; |
||
| 161 | while(\$myrow = \$xoopsDB->fetchArray(\$result)) |
||
| 162 | { |
||
| 163 | \$ret[\$i]['image'] = 'assets/icons/32/{$img_search}'; |
||
| 164 | \$ret[\$i]['link'] = '{$tableName}.php?{$fieldId}='.\$myrow['{$fieldId}']; |
||
| 165 | \$ret[\$i]['title'] = \$myrow['{$fieldMain}']; |
||
| 166 | ++\$i; |
||
| 167 | } |
||
| 168 | unset(\$i); |
||
| 169 | } |
||
| 170 | EOT; |
||
| 171 | |||
| 172 | return $ret; |
||
| 173 | } |
||
| 193 |