How to get the current courseid for the current page in moodle - moodle

i have an addres moodle/course/modedit.php?add=page&type=&course=4&section=1&return=0&sr=0 in moodle. How can i get the courseid that is 4? I tried $COURSE->id but it doesnot worked.
Please help me with the solution.

Could you show the code?
You could try
$courseid = $PAGE->course->id
or
$courseid = optional_param('course', null, PARAM_INT);

make sure that you are using global $COURSE firstly.
function getCourses(){
global $COURSE;
echo $COURSE->id;
}

Related

How to insert an option value into a select tag with CasperJS?

Well, the question is very self-explanatory.
Right now, I'm front of a form which has a select tag with a couple of options already. But I must insert a new one, with a different value that I will receive from a .json file.
The thing is: I haven't been able to find a suitable solution from the CasperJS documentation.
I've tried something like this:
this.fill('form.coworkerdiscountcode', {
'CoworkerDiscountCode.DiscountCode': ['Value1']
});
But no results. Any ideas?
Thanks in advance.
You can execute any javascript code by passing it to casper.evaluate like this:
casper.evaluate(function() {
var x = document.getElementById("coworkerdiscountcode");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option);
});

Set item email field in Podio

I'm having a hard time trying to guess how to set the item email field value, since there is nothing about this in the documentation (http://podio.github.io/podio-php/fields/)
I have tried :
$item->fields['email']->values = array("type"=>"work","value"=>"a#a.com");
$item->fields['email']->values = array("value"=>"a#a.com");
$item->fields['email']->values = "a#a.com";
$item->fields[$field_id]->value ="i#i.com";
$item->fields[$field_id]->type ="work";
$item->save();
Nothing works, please help! Thank you!
I have figured it out , here is the code that works (if anyone runs into the same problem)
$field_id = 'email';
$emails=$item->fields[$field_id]->values;
$item->fields[$field_id]->values =array('value'=>"i#oooo.com",'type'=>'work');
$item->save();

Adding placeholder text to Drupal 7 user_register_form

So I can get the email and username field to work just fine.
here is the code
if ( TRUE === in_array( $form_id, array('user_register_form'))) {
$form['account']['name']['#attributes']['placeholder'] = t(' Username ');
$form['account']['name']['#title_display'] = "invisible";
$form['account']['mail']['#attributes']['placeholder'] = t(' Your Email ');
$form['account']['mail']['#title_display'] = "invisible";
}
This works fine. But it seems the person who set this up is using custom field in the form because the it shows:
name="profile_installer_contractor[field_installer_first_name][und][0][value]"
How can I get these fields to show the placeholder text? I have tried:
$form['account']['field_installer_first_name'][und][0]['value']['#attributes']['placeholder'] = t(' First Name ');
but that doesn't seem to work. Any help is greatly appreciated.
Thanks,
Kevin
nevermind I figured it out on my own.
$form[profile_installer_contractor]['field_installer_first_name'][und][0]['value']['#attributes']['placeholder'] = t(' First Name ');
this worked

How to get moodle module name from module id

I want to list the names of the modules (activities) in my course sections from moodle function or from db query.
I can get section details and module id from mdl_course_sections and mdl_course_modules tables I want to get name or tile put in every activity to be list down.
I already tried mod_frog_get_coursemodule_info($cm) but I hadn't any luck with it.
Use get_fast_mod_info() e.g.:
$modinfo = get_fast_modinfo($courseid);
foreach ($modinfo as $cm) {
echo $cm->modname;
}
I advise you :
$modinfo = get_fast_modinfo($courseid);
$cm = $modinfo->get_cm($moduleid);
Reference: https://docs.moodle.org/dev/Module_visibility_and_display#get_fast_modinfo_data
I found a solution to this with following code
$activity_modules = $DB->get_record('modules',array('id' =>$moduleid));
$dynamic_activity_modules_data = $DB->get_record($activity_modules->name,array('id' =>$instanceid));
echo $dynamic_activity_modules_data->name;
Use get_fast_modinfo() :
$cm = $modinfo->cms[$moduleid];
$modulename = $cm->modname;
This can be achieved in 2 lines within moodle structure:
global $DB;
$moduleName = $DB->get_field('modules','name',array('id' => $moduleID));

Access _users table in SocialEngine?

i got a (simple?) problem accessing _users table in SocialEngine. To access tables in SE4 i use this:
$table = Engine_Api::_()->getDbTable(tablename,tablegroup);
and this works fine for _user_online (->getDbTable('online','user')) etc. but I don't know how to access _users table (which has not tablegroup prefix).
i tried:
->getDbTable('users')
->getDbTable('','users')
->getDbTable(null,'users')
->getDbTable('foo','what_a')
no way.
Engine_Api::_()->getItemTable('user');
I suggest you read SocialEngine factory codes to find out answer to this kind of questions.
you are missing commas
try this
$table = Engine_Api::_()->getDbTable('users','user');
it will give you users table object. hope this will help
You can use below 2 methods to get the "engine4_users" table object:
1) $userTable = Engine_Api::_()->getItemTable('user);
2) $userTable = Engine_Api::_()->getDbTable('users', 'user');
Try this one.
$query=Engine_Db_Table::getDefaultAdapter()->select()
->from('engine4_yourtablename')
->where("your_field_name = ?", $variable)->limit(1);
$query= $query->query()->fetch();
Hope this will help.