Page activity - show author?

Page activity - show author?

by Laura DiFiore -
Number of replies: 2

Using Moodle 2.6

On my (under construction) Moodle, I have multiple people working on writing and editing content, and much of the content is using the 'Page' activity.  Being able to track who did what when is really important to me.  

Hours of searching and digging into the code, and I can't seem to find an answer to accomplishing something that should be very simple:  How do you display the name of the person who wrote/authored a 'Page' activity automatically on it, when you add a 'Page' as an activity?  

Related, is it possible to automatically display the name of the person who last edited a particular 'Page'?

When a 'Page' is edited, it automatically shows the date and time that the 'Page' was last updated/edited, but it does not show who wrote that 'Page' originally, nor who last edited.

Looking at the mdl_page table in the Moodle database, I note that the table has a timestamp field, but no author/last edited by field, and looking at the php files just hurt my brain ;)  but if anyone has any suggestions on how I can edit the table and/or php files so that every time I create a 'Page' (or modify it), my name is recorded and displayed.

Does anyone know if there is already a plugin that would do this or can point me in the right direction to modify the code in order to do this?  

Thank you very much in advance!

Laura

 

Average of ratings: -
In reply to Laura DiFiore

Re: Page activity - show author?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The wiki activity is one that keeps track of who has edited each page, so that may be something you can use without modifying the code.

However, if you want to modify the page code you will need to do the following:

  1. Add 'createdby' and 'modifiedby' fields to the mdl_page table, either manually (easiest to do), or via statements in upgrade.php ( http://docs.moodle.org/dev/Upgrade_API - better if someone else ever needs to maintain your code ).
  2. Open up page/lib.php and edit the page_add_instance() function to insert the lines:
    global $USER;
    $data->createdby = $USER->id;
  3. Similarly in page_update_instance():
    global $USER;
    $data->modifiedby = $USER->id;
  4. Somewhere in view.php add the lines:
    if ($createdby = $DB->get_record('user', array('id' => $page->createdby)) {
      echo 'Created by '.fullname($createdby);
    }
    // Plus similar lines for 'modified by'

Step 4 should really make use of get_string - but I'll leave that up to you to figure out.

Average of ratings: Useful (1)
In reply to Davo Smith

Re: Page activity - show author?

by Laura DiFiore -

Thank you, Davo!  That's EXACTLY the information I needed to point me not only in the right direction, but get me started on it, too!  Thanks also for the suggestion to use the Upgrade API approach - although I'm the only one with actual access at the server level at this stage of the project, that will change in the future. 

Thank you again for your time answering my question.  I'll let you know how it goes!  

Laura