How to get moodle module name from module id - moodle

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));

Related

Confluence: Accessing multiple values from param

I am trying to create a user macro in confluence that creates a number of links (can be however many) based on user input. The 2 params I use look like this:
## #param LNK:title=Link|type=string|required=true|multiple=true
## #param TTL:title=Title|type=string|required=true|multiple=true
The user will input something like this:
Link: link_1, link_2, link_3
Title: title_1, title_2, title_3
The macro should then create a list of links like this:
title_1; title_2....
My question is: how can I access the content of the LNK/TTL param so that I can retrieve link_1, link_2, etc.? I need to get some kind of index so that I can correctly link LNK[1] to TTL[1].
Any help is welcomed!
Thank you!
Ok, so I found a way (which seems a bit complicated) to do what I needed. Here's the code:
## #param VTP:title=VTP Number|type=string|required=true|multiple=true|desc=VTP number from JIRA (ex: VTP-1)
## #param TCI:title=Test Case Identifier |type=string|required=true|multiple=true|desc=Test Case Identifier (ex: IN_TC01)
#set ($LVTP = [])
#set ($LTCI = [])
#set ($VTP = $paramVTP.split(";"))
#set ($TCI = $paramTCI.split(";"))
#foreach ($element in $VTP)
#set ($xxx = $LVTP.add($element))
#end
#foreach ($element in $TCI)
#set( $xxx = $LTCI.add($element))
#end
#set ($end = ($LVTP.size() - 1))
#foreach ($i in [0..$end])
[$LTCI.get($i)]
#end
I had to do this since it seems that the only way to access the content of an array ($VTP and $TCI in my case) in Confluence if through the #foreach loop. Things like arrays.asList didn't work for me.
If anyone has a more elegant solution, please let me know.

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.

Call TYPO3 plugin from other plugin's body

I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!

How to add two numbers in sugar crm

I made module addition and in this made three fields amount1_c, amount2_c and total_amount_c to add the two numbers and display the result in the third field. I done coding in the logic looks here is my code
<?
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calculate_field', 'custom/modules/cases/LogicHookMath.php','LogicHookMath', 'calculate_field');
?>
and made one more file logic hook math. here is my code for
<?php
class LogicHookMath {
function calculate_field(&$bean, $event, $arguments) {
$field1 = $bean->amount1_c;
$field2 = $bean->amount2_c;
$field3 = $field1 + $field2;
$bean->amount_total_c = $field3;
}
}
?>
but still i did not get any result. Please help me out for this.
The code looks correct.
Some common "mistakes" when custom logic hooks are not working:
Make sure, the custom logic hook has the correct name (LogicHookMath.php)
Make sure, that the $bean variable is prefixed with &, so the variable is passed as a reference
Make sure the logic_hooks.php and the LogicHookMath.php files are readable by the web server user
The entire custom directory should also be writeable for the web server user
If the above does not help, try logging the progress to the sugarcrm.log using $GLOBALS['log']->info( "Value 3: ". $field3); in the custom logic hook.

How to get Column Name With Zend DB

How to get Column Name With Zend DB
This is the correct answer, the older answers are wrong or outdated:
$cols = $table->info(Zend_Db_Table_Abstract::COLS);
$metadata = $db->describeTable($tableName);
$columnNames = array_keys($metadata);
http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.list-describe
Previous answer applies only to version < 2.
For current version of ZF (2.2) use:
$table = new Zend\Db\TableGateway\TableGateway('table', $Dbadapter, new Zend\Db\TableGateway\Feature\MetadataFeature());
$columns = $table->getColumns();
http://framework.zend.com/manual/2.2/en/modules/zend.db.table-gateway.html#tablegateway-features
http://framework.zend.com/manual/2.2/en/modules/zend.db.metadata.html
You could use the describeTable method
I like this way:
$table->info('cols');