sql - Moodle changing PDO-Query to Moodle DB API -


i want change pdo-query moodle db api:

foreach($course $courses) {         foreach($user $users)         {             $statement = $pdo->prepare("select round(gg.finalgrade,2) finalgrade                                          mdl_grade_items gi                        right outer join mdl_course c on c.id = gi.courseid                                  join mdl_course_categories cc on cc.id = c.category                             left join mdl_grade_grades gg on gg.itemid = gi.id                             left join mdl_user u on gg.userid = u.id                                  join mdl_cohort_members cm on cm.userid = u.id                                  join mdl_cohort cohort on cohort.id = cm.cohortid                                    gi.itemtype = :itemtype                                   , cc.name = :coursecategory                                   , (u.institution = :institution or u.username null)                                          , cohort.name = '$cohort'                                   , c.fullname = '$courses' , u.username = '$users'                                  order c.id asc");              $statement->execute(array(                 ':itemtype'       => 'mod',                 ':coursecategory' => $coursecategory,                 'institution'     => $user->institution));                             $row = $statement->fetch(pdo::fetch_assoc);              if($row['finalgrade'] <  $grade_lowerboundary[1] && (!empty($row['finalgrade'])))               {$style ='background-color: #ff0000';}        else if($row['finalgrade'] <  $grade_lowerboundary[2] && (!empty($row['finalgrade'])))               {$style ='background-color: #f03131';}        else if($row['finalgrade'] <  $grade_lowerboundary[3] && (!empty($row['finalgrade'])))               {$style ='background-color: #f76402';}        else if($row['finalgrade'] <  $grade_lowerboundary[4] && (!empty($row['finalgrade'])))               {$style ='background-color: #e96d1a';}        else if($row['finalgrade'] <  $grade_lowerboundary[5] && (!empty($row['finalgrade'])))               {$style ='background-color: #f57d2c';}        else if($row['finalgrade'] <  $grade_lowerboundary[6] && (!empty($row['finalgrade'])))               {$style ='background-color: #edb50c';}        else if($row['finalgrade'] <  $grade_lowerboundary[7] && (!empty($row['finalgrade'])))               {$style ='background-color: #edcb0c';}        else if($row['finalgrade'] <  $grade_lowerboundary[8] && (!empty($row['finalgrade'])))               {$style ='background-color: #f9ec36';}        else if($row['finalgrade'] <  $grade_lowerboundary[9] && (!empty($row['finalgrade'])))               {$style ='background-color: #378def';}        else if($row['finalgrade'] <  $grade_lowerboundary[10] && (!empty($row['finalgrade'])))              {$style ='background-color: #1c7be6';}        else if($row['finalgrade'] <  $grade_lowerboundary[11] && (!empty($row['finalgrade'])))              {$style ='background-color: #0e5fbc';}        else if($row['finalgrade'] <  $grade_lowerboundary[12] && (!empty($row['finalgrade'])))              {$style ='background-color: #16def0';}        else if($row['finalgrade'] <  $grade_lowerboundary[13] && (!empty($row['finalgrade'])))              {$style ='background-color: #24c7d6';}        else if($row['finalgrade'] <  $grade_lowerboundary[14] && (!empty($row['finalgrade'])))              {$style ='background-color: #1da9b5';}        else if($row['finalgrade'] <  $grade_lowerboundary[15] && (!empty($row['finalgrade'])))              {$style ='background-color: #22b51d';}        else if($row['finalgrade'] >= $grade_lowerboundary[15] && (!empty($row['finalgrade'])))              {$style ='background-color: #25d41f';}        else if($row['finalgrade'] == null) {$style = 'background-color: gray';}         echo "<td align=\"right\" style=\"$style; min-width: 48px\">".$row['finalgrade']."</td>";          } 

this tried far:

    //courses     foreach($kurse $courses)     {        //users           foreach($nutzer $users)       {          $sql = "select round(gg.finalgrade,2) finalgrade                          {grade_items} gi                right outer join {course} c on c.id = gi.courseid                         join {course_categories} cc on cc.id = c.category                    left join {grade_grades} gg on gg.itemid = gi.id                    left join {user} u on gg.userid = u.id                         join {cohort_members} cm on cm.userid = u.id                         join {cohort} cohort on cohort.id = cm.cohortid                           gi.itemtype = :itemtype                          , cc.name = :coursecategory                          , (u.institution = :institution or u.username null)                          , cohort.name = '$cohort'                          , c.fullname = '$courses' , u.username = '$users'                         order c.id asc";          $statement = $db->get_records_sql($sql, array('itemtype'         =>'mod',                                                       'coursecategory'=>$coursecategory,                                                       'institution'   =>$user->institution));              foreach($statement $statements)         {                                $points_user = $statements->finalgrade;                if($points_user <  $grade_lowerboundary[1]  && (!empty($punkte_user))) {$style ='background-color: #ff0000';}                  //; $value = $grade_letters[0];}//6          else if($points_user <  $grade_lowerboundary[2]  && (!empty($punkte_user))) {$style ='background-color: #f03131';}          else if($points_user <  $grade_lowerboundary[3]  && (!empty($punkte_user))) {$style ='background-color: #f76402';}          else if($points_user <  $grade_lowerboundary[4]  && (!empty($punkte_user))) {$style ='background-color: #e96d1a';}          else if($points_user <  $grade_lowerboundary[5]  && (!empty($punkte_user))) {$style ='background-color: #f57d2c';}          else if($points_user <  $grade_lowerboundary[6]  && (!empty($punkte_user))) {$style ='background-color: #edb50c';}          else if($points_user <  $grade_lowerboundary[7]  && (!empty($punkte_user))) {$style ='background-color: #edcb0c';}          else if($points_user <  $grade_lowerboundary[8]  && (!empty($punkte_user))) {$style ='background-color: #f9ec36';}          else if($points_user <  $grade_lowerboundary[9]  && (!empty($punkte_user))) {$style ='background-color: #378def';}          else if($points_user <  $grade_lowerboundary[10] && (!empty($punkte_user))) {$style ='background-color: #1c7be6';}          else if($points_user <  $grade_lowerboundary[11] && (!empty($punkte_user))) {$style ='background-color: #0e5fbc';}          else if($points_user <  $grade_lowerboundary[12] && (!empty($punkte_user))) {$style ='background-color: #16def0';}          else if($points_user <  $grade_lowerboundary[13] && (!empty($punkte_user))) {$style ='background-color: #24c7d6';}          else if($points_user <  $grade_lowerboundary[14] && (!empty($punkte_user))) {$style ='background-color: #1da9b5';}          else if($points_user <  $grade_lowerboundary[15] && (!empty($punkte_user))) {$style ='background-color: #22b51d';}          else if($points_user >= $grade_lowerboundary[15] && (!empty($punkte_user))) {$style ='background-color: #25d41f';}          else   {$points_user = ""; $style ='background-color: gray';}          echo "<td align=\"right\" style=\"$style; min-width:48px\">".$punkte_user."</td>";             } 

the pdo-query works perfectly, when try change moodle db api version, makes 'td' when there value in 'finalgrade', rest of table blank. want have 'td's when there no value, too. var_dump($statements) shows me empty array (array(0) {} ) when there no value in finalgrade:

array(1) {   ["87.50"]=>   object(stdclass)#145 (1) {     ["finalgrade"]=>     string(5) "87.50"   } }  array(1) {   ["37.50"]=>   object(stdclass)#94 (1) {     ["finalgrade"]=>     string(5) "37.50"   } }  array(1) {   ["12.50"]=>   object(stdclass)#93 (1) {     ["finalgrade"]=>     string(5) "12.50"   } }  array(1) {   ["75.00"]=>   object(stdclass)#145 (1) {     ["finalgrade"]=>     string(5) "75.00"   } }  array(0) { } //... 

var_dump($row['finalgrades']) looks this:

array(1) {   ["53.33"]=>   object(stdclass)#131 (1) {     ["finalgrade"]=>     string(5) "53.33"   } }  array(1) {   [""]=>   object(stdclass)#97 (1) {     ["finalgrade"]=>     null   } }  array(1) {   [""]=>   object(stdclass)#96 (1) {     ["finalgrade"]=>     null   } }  array(1) {   [""]=>   object(stdclass)#131 (1) {     ["finalgrade"]=>     null   } } //... 

can explain me, why in pdo there null value in array , in moodle api empty array. i'm stuck here.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -