Search This Blog

Monday, July 13, 2015

New posts, plugins and moodle updates

I wanted to let everyone that follows this blog know that new content is coming. I'm been working on Moodle as a freelance developer for over the last six years and I'm still learning a lot about the platform with every new release that comes out. But now that I have the time, I will be writing new posts on other customizations I created.

I decided to start adding my newest posts on another moodle blog, located here:   http://moodle24custom.blogspot.com

My latest post is about making a custom course format, with a focus on eliminating confirmation boxes and backtracking to the course page. The first part is about setting up your course format and installing it within Moodle. The next post will describe some of the customizations we've made.

Here's the post:   Simplenav:  Custom course format - Part 1
Enjoy!

For now if you have any questions, leave a comment below or visit my website for more Moodle examples:

Thursday, January 17, 2013

Only show "preferred theme" to admins

Something I've been wanting to do, is hide the themeselector on the profile page -- only for normal users. This allows me to choose a default theme for a new user and they can never change it.

1) Go to:  /moodleroot/user/editlib.php
2)  Close to the end of the file, you will see this code:


if (!empty($CFG->allowuserthemes)) 
    {
        $choices = array();
        $choices[''] = get_string('default');
        $themes = get_list_of_themes();
        foreach ($themes as $key=>$theme) {
            if (empty($theme->hidefromselector)) {
                $choices[$key] = $theme->name;
            }
        }
        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
    }

3)  All we are going to do is add an extra statement within the "if", to check also if the user is an admin:


if (!empty($CFG->allowuserthemes) && is_siteadmin($user)) 

4)  And voila! Only admins can see that field on the profile page now.


Wednesday, December 19, 2012

Stop the navigation block from expanding


If you want to stop the navigation from automatically expanding everything you click a course, this is the code you need to change:

1) Go to:  blocks\navigation in your root moddle directory
2)  open renderer.php file
and change this line
if ($item->has_children() && (!$item->forceopen || $item->collapse)) {
to this
if ($item->has_children() && ($depth > 1)) {


Thursday, December 13, 2012

Only show block to certain user

I wanted to hide my "Settings" block from all other users, except the admin role.

1)  I went into the file called:  mymoodleroot/blocks/settings/block_settings.php
2)  Inside two functions, I simply placed a role check at the beginning:

 function get_content() 
 {
    // only shows the settings block to admins
    global $USER, $CFG, $DB;
    if(!is_siteadmin($USER)) {return;}
        ...
}


function init() 
    {
    global $USER, $CFG, $DB;
    if(!is_siteadmin($USER)) {return;}

      ...
}



I'm sure that code could be modified to display to different roles and possibilities. This is just a simple example and it works!

Monday, July 23, 2012

Make a custom login page

Inside your theme folder, you need to change a couple files:

1) Inside the main theme folder, open the config.php file. Scroll down to where you see "login" and you can change that to read your own custom page. In my case, I made this change:
       From:
       ...
        ),
       'login' => array(
        'file' => 'general.php',
        'regions' => array(),
    ),
    ...

    To:
     ...
     ),
    'login' => array(
        'file' => 'login.php',
        'regions' => array(),
    ),
    ....

2) Next, I copied the general.php file, so I can use the same theme settings for my login.php page. However, I took out all the unnecessary sections: langmenu, custom menu, and side blocks. So basically I just show my logo, the main content, and the footer.

3) Lastly, I added some custom CSS to my core.php page to make the login elements look the way I wanted to. I centered all the elements on screen with a nice background like this:

Here is the CSS I used to make this:

/* ////////////////////////////////////////////////////  LOGIN PANEL //////////////////////////////////////////// */
.twocolumns div.loginpanel 
{
     border-right: 1px dashed #dadada !important; 
}
.onecolumn div.loginpanel
{
    position:relative;
    width:35%;
    margin: 0 auto;
    
    background:#ececec;
    background: -webkit-gradient(linear, 0 100, 0 bottom, from(#ececec), to(#bfbfbf)); 
    background: -moz-linear-gradient(#ececec, #bfbfbf);
    background: -ms-linear-gradient(#ececec, #bfbfbf);
    background: -o-linear-gradient(#ececec, #bfbfbf);
    background: linear-gradient(#ececec, #bfbfbf);
    -pie-background: linear-gradient(#ececec, #bfbfbf);
    
    border: 1px solid #a2a2a2;
    -webkit-border-radius:10px;
    -moz-border-radius:10px;
    border-radius:10px;
    behavior: url(PIE.htc);
}
div.loginpanel h2
{
    text-align:center;
    text-transform:none;
}

.loginbox .loginform
{
   width: 100%;
   height:20em;
   vertical-align:middle;
}
.loginbox .loginform .form-input
{
     vertical-align:middle;
     text-align:center;
     float:none;
     clear:both;
     width:100%;
     padding-bottom:1em;
}
.loginbox .loginform .form-label
{
    padding: 0em 0em 0.3em 2em;
    text-align:center;
}
.loginbox .loginform .form-input #username, 
.loginbox .loginform .form-input #password 
{
    position:relative;
    min-height:1.7em;
    width:60%;
    border-size:1px inset #d9d9d9;
    
    -webkit-border-radius:10px;
    -moz-border-radius:10px;
    border-radius:10px;
    behavior: url(PIE.htc);
}
.loginbox .loginform .form-input #loginbtn
{
    vertical-align:middle;
    display:block;
    padding:1em;
    width:10em;
    border:1px solid #bfbfbf;
    
    position:relative;
    -webkit-border-radius:5px;
    -moz-border-radius:5px;
    border-radius:5px;
    behavior: url(PIE.htc);
}
.loginbox .loginform .form-input #loginbtn:hover
{
    color:white;
    background:#5b2d7e;
}

div.forgetpass, 
div.centeredcookies 
{
   text-align:center;
}

/* ////////////////////////////////////////////////////  END OF LOGIN PANEL //////////////////////////////////////////// */


Adding search bar in top menu bar

Using the new Aardvark theme (2.2 blackbird version), I was able to insert a search bar in the top menu by making some modifications:

1) In styles/general.php, I added the header information I needed between the <head> tags
2) In layout/profileblock.php, I added my own code around line 62:

....

<?php
echo '</div>'; // end of headerwrap
?>
<!--/////////// This is the search bar  ////////////-->
<div id="mysearchbar"  >
<input type="text" class="autosuggest_search" />
</div>

</div>
<div class="profilebar" id="profilebar" style="display: none;">
...

Now my searchbar is inline with the custom menu and other elements. Yippee!

Wednesday, May 16, 2012

Easily finding an entry in your database activity

Here is a nice sql query to find an entry in your database activity, while searching for a specific text string:


$query = "SELECT * FROM {data_content} c JOIN {data_records} r ON r.id = c.recordid WHERE r.dataid=? AND c.content=?";
if($results = $DB->get_records_sql($query, array($data->id, 'my search string')))
{
    // do something here with results
}

It's a nice snippet!