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


PHP grade_item::normalize_formula方法代码示例

本文整理汇总了PHP中grade_item::normalize_formula方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::normalize_formula方法的具体用法?PHP grade_item::normalize_formula怎么用?PHP grade_item::normalize_formula使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grade_item的用法示例。


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

示例1: validate_formula

 /**
  * Validate the formula.
  * @param string $formula
  * @return boolean true if calculation possible, false otherwise
  */
 function validate_formula($formulastr)
 {
     global $CFG;
     require_once $CFG->libdir . '/mathslib.php';
     $formulastr = grade_item::normalize_formula($formulastr, $this->courseid);
     if (empty($formulastr)) {
         return true;
     }
     if (strpos($formulastr, '=') !== 0) {
         return get_string('errorcalculationnoequal', 'grades');
     }
     // get used items
     if (preg_match_all('/##gi(\\d+)##/', $formulastr, $matches)) {
         $useditems = array_unique($matches[1]);
         // remove duplicates
     } else {
         $useditems = array();
     }
     // MDL-11902
     // unset the value if formula is trying to reference to itself
     // but array keys does not match itemid
     if (!empty($this->id)) {
         $useditems = array_diff($useditems, array($this->id));
         //unset($useditems[$this->id]);
     }
     // prepare formula and init maths library
     $formula = preg_replace('/##(gi\\d+)##/', '\\1', $formulastr);
     $formula = new calc_formula($formula);
     if (empty($useditems)) {
         $grade_items = array();
     } else {
         $gis = implode(',', $useditems);
         $sql = "SELECT gi.*\n                      FROM {$CFG->prefix}grade_items gi\n                     WHERE gi.id IN ({$gis}) and gi.courseid={$this->courseid}";
         // from the same course only!
         if (!($grade_items = get_records_sql($sql))) {
             $grade_items = array();
         }
     }
     $params = array();
     foreach ($useditems as $itemid) {
         // make sure all grade items exist in this course
         if (!array_key_exists($itemid, $grade_items)) {
             return false;
         }
         // use max grade when testing formula, this should be ok in 99.9%
         // division by 0 is one of possible problems
         $params['gi' . $grade_items[$itemid]->id] = $grade_items[$itemid]->grademax;
     }
     // do the calculation
     $formula->set_params($params);
     $result = $formula->evaluate();
     // false as result indicates some problem
     if ($result === false) {
         // TODO: add more error hints
         return get_string('errorcalculationunknown', 'grades');
     } else {
         return true;
     }
 }
开发者ID:r007,项目名称:PMoodle,代码行数:64,代码来源:grade_item.php

示例2: format_float

    $item->aggregationcoef = 0;
} else {
    if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
        $item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
        $item->aggregationcoef2 = format_float($item->aggregationcoef2 * 100.0);
    } else {
        $item->aggregationcoef = format_float($item->aggregationcoef, 4);
    }
}
$mform->set_data($item);
if ($data = $mform->get_data()) {
    if (!isset($data->aggregationcoef)) {
        $data->aggregationcoef = 0;
    }
    if (property_exists($data, 'calculation')) {
        $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
    }
    $hidden = empty($data->hidden) ? 0 : $data->hidden;
    $hiddenuntil = empty($data->hiddenuntil) ? 0 : $data->hiddenuntil;
    unset($data->hidden);
    unset($data->hiddenuntil);
    $locked = empty($data->locked) ? 0 : $data->locked;
    $locktime = empty($data->locktime) ? 0 : $data->locktime;
    unset($data->locked);
    unset($data->locktime);
    $convert = array('gradepass', 'aggregationcoef', 'aggregationcoef2');
    foreach ($convert as $param) {
        if (property_exists($data, $param)) {
            $data->{$param} = unformat_float($data->{$param});
        }
    }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:31,代码来源:outcomeitem.php


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