Update ruleoutcome value for a course competency.

@param int|course_competency $coursecompetencyorid The course_competency, or its ID.
@param int $ruleoutcome The value of ruleoutcome.
@return bool True on success.
517921
public static function set_course_competency_ruleoutcome($coursecompetencyorid, $ruleoutcome) {
        static::require_enabled();
        $coursecompetency = $coursecompetencyorid;
        if (!is_object($coursecompetency)) {
            $coursecompetency = new course_competency($coursecompetencyorid);
        }

        $courseid = $coursecompetency->get('courseid');
        self::validate_course($courseid);
        $coursecontext = context_course::instance($courseid);

        require_capability('moodle/competency:coursecompetencymanage', $coursecontext);

        $coursecompetency->set('ruleoutcome', $ruleoutcome);
        return $coursecompetency->update();
    }
240959
public function course_updated($inserted, $course, $data) {
        if ($inserted) {
            if ($this->get_config('defaultenrol')) {
                $this->add_default_instance($course);
            }
        }
    }
339935
public function validate($addCartItemCommand, Constraint $constraint): void
    {
        Assert::isInstanceOf($addCartItemCommand, AddToCartCommandInterface::class);
        Assert::isInstanceOf($constraint, CartItemAvailability::class);

        /** @var OrderItemInterface $cartItem */
        $cartItem = $addCartItemCommand->getCartItem();

        $isStockSufficient = $this->availabilityChecker->isStockSufficient(
            $cartItem->getVariant(),
            $cartItem->getQuantity() + $this->getExistingCartItemQuantityFromCart($addCartItemCommand->getCart(), $cartItem)
        );

        if (!$isStockSufficient) {
            $this->context->addViolation(
                $constraint->message,
                ['%itemName%' => $cartItem->getVariant()->getInventoryName()]
            );
        }
    }
461996
public function validateConditionUpdateStruct(Condition $condition, ConditionUpdateStruct $conditionUpdateStruct): void
    {
        $conditionType = $condition->getConditionType();

        $this->validate(
            $conditionUpdateStruct->value,
            $conditionType->getConstraints(),
            'value'
        );
    }
1072947
public static function observe_course_completed(\core\event\course_completed $event) {
        if (!static::is_enabled()) {
            return;
        }

        $sql = 'courseid = :courseid AND ruleoutcome != :nooutcome';
        $params = array(
            'courseid' => $event->courseid,
            'nooutcome' => course_competency::OUTCOME_NONE
        );
        $coursecompetencies = course_competency::get_records_select($sql, $params);

        $course = get_course($event->courseid);
        $courseshortname = format_string($course->shortname, null, array('context' => $event->contextid));

        foreach ($coursecompetencies as $coursecompetency) {

            $outcome = $coursecompetency->get('ruleoutcome');
            $action = null;
            $recommend = false;
            $strdesc = 'evidence_coursecompleted';

            if ($outcome == course_competency::OUTCOME_EVIDENCE) {
                $action = evidence::ACTION_LOG;

            } else if ($outcome == course_competency::OUTCOME_RECOMMEND) {
                $action = evidence::ACTION_LOG;
                $recommend = true;

            } else if ($outcome == course_competency::OUTCOME_COMPLETE) {
                $action = evidence::ACTION_COMPLETE;

            } else {
                throw new moodle_exception('Unexpected rule outcome: ' + $outcome);
            }

            static::add_evidence(
                $event->relateduserid,
                $coursecompetency->get('competencyid'),
                $event->contextid,
                $action,
                $strdesc,
                'core_competency',
                $courseshortname,
                $recommend,
                $event->get_url()
            );
        }
    }
1291958
public void updateRuleAttribStatistics(Instance inst, RuleClassification rl, int ruleIndex){
		rl.instancesSeen++; 
		if(rl.squaredAttributeStatisticsSupervised.size() == 0 && rl.attributeStatisticsSupervised.size() == 0){
			for (int s = 0; s < inst.numAttributes() -1; s++) {
				ArrayList<Double> temp1 = new ArrayList<Double>();
				ArrayList<Double> temp2 = new ArrayList<Double>();
				rl.attributeStatisticsSupervised.add(temp1);
				rl.squaredAttributeStatisticsSupervised.add(temp2);
				int instAttIndex = modelAttIndexToInstanceAttIndex(s, inst);
				if(instance.attribute(instAttIndex).isNumeric()){
					for(int i=0; i<inst.numClasses(); i++){
						rl.attributeStatisticsSupervised.get(s).add(0.0);
						rl.squaredAttributeStatisticsSupervised.get(s).add(1.0);
					}
					}
				}
			}
		for (int s = 0; s < inst.numAttributes() -1; s++) {
			int instAttIndex = modelAttIndexToInstanceAttIndex(s, inst);
			if(!inst.isMissing(instAttIndex)){
			if(instance.attribute(instAttIndex).isNumeric()){
			rl.attributeStatistics.addToValue(s, inst.value(s));	
			rl.squaredAttributeStatistics.addToValue(s, inst.value(s) * inst.value(s));
			double sumValue = rl.attributeStatisticsSupervised.get(s).get((int)inst.classValue()) + inst.value(s);
			rl.attributeStatisticsSupervised.get(s).set((int)inst.classValue(), sumValue);
			double squaredSumvalue = rl.squaredAttributeStatisticsSupervised.get(s).get((int)inst.classValue()) + (inst.value(s) * inst.value(s));
			rl.squaredAttributeStatisticsSupervised.get(s).set((int)inst.classValue(), squaredSumvalue);
			}
			}else{
				rl.attributeMissingValues.addToValue(s, 1);
				}
			}
		}
1346658
public function setOutcomeIdentifier($outcomeIdentifier)
    {
        if (Format::isIdentifier($outcomeIdentifier, false) === true) {
            $this->outcomeIdentifier = $outcomeIdentifier;
        } else {
            $msg = "The 'outcomeIdentifier' argument must be a valid QTI identifier, '" . $outcomeIdentifier . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
1198048
public static function create_from_user_competency_plan(user_competency_plan $usercompetencyplan) {
        if (!$usercompetencyplan->get('id')) {
            throw new \coding_exception('The user competency plan ID must be set.');
        }
        $event = static::create(array(
            'contextid' => $usercompetencyplan->get_context()->id,
            'objectid' => $usercompetencyplan->get('id'),
            'relateduserid' => $usercompetencyplan->get('userid'),
            'other' => array(
                'planid' => $usercompetencyplan->get('planid'),
                'competencyid' => $usercompetencyplan->get('competencyid')
            )
        ));
        $event->add_record_snapshot(user_competency_plan::TABLE, $usercompetencyplan->to_record());
        return $event;
    }
1170071
public static function get_ruleoutcome_name($ruleoutcome) {

        switch ($ruleoutcome) {
            case self::OUTCOME_NONE:
                $strname = 'none';
                break;
            case self::OUTCOME_EVIDENCE:
                $strname = 'evidence';
                break;
            case self::OUTCOME_RECOMMEND:
                $strname = 'recommend';
                break;
            case self::OUTCOME_COMPLETE:
                $strname = 'complete';
                break;
            default:
                throw new \moodle_exception('errorcompetencyrule', 'core_competency', '', $ruleoutcome);
                break;
        }

        return new lang_string('coursemodulecompetencyoutcome_' . $strname, 'core_competency');
    }
1300729
public function updateAttributeValueFromTextRepresentation($textRepresentation, ErrorList $warnings)
    {
        $value = $this->getAttributeValueObject();
        $optionTexts = explode("\n", $textRepresentation);
        $optionTexts = array_filter(
            array_map('trim', $optionTexts),
            function ($optionText) {
                return $optionText !== '';
            }
        );
        $numOptions = count($optionTexts);
        if ($numOptions === 0) {
            if ($value !== null) {
                $value->getSelectedOptions()->clear();
            }
        } else {
            $settings = $this->getAttributeKeySettings();
            /* @var SelectSettings $settings */
            if ($numOptions > 1 && !$settings->getAllowMultipleValues()) {
                $warnings->add(t('The Select Attribute with handle "%s" does not support multiple options: only the first one will be imported', $this->attributeKey->getAttributeKeyHandle()));
                $firstOptionText = array_shift($optionTexts);
                $optionTexts = [$firstOptionText];
                $numOptions = 1;
            }
            $optionList = $settings->getOptionList();
            $firstOption = true;
            foreach ($optionTexts as $optionText) {
                $selectedOption = null;
                $deletedOptions = [];
                foreach ($optionList->getOptions() as $option) {
                    if ($option->isOptionDeleted()) {
                        $deletedOptions[$option->getSelectAttributeOptionValue()] = $option;
                    } elseif ($option->getSelectAttributeOptionValue() === $optionText) {
                        $selectedOption = $option;
                        break;
                    }
                }
                if ($selectedOption === null) {
                    if ($settings->getAllowOtherValues()) {
                        $displayOrder = 0;
                        if ($optionList) {
                            $displayOrder = count($optionList->getOptions());
                        }
                        $selectedOption = new SelectValueOption();
                        $selectedOption->setOptionList($optionList);
                        $selectedOption->setIsEndUserAdded(true);
                        $selectedOption->setDisplayOrder($displayOrder);
                        $selectedOption->setSelectAttributeOptionValue($optionText);
                        $optionList->getOptions()->add($selectedOption);
                    } elseif (isset($deletedOptions[$optionText])) {
                        $selectedOption = $deletedOptions[$optionText];
                        $warnings->add(t('"%1$s" matches a deleted option the Select Attribute with handle "%2$s"', $optionText, $this->attributeKey->getAttributeKeyHandle()));
                    } else {
                        $warnings->add(t('"%1$s" is not a valid option for the Select Attribute with handle "%2$s"', $optionText, $this->attributeKey->getAttributeKeyHandle()));
                    }
                }
                if ($selectedOption !== null) {
                    if ($value === null) {
                        $value = new SelectValue();
                    }
                    if ($firstOption) {
                        $firstOption = false;
                        $value->getSelectedOptions()->clear();
                    }
                    $value->getSelectedOptions()->add($selectedOption);
                }
            }
        }

        return $value;
    }
1219430
public static function observe_course_module_completion_updated(\core\event\course_module_completion_updated $event) {
        if (!static::is_enabled()) {
            return;
        }

        $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid);

        if ($eventdata->completionstate == COMPLETION_COMPLETE
                || $eventdata->completionstate == COMPLETION_COMPLETE_PASS) {
            $coursemodulecompetencies = course_module_competency::list_course_module_competencies($eventdata->coursemoduleid);

            $cm = get_coursemodule_from_id(null, $eventdata->coursemoduleid);
            $fastmodinfo = get_fast_modinfo($cm->course)->cms[$cm->id];

            $cmname = $fastmodinfo->name;
            $url = $fastmodinfo->url;

            foreach ($coursemodulecompetencies as $coursemodulecompetency) {
                $outcome = $coursemodulecompetency->get('ruleoutcome');
                $action = null;
                $recommend = false;
                $strdesc = 'evidence_coursemodulecompleted';

                if ($outcome == course_module_competency::OUTCOME_EVIDENCE) {
                    $action = evidence::ACTION_LOG;

                } else if ($outcome == course_module_competency::OUTCOME_RECOMMEND) {
                    $action = evidence::ACTION_LOG;
                    $recommend = true;

                } else if ($outcome == course_module_competency::OUTCOME_COMPLETE) {
                    $action = evidence::ACTION_COMPLETE;

                } else {
                    throw new moodle_exception('Unexpected rule outcome: ' + $outcome);
                }

                static::add_evidence(
                    $event->relateduserid,
                    $coursemodulecompetency->get('competencyid'),
                    $event->contextid,
                    $action,
                    $strdesc,
                    'core_competency',
                    $cmname,
                    $recommend,
                    $url
                );
            }
        }
    }
1239072
public static function add_related_competency($competencyid, $relatedcompetencyid) {
        static::require_enabled();
        $competency1 = new competency($competencyid);
        $competency2 = new competency($relatedcompetencyid);

        require_capability('moodle/competency:competencymanage', $competency1->get_context());

        $relatedcompetency = related_competency::get_relation($competency1->get('id'), $competency2->get('id'));
        if (!$relatedcompetency->get('id')) {
            $relatedcompetency->create();
            return true;
        }

        return true;
    }
648646
public function updateAttributeValueFromTextRepresentation($textRepresentation, ErrorList $warnings)
    {
        $value = $this->getAttributeValueObject();
        $textRepresentation = trim($textRepresentation);
        if ($textRepresentation === '') {
            if ($value !== null) {
                $value->setValue(null);
            }
        } else {
            $i = filter_var($textRepresentation, FILTER_VALIDATE_INT);
            if ($i === null) {
                $warnings->add(t('"%1$s" is not a valid rating value for the attribute with handle %2$s', $textRepresentation, $this->attributeKey->getAttributeKeyHandle()));
            } elseif ($i < 0 || $i > 5) {
                $warnings->add(t('The rating value of the attribute with handle %2$s must range from 0 to 5 (value received: %1$s)', $textRepresentation, $this->attributeKey->getAttributeKeyHandle()));
            } else {
                $i = $i * 20;
                if ($value === null) {
                    $value = $this->createAttributeValue($i);
                } else {
                    $value->setValue($i);
                }
            }
        }

        return $value;
    }
238032
public function handleSalesRuleValidatorProcess(Varien_Event_Observer $observer)
    {
        /** @var Varien_Event $event */
        $event = $observer->getEvent();
        /** @var Mage_SalesRule_Model_Rule $rule */
        $rule = $event->getRule();
        /** @var Mage_Sales_Model_Quote $quote */
        $quote = $event->getQuote();
        /** @var Mage_Core_Model_Store $store */
        $store = $quote->getStore();
        /** @var Mage_Sales_Model_Quote_Item $item */
        $item = $event->getItem();
        /** @var Varien_Object */
        $result = $event->getResult();
        $data = (array) $item->getEbayEnterpriseOrderDiscountData();
        $ruleId = $rule->getId();
        // Use the rule id to prevent duplicates.
        $data[$ruleId] = [
            'amount' => $this->calculateDiscountAmount($item, $result, $data),
            'applied_count' => $event->getQty(),
            'code' => $this->helper->getQuoteCouponCode($quote, $rule),
            'description' => $rule->getStoreLabel($store) ?: $rule->getName(),
            'effect_type' => $rule->getSimpleAction(),
            'id' => $ruleId,
        ];
	if( $item instanceof Mage_Sales_Model_Quote_Address_Item )
	{
		$item->setEbayEnterpriseOrderDiscountData($data);

		foreach( $quote->getAllItems() as $quoteItem )
		{
			if( $quoteItem->getId() === $item->getQuoteItemId())
			{
				$quoteItem->setData('ebayenterprise_order_discount_data', serialize($data));
                		$quoteItem->save();
				break;
			}
		}
	} else {
		$item->setEbayEnterpriseOrderDiscountData($data);
		$item->setData('ebayenterprise_order_discount_data', serialize($data));
		$item->save();
	}
    }
243961
public static function add_competency_to_course($courseid, $competencyid) {
        $params = self::validate_parameters(self::add_competency_to_course_parameters(), array(
            'courseid' => $courseid,
            'competencyid' => $competencyid,
        ));
        self::validate_context(context_course::instance($params['courseid']));
        return api::add_competency_to_course($params['courseid'], $params['competencyid']);
    }
677697
protected function updatePriceRule($price_rule_id)
    {
        if (!$this->isError() && !$this->price_rule->update($price_rule_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
1111410
public static function reorder_plan_competency($planid, $competencyidfrom, $competencyidto) {
        $params = self::validate_parameters(self::reorder_plan_competency_parameters(), array(
            'planid' => $planid,
            'competencyidfrom' => $competencyidfrom,
            'competencyidto' => $competencyidto,
        ));

        $plan = api::read_plan($params['planid']);
        self::validate_context($plan->get_context());

        return api::reorder_plan_competency($params['planid'], $params['competencyidfrom'], $params['competencyidto']);
    }