https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113702

Revision: 113702
Author:   jeroendedauw
Date:     2012-03-13 01:36:02 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
use proper array empty check and prioritized todos

Modified Paths:
--------------
    trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
    trunk/extensions/EducationProgram/actions/EPViewAction.php
    trunk/extensions/EducationProgram/actions/ViewCourseAction.php
    trunk/extensions/EducationProgram/api/ApiDeleteEducation.php
    trunk/extensions/EducationProgram/includes/DBDataObject.php
    trunk/extensions/EducationProgram/includes/EPCourse.php
    trunk/extensions/EducationProgram/includes/EPOrg.php
    trunk/extensions/EducationProgram/includes/EPPageTable.php
    trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
    trunk/extensions/EducationProgram/includes/EPRoleObject.php
    trunk/extensions/EducationProgram/resources/ep.articletable.js
    trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
    trunk/extensions/EducationProgram/specials/SpecialStudent.php

Modified: trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php 
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php 
2012-03-13 01:36:02 UTC (rev 113702)
@@ -33,7 +33,7 @@
                        'format' => 'json',
                        'courseid' => $this->getRequest()->getInt( 'course-id' 
),
                        'userid' => $this->getRequest()->getInt( 'user-id' ),
-                       'reason' => '', // TODO
+                       'reason' => '', // TODO high
                        'role' => 'student'
                ), true ), true );
 

Modified: trunk/extensions/EducationProgram/actions/EPViewAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPViewAction.php  2012-03-13 
01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/actions/EPViewAction.php  2012-03-13 
01:36:02 UTC (rev 113702)
@@ -55,7 +55,7 @@
                                ) );
 
                                if ( $rev === false ) {
-                                       // TODO
+                                       // TODO high
                                }
                                else {
                                        $object = $rev->getObject();

Modified: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/ViewCourseAction.php      
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/actions/ViewCourseAction.php      
2012-03-13 01:36:02 UTC (rev 113702)
@@ -54,7 +54,7 @@
                        $course->getStudents( 'id' )
                );
 
-               if ( count( $studentIds ) > 0 ) {
+               if ( !empty( $studentIds ) ) {
                        $out->addElement( 'h2', array(), wfMsg( 
'ep-course-students' ) );
 
                        $pager = new EPArticleTable(
@@ -131,7 +131,10 @@
        protected function getRoleList( EPCourse $course, $roleName ) {
                $users = $course->getUserWithRole( $roleName );
 
-               if ( count( $users ) > 0 ) {
+               if ( empty( $users ) ) {
+                       $html = wfMsgHtml( 'ep-course-no-' . $roleName );
+               }
+               else {
                        $instList = array();
 
                        foreach ( $users as /* EPIRole */ $user ) {
@@ -145,9 +148,6 @@
                                $html = '<ul><li>' . implode( '</li><li>', 
$instList ) . '</li></ul>';
                        }
                }
-               else {
-                       $html = wfMsgHtml( 'ep-course-no-' . $roleName );
-               }
 
                return Html::rawElement(
                        'div',
@@ -204,13 +204,13 @@
                        );
                }
 
-               if ( count( $links ) > 0 ) {
+               if ( empty( $links ) ) {
+                       return '';
+               }
+               else {
                        $this->getOutput()->addModules( 'ep.enlist' );
                        return '<br />' . $this->getLanguage()->pipeList( 
$links );
                }
-               else {
-                       return '';
-               }
        }
        
 }

Modified: trunk/extensions/EducationProgram/api/ApiDeleteEducation.php
===================================================================
--- trunk/extensions/EducationProgram/api/ApiDeleteEducation.php        
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/api/ApiDeleteEducation.php        
2012-03-13 01:36:02 UTC (rev 113702)
@@ -56,7 +56,7 @@
 
                $class = self::$typeMap[$params['type']];
                
-               if ( count( $params['ids'] ) > 0 ) {
+               if ( !empty( $params['ids'] ) ) {
                        $revAction = new EPRevisionAction();
                        
                        $revAction->setUser( $this->getUser() );

Modified: trunk/extensions/EducationProgram/includes/DBDataObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/DBDataObject.php 2012-03-13 
01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/includes/DBDataObject.php 2012-03-13 
01:36:02 UTC (rev 113702)
@@ -127,7 +127,7 @@
                        $fields = array_diff( $fields, array_keys( 
$this->fields ) );
                }
 
-               if ( count( $fields ) > 0 ) {
+               if ( !empty( $fields ) ) {
                        $result = $this->table->rawSelectRow(
                                $this->table->getPrefixedFields( $fields ),
                                array( $this->table->getPrefixedField( 'id' ) 
=> $this->getId() ),

Modified: trunk/extensions/EducationProgram/includes/EPCourse.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPCourse.php     2012-03-13 
01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/includes/EPCourse.php     2012-03-13 
01:36:02 UTC (rev 113702)
@@ -180,7 +180,7 @@
                                        $changedSummaries[] = 
$countMap[$usersField];
                                }
 
-                               if ( count( $removedIds ) > 0 ) {
+                               if ( !empty( $removedIds ) ) {
                                        $dbw->delete( 'ep_users_per_course', 
array(
                                                'upc_course_id' => 
$this->getId(),
                                                'upc_user_id' => $removedIds,
@@ -579,7 +579,10 @@
                $users = $this->getField( $field );
                $addedUsers = array_diff( (array)$newUsers, $users );
 
-               if ( count( $addedUsers ) > 0 ) {
+               if ( empty( $addedUsers ) ) {
+                       return 0;
+               }
+               else {
                        $this->setField( $field, array_merge( $users, 
$addedUsers ) );
 
                        $success = true;
@@ -597,9 +600,6 @@
 
                        return $success ? count( $addedUsers ) : false;
                }
-               else {
-                       return 0;
-               }
        }
 
        /**
@@ -630,7 +630,10 @@
                
                $removedUsers = array_intersect( $sadUsers, $this->getField( 
$field ) );
 
-               if ( count( $removedUsers ) > 0 ) {
+               if ( empty( $removedUsers ) ) {
+                       return 0;
+               }
+               else {
                        $this->setField( $field, array_diff( $this->getField( 
$field ), $sadUsers ) );
 
                        if ( $role === 'student' ) {
@@ -658,9 +661,6 @@
 
                        return $success ? count( $removedUsers ) : false;
                }
-               else {
-                       return 0;
-               }
        }
 
        /**

Modified: trunk/extensions/EducationProgram/includes/EPOrg.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPOrg.php        2012-03-13 
01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/includes/EPOrg.php        2012-03-13 
01:36:02 UTC (rev 113702)
@@ -117,7 +117,7 @@
                        $courseRevAction = new EPRevisionAction();
                
                        $courseRevAction->setUser( $revAction->getUser() );
-                       $courseRevAction->setComment( '' ); // TODO
+                       $courseRevAction->setComment( $revAction->getComment() 
);
                        
                        foreach ( $this->getField( 'courses' ) as $courseId ) {
                                $courseRevision = 
EPRevisions::singleton()->getLatestRevision( array(

Modified: trunk/extensions/EducationProgram/includes/EPPageTable.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPPageTable.php  2012-03-13 
01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/includes/EPPageTable.php  2012-03-13 
01:36:02 UTC (rev 113702)
@@ -76,7 +76,7 @@
 
                $success = true;
 
-               if ( count( $objects ) > 0 ) {
+               if ( !empty( $objects ) ) {
                        $revAction->setDelete( true );
 
                        foreach ( $objects as /* EPPageObject */ $object ) {

Modified: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionedObject.php   
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/includes/EPRevisionedObject.php   
2012-03-13 01:36:02 UTC (rev 113702)
@@ -260,7 +260,7 @@
                        array( 'LIMIT' => 1 )
                );
 
-               return count( $objects ) > 0 ? $objects[0] : false;
+               return empty( $objects ) ? false : $objects[0];
        }
        
        /**

Modified: trunk/extensions/EducationProgram/includes/EPRoleObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRoleObject.php 2012-03-13 
01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/includes/EPRoleObject.php 2012-03-13 
01:36:02 UTC (rev 113702)
@@ -163,7 +163,7 @@
 
                $field = $fieldMap[$this->getRoleName()];
 
-               if ( count( $courseIds ) > 0 ) {
+               if ( !empty( $courseIds ) ) {
                        EPOrgs::singleton()->updateSummaryFields( $field, 
array( 'id' => array_unique( $courseIds ) ) );
                        EPCourses::singleton()->updateSummaryFields( $field, 
array( 'id' => $courseIds ) );
                }

Modified: trunk/extensions/EducationProgram/resources/ep.articletable.js
===================================================================
--- trunk/extensions/EducationProgram/resources/ep.articletable.js      
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/resources/ep.articletable.js      
2012-03-13 01:36:02 UTC (rev 113702)
@@ -262,7 +262,7 @@
 
                $( '.ep-rem-article' ).click( removeArticle );
 
-               $( '#addarticlename' ).autocomplete( { // TODO
+               $( '#addarticlename' ).autocomplete( {
                        source: function( request, response ) {
                                $.getJSON(
                                        wgScriptPath + '/api.php',

Modified: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialMyCourses.php     
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/specials/SpecialMyCourses.php     
2012-03-13 01:36:02 UTC (rev 113702)
@@ -47,7 +47,7 @@
                                $course = EPCourses::singleton()->selectRow( 
null, array( 'name' => $this->subPage ) );
                                
                                if ( $course === false ) {
-                                       // TODO
+                                       // TODO high
                                }
                                else {
                                        $this->displayCourse( $course );
@@ -155,7 +155,7 @@
                                break;
                }
 
-               if ( count( $courses ) > 0 ) {
+               if ( !empty( $courses ) ) {
                        $message = wfMsgExt( 'ep-mycourses-courses-' . 
strtolower( $class ), 'parsemag', count( $courses ), 
$this->getUser()->getName() );
                        $this->getOutput()->addElement( 'h2', array(), $message 
);
 

Modified: trunk/extensions/EducationProgram/specials/SpecialStudent.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudent.php       
2012-03-13 01:18:25 UTC (rev 113701)
+++ trunk/extensions/EducationProgram/specials/SpecialStudent.php       
2012-03-13 01:36:02 UTC (rev 113702)
@@ -57,13 +57,13 @@
                                        $student->getCourses( 'id' )
                                );
 
-                               if ( count( $courseIds ) > 0 ) {
+                               if ( empty( $courseIds ) ) {
+                                       // TODO: high
+                               }
+                               else {
                                        $out->addElement( 'h2', array(), wfMsg( 
'ep-student-courses' ) );
                                        EPCourse::displayPager( 
$this->getContext(), array( 'id' => $courseIds ) );
                                }
-                               else {
-                                       // TODO
-                               }
                        }
                }
        }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to