当前位置: 首页>>代码示例>>PHP>>正文


PHP data_get_field函数代码示例

本文整理汇总了PHP中data_get_field函数的典型用法代码示例。如果您正苦于以下问题:PHP data_get_field函数的具体用法?PHP data_get_field怎么用?PHP data_get_field使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了data_get_field函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: str_ireplace

        $patterns[] = "[[" . $field->field->name . "#id]]";
        $replacements[] = 'field_' . $field->field->id;
    }
    $newtext = str_ireplace($patterns, $replacements, $data->{$mode});
} else {
    //if the add template is not yet defined, print the default form!
    echo data_generate_default_template($data, 'addtemplate', $rid, true, false);
    $newtext = '';
}
echo $newtext;
echo '<div class="mdl-align"><input type="submit" name="saveandview" value="' . get_string('saveandview', 'data') . '" />';
if ($rid) {
    echo '&nbsp;<input type="submit" name="cancel" value="' . get_string('cancel') . '" onclick="javascript:history.go(-1)" />';
} else {
    if (!$data->maxentries || has_capability('mod/data:manageentries', $context) || data_numentries($data) < $data->maxentries - 1) {
        echo '&nbsp;<input type="submit" value="' . get_string('saveandadd', 'data') . '" />';
    }
}
echo '</div>';
echo $OUTPUT->box_end();
echo '</div></form>';
/// Finish the page
// Print the stuff that need to come after the form fields.
if (!($fields = $DB->get_records('data_fields', array('dataid' => $data->id)))) {
    print_error('nofieldindatabase', 'data');
}
foreach ($fields as $eachfield) {
    $field = data_get_field($eachfield, $data);
    $field->print_after_form();
}
echo $OUTPUT->footer();
开发者ID:nigeldaley,项目名称:moodle,代码行数:31,代码来源:edit.php

示例2: data_pluginfile

/**
 * Serves the data attachments. Implements needed access control ;-)
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function data_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
    global $CFG, $DB;

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_course_login($course, true, $cm);

    if ($filearea === 'content') {
        $contentid = (int)array_shift($args);

        if (!$content = $DB->get_record('data_content', array('id'=>$contentid))) {
            return false;
        }

        if (!$field = $DB->get_record('data_fields', array('id'=>$content->fieldid))) {
            return false;
        }

        if (!$record = $DB->get_record('data_records', array('id'=>$content->recordid))) {
            return false;
        }

        if (!$data = $DB->get_record('data', array('id'=>$field->dataid))) {
            return false;
        }

        if ($data->id != $cm->instance) {
            // hacker attempt - context does not match the contentid
            return false;
        }

        //check if approved
        if ($data->approval and !$record->approved and !data_isowner($record) and !has_capability('mod/data:approve', $context)) {
            return false;
        }

        // group access
        if ($record->groupid) {
            $groupmode = groups_get_activity_groupmode($cm, $course);
            if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
                if (!groups_is_member($record->groupid)) {
                    return false;
                }
            }
        }

        $fieldobj = data_get_field($field, $data, $cm);

        $relativepath = implode('/', $args);
        $fullpath = "/$context->id/mod_data/content/$content->id/$relativepath";

        if (!$fieldobj->file_ok($relativepath)) {
            return false;
        }

        $fs = get_file_storage();
        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
            return false;
        }

        // finally send the file
        send_stored_file($file, 0, 0, true); // download MUST be forced - security!
    }

    return false;
}
开发者ID:nottmoo,项目名称:moodle,代码行数:79,代码来源:lib.php

示例3: require_login

require_login($course->id, false, $cm);
require_capability(DATA_CAP_EXPORT, $context);
// get fields for this database
$fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id), 'id');
if (empty($fieldrecords)) {
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if (has_capability('mod/data:managetemplates', $context)) {
        redirect($CFG->wwwroot . '/mod/data/field.php?d=' . $data->id);
    } else {
        print_error('nofieldindatabase', 'data');
    }
}
// populate objets for this databases fields
$fields = array();
foreach ($fieldrecords as $fieldrecord) {
    $fields[] = data_get_field($fieldrecord, $data);
}
$mform = new mod_data_export_form('export.php?d=' . $data->id, $fields, $cm);
if ($mform->is_cancelled()) {
    redirect('view.php?d=' . $data->id);
} elseif (!($formdata = (array) $mform->get_data())) {
    // build header to match the rest of the UI
    $nav = build_navigation('', $cm);
    print_header_simple($data->name, '', $nav, '', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')), navmenu($course, $cm), '', '');
    echo $OUTPUT->heading(format_string($data->name));
    // these are for the tab display
    $currentgroup = groups_get_activity_group($cm);
    $groupmode = groups_get_activity_groupmode($cm);
    $currenttab = 'export';
    include 'tabs.php';
    $mform->display();
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:export.php

示例4: data_process_submission

/**
 * Check for required fields, and build a list of fields to be updated in a
 * submission.
 *
 * @param $mod stdClass The current recordid - provided as an optimisation.
 * @param $fields array The field data
 * @param $datarecord stdClass The submitted data.
 * @return stdClass containing:
 * * string[] generalnotifications Notifications for the form as a whole.
 * * string[] fieldnotifications Notifications for a specific field.
 * * bool validated Whether the field was validated successfully.
 * * data_field_base[] fields The field objects to be update.
 */
function data_process_submission(stdClass $mod, $fields, stdClass $datarecord)
{
    $result = new stdClass();
    // Empty form checking - you can't submit an empty form.
    $emptyform = true;
    $requiredfieldsfilled = true;
    $fieldsvalidated = true;
    // Store the notifications.
    $result->generalnotifications = array();
    $result->fieldnotifications = array();
    // Store the instantiated classes as an optimisation when processing the result.
    // This prevents the fields being re-initialised when updating.
    $result->fields = array();
    $submitteddata = array();
    foreach ($datarecord as $fieldname => $fieldvalue) {
        if (strpos($fieldname, '_')) {
            $namearray = explode('_', $fieldname, 3);
            $fieldid = $namearray[1];
            if (!isset($submitteddata[$fieldid])) {
                $submitteddata[$fieldid] = array();
            }
            if (count($namearray) === 2) {
                $subfieldid = 0;
            } else {
                $subfieldid = $namearray[2];
            }
            $fielddata = new stdClass();
            $fielddata->fieldname = $fieldname;
            $fielddata->value = $fieldvalue;
            $submitteddata[$fieldid][$subfieldid] = $fielddata;
        }
    }
    // Check all form fields which have the required are filled.
    foreach ($fields as $fieldrecord) {
        // Check whether the field has any data.
        $fieldhascontent = false;
        $field = data_get_field($fieldrecord, $mod);
        if (isset($submitteddata[$fieldrecord->id])) {
            // Field validation check.
            if (method_exists($field, 'field_validation')) {
                $errormessage = $field->field_validation($submitteddata[$fieldrecord->id]);
                if ($errormessage) {
                    $result->fieldnotifications[$field->field->name][] = $errormessage;
                    $fieldsvalidated = false;
                }
            }
            foreach ($submitteddata[$fieldrecord->id] as $fieldname => $value) {
                if ($field->notemptyfield($value->value, $value->fieldname)) {
                    // The field has content and the form is not empty.
                    $fieldhascontent = true;
                    $emptyform = false;
                }
            }
        }
        // If the field is required, add a notification to that effect.
        if ($field->field->required && !$fieldhascontent) {
            if (!isset($result->fieldnotifications[$field->field->name])) {
                $result->fieldnotifications[$field->field->name] = array();
            }
            $result->fieldnotifications[$field->field->name][] = get_string('errormustsupplyvalue', 'data');
            $requiredfieldsfilled = false;
        }
        // Update the field.
        if (isset($submitteddata[$fieldrecord->id])) {
            foreach ($submitteddata[$fieldrecord->id] as $value) {
                $result->fields[$value->fieldname] = $field;
            }
        }
    }
    if ($emptyform) {
        // The form is empty.
        $result->generalnotifications[] = get_string('emptyaddform', 'data');
    }
    $result->validated = $requiredfieldsfilled && !$emptyform && $fieldsvalidated;
    return $result;
}
开发者ID:gabrielrosset,项目名称:moodle,代码行数:89,代码来源:lib.php

示例5: data_print_header

 /// Display the main listing of all fields
 data_print_header($course, $cm, $data, 'fields');
 if (!$DB->record_exists('data_fields', array('dataid' => $data->id))) {
     echo $OUTPUT->notification(get_string('nofieldindatabase', 'data'));
     // nothing in database
     echo $OUTPUT->notification(get_string('pleaseaddsome', 'data', 'preset.php?id=' . $cm->id));
     // link to presets
 } else {
     //else print quiz style list of fields
     $table = new html_table();
     $table->head = array(get_string('fieldname', 'data'), get_string('type', 'data'), get_string('fielddescription', 'data'), get_string('action', 'data'));
     $table->align = array('left', 'left', 'left', 'center');
     $table->wrap = array(false, false, false, false);
     if ($fff = $DB->get_records('data_fields', array('dataid' => $data->id), 'id')) {
         foreach ($fff as $ff) {
             $field = data_get_field($ff, $data);
             $table->data[] = array('<a href="field.php?mode=display&amp;d=' . $data->id . '&amp;fid=' . $field->field->id . '&amp;sesskey=' . sesskey() . '">' . $field->field->name . '</a>', $field->image() . '&nbsp;' . get_string($field->type, 'data'), shorten_text($field->field->description, 30), '<a href="field.php?d=' . $data->id . '&amp;mode=display&amp;fid=' . $field->field->id . '&amp;sesskey=' . sesskey() . '">' . '<img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>' . '&nbsp;' . '<a href="field.php?d=' . $data->id . '&amp;mode=delete&amp;fid=' . $field->field->id . '&amp;sesskey=' . sesskey() . '">' . '<img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>');
         }
     }
     echo html_writer::table($table);
 }
 echo '<div class="fieldadd">';
 echo '<label for="fieldform_jump">' . get_string('newfield', 'data') . '</label>';
 $popupurl = $CFG->wwwroot . '/mod/data/field.php?d=' . $data->id . '&mode=new&sesskey=' . sesskey();
 echo $OUTPUT->single_select(new moodle_url($popupurl), 'newtype', $menufield, null, array('' => 'choosedots'), 'fieldform');
 echo $OUTPUT->help_icon('newfield', 'data');
 echo '</div>';
 echo '<div class="sortdefault">';
 echo '<form id="sortdefault" action="' . $CFG->wwwroot . '/mod/data/field.php" method="get">';
 echo '<div>';
 echo '<input type="hidden" name="d" value="' . $data->id . '" />';
开发者ID:vuchannguyen,项目名称:web,代码行数:31,代码来源:field.php

示例6: has_files

 public static function has_files($data)
 {
     global $DB;
     $fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id), 'id');
     // populate objets for this databases fields
     foreach ($fieldrecords as $fieldrecord) {
         $field = data_get_field($fieldrecord, $data);
         if (is_callable(array($field, 'get_file'))) {
             return true;
         }
     }
     return false;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:13,代码来源:locallib.php

示例7: data_print_preference_form


//.........这里部分代码省略.........
        // javascript for hiding/displaying advanced search form

        function showHideAdvSearch(checked) {
            var divs = document.getElementsByTagName(\'div\');
            for(i=0;i<divs.length;i++) {
                if(divs[i].id.match(\'data_adv_form\')) {
                    if(checked) {
                        divs[i].style.display = \'inline\';
                    }
                    else {
                        divs[i].style.display = \'none\';
                    }
                }
                else if (divs[i].id.match(\'reg_search\')) {
                    if (!checked) {
                        divs[i].style.display = \'inline\';
                    }
                    else {
                        divs[i].style.display = \'none\';
                    }
                }
            }
        }
        //  End -->
        //]]>
        </script>';
    echo '&nbsp;<input type="hidden" name="advanced" value="0" />';
    echo '&nbsp;<input type="hidden" name="filter" value="1" />';
    echo '&nbsp;<input type="checkbox" id="advancedcheckbox" name="advanced" value="1" ' . $checked . ' onchange="showHideAdvSearch(this.checked);" /><label for="advancedcheckbox">' . get_string('advancedsearch', 'data') . '</label>';
    echo '&nbsp;<input type="submit" value="' . get_string('savesettings', 'data') . '" />';
    echo '<br />';
    echo '<div class="dataadvancedsearch" id="data_adv_form" style="display: ';
    if ($advanced) {
        echo 'inline';
    } else {
        echo 'none';
    }
    echo ';margin-left:auto;margin-right:auto;" >';
    echo '<table class="boxaligncenter">';
    // print ASC or DESC
    echo '<tr><td colspan="2">&nbsp;</td></tr>';
    $i = 0;
    // Determine if we are printing all fields for advanced search, or the template for advanced search
    // If a template is not defined, use the deafault template and display all fields.
    if (empty($data->asearchtemplate)) {
        data_generate_default_template($data, 'asearchtemplate');
    }
    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;
    if (empty($dataid)) {
        $dataid = $data->id;
    } else {
        if ($dataid != $data->id) {
            $fields = NULL;
        }
    }
    if (empty($fields)) {
        $fieldrecords = get_records('data_fields', 'dataid', $data->id);
        foreach ($fieldrecords as $fieldrecord) {
            $fields[] = data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }
    // Replacing tags
    $patterns = array();
    $replacement = array();
    // Then we generate strings to replace for normal tags
    foreach ($fields as $field) {
        $fieldname = $field->field->name;
        $fieldname = preg_quote($fieldname, '/');
        $patterns[] = "/\\[\\[{$fieldname}\\]\\]/i";
        $searchfield = data_get_field_from_id($field->field->id, $data);
        if (!empty($search_array[$field->field->id]->data)) {
            $replacement[] = $searchfield->display_search_field($search_array[$field->field->id]->data);
        } else {
            $replacement[] = $searchfield->display_search_field();
        }
    }
    $fn = !empty($search_array[DATA_FIRSTNAME]->data) ? $search_array[DATA_FIRSTNAME]->data : '';
    $ln = !empty($search_array[DATA_LASTNAME]->data) ? $search_array[DATA_LASTNAME]->data : '';
    $patterns[] = '/##firstname##/';
    $replacement[] = '<input type="text" size="16" name="u_fn" value="' . $fn . '" />';
    $patterns[] = '/##lastname##/';
    $replacement[] = '<input type="text" size="16" name="u_ln" value="' . $ln . '" />';
    // actual replacement of the tags
    $newtext = preg_replace($patterns, $replacement, $data->asearchtemplate);
    $options = new object();
    $options->para = false;
    $options->noclean = true;
    echo '<tr><td>';
    echo format_text($newtext, FORMAT_HTML, $options);
    echo '</td></tr>';
    echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="' . get_string('savesettings', 'data') . '" /><input type="submit" name="resetadv" value="' . get_string('resetsettings', 'data') . '" /></td></tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    echo '</form>';
    echo '</div>';
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:101,代码来源:lib.php

示例8: create_entry

 /**
  * Creates a field for a mod_data instance.
  * Currently, the field types in the ignoredfieldtypes array aren't supported.
  * The developers using the generator must adhere to the following format :
  *
  *   Syntax : $contents[ fieldid ] = fieldvalue
  *   $contents['checkbox'] = array('val1', 'val2', 'val3' .....)
  *   $contents['data'] = 'dd-mm-yyyy'
  *   $contents['menu'] = 'value';
  *   $contents['multimenu'] =  array('val1', 'val2', 'val3' .....)
  *   $contents['number'] = 'numeric value'
  *   $contents['radiobuton'] = 'value'
  *   $contents['text'] = 'text'
  *   $contents['textarea'] = 'text'
  *   $contents['url'] = 'example.url' or array('example.url', 'urlname')
  *
  * @param mod_data $data
  * @param array $contents
  * @return data_field_{type}
  */
 public function create_entry($data, array $contents)
 {
     global $DB;
     $this->databaserecordcount++;
     $recordid = data_add_record($data);
     $fields = $DB->get_records('data_fields', array('dataid' => $data->id));
     // Validating whether required field are filled.
     foreach ($fields as $field) {
         $fieldhascontent = true;
         if (in_array($field->type, $this->ignoredfieldtypes)) {
             continue;
         }
         $field = data_get_field($field, $data);
         $fieldid = $field->field->id;
         if ($field->type === 'date') {
             $values = array();
             $temp = explode('-', $contents[$fieldid], 3);
             $values['field_' . $fieldid . '_day'] = (int) trim($temp[0]);
             $values['field_' . $fieldid . '_month'] = (int) trim($temp[1]);
             $values['field_' . $fieldid . '_year'] = (int) trim($temp[2]);
             // Year should be less than 2038, so it can be handled by 32 bit windows.
             if ($values['field_' . $fieldid . '_year'] > 2038) {
                 throw new coding_exception('DateTime::getTimestamp resturns false on 32 bit win for year beyond ' . '2038. Please use year less than 2038.');
             }
             $contents[$fieldid] = $values;
             foreach ($values as $fieldname => $value) {
                 if (!$field->notemptyfield($value, $fieldname)) {
                     $fieldhascontent = false;
                 }
             }
         } else {
             if ($field->type === 'textarea') {
                 $values = array();
                 $values['field_' . $fieldid] = $contents[$fieldid];
                 $values['field_' . $fieldid . '_content1'] = 1;
                 $contents[$fieldid] = $values;
                 foreach ($values as $fieldname => $value) {
                     if (!$field->notemptyfield($value, $fieldname)) {
                         $fieldhascontent = false;
                     }
                 }
             } else {
                 if ($field->type === 'url') {
                     $values = array();
                     if (is_array($contents[$fieldid])) {
                         foreach ($contents[$fieldid] as $key => $value) {
                             $values['field_' . $fieldid . '_' . $key] = $value;
                         }
                     } else {
                         $values['field_' . $fieldid . '_0'] = $contents[$fieldid];
                     }
                     $contents[$fieldid] = $values;
                     foreach ($values as $fieldname => $value) {
                         if (!$field->notemptyfield($value, $fieldname)) {
                             $fieldhascontent = false;
                         }
                     }
                 } else {
                     if ($field->notemptyfield($contents[$fieldid], 'field_' . $fieldid . '_0')) {
                         continue;
                     }
                 }
             }
         }
         if ($field->field->required && !$fieldhascontent) {
             return false;
         }
     }
     foreach ($contents as $fieldid => $content) {
         $field = data_get_field_from_id($fieldid, $data);
         if (is_array($content)) {
             foreach ($content as $fieldname => $value) {
                 $field->update_content($recordid, $value, $fieldname);
             }
         } else {
             $field->update_content($recordid, $content);
         }
     }
     return $recordid;
 }
开发者ID:alexandru-elisei,项目名称:moodle,代码行数:100,代码来源:lib.php

示例9: load_data

 public function load_data()
 {
     global $DB;
     if (!($this->cm = get_coursemodule_from_id('data', $this->id))) {
         throw new portfolio_caller_exception('invalidid', 'data');
     }
     $this->data = $DB->get_record('data', array('id' => $this->cm->instance));
     $fieldrecords = $DB->get_records('data_fields', array('dataid' => $this->cm->instance), 'id');
     // populate objets for this databases fields
     $this->fields = array();
     foreach ($fieldrecords as $fieldrecord) {
         $tmp = data_get_field($fieldrecord, $this->data);
         $this->fields[] = $tmp;
         $this->fieldtypes[] = $tmp->type;
     }
     if ($this->recordid) {
         //user has selected to export one single entry rather than the whole thing
         // which is completely different
         $this->singlerecord = $DB->get_record('data_records', array('id' => $this->recordid));
         $this->singlerecord->content = $DB->get_records('data_content', array('recordid' => $this->singlerecord->id));
         $this->exporttype = 'single';
         list($formats, $files) = self::formats($this->fields, $this->singlerecord);
         $this->supportedformats = $formats;
         if (count($files) == 1 && count($this->fields) == 1) {
             $this->singlefile = $files[0];
             $this->exporttype = 'singlefile';
         } else {
             if (count($files) > 0) {
                 $this->multifiles = $files;
             }
         }
     } else {
         // all records as csv or whatever
         $this->exportdata = data_get_exportdata($this->cm->instance, $this->fields, $this->selectedfields);
     }
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:36,代码来源:lib.php

示例10: data_print_template

function data_print_template($template, $records, $data, $search = '', $page = 0, $return = false)
{
    global $CFG;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;
    if (empty($dataid)) {
        $dataid = $data->id;
    } else {
        if ($dataid != $data->id) {
            $fields = NULL;
        }
    }
    if (empty($fields)) {
        $fieldrecords = get_records('data_fields', 'dataid', $data->id);
        foreach ($fieldrecords as $fieldrecord) {
            $fields[] = data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }
    if (empty($records)) {
        return;
    }
    foreach ($records as $record) {
        /// Might be just one for the single template
        /// Replacing tags
        $patterns = array();
        $replacement = array();
        /// Then we generate strings to replace for normal tags
        foreach ($fields as $field) {
            $patterns[] = '[[' . $field->field->name . ']]';
            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
        }
        /// Replacing special tags (##Edit##, ##Delete##, ##More##)
        $patterns[] = '##edit##';
        $patterns[] = '##delete##';
        if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) {
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '&amp;rid=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/edit.gif" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>';
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;delete=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>';
        } else {
            $replacement[] = '';
            $replacement[] = '';
        }
        $patterns[] = '##more##';
        $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id . '"><img src="' . $CFG->pixpath . '/i/search.gif" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';
        $patterns[] = '##moreurl##';
        $replacement[] = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id;
        $patterns[] = '##user##';
        $replacement[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->userid . '&amp;course=' . $data->course . '">' . fullname($record) . '</a>';
        $patterns[] = '##approve##';
        if (has_capability('mod/data:approve', $context) && $data->approval && !$record->approved) {
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;approve=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/i/approve.gif" class="iconsmall" alt="' . get_string('approve') . '" /></a>';
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##comments##';
        if ($template == 'listtemplate' && $data->comments) {
            $comments = count_records('data_comments', 'recordid', $record->id);
            $replacement[] = '<a href="view.php?rid=' . $record->id . '#comments">' . get_string('commentsn', 'data', $comments) . '</a>';
        } else {
            $replacement[] = '';
        }
        ///actual replacement of the tags
        $newtext = str_ireplace($patterns, $replacement, $data->{$template});
        /// no more html formatting and filtering - see MDL-6635
        if ($return) {
            return $newtext;
        } else {
            echo $newtext;
            // hack alert - return is always false in singletemplate anyway ;-)
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate') {
                //prints ratings options
                data_print_ratings($data, $record);
            }
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate' && $data->comments) {
                //prints ratings options
                data_print_comments($data, $record, $page);
            }
        }
    }
}
开发者ID:veritech,项目名称:pare-project,代码行数:89,代码来源:lib.php


注:本文中的data_get_field函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。