| Conditions | 24 |
| Paths | 87 |
| Total Lines | 110 |
| 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 |
||
| 127 | protected function getResultText( SMWQueryResult $queryResult, $outputmode ) {
|
||
| 128 | |||
| 129 | // Show warning if Extension:Mermaid is not available |
||
| 130 | if ( !class_exists( 'Mermaid' ) && !class_exists( 'Mermaid\\MermaidParserFunction' ) ) {
|
||
| 131 | $queryResult->addErrors( [wfMessage('')->text()] );
|
||
| 132 | return ''; |
||
| 133 | } |
||
| 134 | |||
| 135 | // Load general Modules |
||
| 136 | SMWOutputs::requireResource( 'ext.srf.gantt' ); |
||
| 137 | |||
| 138 | //Add Tasks & Sections |
||
| 139 | while ( $row = $queryResult->getNext() ) {
|
||
| 140 | |||
| 141 | $status = []; |
||
| 142 | $priority = []; |
||
| 143 | $startDate = ''; |
||
| 144 | $endDate = ''; |
||
| 145 | $taskID = ''; |
||
| 146 | $taskTitle = ''; |
||
| 147 | $sections = []; |
||
| 148 | |||
| 149 | // Loop through all field of a row |
||
| 150 | foreach ( $row as $field ) {
|
||
| 151 | |||
| 152 | $fieldLabel = $field->getPrintRequest()->getLabel(); |
||
| 153 | |||
| 154 | //get values |
||
| 155 | foreach ( $field->getContent() as $dataItem ) {
|
||
| 156 | |||
| 157 | switch ( $fieldLabel ) {
|
||
| 158 | case 'section': |
||
| 159 | $sections[$dataItem->getTitle()->getPrefixedDBKey()] = $dataItem->getSortKey(); |
||
| 160 | break; |
||
| 161 | case 'task': |
||
| 162 | if ( $dataItem instanceof SMWDIBlob ) {
|
||
| 163 | $taskTitle = $dataItem->getString(); |
||
| 164 | $taskID = $field->getResultSubject()->getTitle()->getPrefixedDBKey(); |
||
| 165 | } |
||
| 166 | break; |
||
| 167 | case 'startdate': |
||
| 168 | if ( $dataItem instanceof SMWDITime ) {
|
||
| 169 | $startDate = $dataItem->getMwTimestamp(); |
||
| 170 | } |
||
| 171 | break; |
||
| 172 | case 'enddate': |
||
| 173 | if ( $dataItem instanceof SMWDITime ) {
|
||
| 174 | $endDate = $dataItem->getMwTimestamp(); |
||
| 175 | } |
||
| 176 | break; |
||
| 177 | case 'status': |
||
| 178 | if ( $dataItem instanceof SMWDIBlob ) {
|
||
| 179 | $status[] = $dataItem->getString(); |
||
| 180 | } |
||
| 181 | break; |
||
| 182 | case 'priority': |
||
| 183 | if ( $dataItem instanceof SMWDIBlob ) {
|
||
| 184 | $priority[] = $dataItem->getString(); |
||
| 185 | } |
||
| 186 | break; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | // Add section/Task |
||
| 192 | // Title, TaskID, StartDate and EndDate are required |
||
| 193 | if ( $taskID !== '' && $taskTitle !== '' && $startDate !== '' && $endDate !== '' ) {
|
||
| 194 | $this->mGantt->addTask( $taskID, $taskTitle, $status, $priority, $startDate, $endDate ); |
||
| 195 | |||
| 196 | // If no section was found, put task into a dummy section object |
||
| 197 | // "gantt-no-section#21780240" is used to identify Tasks that with no section (dummy section) |
||
| 198 | if ( count( $sections ) == 0 ) {
|
||
| 199 | $this->mGantt->addSection( 'gantt-no-section#21780240', '', $startDate, $endDate, $taskID ); |
||
| 200 | } else {
|
||
| 201 | foreach ( $sections as $sectionID => $sectionTitle ) {
|
||
| 202 | $this->mGantt->addSection( $sectionID, $sectionTitle, $startDate, $endDate, $taskID ); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | // Improve unique id by adding a random number |
||
| 209 | $id = uniqid( 'srf-gantt-' . rand( 1, 10000 ) ); |
||
| 210 | |||
| 211 | // Add gantt configurations |
||
| 212 | $config = [ |
||
| 213 | 'theme' => $this->params['theme'], |
||
| 214 | 'gantt' => [ |
||
| 215 | 'leftPadding' => intval( $this->params['leftpadding'] ), |
||
| 216 | 'titleTopMargin' => intval( $this->params['titletopmargin'] ), |
||
| 217 | 'barHeight' => intval( $this->params['barheight'] ), |
||
| 218 | 'barGap' => intval( $this->params['bargap'] ) |
||
| 219 | ] |
||
| 220 | ]; |
||
| 221 | |||
| 222 | |||
| 223 | // Manage Output |
||
| 224 | if ( !empty( $this->mErrors ) ) {
|
||
| 225 | return $queryResult->addErrors( $this->mErrors ); |
||
| 226 | } else {
|
||
| 227 | return Html::rawElement( 'div', [ |
||
| 228 | 'id' => $id, |
||
| 229 | 'class' => 'srf-gantt', |
||
| 230 | 'data-mermaid' => html_entity_decode( json_encode( [ |
||
| 231 | 'content' => $this->mGantt->getGanttOutput(), |
||
| 232 | 'config' => $config |
||
| 233 | ])) |
||
| 234 | ], Html::rawElement( 'div', [ 'class' => 'mermaid-dots' ])); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 284 | } |