Jump to content

huck

Members
  • Posts

    10
  • Joined

  • Last visited

Posts posted by huck

  1. Hey Mac,

    Thanks for the tip, it led me to the answer in a roundabout way. Moodle uses associative array on with the fucntion call get_records_sql(), and as such requires a proper 'id' field to build a fully populated query, if you use the wrong 'id', it filters out what it perceives as duplicates based on the 'id' value, so if the same 'id' has more than one record, the function will only return one record.

    First I tried:

    SELECT u.id , ...(rest of query)

    and it failed, but then I tried:

    SELECT gg.id , ...(rest of query)

    It gave back the full listing as expected when I do a query through phpmyadmin.

    Thanks guys, appreciate the help.

    huck
  2. Moodle 2.5

     

    *nix server

     

    Theme: Essential

     

    ----------------------

     

    Hi Folks

     

     

    I have a small mind bender in how php is returning results from a mysql query. There are two issues:

     

    1) The mysql query from phpmyadmin is correct, while the php function that handles the query from the website is not.

    2) It takes a very long time to run this query with php, 30 seconds to over a minute. Phpmyadmin is rather quick (Query took 0.0239 seconds).

     

    The query is:

     

    
    SELECT u.firstname AS 'Name' , u.lastname AS 'Surname', c.shortname AS 'Course', (
                CASE
                WHEN gi.itemname LIKE '%summative%' THEN 'SUMMATIVE'
                WHEN gi.itemname LIKE '%formative 2%' THEN 'FORMATIVE 2'
                ELSE 'MC'
                END) AS 'Assessment', from_unixtime(gi.timemodified, '%d/%m/%y') AS 'Date',
                IF (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) > 70,'Yes' , 'No') AS Pass, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark', ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark'
                FROM mdl_course AS c
                JOIN mdl_context AS ctx ON c.id = ctx.instanceid
                JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id
                JOIN mdl_user AS u ON u.id = ra.userid
                JOIN mdl_grade_grades AS gg ON gg.userid = u.id
                JOIN mdl_grade_items AS gi ON gi.id = gg.itemid
                JOIN mdl_course_categories AS cc ON cc.id = c.category
                WHERE gi.courseid = c.id
                AND gi.itemname != 'Attendance'
                AND u.firstname LIKE '%03%'
                AND gi.itemname LIKE '%mative%'
                ORDER BY  `Name` , `Surname` , `Course`, `Assessment` ASC
    
    
    When I run the query in phpmyadmin , it gives back;

     

    Name 		Surname		Category 	Module 		Course 		Assessment 	Date 		Competent 	Mark 	
    G03 Itumeleng 	Velmah Mokwa 	Fundamentals 	Communications 	CO1 119472 	FORMATIVE 2 	07/04/14 	Yes 		100.00
    G03 Itumeleng 	Velmah Mokwa 	Fundamentals 	Communications 	CO1 119472 	SUMMATIVE 	07/04/14 	Yes 		100.00
    G03 Itumeleng 	Velmah Mokwa 	Fundamentals 	Communications 	CO2 119457 	FORMATIVE 2 	05/04/14 	Yes 		100.00
    G03 Itumeleng 	Velmah Mokwa 	Fundamentals 	Communications 	CO2 119457 	SUMMATIVE 	05/04/14 	Yes 		88.00
    G03 Lally 	Sheila Mokane 	Fundamentals 	Communications 	CO1 119472 	FORMATIVE 2 	07/04/14 	NYC 		59.00
    G03 Lally 	Sheila Mokane 	Fundamentals 	Communications 	CO1 119472 	SUMMATIVE 	07/04/14 	Yes 		90.00
    G03 Lally 	Sheila Mokane 	Fundamentals 	Communications 	CO2 119457 	FORMATIVE 2 	05/04/14 	Yes 		100.00
    G03 Lally 	Sheila Mokane 	Fundamentals 	Communications 	CO2 119457 	SUMMATIVE 	05/04/14 	Yes 		98.00
    
    And it is perfect so I have no issues with that. Now in php I call;

     

    
    function print_overview_table_groups($COURSE, $choosegroup, $fromdate, $todate, $numarray)
    {
        global $DB;
        //check data
        if(!$choosegroup){
            die('No Records To Display.');
        }
       
        $thisgroup = $numarray[$choosegroup];
           
            $sql = "SELECT DISTINCT u.firstname AS 'Name' , u.lastname AS 'Surname', 
    			(CASE
    			WHEN cc.parent = '2' THEN 'Fundamentals'
    			WHEN cc.parent = '3' THEN 'Core'
    			WHEN cc.parent = '4' THEN 'Elective'			
    			END) AS 'Category',
    			cc.name AS 'Module', 
    			c.shortname AS 'Course', 
    			(CASE
    			WHEN gi.itemname LIKE '%summative%' THEN 'SUMMATIVE'
    			WHEN gi.itemname LIKE '%formative 2%' THEN 'FORMATIVE 2'
    			ELSE 'MC'
    			END) AS 'Assessment', from_unixtime(gi.timemodified, '%d/%m/%y') AS 'Date',
    			IF (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) > 70,'Yes' , 'NYC') AS Competent, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark'
    			FROM mdl_course AS c
    			JOIN mdl_context AS ctx ON c.id = ctx.instanceid
    			JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id
    			JOIN mdl_user AS u ON u.id = ra.userid
    			JOIN mdl_grade_grades AS gg ON gg.userid = u.id
    			JOIN mdl_grade_items AS gi ON gi.id = gg.itemid
    			JOIN mdl_course_categories AS cc ON cc.id = c.category
    			WHERE gi.courseid = c.id
    			AND gi.itemname != 'Attendance'
    			AND u.firstname LIKE '%03%'
    			AND gi.itemname LIKE '%mative%'
    			ORDER BY  `Name` , `Surname` , `Course`, `Assessment` ASC";
    
            return $DB->get_records_sql($sql);
       
    }
    
    
    This is returned to the index.php page from the function call;

     

    
    $lists = print_overview_table_groups($COURSE, $choosegroup, $fromdate, $todate, $numarray);
       
    	print "<pre>";
    	print_r($lists);
    	print "</pre>";
    
    The result is baffling...

     

    
    Array
    (
        [G03 Itumeleng] => stdClass Object
            (
                [name] => G03 Itumeleng
                [surname] => Mokwa
                [category] => Fundamentals
                [module] => Communications
                [course] => CO2 119457
                [assessment] => SUMMATIVE
                [date] => 05/04/14
                [pass] => Yes
                [mark] => 88.00
            )
    
        [G03 Lally] => stdClass Object
            (
                [name] => G03 Lally
                [surname] => Mokane
                [category] => Fundamentals
                [module] => Communications
                [course] => CO2 119457
                [assessment] => SUMMATIVE
                [date] => 05/04/14
                [pass] => Yes
                [mark] => 98.00
            )
    
    )
    
    I only get one record for each student.

     

    Can anyone help me solve this?

     

     

    Regards

     

    Leon

  3. Querying this with phpmyadmin I get

     

     

    	
    		
    			
    				firstname 
    			
    				lastname 
    			
    				shortname 
    			
    				 
    		
    	
    	
    		
    			
    				G01 Moloko
    			
    				Samuel Madibana
    			
    				CO119472
    		
    	
    
     
    

     

    The complete function called is as follows; but when used in my lib.php file it fails.

     

    Look for the line "EVERYTHING BELOW DOES NOT WORK" within the function function print_overview_table2. Otherwise everything above it is fine.

     

    NOTE: I originally tried the query in a for loop which I know is bad so just bear with the code, I commented out the foreach to test it and it pushes out an error;

     

     

    function print_overview_table2($COURSE, $users, $choosegroup, $fromdate, $todate)
    {
        global $DB, $USER;
        //check data
        if(!$choosegroup){
            die('No Records To Display.');
        }
        
         
        //start table
        echo '<br><br><table class="logtable generalbox boxaligncenter" width="95%" border="1" cellspacing="0" cellpadding="5" style="padding:2px;">';
        
        //add report name
        
        $numarray=array();
        array_unshift($numarray, "");
        unset($numarray[0]);
        foreach (range(1,99) as $number)
        {
            $num_padded = sprintf("%02s", $number);
            $alphanum="G" . $num_padded;
            $numarray[]=$alphanum;
        }
        
        echo '<tr><td colspan="6">Admin Report - Group ' . $numarray[$choosegroup] . ' - Learner Progress</td></tr>';
        
        //add report headings
        echo '<tr>
        <th>Learner</th>
        <th>Unit Standard</th>
        <th>F2</th>
        <th>Summ</th>    
        <th>Competent</th>
        <th>Date</th>
        
          </tr>';
        
        
        
        //populate
        
        //foreach($users as $user){
        foreach($users as $key => $user)
        {
            
          
            echo '<tr>';
            
            echo "<td><a href=\"viewdash.php?learner=$user->id&todate=$todate&fromdate=$fromdate\">", $users[$key]->firstname ,' ',$users[$key]->lastname,"      </a></td>";
            
            echo "<td>US</td>";
            echo "<td>Formative2</td>";
            echo "<td>Summative</td>";
            echo "<td>C / NYC</td>";
            echo "<td>completed</td>";
            echo '</tr>';
           
        }
        
        echo '</table><br><br>';
      
        // EVERYTHING BELOW DOES NOT WORK
       
        //$sql = '';
        
        //~ foreach($users as $key => $user)
        //~ {
            
            $sql =
            "SELECT c.shortname, usr.firstname, usr.lastname
            FROM mdl_course c
            INNER JOIN mdl_context cx ON c.id = cx.instanceid
            AND cx.contextlevel = '50'
            INNER JOIN mdl_role_assignments ra ON cx.id = ra.contextid
            INNER JOIN mdl_role r ON ra.roleid = r.id
            INNER JOIN mdl_user usr ON ra.userid = usr.id
            WHERE r.name = 'Learner'
            AND usr.firstname = '$users[$key]->firstname'
            AND usr.lastname = '$users[$key]->lastname'
            ORDER BY usr.firstname, usr.lastname, c.shortname";
            
            //$result = $DB->get_records_sql($sql);
            
            print "<pre>";
            print_r($sql);
            print "</pre>";
            
            echo $sql;
            //return key($result);
            
            
        //~ }
           //end of foreach
       
    }
    

     

    I tried to first check that the $sql string was valid by echoing it to the screen, but this fails as well. So I have not been able to execute the sql query yet.

     

    The intent was to iterate through each user and build a list of courses that each user is enrolled for.

  4. Hi All

     

    I am having problems running a query to get the courses a student is enrolled for.

     

    The format I need is somthing like this:

    firstname    - lastname   - course
    -------------------------------------------
    Joe           Bloke       US232456
    Joe           Bloke       US554665
    Joe           Bloke       US332098
    

    or like this

     
    firstname    - lastname          - course
    -------------------------------------------------
    Joe              Bloke           US232456
                                     US554665
                                     US332098
     
     
    

    The query I am running is

    SELECT usr.firstname, usr.lastname, c.shortname
    
    FROM mdl_course c
    
    INNER JOIN mdl_context cx ON c.id = cx.instanceid
    
    AND cx.contextlevel = '50'
    
    INNER JOIN mdl_role_assignments ra ON cx.id = ra.contextid
    
    INNER JOIN mdl_role r ON ra.roleid = r.id
    
    INNER JOIN mdl_user usr ON ra.userid = usr.id
    
    WHERE r.name = 'Learner'
    
    AND usr.firstname = 'G01 Moloko'
    
    ORDER BY usr.firstname, c.shortname
    

    The problem is that I know this student is enrolled for 3 courses, but it only returns 1 course.

     

    Any help is welcomed.

     

    huck

  5. Only manually while testing. I have printed the entire date array to screen, and I get valid results as below. If there is a better way to check, would appreciate some pointers.

    Array
    (
        [1396735200] => Today, 6 April 2014
        [1396648800] => Saturday, 5 April 2014
        [1396562400] => Friday, 4 April 2014
        [1396476000] => Thursday, 3 April 2014
        [1396389600] => Wednesday, 2 April 2014
        [1396303200] => Tuesday, 1 April 2014
        [1396216800] => Monday, 31 March 2014
        [1396130400] => Sunday, 30 March 2014
        [1396044000] => Saturday, 29 March 2014
        [1395957600] => Friday, 28 March 2014
        [1395871200] => Thursday, 27 March 2014
        [1395784800] => Wednesday, 26 March 2014
        [1395698400] => Tuesday, 25 March 2014
        [1395612000] => Monday, 24 March 2014
        [1395525600] => Sunday, 23 March 2014
        [1395439200] => Saturday, 22 March 2014
        [1395352800] => Friday, 21 March 2014
        [1395266400] => Thursday, 20 March 2014
        [1395180000] => Wednesday, 19 March 2014
        [1395093600] => Tuesday, 18 March 2014
        [1395007200] => Monday, 17 March 2014
        [1394920800] => Sunday, 16 March 2014
        [1394834400] => Saturday, 15 March 2014
        [1394748000] => Friday, 14 March 2014
        [1394661600] => Thursday, 13 March 2014
        [1394575200] => Wednesday, 12 March 2014
        [1394488800] => Tuesday, 11 March 2014
        [1394402400] => Monday, 10 March 2014
        [1394316000] => Sunday, 9 March 2014
        [1394229600] => Saturday, 8 March 2014
        [1394143200] => Friday, 7 March 2014
        [1394056800] => Thursday, 6 March 2014
        [1393970400] => Wednesday, 5 March 2014
        [1393884000] => Tuesday, 4 March 2014
        [1393797600] => Monday, 3 March 2014
        [1393711200] => Sunday, 2 March 2014
        [1393624800] => Saturday, 1 March 2014
        [1393538400] => Friday, 28 February 2014
        [1393452000] => Thursday, 27 February 2014
        [1393365600] => Wednesday, 26 February 2014
        [1393279200] => Tuesday, 25 February 2014
        [1393192800] => Monday, 24 February 2014
        [1393106400] => Sunday, 23 February 2014
        [1393020000] => Saturday, 22 February 2014
        [1392933600] => Friday, 21 February 2014
        [1392847200] => Thursday, 20 February 2014
        [1392760800] => Wednesday, 19 February 2014
        [1392674400] => Tuesday, 18 February 2014
        [1392588000] => Monday, 17 February 2014
        [1392501600] => Sunday, 16 February 2014
        [1392415200] => Saturday, 15 February 2014
        [1392328800] => Friday, 14 February 2014
        [1392242400] => Thursday, 13 February 2014
        [1392156000] => Wednesday, 12 February 2014
        [1392069600] => Tuesday, 11 February 2014
        [1391983200] => Monday, 10 February 2014
        [1391896800] => Sunday, 9 February 2014
        [1391810400] => Saturday, 8 February 2014
        [1391724000] => Friday, 7 February 2014
        [1391637600] => Thursday, 6 February 2014
        [1391551200] => Wednesday, 5 February 2014
        [1391464800] => Tuesday, 4 February 2014
        [1391378400] => Monday, 3 February 2014
        [1391292000] => Sunday, 2 February 2014
        [1391205600] => Saturday, 1 February 2014
        [1391119200] => Friday, 31 January 2014
        [1391032800] => Thursday, 30 January 2014
        [1390946400] => Wednesday, 29 January 2014
        [1390860000] => Tuesday, 28 January 2014
        [1390773600] => Monday, 27 January 2014
        [1390687200] => Sunday, 26 January 2014
        [1390600800] => Saturday, 25 January 2014
        [1390514400] => Friday, 24 January 2014
        [1390428000] => Thursday, 23 January 2014
        [1390341600] => Wednesday, 22 January 2014
        [1390255200] => Tuesday, 21 January 2014
        [1390168800] => Monday, 20 January 2014
        [1390082400] => Sunday, 19 January 2014
        [1389996000] => Saturday, 18 January 2014
        [1389909600] => Friday, 17 January 2014
        [1389823200] => Thursday, 16 January 2014
        [1389736800] => Wednesday, 15 January 2014
        [1389650400] => Tuesday, 14 January 2014
        [1389564000] => Monday, 13 January 2014
        [1389477600] => Sunday, 12 January 2014
        [1389391200] => Saturday, 11 January 2014
        [1389304800] => Friday, 10 January 2014
        [1389218400] => Thursday, 9 January 2014
        [1389132000] => Wednesday, 8 January 2014
        [1389045600] => Tuesday, 7 January 2014
        [1388959200] => Monday, 6 January 2014
        [1388872800] => Sunday, 5 January 2014
        [1388786400] => Saturday, 4 January 2014
        [1388700000] => Friday, 3 January 2014
        [1388613600] => Thursday, 2 January 2014
        [1388527200] => Wednesday, 1 January 2014
        [1388440800] => Tuesday, 31 December 2013
        [1388354400] => Monday, 30 December 2013
        [1388268000] => Sunday, 29 December 2013
        [1388181600] => Saturday, 28 December 2013
        [1388095200] => Friday, 27 December 2013
        [1388008800] => Thursday, 26 December 2013
        [1387922400] => Wednesday, 25 December 2013
        [1387836000] => Tuesday, 24 December 2013
        [1387749600] => Monday, 23 December 2013
        [1387663200] => Sunday, 22 December 2013
        [1387576800] => Saturday, 21 December 2013
        [1387490400] => Friday, 20 December 2013
        [1387404000] => Thursday, 19 December 2013
        [1387317600] => Wednesday, 18 December 2013
        [1387231200] => Tuesday, 17 December 2013
        [1387144800] => Monday, 16 December 2013
        [1387058400] => Sunday, 15 December 2013
        [1386972000] => Saturday, 14 December 2013
        [1386885600] => Friday, 13 December 2013
        [1386799200] => Thursday, 12 December 2013
        [1386712800] => Wednesday, 11 December 2013
        [1386626400] => Tuesday, 10 December 2013
        [1386540000] => Monday, 9 December 2013
        [1386453600] => Sunday, 8 December 2013
        [1386367200] => Saturday, 7 December 2013
        [1386280800] => Friday, 6 December 2013
        [1386194400] => Thursday, 5 December 2013
        [1386108000] => Wednesday, 4 December 2013
        [1386021600] => Tuesday, 3 December 2013
        [1385935200] => Monday, 2 December 2013
        [1385848800] => Sunday, 1 December 2013
        [1385762400] => Saturday, 30 November 2013
        [1385676000] => Friday, 29 November 2013
        [1385589600] => Thursday, 28 November 2013
        [1385503200] => Wednesday, 27 November 2013
        [1385416800] => Tuesday, 26 November 2013
        [1385330400] => Monday, 25 November 2013
        [1385244000] => Sunday, 24 November 2013
        [1385157600] => Saturday, 23 November 2013
        [1385071200] => Friday, 22 November 2013
        [1384984800] => Thursday, 21 November 2013
        [1384898400] => Wednesday, 20 November 2013
        [1384812000] => Tuesday, 19 November 2013
        [1384725600] => Monday, 18 November 2013
        [1384639200] => Sunday, 17 November 2013
        [1384552800] => Saturday, 16 November 2013
        [1384466400] => Friday, 15 November 2013
        [1384380000] => Thursday, 14 November 2013
        [1384293600] => Wednesday, 13 November 2013
        [1384207200] => Tuesday, 12 November 2013
        [1384120800] => Monday, 11 November 2013
        [1384034400] => Sunday, 10 November 2013
        [1383948000] => Saturday, 9 November 2013
        [1383861600] => Friday, 8 November 2013
        [1383775200] => Thursday, 7 November 2013
        [1383688800] => Wednesday, 6 November 2013
        [1383602400] => Tuesday, 5 November 2013
        [1383516000] => Monday, 4 November 2013
        [1383429600] => Sunday, 3 November 2013
        [1383343200] => Saturday, 2 November 2013
        [1383256800] => Friday, 1 November 2013
        [1383170400] => Thursday, 31 October 2013
        [1383084000] => Wednesday, 30 October 2013
        [1382997600] => Tuesday, 29 October 2013
        [1382911200] => Monday, 28 October 2013
        [1382824800] => Sunday, 27 October 2013
        [1382738400] => Saturday, 26 October 2013
        [1382652000] => Friday, 25 October 2013
        [1382565600] => Thursday, 24 October 2013
        [1382479200] => Wednesday, 23 October 2013
        [1382392800] => Tuesday, 22 October 2013
        [1382306400] => Monday, 21 October 2013
        [1382220000] => Sunday, 20 October 2013
        [1382133600] => Saturday, 19 October 2013
        [1382047200] => Friday, 18 October 2013
        [1381960800] => Thursday, 17 October 2013
        [1381874400] => Wednesday, 16 October 2013
        [1381788000] => Tuesday, 15 October 2013
        [1381701600] => Monday, 14 October 2013
        [1381615200] => Sunday, 13 October 2013
        [1381528800] => Saturday, 12 October 2013
        [1381442400] => Friday, 11 October 2013
        [1381356000] => Thursday, 10 October 2013
        [1381269600] => Wednesday, 9 October 2013
        [1381183200] => Tuesday, 8 October 2013
        [1381096800] => Monday, 7 October 2013
        [1381010400] => Sunday, 6 October 2013
        [1380924000] => Saturday, 5 October 2013
        [1380837600] => Friday, 4 October 2013
        [1380751200] => Thursday, 3 October 2013
        [1380664800] => Wednesday, 2 October 2013
        [1380578400] => Tuesday, 1 October 2013
        [1380492000] => Monday, 30 September 2013
        [1380405600] => Sunday, 29 September 2013
        [1380319200] => Saturday, 28 September 2013
        [1380232800] => Friday, 27 September 2013
        [1380146400] => Thursday, 26 September 2013
        [1380060000] => Wednesday, 25 September 2013
        [1379973600] => Tuesday, 24 September 2013
        [1379887200] => Monday, 23 September 2013
        [1379800800] => Sunday, 22 September 2013
        [1379714400] => Saturday, 21 September 2013
        [1379628000] => Friday, 20 September 2013
        [1379541600] => Thursday, 19 September 2013
        [1379455200] => Wednesday, 18 September 2013
        [1379368800] => Tuesday, 17 September 2013
        [1379282400] => Monday, 16 September 2013
        [1379196000] => Sunday, 15 September 2013
        [1379109600] => Saturday, 14 September 2013
        [1379023200] => Friday, 13 September 2013
        [1378936800] => Thursday, 12 September 2013
        [1378850400] => Wednesday, 11 September 2013
        [1378764000] => Tuesday, 10 September 2013
        [1378677600] => Monday, 9 September 2013
        [1378591200] => Sunday, 8 September 2013
        [1378504800] => Saturday, 7 September 2013
        [1378418400] => Friday, 6 September 2013
        [1378332000] => Thursday, 5 September 2013
        [1378245600] => Wednesday, 4 September 2013
        [1378159200] => Tuesday, 3 September 2013
        [1378072800] => Monday, 2 September 2013
        [1377986400] => Sunday, 1 September 2013
        [1377900000] => Saturday, 31 August 2013
        [1377813600] => Friday, 30 August 2013
        [1377727200] => Thursday, 29 August 2013
        [1377640800] => Wednesday, 28 August 2013
        [1377554400] => Tuesday, 27 August 2013
        [1377468000] => Monday, 26 August 2013
        [1377381600] => Sunday, 25 August 2013
        [1377295200] => Saturday, 24 August 2013
        [1377208800] => Friday, 23 August 2013
        [1377122400] => Thursday, 22 August 2013
        [1377036000] => Wednesday, 21 August 2013
        [1376949600] => Tuesday, 20 August 2013
        [1376863200] => Monday, 19 August 2013
        [1376776800] => Sunday, 18 August 2013
        [1376690400] => Saturday, 17 August 2013
        [1376604000] => Friday, 16 August 2013
        [1376517600] => Thursday, 15 August 2013
        [1376431200] => Wednesday, 14 August 2013
        [1376344800] => Tuesday, 13 August 2013
        [1376258400] => Monday, 12 August 2013
        [1376172000] => Sunday, 11 August 2013
        [1376085600] => Saturday, 10 August 2013
        [1375999200] => Friday, 9 August 2013
        [1375912800] => Thursday, 8 August 2013
        [1375826400] => Wednesday, 7 August 2013
        [1375740000] => Tuesday, 6 August 2013
        [1375653600] => Monday, 5 August 2013
        [1375567200] => Sunday, 4 August 2013
        [1375480800] => Saturday, 3 August 2013
        [1375394400] => Friday, 2 August 2013
        [1375308000] => Thursday, 1 August 2013
        [1375221600] => Wednesday, 31 July 2013
        [1375135200] => Tuesday, 30 July 2013
        [1375048800] => Monday, 29 July 2013
        [1374962400] => Sunday, 28 July 2013
        [1374876000] => Saturday, 27 July 2013
        [1374789600] => Friday, 26 July 2013
        [1374703200] => Thursday, 25 July 2013
        [1374616800] => Wednesday, 24 July 2013
        [1374530400] => Tuesday, 23 July 2013
    )
    
  6. Inserted the following at the top of both index.php and lib.php.

    error_reporting(E_ALL | E_STRICT);
    
      ini_set("display_errors", 1);
    

    No errors pop up when submitting values but page still goes blank.

     

    SIDE NOTE: If no values are input, the report shows all mentors and how far they have marked, but as soon as date ranges are set, and submitted, the page goes blank.

     

    NOTE: $selecteddate can safely be ignored, since it is not used in index.php or lib.php.

     

    After selecting date range and clicking "Get these logs", the page url shows:

    http://"something.com"/admin/report/mentorprogress/index.php?chooselog=1&fromdate=1394748000&todate=1396216800&logformat=showashtml 
    

    Then on the page

    
    	Not Found
    The requested URL /admin/report/mentorprogress/index.php was not found on this server.
    
    
    	Apache Server at "something.com" Port 80
    

    Only thing is that index.php does exist. Full code for both files included.

     

    mentor.zip

  7. Hi Folks

     

    There is a bit of code I am struggling to grasp. It is used to print a range of data based on a custom date range.

    function print_log_selector_form_range($selectedfromdate='today', $selectedtodate='today', $logformat='showashtml') {
    
        global $USER, $CFG;
    
        $strftimedate = get_string("strftimedate");
    
        $strftimedaydate = get_string("strftimedaydate");
    
        // Prepare the list of action options.
    
        $actions = array(
    
            'view' => get_string('view'),
    
            'add' => get_string('add'),
    
            'update' => get_string('update'),
    
            'delete' => get_string('delete'),
    
            '-view' => get_string('allchanges')
    
        );
    
    
        // Get all the possible dates
    
        // Note that we are keeping track of real (GMT) time and user time
    
        // User time is only used in displays - all calcs and passing is GMT
    
        $timenow = time(); // GMT
    
        //echo "<br />";    
    
        // What day is it now for the user, and when is midnight that day (in GMT).
    
        $timemidnight = $today = usergetmidnight($timenow);
    
        //echo "<br />";    
    
        // Put today up the top of the list
    
        $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) );
    
        $numdates = 1;
    
        while ($timemidnight > $COURSE->startdate and $numdates < 365) {
    
            $timemidnight = $timemidnight - 86400;
    
            $timenow = $timenow - 86400;
    
            $dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
    
            $numdates++;
    
        }
    
        if ($selecteddate == "today") {
    
            $selecteddate = $today;
    
        }
    
        echo "<form class=\"logselectform\" action=\"$CFG->wwwroot/admin/report/mentorprogress/index.php\" method=\"get\">\n";
    
        echo "<div>\n";
    
        echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n";
        
    
      // echo html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
    
    //choose_from_menu ($dates, "fromdate", $selectedfromdate, get_string("alldays"));
    
    //~ print "<pre>";
    
    //~ print_r($dates);
    
    //~ print "</pre>";
    
        echo $selectedfromdate;
    
        echo "<br />";    
    
        echo $selectedtodate;
    
        echo "<br />";    
    
      echo  html_writer::select($dates, "fromdate",$selectedfromdate, get_string("alldays"));
    
       // choose_from_menu ($dates, "todate", $selectedtodate, get_string("alldays"));
    
       echo html_writer::select($dates,"todate",$selectedtodate, get_string("alldays"));
    
        $logformats = array('showashtml' => get_string('displayonpage'),
    
                            'downloadasexcel' => get_string('downloadexcel'));
    
        //choose_from_menu ($logformats, 'logformat', $logformat, false);
    
       echo html_writer::select($logformats, 'logformat', $logformat, false);
    
        echo '<input type="submit" value="'.get_string('gettheselogs').'" />';
    
        echo '</div>';
    
        echo '</form>';
    
    }
    

    This function above is in lib.php, and is called from index.php via this function:

    //echo $fromdate;
    //echo $todate;
     
    print_log_selector_form_range($fromdate, $todate, $logformat);
     
    //echo $fromdate;
    //echo $todate; 
    
    if($logformat == 'showashtml'){
                
            print_overview_table($users, $fromdate, $todate);
            
        } 
    

    I check the dates before and after this function is called and the dates remain at zero, even after selecting valid date ranges. By printing the array to screen I can see that the $dates array has valid entries.

     

    The function "print_overview_table" below "print_log_selector_form_range" is supposed to print the valid range to the screen.

    function print_overview_table($users, $fromdate, $todate){
    
        //check data
    
        if(!$users){
    
            die('No Records To Display.');
    
        }   
    
        //$users = get_mentor_users($DB, $fromdate, $todate, $sumpcat);
    
        //~ print "<pre>";
    
        //~ print_r($users);
    
        //~ print "</pre>";
         
    
        //start table
    
        echo '<br><br><table class="logtable generalbox boxaligncenter" width="95%" border="1" cellspacing="0" cellpadding="5" style="padding:2px;">';
    
        //add report name
    
        echo '<tr><td colspan="5">Admin Report - Mentor Marking Progress</td></tr>';
    
        //add report headings
    
        echo '<tr>
    
        <th>Mentor</th>
    
        <th>Total Summative marked</th>
    
        <th>Competent</th>
    
        <th>Not Yet Competent</th>
    
          </tr>';
      
        //populate
       
        //foreach($users as $user){
    
        foreach($users as $key => $user)
    
        {
           
    /*[id] => 2
    
                [totalmarked] => 1
    
                [totalcommarked] => 1
    
                [totalsummarked] => 0
    
                [markedcompetent] => 1
    
                [markedincompetent] => 0
    
     *
    
     */
          
    
            echo '<tr>';
          
            //echo "<td><a href=\"viewdash.php?mentor=$user->id&todate=$todate&fromdate=$fromdate\">", get_mentor_name($DB, $users[$key]->id),"</a></td>";
    
            echo "<td><a href=\"viewdash.php?mentor=$user->id&todate=$todate&fromdate=$fromdate\">", $users[$key]->firstname ,' ',$users[$key]->lastname,"</a></td>";
           
            echo "<td>",$users[$key]->totalsummarked,"</td>";
    
            echo "<td>",$users[$key]->markedcompetent,"</td>";
    
            echo "<td>",$users[$key]->markedincompetent,"</td>";
    
            echo '</tr>';
           
        }
       
        //end table
    
        echo '</table><br><br>';
    
    }
    

    When a user submits the date ranges the page goes blank.

     

    Can anyone give me some pointers to fix this.

  8. Hi Folks

     

    I have been trying to get a sql query to pass between pages in moodle 2.x. Moodle uses object orientation. The problem I have is the processed query return $DB->get_records($sql) will not pass back to index.php without a horrible hack.

     

    First: There are two files, index.php and lib.php (has functions in it)

     

    index.php calls lib.php with this line:

    $users = get_mentor_users($fromdate, $todate);
    

    lib.php executes this function:

    function get_mentor_users($fromdate = 0, $todate = 0){
    
        $sql = "SELECT DISTINCT u.id , u.firstname, u.lastname
    
        FROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt
    
        WHERE ra.userid = u.id
    
        AND ra.contextid = cxt.id
    
        AND cxt.contextlevel =50
    
        AND ( roleid =3 )
    
        AND u.firstname LIKE '%mentor%'";
    
        
    
        if($datesql = generate_sql_range($fromdate, $todate, ', mdl_grade_grades.timemodified'))
    
        {
    
            $sql .= " AND $datesql";
    
        }
    
        
    
        return $DB->get_records_sql($sql);
    
        
    
    }
    

    Now for the perplexing part. index.php throws out a blank screen.

     

    I rewrote this function to pass the sql string from lib.php to index.php then for index.php to do the sql query locally and then it works fine. Like so:

     

    index.php

    $sql2 = get_mentor_users($fromdate, $todate);
    $users = array();
    $users = $DB->get_records_sql($sql2);
    

    But then accessing the array gets kinda ugly. Then in lib.php only the unprocessed sql string is returned back to index.php.

    function get_mentor_users($fromdate = 0, $todate = 0){
    
        $sql = "SELECT DISTINCT u.id , u.firstname, u.lastname
    
        FROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt
    
        WHERE ra.userid = u.id
    
        AND ra.contextid = cxt.id
    
        AND cxt.contextlevel =50
    
        AND ( roleid =3 )
    
        AND u.firstname LIKE '%mentor%'";
    
        
    
        if($datesql = generate_sql_range($fromdate, $todate, ', mdl_grade_grades.timemodified'))
    
        {
    
            $sql .= " AND $datesql";
    
        }
    
        
    
       return  $sql;   
    
    }
    

    The output of the array below:

    Array
    (
        [12] => stdClass Object
            (
                [id] => 12
                [firstname] => Mentor Peter
                [lastname] => Swananipoel
                [totalmarked] => 
                [totalcommarked] => 0
                [totalsummarked] => 0
                [markedcompetent] => 0
                [markedincompetent] => 0
            )
    
        [14] => stdClass Object
            (
                [id] => 14
                [firstname] => Mentor Garfield
                [lastname] => Robertson
                [totalmarked] => 
                [totalcommarked] => 0
                [totalsummarked] => 0
                [markedcompetent] => 0
                [markedincompetent] => 0
            )
    
        [15] => stdClass Object
            (
                [id] => 15
                [firstname] => Mentor Bert
                [lastname] => Cat
                [totalmarked] => 
                [totalcommarked] => 0
                [totalsummarked] => 0
                [markedcompetent] => 0
                [markedincompetent] => 0
            )
    
    )
    

    How can I pass this array between pages without the shenanigans?

     

    Thanks

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.