public static function add_entry($glossaryid, $concept, $definition, $definitionformat, $options = array()) {
        global $CFG;

        $params = self::validate_parameters(self::add_entry_parameters(), array(
            'glossaryid' => $glossaryid,
            'concept' => $concept,
            'definition' => $definition,
            'definitionformat' => $definitionformat,
            'options' => $options,
        ));
        $warnings = array();

        // Get and validate the glossary.
        list($glossary, $context, $course, $cm) = self::validate_glossary($params['glossaryid']);
        require_capability('mod/glossary:write', $context);

        if (!$glossary->allowduplicatedentries) {
            if (glossary_concept_exists($glossary, $params['concept'])) {
                throw new moodle_exception('errconceptalreadyexists', 'glossary');
            }
        }

        // Prepare the entry object.
        $entry = new stdClass;
        $entry->id = null;
        $entry->aliases = '';
        $entry->usedynalink = $CFG->glossary_linkentries;
        $entry->casesensitive = $CFG->glossary_casesensitive;
        $entry->fullmatch = $CFG->glossary_fullmatch;
        $entry->concept = $params['concept'];
        $entry->definition_editor = array(
            'text' => $params['definition'],
            'format' => $params['definitionformat'],
        );
        // Options.
        foreach ($params['options'] as $option) {
            $name = trim($option['name']);
            switch ($name) {
                case 'inlineattachmentsid':
                    $entry->definition_editor['itemid'] = clean_param($option['value'], PARAM_INT);
                    break;
                case 'attachmentsid':
                    $entry->attachment_filemanager = clean_param($option['value'], PARAM_INT);
                    break;
                case 'categories':
                    $entry->categories = clean_param($option['value'], PARAM_SEQUENCE);
                    $entry->categories = explode(',', $entry->categories);
                    break;
                case 'aliases':
                    $entry->aliases = clean_param($option['value'], PARAM_NOTAGS);
                    // Convert to the expected format.
                    $entry->aliases = str_replace(",", "\n", $entry->aliases);
                    break;
                case 'usedynalink':
                case 'casesensitive':
                case 'fullmatch':
                    // Only allow if linking is enabled.
                    if ($glossary->usedynalink) {
                        $entry->{$name} = clean_param($option['value'], PARAM_BOOL);
                    }
                    break;
                default:
                    throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
            }
        }

        $entry = glossary_edit_entry($entry, $course, $cm, $glossary, $context);

        return array(
            'entryid' => $entry->id,
            'warnings' => $warnings
        );
    }
public static function add_entry($glossaryid, $concept, $definition, $definitionformat, $options = array()) {
        global $CFG;

        $params = self::validate_parameters(self::add_entry_parameters(), array(
            'glossaryid' => $glossaryid,
            'concept' => $concept,
            'definition' => $definition,
            'definitionformat' => $definitionformat,
            'options' => $options,
        ));
        $warnings = array();

        // Get and validate the glossary.
        list($glossary, $context, $course, $cm) = self::validate_glossary($params['glossaryid']);
        require_capability('mod/glossary:write', $context);

        if (!$glossary->allowduplicatedentries) {
            if (glossary_concept_exists($glossary, $params['concept'])) {
                throw new moodle_exception('errconceptalreadyexists', 'glossary');
            }
        }

        // Prepare the entry object.
        $entry = new stdClass;
        $entry->id = null;
        $entry->aliases = '';
        $entry->usedynalink = $CFG->glossary_linkentries;
        $entry->casesensitive = $CFG->glossary_casesensitive;
        $entry->fullmatch = $CFG->glossary_fullmatch;
        $entry->concept = $params['concept'];
        $entry->definition_editor = array(
            'text' => $params['definition'],
            'format' => $params['definitionformat'],
        );
        // Options.
        foreach ($params['options'] as $option) {
            $name = trim($option['name']);
            switch ($name) {
                case 'inlineattachmentsid':
                    $entry->definition_editor['itemid'] = clean_param($option['value'], PARAM_INT);
                    break;
                case 'attachmentsid':
                    $entry->attachment_filemanager = clean_param($option['value'], PARAM_INT);
                    break;
                case 'categories':
                    $entry->categories = clean_param($option['value'], PARAM_SEQUENCE);
                    $entry->categories = explode(',', $entry->categories);
                    break;
                case 'aliases':
                    $entry->aliases = clean_param($option['value'], PARAM_NOTAGS);
                    // Convert to the expected format.
                    $entry->aliases = str_replace(",", "\n", $entry->aliases);
                    break;
                case 'usedynalink':
                case 'casesensitive':
                case 'fullmatch':
                    // Only allow if linking is enabled.
                    if ($glossary->usedynalink) {
                        $entry->{$name} = clean_param($option['value'], PARAM_BOOL);
                    }
                    break;
                default:
                    throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
            }
        }

        $entry = glossary_edit_entry($entry, $course, $cm, $glossary, $context);

        return array(
            'entryid' => $entry->id,
            'warnings' => $warnings
        );
    }
public static function add_entry ( $ glossaryid , $ concept , $ definition , $ definitionformat , $ options = array ( ) ) { global $ CFG ; $ params = self :: validate_parameters ( self :: add_entry_parameters ( ) , array ( 'glossaryid' => $ glossaryid , 'concept' => $ concept , 'definition' => $ definition , 'definitionformat' => $ definitionformat , 'options' => $ options , ) ) ; $ warnings = array ( ) ; // Get and validate the glossary. list ( $ glossary , $ context , $ course , $ cm ) = self :: validate_glossary ( $ params [ 'glossaryid' ] ) ; require_capability ( 'mod/glossary:write' , $ context ) ; if ( ! $ glossary -> allowduplicatedentries ) { if ( glossary_concept_exists ( $ glossary , $ params [ 'concept' ] ) ) { throw new moodle_exception ( 'errconceptalreadyexists' , 'glossary' ) ; } } // Prepare the entry object. $ entry = new stdClass ; $ entry -> id = null ; $ entry -> aliases = '' ; $ entry -> usedynalink = $ CFG -> glossary_linkentries ; $ entry -> casesensitive = $ CFG -> glossary_casesensitive ; $ entry -> fullmatch = $ CFG -> glossary_fullmatch ; $ entry -> concept = $ params [ 'concept' ] ; $ entry -> definition_editor = array ( 'text' => $ params [ 'definition' ] , 'format' => $ params [ 'definitionformat' ] , ) ; // Options. foreach ( $ params [ 'options' ] as $ option ) { $ name = trim ( $ option [ 'name' ] ) ; switch ( $ name ) { case 'inlineattachmentsid' : $ entry -> definition_editor [ 'itemid' ] = clean_param ( $ option [ 'value' ] , PARAM_INT ) ; break ; case 'attachmentsid' : $ entry -> attachment_filemanager = clean_param ( $ option [ 'value' ] , PARAM_INT ) ; break ; case 'categories' : $ entry -> categories = clean_param ( $ option [ 'value' ] , PARAM_SEQUENCE ) ; $ entry -> categories = explode ( ',' , $ entry -> categories ) ; break ; case 'aliases' : $ entry -> aliases = clean_param ( $ option [ 'value' ] , PARAM_NOTAGS ) ; // Convert to the expected format. $ entry -> aliases = str_replace ( "," , "\n" , $ entry -> aliases ) ; break ; case 'usedynalink' : case 'casesensitive' : case 'fullmatch' : // Only allow if linking is enabled. if ( $ glossary -> usedynalink ) { $ entry -> { $ name } = clean_param ( $ option [ 'value' ] , PARAM_BOOL ) ; } break ; default : throw new moodle_exception ( 'errorinvalidparam' , 'webservice' , '' , $ name ) ; } } $ entry = glossary_edit_entry ( $ entry , $ course , $ cm , $ glossary , $ context ) ; return array ( 'entryid' => $ entry -> id , 'warnings' => $ warnings ) ; }
Add a new entry to a given glossary.

@param int $glossaryid the glosary id
@param string $concept    the glossary concept
@param string $definition the concept definition
@param int $definitionformat the concept definition format
@param array  $options    additional settings
@return array Containing entry and warnings.
@since Moodle 3.2
@throws moodle_exception
@throws invalid_parameter_exception
Add a new entry to a given glossary .