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


PHP float_format函数代码示例

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


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

示例1: executeReport

 /**
  * Execute report
  *
  * @param User $user
  * @param TimeReport $report
  * @param Project $project
  * @return array
  */
 function executeReport($user, $report, $project = null)
 {
     $conditions = $report->prepareConditions($user, $project);
     if (empty($conditions)) {
         return null;
     }
     // if
     if ($report->getSumByUser()) {
         $rows = db_execute_all('SELECT SUM(float_field_1) AS total_time, integer_field_1 AS user_id FROM ' . TABLE_PREFIX . 'project_objects WHERE ' . $conditions . ' GROUP BY integer_field_1');
         if (is_foreachable($rows)) {
             $result = array();
             foreach ($rows as $row) {
                 $user = Users::findById($row['user_id']);
                 if (instance_of($user, 'User')) {
                     $result[] = array('user' => $user, 'total_time' => float_format($row['total_time'], 2));
                 }
                 // if
             }
             // foreach
             return $result;
         } else {
             return null;
         }
         // if
     } else {
         return TimeRecords::findBySQL('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE ' . $conditions . ' ORDER BY date_field_1');
     }
     // if
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:37,代码来源:TimeReports.class.php

示例2: smarty_function_mobile_access_object_properties

/**
 * Show a object properties
 *
 * Parameters:
 * 
 * - object - Object of which properties are shown
 * - show_completed_status - To display object completed status
 * - show_milestone - To display object milestone
 * - show_tags - To display object tags
 * - show_body - To display object description
 * - show_category - To display object category
 * - show_file_details - To display file details, if object is file
 * - show_name - To display object name
 * - show_priority - To display object priority
 * - show_milestone_day_info - To display milestone due on info
 * - show_assignees - To show assignees
 * - only_show_body - To display only body
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_properties($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $smarty->assign(array('_mobile_access_object_properties_object' => $object, '_mobile_access_object_properties_show_completed_status' => (bool) array_var($params, 'show_completed_status', false), '_mobile_access_object_properties_show_milestone' => (bool) array_var($params, 'show_milestone', false), '_mobile_access_object_properties_show_tags' => (bool) array_var($params, 'show_tags', false), '_mobile_access_object_properties_show_body' => (bool) array_var($params, 'show_body', false), '_mobile_access_object_properties_show_category' => (bool) array_var($params, 'show_category', false), '_mobile_access_object_properties_show_file_details' => (bool) array_var($params, 'show_file_details', false), '_mobile_access_object_properties_show_name' => (bool) array_var($params, 'show_name', false), '_mobile_access_object_properties_show_assignees' => (bool) array_var($params, 'show_assignees', false), '_mobile_access_object_properties_show_priority' => (bool) array_var($params, 'show_priority', false), '_mobile_access_object_properties_show_milestone_day_info' => (bool) array_var($params, 'show_milestone_day_info', false), '_mobile_access_object_properties_show_total_time' => (bool) array_var($params, 'show_total_time', false), '_mobile_access_object_properties_only_show_body' => (bool) array_var($params, 'only_show_body', false)));
    if (module_loaded(TIMETRACKING_MODULE)) {
        $smarty->assign(array('_mobile_access_object_properties_total_time' => float_format(TimeRecords::sumObjectTime($object), 2)));
    }
    return $smarty->fetch(get_template_path('_object_properties', null, MOBILE_ACCESS_MODULE));
}
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:35,代码来源:function.mobile_access_object_properties.php

示例3: createAnswersForm

 /**
  * function which redifines Question::createAnswersForm
  * @param formvalidator $form
  */
 function createAnswersForm($form)
 {
     $form->addElement('text', 'weighting', get_lang('Weighting'));
     global $text, $class;
     // setting the save button here and not in the question class.php
     $form->addButtonSave($text, 'submitQuestion');
     if (!empty($this->id)) {
         $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults(array('weighting' => '10'));
         }
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:18,代码来源:freeanswer.class.php

示例4: render_tab

 /**
  * Standard modular render function for profile tabs edit hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return ?array			A tuple: The tab title, the tab body text (may be blank), the tab fields, extra Javascript (may be blank) the suggested tab order, hidden fields (optional) (NULL: if $leave_to_ajax_if_possible was set)
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     $title = do_lang_tempcode('PHOTO');
     $order = 30;
     // Actualiser
     if (post_param_integer('submitting_photo_tab', 0) == 1) {
         require_code('ocf_members_action');
         require_code('ocf_members_action2');
         ocf_member_choose_photo('photo_url', 'photo_file', $member_id_of);
         attach_message(do_lang_tempcode('SUCCESS_SAVE'), 'inform');
     }
     if ($leave_to_ajax_if_possible) {
         return NULL;
     }
     $photo_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_url');
     $thumb_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_thumb_url');
     // UI fields
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD'), 'photo_file', false, NULL, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     $fields->attach(form_input_line(do_lang_tempcode('ALT_FIELD', do_lang_tempcode('URL')), do_lang_tempcode('DESCRIPTION_ALTERNATE_URL'), 'photo_url', $photo_url, false));
     if (get_option('is_on_gd') == '0' || !function_exists('imagetypes')) {
         $thumb_width = get_option('thumb_width');
         $fields->attach(form_input_upload(do_lang_tempcode('THUMBNAIL'), do_lang_tempcode('DESCRIPTION_THUMBNAIL', escape_html($thumb_width)), 'photo_file2', false, NULL, NULL, true, str_replace(' ', '', get_option('valid_images'))));
         $fields->attach(form_input_line(do_lang_tempcode('ALT_FIELD', do_lang_tempcode('URL')), do_lang_tempcode('DESCRIPTION_ALTERNATE_URL'), 'photo_thumb_url', $thumb_url, false));
     }
     $hidden = new ocp_tempcode();
     handle_max_file_size($hidden, 'image');
     $hidden->attach(form_input_hidden('submitting_photo_tab', '1'));
     $text = new ocp_tempcode();
     require_code('images');
     $max = floatval(get_max_image_size()) / floatval(1024 * 1024);
     if ($max < 3.0) {
         require_code('files2');
         $config_url = get_upload_limit_config_url();
         $text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), is_null($config_url) ? '' : escape_html($config_url))));
     }
     $text = do_template('OCF_EDIT_PHOTO_TAB', array('TEXT' => $text, 'MEMBER_ID' => strval($member_id_of), 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($member_id_of), 'PHOTO' => $GLOBALS['FORUM_DRIVER']->get_member_photo_url($member_id_of)));
     $javascript = '';
     return array($title, $fields, $text, $javascript, $order, $hidden);
 }
开发者ID:erico-deh,项目名称:ocPortal,代码行数:49,代码来源:photo.php

示例5: smarty_function_object_time

/**
 * Render object time widget
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_time($params, &$smarty)
{
    if (!module_loaded('timetracking')) {
        return '';
    }
    // if
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('$object', $object, '$object is expected to be a valid instance of ProjectObject class');
    }
    // if
    $show_time = '';
    $additional_class = '';
    if (array_var($params, 'show_time', true)) {
        $object_time = TimeRecords::sumObjectTime($object);
        if ($object->can_have_tasks) {
            $tasks_time = TimeRecords::sumTasksTime($object);
        } else {
            $tasks_time = 0;
        }
        // if
        $additional_class = 'with_text';
        $total_time = $object_time + $tasks_time;
        if ($object_time == 0 && $tasks_time == 0) {
            $show_time = '<span class="time_widget_text">' . lang('No time tracked') . '</span> ';
        } elseif ($tasks_time == 0) {
            $show_time = '<span class="time_widget_text">' . lang(':total hours logged', array('total' => float_format($total_time, 2))) . '</span> ';
        } else {
            $show_time = '<span class="time_widget_text">' . lang(':total hours logged - :object_time for the ticket and :tasks_time for tasks', array('type' => $object->getVerboseType(true), 'total' => float_format($total_time, 2), 'object_time' => float_format($object_time, 2), 'tasks_time' => float_format($tasks_time, 2))) . '</span> ';
        }
        // if
    }
    // if
    $wrapper_id = 'object_time_widget_' . $object->getId();
    $image_url = $object->getHasTime() ? get_image_url('clock-small.gif') : get_image_url('gray-clock-small.gif');
    return '<span id="' . $wrapper_id . '" class="time_popup_widget ' . $additional_class . '">' . $show_time . '<a href="' . $object->getTimeUrl() . '" title="' . lang('Time') . '"><img src="' . $image_url . '" alt="" /></a></span><script type="text/javascript">App.TimePopup.init("' . $wrapper_id . '")</script>';
}
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:44,代码来源:function.object_time.php

示例6: export_to_xml

/**
 * Export ocPortal database tables to an equivalent XML format, automatically.
 *
 * @param  ?array			List of tables to export (NULL: all tables except those skippable)
 * @param  boolean		Whether to export Comcode as Comcode XML
 * @return string			Exported data in XML format
 */
function export_to_xml($tables = NULL, $comcode_xml = true)
{
    if ($comcode_xml) {
        require_code('comcode_conversion');
    }
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
    if (is_null($tables)) {
        $tables = find_all_xml_tables();
    }
    // Build up data
    $xml_data = '';
    $xml_data .= '<!-- Exported on ' . xmlentities(date('Y-m-d h:i:s')) . ' by ' . xmlentities($GLOBALS['FORUM_DRIVER']->get_username(get_member())) . ' -->' . chr(10);
    $xml_data .= '<ocportal origin="' . xmlentities(get_base_url()) . '" version="' . xmlentities(float_format(ocp_version_number())) . '">' . chr(10);
    foreach ($tables as $table) {
        $table_xml = _export_table_to_xml($table, $comcode_xml);
        if ($table_xml != '') {
            $xml_data .= _tab($table_xml) . chr(10);
        }
    }
    $xml_data = rtrim($xml_data) . chr(10);
    $xml_data .= '</ocportal>' . chr(10);
    return $xml_data;
}
开发者ID:erico-deh,项目名称:ocPortal,代码行数:31,代码来源:xml_storage.php

示例7: createAnswersForm

 /**
  * function which redifines Question::createAnswersForm
  * @param FormValidator $form
  * @param the answers number to display
  */
 function createAnswersForm($form)
 {
     // getting the exercise list
     $obj_ex = Session::read('objExercise');
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line define how many question by default appear when creating a choice question
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
      Types of Feedback
      $feedback_option[0]=get_lang('Feedback');
      $feedback_option[1]=get_lang('DirectFeedback');
      $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     $comment_title = '';
     if ($obj_ex->selectFeedbackType() == 1) {
         $editor_config['Width'] = '250';
         $editor_config['Height'] = '110';
         $comment_title = '<th width="50%" >' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="50%" >' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th width="50%">' . get_lang('Comment') . '</th>';
     }
     $html = '<table class="table table-striped table-hover">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th>' . get_lang('Number') . '</th>';
     $html .= '<th>' . get_lang('True') . '</th>';
     $html .= '<th width="50%">' . get_lang('Answer') . '</th>';
     $html .= $comment_title . $feedback_title;
     $html .= '<th>' . get_lang('Weighting') . '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     $html .= '<tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : false;
     if ($editQuestion) {
         //fixing $nb_answers
         $new_list = array();
         $count = 1;
         if (isset($_POST['lessAnswers'])) {
             $lessFromSession = Session::read('less_answer');
             if (!isset($lessFromSession)) {
                 Session::write('less_answer', $this->id);
                 $nb_answers--;
             }
         }
         for ($k = 1; $k <= $nb_answers; ++$k) {
             if ($answer->position[$k] != '666') {
                 $new_list[$count] = $count;
                 $count++;
             }
         }
     } else {
         for ($k = 1; $k <= $nb_answers; ++$k) {
             $new_list[$k] = $k;
         }
     }
     $i = 1;
     //for ($k = 1 ; $k <= $real_nb_answers; $k++) {
     foreach ($new_list as $key) {
         $i = $key;
         $form->addElement('html', '<tr>');
         if (is_object($answer)) {
             if ($answer->position[$i] == 666) {
                 //we set nothing
             } else {
                 if ($answer->correct[$i]) {
                     $correct = $i;
                 }
                 $answer_result = $answer->answer[$i];
                 $weight_result = float_format($answer->weighting[$i], 1);
                 if ($nb_answers == $i) {
                     $weight_result = '0';
                 }
                 $defaults['answer[' . $i . ']'] = $answer_result;
                 $defaults['comment[' . $i . ']'] = $answer->comment[$i];
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:unique_answer_no_option.class.php

示例8: _ed


//.........这里部分代码省略.........
     // SEO?
     if (!is_null($this->seo_type)) {
         require_code('seo2');
         $fields2->attach(seo_get_fields($this->seo_type, $id));
     }
     // Awards?
     if (addon_installed('awards')) {
         if (!is_null($this->award_type)) {
             require_code('awards');
             $fields2->attach(get_award_fields($this->award_type, $id));
         }
     }
     // Action fields / deletion options
     $delete_permission = true;
     if (!is_null($this->permissions_require)) {
         $delete_permission = has_delete_permission($this->permissions_require, get_member(), $submitter, is_null($this->permission_page_name) ? get_page_name() : $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)));
     }
     $may_delete = (!method_exists($this, 'may_delete_this') || $this->may_delete_this($id)) && (!is_numeric($id) || intval($id) >= db_get_first_id() + $this->protect_first) && $delete_permission;
     // Deletion options
     $action_fields = new ocp_tempcode();
     if ($may_delete) {
         if (!$all_delete_fields_given) {
             $action_fields->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), 'delete', false));
         }
         if (addon_installed('points') && !is_null($submitter) && !is_null($date_and_time)) {
             $points_test = $GLOBALS['SITE_DB']->query_value_null_ok('gifts', 'id', array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id()));
             if (!is_null($points_test)) {
                 require_lang('points');
                 $action_fields->attach(form_input_tick(do_lang_tempcode('REVERSE_TITLE'), do_lang_tempcode('REVERSE_TITLE_DESCRIPTION'), 'reverse_point_transaction', false));
             }
         }
         $action_fields->attach($delete_fields);
     }
     if (!$this->appended_actions_already && !$action_fields->is_empty()) {
         $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS'))));
     }
     $fields2->attach($action_fields);
     if (!is_object($this->edit_text)) {
         $this->edit_text = make_string_tempcode(is_null($this->edit_text) ? '' : $this->edit_text);
     }
     if (!is_null($this->upload)) {
         if ($this->upload == 'image') {
             require_code('images');
             $max = floatval(get_max_image_size()) / floatval(1024 * 1024);
             if ($max < 3.0) {
                 require_code('files2');
                 $config_url = get_upload_limit_config_url();
                 $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url))));
             }
         } else {
             require_code('files2');
             $max = floatval(get_max_file_size()) / floatval(1024 * 1024);
             if ($max < 30.0) {
                 $config_url = get_upload_limit_config_url();
                 $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url))));
             }
         }
     }
     if (get_param('type', '_ed') == '_edit_catalogue') {
         require_javascript('javascript_catalogues');
         // Existing fields
         $field_count = 0;
         $c_name = get_param('id', false, true);
         $rows = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $c_name), 'ORDER BY cf_order');
         $fields_existing = new ocp_tempcode();
         foreach ($rows as $i => $myrow) {
             $name = get_translated_text($myrow['cf_name']);
             $description = get_translated_text($myrow['cf_description']);
             $prefix = 'existing_field_' . strval($myrow['id']) . '_';
             list($_fields_existing, $_fields_hidden) = $this->get_field_fields($i == 0 && substr($c_name, 0, 1) != '_', count($rows) + 10, $prefix, $field_count, $name, $description, $myrow['cf_type'], $myrow['cf_defines_order'], $myrow['cf_visible'], $myrow['cf_searchable'], $myrow['cf_default'], $myrow['cf_required'], $myrow['cf_put_in_category'], $myrow['cf_put_in_search']);
             if (!is_ecommerce_catalogue($c_name) || $i > 9) {
                 $_fields_existing->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS'))));
                 $_fields_existing->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), $prefix . 'delete', false));
             }
             $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '1492d973db45cbecff892ad4ac1af28f' . get_class($this), 'NAME' => $name, 'ID' => 'FIELD_' . strval($i + 1), 'FIELDS' => $_fields_existing->evaluate()));
             $fields_existing->attach($temp);
             $hidden->attach($_fields_hidden);
             $field_count++;
         }
         // New field
         $fields_new = new ocp_tempcode();
         for ($i = 0; $i < 5; $i++) {
             list($_fields_new, $_fields_hidden) = $this->get_field_fields(false, count($rows) + 10, 'new_field_' . strval($i) . '_', $field_count);
             $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '8b9a632eafae003ccc6b007eefb0ce3d' . get_class($this), 'NAME' => do_lang_tempcode('NEW_FIELD', strval($i + 1)), 'ID' => 'NEW_FIELD_' . strval($i + 1), 'FIELDS' => $_fields_new->evaluate()));
             $fields_new->attach($temp);
             $hidden->attach($_fields_hidden);
             $field_count++;
         }
         $fields->attach($fields2);
         return do_template('CATALOGUE_EDITING_SCREEN', array('_GUID' => '584d7dc7c2c13939626102374f13f508' . get_class($this), 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $this->add_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'FIELDS_EXISTING' => $fields_existing->evaluate(), 'FIELDS_NEW' => $fields_new->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript));
     }
     list($warning_details, $ping_url) = handle_conflict_resolution();
     if (!is_null($this->posting_form_title)) {
         $posting_form = get_posting_form($submit_name, $this->posting_form_text, $post_url, $hidden, $fields, $this->posting_form_title, '', $fields2, $this->posting_form_text_parsed, $this->javascript, NULL, $this->posting_field_required);
         return do_template('POSTING_SCREEN', array('_GUID' => '841b9af3aa80bcab86b907e4b942786a' . get_class($this), 'PREVIEW' => $this->do_preview, 'TITLE' => $title, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'TEXT' => $this->add_text, 'POSTING_FORM' => $posting_form->evaluate(), 'JAVASCRIPT' => $this->javascript));
     } else {
         $fields->attach($fields2);
         return do_template('FORM_SCREEN', array('_GUID' => '2d70be34595a16c6f170d966b894bfe2' . get_class($this), 'PREVIEW' => $this->do_preview, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'TITLE' => $title, 'SKIP_VALIDATION' => $this->skip_validation, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'HIDDEN' => $hidden, 'TEXT' => $this->edit_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript));
     }
 }
开发者ID:erico-deh,项目名称:ocPortal,代码行数:101,代码来源:aed_module.php

示例9: tpl_preview__iotd_view_screen

 /**
  * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
  * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive.
  * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required.
  *
  * @return array			Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data).
  */
 function tpl_preview__iotd_view_screen()
 {
     require_lang('ocf');
     require_lang('captcha');
     require_lang('trackbacks');
     $trackbacks = new ocp_tempcode();
     foreach (placeholder_array(1) as $k => $v) {
         $trackbacks->attach(do_lorem_template('TRACKBACK', array('ID' => placeholder_id(), 'TIME_RAW' => placeholder_date_raw(), 'TIME' => placeholder_date(), 'URL' => placeholder_url(), 'TITLE' => lorem_phrase(), 'EXCERPT' => lorem_paragraph(), 'NAME' => lorem_phrase())));
     }
     $trackback_details = do_lorem_template('TRACKBACK_WRAPPER', array('TRACKBACKS' => $trackbacks, 'TRACKBACK_PAGE' => placeholder_id(), 'TRACKBACK_ID' => placeholder_id(), 'TRACKBACK_TITLE' => lorem_phrase()));
     $rating_details = new ocp_tempcode();
     $review_titles = array();
     $review_titles[] = array('REVIEW_TITLE' => lorem_word(), 'REVIEW_RATING' => make_string_tempcode(float_format(10.0)));
     $comments = '';
     $form = do_lorem_template('COMMENTS_POSTING_FORM', array('JOIN_BITS' => lorem_phrase_html(), 'FIRST_POST_URL' => placeholder_url(), 'FIRST_POST' => lorem_paragraph_html(), 'TYPE' => 'downloads', 'ID' => placeholder_id(), 'REVIEW_RATING_CRITERIA' => $review_titles, 'USE_CAPTCHA' => true, 'GET_EMAIL' => false, 'EMAIL_OPTIONAL' => true, 'GET_TITLE' => true, 'POST_WARNING' => do_lang('POST_WARNING'), 'COMMENT_TEXT' => get_option('comment_text'), 'EM' => placeholder_emoticon_chooser(), 'DISPLAY' => 'block', 'COMMENT_URL' => placeholder_url(), 'TITLE' => lorem_word(), 'MAKE_POST' => true, 'CREATE_TICKET_MAKE_POST' => true));
     $comment_details = do_lorem_template('COMMENTS_WRAPPER', array('TYPE' => lorem_phrase(), 'ID' => placeholder_id(), 'REVIEW_RATING_CRITERIA' => $review_titles, 'AUTHORISED_FORUM_LINK' => placeholder_url(), 'FORM' => $form, 'COMMENTS' => $comments));
     return array(lorem_globalise(do_lorem_template('IOTD_VIEW_SCREEN', array('TITLE' => lorem_title(), 'SUBMITTER' => lorem_word_html(), 'I_TITLE' => lorem_phrase(), 'CAPTION' => lorem_phrase(), 'DATE_RAW' => placeholder_date_raw(), 'ADD_DATE_RAW' => placeholder_date_raw(), 'EDIT_DATE_RAW' => placeholder_date_raw(), 'DATE' => placeholder_time(), 'ADD_DATE' => placeholder_time(), 'EDIT_DATE' => placeholder_time(), 'VIEWS' => placeholder_number(), 'TRACKBACK_DETAILS' => $trackback_details, 'RATING_DETAILS' => $rating_details, 'COMMENT_DETAILS' => $comment_details, 'EDIT_URL' => placeholder_url(), 'URL' => placeholder_image_url())), NULL, '', true));
 }
开发者ID:erico-deh,项目名称:ocPortal,代码行数:25,代码来源:iotds.php

示例10: createAnswersForm

 /**
  * function which redifines Question::createAnswersForm
  * @param the formvalidator instance
  * @param the answers number to display
  */
 function createAnswersForm($form)
 {
     $editorConfig = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     $obj_ex = $_SESSION['objExercise'];
     $form->addHeader(get_lang('Answers'));
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="10">' . get_lang('Number') . '</th>
                 <th width="10">' . get_lang('True') . '</th>
                 <th width="50%">' . get_lang('Answer') . '</th>
                 <th width="50%">' . get_lang('Comment') . '</th>
                 <th width="10">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     $boxes_names = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addHtml('<tr>');
         if (is_object($answer)) {
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $defaults['correct[' . $i . ']'] = $answer->correct[$i];
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
             $defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
             $defaults['correct[1]'] = true;
             $defaults['weighting[1]'] = 10;
             $defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1');
             $defaults['comment[2]'] = get_lang('DefaultMultipleComment1');
             $defaults['correct[2]'] = false;
             $defaults['weighting[2]'] = -5;
         }
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox" style="margin-left: 0em;"');
         $boxes_names[] = 'correct[' . $i . ']';
         $form->addHtmlEditor("answer[{$i}]", null, null, true, $editorConfig);
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         $form->addHtmlEditor("comment[{$i}]", null, null, true, $editorConfig);
         $form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "col-md-1", 'value' => '0'));
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody>');
     $form->addHtml('</table>');
     $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
     $buttonGroup = [];
     global $text, $class;
     if ($obj_ex->edit_exercise_in_lp == true) {
         // setting the save button here and not in the question class.php
         $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
         $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
         $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
     }
     $form->addGroup($buttonGroup);
     $defaults['correct'] = $correct;
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults($defaults);
         }
     }
     $form->setConstants(array('nb_answers' => $nb_answers));
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:96,代码来源:multiple_answer.class.php

示例11: render_tab


//.........这里部分代码省略.........
     $time_for_them_raw = tz_time(time(), get_users_timezone($member_id_of));
     $time_for_them = get_timezoned_time(time(), true, $member_id_of);
     $banned = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_is_perm_banned') == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
     $last_submit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_submit_time');
     $submit_days_ago = intval(floor(floatval(time() - $last_submit_time) / 60.0 / 60.0 / 24.0));
     require_code('ocf_groups');
     $primary_group_id = ocf_get_member_primary_group($member_id_of);
     $primary_group = ocf_get_group_link($primary_group_id);
     $signature = get_translated_tempcode($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_signature'), $GLOBALS['FORUM_DB']);
     $last_visit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_visit_time');
     if (member_is_online($member_id_of)) {
         $online_now = do_lang_tempcode('YES');
         $_online_now = true;
     } else {
         $_online_now = false;
         $minutes_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0));
         $hours_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0));
         $days_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0));
         $months_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0 / 31.0));
         if ($minutes_ago < 180) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MINUTES', integer_format($minutes_ago));
         } elseif ($hours_ago < 72) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_HOURS', integer_format($hours_ago));
         } elseif ($days_ago < 93) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_DAYS', integer_format($days_ago));
         } else {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MONTHS', integer_format($months_ago));
         }
     }
     $join_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_join_time');
     $days_joined = intval(round((time() - $join_time) / 60 / 60 / 24));
     $total_posts = $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)');
     $join_date = $join_time == 0 ? '' : get_timezoned_date($join_time, false);
     $count_posts = do_lang_tempcode('_COUNT_POSTS', integer_format($post_count), float_format(floatval($post_count) / floatval($days_joined == 0 ? 1 : $days_joined)), array(float_format(floatval(100 * $post_count) / floatval($total_posts == 0 ? 1 : $total_posts))));
     $a = $avatar_url == '' ? 0 : ocf_get_member_best_group_property($member_id_of, 'max_avatar_width');
     $b = $photo_thumb_url == '' ? 0 : intval(get_option('thumb_width'));
     $right_margin = max($a, $b) == 0 ? 'auto' : strval(max($a, $b) + 6) . 'px';
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MEMBERS'))));
     if (has_specific_permission($member_id_viewing, 'see_ip')) {
         $ip_address = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_ip_address');
     } else {
         $ip_address = '';
     }
     $secondary_groups = ocf_get_members_groups($member_id_of, true);
     unset($secondary_groups[$primary_group_id]);
     if (count($secondary_groups) > 0) {
         $_secondary_groups = array();
         $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, array_keys($secondary_groups), $member_id_of);
         foreach (array_keys($secondary_groups) as $key) {
             $_secondary_groups[$key] = $all_groups[$key];
         }
         $secondary_groups = $_secondary_groups;
     }
     if (addon_installed('points')) {
         require_code('points');
         $count_points = integer_format(total_points($member_id_of));
     } else {
         $count_points = '';
     }
     $user_agent = NULL;
     $operating_system = NULL;
     if (has_specific_permission($member_id_viewing, 'show_user_browsing') && addon_installed('stats')) {
         $last_stats = $GLOBALS['SITE_DB']->query_select('stats', array('browser', 'operating_system'), array('the_user' => $member_id_of), 'ORDER BY date_and_time DESC', 1);
         if (array_key_exists(0, $last_stats)) {
             $user_agent = $last_stats[0]['browser'];
             $operating_system = $last_stats[0]['operating_system'];
开发者ID:erico-deh,项目名称:ocPortal,代码行数:67,代码来源:about.php

示例12: render_as_comment_topic

 /**
  * Render a comment topic.
  *
  * @param  ID_TEXT		Content type to show topic for
  * @param  ID_TEXT		Content ID of content type to show topic for
  * @param  boolean		Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
  * @param  boolean		Whether the comment box will be invisible if there are not yet any comments (and you're not staff)
  * @param  ?string		The name of the forum to use (NULL: default comment forum)
  * @param  ?string		The default post to use (NULL: standard courtesy warning)
  * @param  ?mixed			The raw comment array (NULL: lookup). This is useful if we want to pass it through a filter
  * @param  boolean		Whether to skip permission checks
  * @param  boolean		Whether to reverse the posts
  * @param  ?MEMBER		User to highlight the posts of (NULL: none)
  * @param  boolean		Whether to allow ratings along with the comment (like reviews)
  * @return tempcode		The tempcode for the comment topic
  */
 function render_as_comment_topic($content_type, $content_id, $allow_comments, $invisible_if_no_comments, $forum_name, $post_warning, $preloaded_comments, $explicit_allow, $reverse, $highlight_by_user, $allow_reviews)
 {
     if (get_forum_type() == 'ocf' && !addon_installed('ocf_forum')) {
         return new ocp_tempcode();
     }
     $topic_id = $GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum_name, $content_type . '_' . $content_id);
     // Settings we need
     $max_thread_depth = get_param_integer('max_thread_depth', intval(get_option('max_thread_depth')));
     $num_to_show_limit = get_param_integer('max_comments', intval(get_option('comments_to_show_in_thread')));
     $start = get_param_integer('start_comments', 0);
     // Load up posts from DB
     if (is_null($preloaded_comments)) {
         if (!$this->load_from_topic($topic_id, $num_to_show_limit, $start, $reverse)) {
             attach_message(do_lang_tempcode('MISSING_FORUM', escape_html($forum_name)), 'warn');
         }
     } else {
         $this->_inject_posts_for_scoring_algorithm($preloaded_comments);
     }
     if (!$this->error) {
         if (count($this->all_posts_ordered) == 0 && $invisible_if_no_comments) {
             return new ocp_tempcode();
         }
         $may_reply = has_specific_permission(get_member(), 'comment', get_page_name());
         // Prepare review titles
         global $REVIEWS_STRUCTURE;
         if ($allow_reviews) {
             if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) {
                 $this->set_reviews_rating_criteria($REVIEWS_STRUCTURE[$content_type]);
             } else {
                 $this->set_reviews_rating_criteria(array(''));
             }
         }
         // Load up reviews
         if (get_forum_type() == 'ocf' && $allow_reviews) {
             $all_individual_review_ratings = $GLOBALS['SITE_DB']->query_select('review_supplement', array('*'), array('r_topic_id' => $topic_id));
         } else {
             $all_individual_review_ratings = array();
         }
         $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name);
         // Posts
         list($posts, $serialized_options, $hash) = $this->render_posts($num_to_show_limit, $max_thread_depth, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id);
         // Pagination
         $results_browser = NULL;
         if (!$this->is_threaded && is_null($preloaded_comments)) {
             if ($this->total_posts > $num_to_show_limit) {
                 require_code('templates_results_browser');
                 $results_browser = results_browser(do_lang_tempcode('COMMENTS'), NULL, $start, 'start_comments', $num_to_show_limit, 'max_comments', $this->total_posts, NULL, NULL, true);
             }
         }
         // Environment meta data
         $this->inject_rss_url($forum_name, $content_type, $content_id);
         $this->inject_meta_data();
         // Make-a-comment form
         if ($may_reply) {
             $post_url = get_self_url();
             $form = $this->get_posting_form($content_type, $content_id, $allow_reviews, $post_url, $post_warning);
         } else {
             $form = new ocp_tempcode();
         }
         // Existing review ratings
         $reviews_rating_criteria = array();
         if (get_forum_type() == 'ocf' && $allow_reviews) {
             foreach ($this->reviews_rating_criteria as $review_title) {
                 $_rating = $GLOBALS['SITE_DB']->query_value('review_supplement', 'AVG(r_rating)', array('r_rating_type' => $review_title, 'r_topic_id' => $topic_id));
                 $rating = mixed();
                 $rating = is_null($_rating) ? NULL : $_rating;
                 $reviews_rating_criteria[] = array('REVIEW_TITLE' => $review_title, 'REVIEW_RATING' => make_string_tempcode(is_null($rating) ? '' : float_format($rating)));
                 if (!is_null($rating)) {
                     $GLOBALS['META_DATA'] += array('rating' => float_to_raw_string($rating));
                 }
             }
         }
         // Direct links to forum
         $forum_url = is_null($topic_id) ? '' : $GLOBALS['FORUM_DRIVER']->topic_url($topic_id, $forum_name, true);
         if ($GLOBALS['FORUM_DRIVER']->is_staff(get_member()) || $forum_name == get_option('comments_forum_name')) {
             $authorised_forum_url = $forum_url;
         } else {
             $authorised_forum_url = '';
         }
         // Show it all
         return do_template('COMMENTS_WRAPPER', array('_GUID' => 'a89cacb546157d34vv0994ef91b2e707', 'RESULTS_BROWSER' => $results_browser, 'TYPE' => $content_type, 'ID' => $content_id, 'REVIEW_RATING_CRITERIA' => $reviews_rating_criteria, 'FORUM_LINK' => $forum_url, 'AUTHORISED_FORUM_LINK' => $authorised_forum_url, 'FORM' => $form, 'COMMENTS' => $posts, 'HASH' => $hash, 'SERIALIZED_OPTIONS' => $serialized_options));
     }
     return new ocp_tempcode();
 }
开发者ID:erico-deh,项目名称:ocPortal,代码行数:100,代码来源:topics.php

示例13: get_best_average_score_by_exercise

 /**
  * Get average score by score (NO Exercises in LPs )
  * @param    int        exercise id
  * @param    int    $courseId
  * @param    int        session id
  * @return    float    Best average score
  */
 public static function get_best_average_score_by_exercise($exercise_id, $courseId, $session_id, $user_count)
 {
     $user_results = Event::get_best_exercise_results_by_user($exercise_id, $courseId, $session_id);
     $avg_score = 0;
     if (!empty($user_results)) {
         foreach ($user_results as $result) {
             if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
                 $score = $result['exe_result'] / $result['exe_weighting'];
                 $avg_score += $score;
             }
         }
         //We asume that all exe_weighting
         //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']);
         //$avg_score = ($avg_score / count($user_results));
         if (!empty($user_count)) {
             $avg_score = float_format($avg_score / $user_count, 1) * 100;
         } else {
             $avg_score = 0;
         }
     }
     return $avg_score;
 }
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:29,代码来源:exercise.lib.php

示例14: clean_file_size

/**
 * Format the specified filesize.
 *
 * @param  integer		The number of bytes the file has
 * @return string			The formatted-string file size
 */
function clean_file_size($bytes)
{
    if ($bytes < 0) {
        return '-' . clean_file_size(-$bytes);
    }
    if (is_null($bytes)) {
        return do_lang('UNKNOWN') . ' bytes';
    }
    if (floatval($bytes) > 2.0 * 1024.0 * 1024.0 * 1024.0) {
        return strval(intval(round(floatval($bytes) / 1024.0 / 1024.0 / 1024.0))) . ' Gb';
    }
    if (floatval($bytes) > 1024.0 * 1024.0 * 1024.0) {
        return float_format(round(floatval($bytes) / 1024.0 / 1024.0 / 1024.0, 2)) . ' Gb';
    }
    if (floatval($bytes) > 2.0 * 1024.0 * 1024.0) {
        return strval(intval(round(floatval($bytes) / 1024.0 / 1024.0))) . ' Mb';
    }
    if (floatval($bytes) > 1024.0 * 1024.0) {
        return float_format(round(floatval($bytes) / 1024.0 / 1024.0, 2)) . ' Mb';
    }
    if (floatval($bytes) > 2.0 * 1024.0) {
        return strval(intval(round(floatval($bytes) / 1024.0))) . ' Kb';
    }
    if (floatval($bytes) > 1024.0) {
        return float_format(round(floatval($bytes) / 1024.0, 2)) . ' Kb';
    }
    return strval($bytes) . ' Bytes';
}
开发者ID:erico-deh,项目名称:ocPortal,代码行数:34,代码来源:files.php

示例15: createAnswersForm

 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $defaults = array();
     $nb_matches = $nb_options = 2;
     $matches = array();
     $answer = null;
     $counter = 1;
     if (isset($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0) {
             for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                 $correct = $answer->isCorrect($i);
                 if (empty($correct)) {
                     $matches[$answer->selectAutoId($i)] = chr(64 + $counter);
                     $counter++;
                 }
             }
         }
     }
     if ($form->isSubmitted()) {
         $nb_matches = $form->getSubmitValue('nb_matches');
         $nb_options = $form->getSubmitValue('nb_options');
         if (isset($_POST['lessOptions'])) {
             $nb_matches--;
             $nb_options--;
         }
         if (isset($_POST['moreOptions'])) {
             $nb_matches++;
             $nb_options++;
         }
     } else {
         if (!empty($this->id)) {
             if (count($answer->nbrAnswers) > 0) {
                 $nb_matches = $nb_options = 0;
                 for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                     if ($answer->isCorrect($i)) {
                         $nb_matches++;
                         $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                         $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
                         $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
                     } else {
                         $nb_options++;
                         $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                     }
                 }
             }
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
             $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
             $defaults['matches[2]'] = '2';
             $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
             $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
         }
     }
     if (empty($matches)) {
         for ($i = 1; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     } else {
         for ($i = $counter; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     }
     $form->addElement('hidden', 'nb_matches', $nb_matches);
     $form->addElement('hidden', 'nb_options', $nb_options);
     // DISPLAY MATCHES
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="5%">' . get_lang('Number') . '</th>
                 <th width="70%">' . get_lang('Answer') . '</th>
                 <th width="15%">' . get_lang('MatchesTo') . '</th>
                 <th width="10%">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('MakeCorrespond'));
     $form->addHtml($html);
     if ($nb_matches < 1) {
         $nb_matches = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
         $form->addHtml('<tr>');
         $form->addHtml("<td>{$i}</td>");
         $form->addText("answer[{$i}]", null);
         $form->addSelect("matches[{$i}]", null, $matches);
         $form->addText("weighting[{$i}]", null, true, ['value' => 10]);
         $form->addHtml('</tr>');
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:matching.class.php


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