Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
@param grade_item $item
@return string HTML
519774
static function get_weight_input($item) {
        global $OUTPUT;

        if (!is_object($item) || get_class($item) !== 'grade_item') {
            throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
            return false;
        }

        if ($item->is_course_item()) {
            return '';
        }

        $parent_category = $item->get_parent_category();
        $parent_category->apply_forced_settings();
        $aggcoef = $item->get_coefstring();

        $itemname = $item->itemname;
        if ($item->is_category_item()) {
            // Remember, the parent category of a category item is the category itself.
            $itemname = $parent_category->get_name();
        }
        $str = '';

        if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef' || $aggcoef == 'aggregationcoefextraweight') {

            return $OUTPUT->render_from_template('core_grades/weight_field', [
                'id' => $item->id,
                'itemname' => $itemname,
                'value' => self::format_number($item->aggregationcoef)
            ]);

        } else if ($aggcoef == 'aggregationcoefextraweightsum') {

            $tpldata = [
                'id' => $item->id,
                'itemname' => $itemname,
                'value' => self::format_number($item->aggregationcoef2 * 100.0),
                'checked' => $item->weightoverride,
                'disabled' => !$item->weightoverride
            ];
            $str .= $OUTPUT->render_from_template('core_grades/weight_override_field', $tpldata);

        }

        return $str;
    }
1211317
protected function renderItem($item)
    {
        $item['label'] = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];

        $options = ArrayHelper::getValue($item, 'options', $this->itemOptions);
        Html::addCssClass($options, 'section');

        if (isset($item['url'])) {
            $link = Html::a($item['label'], $item['url'], $options);
        } else {
            Html::addCssClass($options, 'active');
            $link = Html::tag('div', $item['label'], $options);
        }
        return $link;
    }
701877
public function process_gradebook_grade_item(array $data, array $raw) {

        // here we use get_nextid() to get a nondecreasing sequence
        $data['sortorder'] = $this->converter->get_nextid();

        if ($data['itemtype'] === 'mod') {
            return $this->process_mod_grade_item($data, $raw);

        } else if (in_array($data['itemtype'], array('manual', 'course', 'category'))) {
            return $this->process_nonmod_grade_item($data, $raw);

        } else {
            $this->log('unsupported grade_item type', backup::LOG_ERROR, $data['itemtype']);
        }
    }
597735
public static function preRenderAccountHeaderElement(array $item) {
    // Retrieve the item children, if any, sorted by weight.
    $children = Element::children($item, TRUE);

    // The link attributes are for the top level link containe in the <li>.
    $link_attributes = [];

    // The link text is a label with an optional icon or image. If an icon or
    // image is used the CSS hides the label for larger screens.
    $link_text = [];

    // If this link has children then it"s a dropdown.
    if (!empty($children)) {
      $link_attributes = [
        "data-toggle" => "dropdown",
        "aria-expanded" => "true",
        "aria-haspopup" => "true",
        "role" => "button",
        "class" => "dropdown-toggle clearfix",
      ];
    }

    // We always add the title attribute to the link.
    $link_attributes["title"] = $item["#title"];

    // Depending on whether an icon, image or title was set. Configure the link.
    if (!empty($item["#image"])) {
      // The image should be a renderable array so we just add it as link text.
      $link_text[] = $item["#image"];
    }
    elseif (!empty($item["#icon"])) {
      // The icon is an SVG icon name without prefix.
      $link_text[] = [
        "#type" => "inline_template",
        "#template" => "<svg class='navbar-nav__icon icon-{{ icon }}'><use xlink:href='#icon-{{ icon }}' /></svg>",
        '#context' => [
          'icon' => $item['#icon'],
        ],
      ];
    }

    // Allow this menu item to include a notification count.
    if ($item['#notification_count'] !== NULL) {
      $count_classes =
        $item['#notification_count'] > 0 ?
          ['badge', 'badge-accent', 'badge--pill'] :
          ['sr-only'];
      $link_text[] = [
        "#type" => "inline_template",
        "#template" => "<span{{ attributes }}>{{ count }}</span>",
        '#context' => [
          'attributes' => new Attribute(['class' => $count_classes]),
          'count' => $item['#notification_count'] > 99 ? "99+" : $item['#notification_count'],
        ],
      ];
    }

    // We always render the label but hide it for non-screenreader users in case
    // an image or icon is used.
    $label_class = !empty($item['#image']) || !empty($item['#icon']) ? 'sr-only' : NULL;
    $link_text[] = [
      "#type" => "inline_template",
      "#template" => "<span{{ attributes }}>{{ label }}</span>",
      '#context' => [
        'attributes' => new Attribute(['class' => [$label_class]]),
        'label' => $item['#label'],
      ],
    ];

    $element = [
      "#type" => "unwrapped_container",
      "link" => [
        "#type" => "link",
        "#attributes" => $link_attributes,
        "#url" => $item["#url"],
        "#title" => $link_text,
      ],
    ];

    // If there are children we add them to a sublist.
    if (!empty($children)) {
      $element["menu_links"] = [
        "#theme" => "item_list",
        '#list_type' => 'ul',
        '#attributes' => [
          'class' => ['dropdown-menu'],
        ],
        "#items" => array_intersect_key($item, array_flip($children)),
      ];
    }

    return $element;
  }
674753
protected function getItemLineCreditNote(\Mage_Sales_Model_Order_Creditmemo_Item $item)
    {
        $result = array();

        $this->addPropertySource('item', $item);

        $this->addProductInfo($result);

        $productPriceEx = -((float) $item->getBasePrice());
        $productPriceInc = -((float) $item->getBasePriceInclTax());
        $lineVat = -((float) $item->getBaseTaxAmount() + (float) $item->getBaseHiddenTaxAmount());

        // Check for cost price and margin scheme.
        if (!empty($line['costPrice']) && $this->allowMarginScheme()) {
            // Margin scheme:
            // - Do not put VAT on invoice: send price incl VAT as unitprice.
            // - But still send the VAT rate to Acumulus.
            $result[Tag::UnitPrice] = $productPriceInc;
        } else {
            // Add price info.
            $result += array(
                Tag::UnitPrice => $productPriceEx,
                Meta::UnitPriceInc => $productPriceInc,
                Meta::RecalculatePrice => $this->productPricesIncludeTax() ? Tag::UnitPrice : Meta::UnitPriceInc,
                Meta::LinesVatAmount => $lineVat,
            );
        }
        $result[Tag::Quantity] = $item->getQty();

        // Add VAT related info.
        $orderItemId = $item->getOrderItemId();
        if (!empty($orderItemId)) {
            $orderItem = $item->getOrderItem();
            $result += array(
                Tag::VatRate => $orderItem->getTaxPercent(),
                Meta::VatRateSource => static::VatRateSource_Exact,
            );
        } else {
            $result += $this->getVatRangeTags($lineVat / $item->getQty(), $productPriceEx, 0.02, $this->productPricesIncludeTax() ? 0.02 : 0.01);
            $result[Meta::FieldsCalculated][] = Meta::VatAmount;
        }

        // Add vat meta data.
        /** @var \Mage_Catalog_Model_Product $product */
        $product = \Mage::getModel('catalog/product');
        $product->getResource()->load($product, $item->getProductId());
        if ($product->getId()) {
            /** @noinspection PhpUndefinedMethodInspection */
            $result += $this->getTaxClassMetaData((int) $product->getTaxClassId());
        }

        // Add discount related info.
        if (!Number::isZero($item->getBaseDiscountAmount())) {
            // Credit note: discounts are cancelled, thus amount is positive.
            $result[Meta::LineDiscountAmountInc] = $item->getBaseDiscountAmount();
        }

        // On a credit note we only have single lines, no compound lines, thus
        // no children that might have to be added.

        $this->removePropertySource('item');

        return $result;
    }
766736
public function itemToString(\stdClass $item)
    {

    	$attributes = (array) $item;

        if (isset($attributes['type']) &&
                (($attributes['type'] == 'text/css') || ($attributes['type'] == 'text/less'))) {

            // This is a stylesheet, consider extension and compile .less to .css
            if (($attributes['type'] == 'text/less') || \MUtil_String::endsWith($attributes['href'], '.less', true)) {
                $this->compile($this->view, $attributes['href'], false);

                // Modify object, not the derived array
                $item->type = 'text/css';
                $item->href = substr($attributes['href'], 0, -4) . 'css';
            }
        }

        if (isset($this->view->currentVersion)) {
            $version = $this->view->currentVersion;

            if (property_exists($item, 'href')) {
                $item->href = $item->href . '?' . $version;
            }
        }
        
        return \Zend_View_Helper_HeadLink::itemToString($item);
    }
1119646
private function parseItem(Item $item)
    {
        // Get and format an item
        $tmp = $this->getFormattedItem($item);

        // Get related data
        $relationships = $this->getRelationships($item);

        // Closure function to internally parse related includes
        $parseRelationships = function($key, Item $item, array $relationships = []) {
            $related = $this->getFormattedItem($item);

            if (!in_array($related, $this->relationships)) {
                $this->relationships[] = $related;
            }

            unset($related['attributes']);
            unset($related['links']);
            $relationships[$key]['data'][] = $related;

            return $relationships;
        };

        // Loop data to create includes response data
        foreach ($relationships as $key => $value) {
            if ($value instanceof Collection) {
                foreach ($value->getData() as $include_value) {
                    $relationships = $parseRelationships($key, new Item($include_value, $value->getTransformer()), $relationships);
                }
            } else if ($value instanceof Item) {
                $relationships = $parseRelationships($key, $value, $relationships);
            }
        }

        // Pass the relationships data into the item
        $tmp['relationships'] = $relationships;

        // Set the response data
        if (is_array($this->data)) {
            $this->data[] = $tmp;
        } else {
            $this->data = $tmp;
        }

        return $this;
    }
425253
protected function _objectToRDF($item) {
    $object = new stdClass();

    if(self::_isValue($item)) {
      $object->type = 'literal';
      $value = $item->{'@value'};
      $datatype = property_exists($item, '@type') ? $item->{'@type'} : null;

      // convert to XSD datatypes as appropriate
      if(is_bool($value)) {
        $object->value = ($value ? 'true' : 'false');
        $object->datatype = $datatype ? $datatype : self::XSD_BOOLEAN;
      } else if(is_double($value) || $datatype == self::XSD_DOUBLE) {
        // canonical double representation
        $object->value = preg_replace(
          '/(\d)0*E\+?/', '$1E', sprintf('%1.15E', $value));
        $object->datatype = $datatype ? $datatype : self::XSD_DOUBLE;
      } else if(is_integer($value)) {
        $object->value = strval($value);
        $object->datatype = $datatype ? $datatype : self::XSD_INTEGER;
      } else if(property_exists($item, '@language')) {
        $object->value = $value;
        $object->datatype = $datatype ? $datatype : self::RDF_LANGSTRING;
        $object->language = $item->{'@language'};
      } else {
        $object->value = $value;
        $object->datatype = $datatype ? $datatype : self::XSD_STRING;
      }
    } else {
      // convert string/node object to RDF
      $id = is_object($item) ? $item->{'@id'} : $item;
      $object->type = (strpos($id, '_:') === 0) ? 'blank node' : 'IRI';
      $object->value = $id;
    }

    // skip relative IRIs
    if($object->type === 'IRI' && !self::_isAbsoluteIri($object->value)) {
      return null;
    }

    return $object;
  }
215913
protected function get_allgradeitems() {
        if (!empty($this->allgradeitems)) {
            return $this->allgradeitems;
        }
        $allgradeitems = grade_item::fetch_all(array('courseid' => $this->courseid));
        // But hang on - don't include ones which are set to not show the grade at all.
        $this->allgradeitems = array_filter($allgradeitems, function($item) {
            return $item->gradetype != GRADE_TYPE_NONE;
        });

        return $this->allgradeitems;
    }
1238379
public function removeStyle(Item $item)
    {
        $item->setIntro(preg_replace('/(<[^>]+) style=".*?"/i', '$1', $item->getIntro()));
        $item->setContent(preg_replace('/(<[^>]+) style=".*?"/i', '$1', $item->getContent()));

        return $item;
    }
70280
protected function get_suggested_class($item) {
        $class = "feedback_itemlist feedback-item-{$item->typ}";
        if ($item->dependitem) {
            $class .= " feedback_is_dependent";
        }
        if ($item->typ !== 'pagebreak') {
            $itemobj = feedback_get_item_class($item->typ);
            if ($itemobj->get_hasvalue()) {
                $class .= " feedback_hasvalue";
            }
        }
        return $class;
    }
509880
protected function getArrayItemsSeparator($item)
    {
        $cfg = $this->file->getRequire($this->configFile);

        if (!$cfg) {
            return $this->defaultSeparator;
        }

        $file = $this->getFileContents();

        $arr = array_get($cfg, $item);

        $lastItem = end($arr);
        $preLastItem = prev($arr);

        if (!$lastItem or !$preLastItem) {
            return $this->defaultSeparator;
        }

        preg_match('/\,/', $file, $matchStart, PREG_OFFSET_CAPTURE, strpos($file, $preLastItem));
        $start = array_get(reset($matchStart), 1);

        $searchEnd = preg_match('/[\'"]/', $file, $matchEnd, PREG_OFFSET_CAPTURE, $start);
        $end = array_get(reset($matchEnd), 1);

        $separator = substr($file, $start, $end - $start);

        // remove comments
        $separator = preg_replace('/\/\/.*/ui', '', $separator);
        $separator = preg_replace('/#.*/ui', '', $separator);
        $separator = preg_replace('/\/\*(.*)\*\//ui', '', $separator);

        return $separator;
    }
184795
public function isValid($item)
    {
        if (!$item) {
            $item = new \stdClass();
        }
        $validator = $this->getValidator();

        return $validator->validate($item);
    }
105569
public function getRow($item)
	{
		$row = [];

		foreach ($this->columns as $column) {
			$row[] = strip_tags($column->render($item));
		}

		return $row;
	}
1177268
protected function getItemLine($item)
    {
        $result = array();

        // @todo: add property source(s) for this item line.
        $this->addPropertySource('item', $item);

        $this->addProductInfo($result);
        $sign = $this->invoiceSource->getSign();

        // @todo: add other tags and available meta tags (* = required):
        // * quantity
        // * unitprice and/or unitpriceinc
        // * vat related tags:
        //     * vatrate and/or vatamount
        //     * vat range tags (call method getVatRangeTags()
        //     * vat rate source
        // - meta-unitprice-recalculate: if admin enters product prices inc vat
        //   (which is normal) then the product price ex vat may be imprecise.
        //   If the exact vat rate is not yet known, it may be recalculated in
        //   the Completor phase.
        // - line totals
        // Should result in something like this:

        // Check for cost price.
        $productPriceEx = $sign * $item->priceEx;
        $precisionEx = 0.01;
        $productVat = $sign * $item->productTax;
        $precisionVat = 0.01;
        $productPriceInc = $sign * $item->priceInc;
        $quantity = $item->quantity;

        // Check for cost price and margin scheme.
        if (!empty($line['costPrice']) && $this->allowMarginScheme()) {
            // Margin scheme:
            // - Do not put VAT on invoice: send price incl VAT as unitprice.
            // - But still send the VAT rate to Acumulus.
            $result[Tag::UnitPrice] = $productPriceInc;
        } else {
            $result += array(
                Tag::UnitPrice => $productPriceEx,
                Meta::UnitPriceInc => $productPriceInc,
                Meta::RecalculatePrice => $productPricesIncludeTax ? Tag::UnitPrice : Meta::UnitPriceInc,
            );
        }
        $result[Tag::Quantity] = $quantity;

        // Add tax info.
        $result += $this->getVatRangeTags($productVat, $productPriceEx, $precisionVat, $precisionEx);

        // @todo: remove property source(s) for this item line.
        $this->removePropertySource('item');

        return $result;
    }
757143
protected function getItemLineCreditNote(CreditmemoItem $item)
    {
        $result = array();

        $this->addPropertySource('item', $item);

        $this->addProductInfo($result);

        $productPriceEx = -((float) $item->getBasePrice());
        $productPriceInc = -((float) $item->getBasePriceInclTax());
        $lineVat = -((float) $item->getBaseTaxAmount() + (float) $item->getBaseDiscountTaxCompensationAmount());

        // Check for cost price and margin scheme.
        if (!empty($line['costPrice']) && $this->allowMarginScheme()) {
            // Margin scheme:
            // - Do not put VAT on invoice: send price incl VAT as unitprice.
            // - But still send the VAT rate to Acumulus.
            $result[Tag::UnitPrice] = $productPriceInc;
        } else {
            // Add price info.
            $result += array(
                Tag::UnitPrice => $productPriceEx,
                Meta::UnitPriceInc => $productPriceInc,
                Meta::RecalculatePrice => $this->productPricesIncludeTax() ? Tag::UnitPrice : Meta::UnitPriceInc,
                Meta::LinesVatAmount => $lineVat,
            );
        }
        $result[Tag::Quantity] = $item->getQty();

        // Add VAT related info.
        $orderItemId = $item->getOrderItemId();
        if (!empty($orderItemId)) {
            $orderItem = $item->getOrderItem();
            $result += array(
                Tag::VatRate => $orderItem->getTaxPercent(),
                Meta::VatRateSource => static::VatRateSource_Exact,
            );
        } else {
            $result += $this->getVatRangeTags($lineVat / $item->getQty(), $productPriceEx, 0.02, $this->productPricesIncludeTax() ? 0.02 : 0.01);
            $result[Meta::FieldsCalculated][] = Meta::VatAmount;
        }

        // Add vat meta data.
        /** @noinspection PhpFullyQualifiedNameUsageInspection */
        $product = ObjectManager::getInstance()->create(\Magento\Catalog\Model\Product::class);
        $product->getResource()->load($product, $item->getProductId());
        if ($product->getId()) {
            /** @noinspection PhpUndefinedMethodInspection */
            $result += $this->getVatClassMetaData((int) $product->getTaxClassId());
        }

        // Add discount related info.
        if (!Number::isZero($item->getDiscountAmount())) {
            // Credit note: discounts are cancelled, thus amount is positive.
            $result[Meta::LineDiscountAmountInc] = $item->getBaseDiscountAmount();
        }

        // On a credit note we only have single lines, no compound lines, thus
        // no children that might have to be added.

        $this->removePropertySource('item');

        return $result;
    }
418741
public function get_value() {
        $this->label = $this->grade->grade_item->itemname;

        $val = $this->grade->finalgrade;
        if ($this->grade->grade_item->scaleid) {
            return $val ? (int)$val : -1;
        } else {
            return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : '';
        }
    }