Add user note as status history comment

@param OrderModel $order
@param string     $userNote

@return OrderModel
341733
public function setOrderUserNote($order, $userNote)
    {
        $order
            ->addStatusHistoryComment($userNote)
            ->setIsVisibleOnFront(true)
            ->setIsCustomerNotified(false);

        return $order;
    }
451451
public function addOrderHistory(&$route, &$args) {	
		if ($this->config->get('config_customer_activity')) {
			// If last order status id is 0 and new order status is not then record as new order
			$this->load->model('checkout/order');
			
			$order_info = $this->model_checkout_order->getOrder($args[0]);

			if ($order_info && !$order_info['order_status_id'] && $args[1]) {
				$this->load->model('account/activity');
	
				if ($order_info['customer_id']) {
					$activity_data = array(
						'customer_id' => $order_info['customer_id'],
						'name'        => $order_info['firstname'] . ' ' . $order_info['lastname'],
						'order_id'    => $args[0]
					);
	
					$this->model_account_activity->addActivity('order_account', $activity_data);
				} else {
					$activity_data = array(
						'name'     => $order_info['firstname'] . ' ' . $order_info['lastname'],
						'order_id' => $args[0]
					);
	
					$this->model_account_activity->addActivity('order_guest', $activity_data);
				}
			}
		}
	}
127227
public function addComment($shipmentIncrementId, $comment = null, $email = null, $includeInEmail = null)
    {
        return $this->__createAction('order_shipment.addComment', func_get_args());
    }
391131
public static function get_users_in_context(userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();

        if (!$context instanceof \context_course) {
            return;
        }

        $params = [
            'instanceid' => $context->instanceid
        ];

        $sql = "SELECT usermodified as userid
                  FROM {post}
                 WHERE module = 'notes'
                       AND courseid = :instanceid";

        $userlist->add_from_sql('userid', $sql, $params);

        $publishstates = [
            NOTES_STATE_PUBLIC,
            NOTES_STATE_SITE
        ];

        list($publishstatesql, $publishstateparams) = $DB->get_in_or_equal($publishstates, SQL_PARAMS_NAMED);
        $params += $publishstateparams;

        $sql = "SELECT userid
                  FROM {post}
                 WHERE module = 'notes'
                       AND courseid = :instanceid
                       AND publishstate {$publishstatesql}";

        $userlist->add_from_sql('userid', $sql, $params);
    }
579732
public static function get_users_in_context(userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();

        if (!is_a($context, \context_user::class)) {
            return;
        }

        // Add user if any messagelist data exists.
        if ($DB->record_exists('messageinbound_messagelist', ['userid' => $context->instanceid])) {
            // Only using user context, so instance ID will be the only user ID.
            $userlist->add_user($context->instanceid);
        }

        // Add users based on userkey (since we also delete those).
        \core_userkey\privacy\provider::get_user_contexts_with_script($userlist, $context, 'messageinbound_handler');
    }
288526
public function addItem($itemData, $locale, $userId, $order)
    {
        $item = $this->itemManager->save($itemData, $locale, $userId);

        $order->addItem($item->getEntity());

        return $item;
    }
149366
protected function visitSirelNodeOrder(Node\Order $order)
    {
        return $this->visit($order->getExpression()) . " "
            . ($order->isAscending() ? "ASC" : "DESC");
    }
699645
protected function updateQuantity(ModelOrder $order, $newStatus, EventDispatcherInterface $dispatcher)
    {
        if ($newStatus !== $order->getStatusId()) {
            if (null !== $newStatusModel = OrderStatusQuery::create()->findPk($newStatus)) {
                $operationEvent = new GetStockUpdateOperationOnOrderStatusChangeEvent($order, $newStatusModel);

                $dispatcher->dispatch(
                    TheliaEvents::ORDER_GET_STOCK_UPDATE_OPERATION_ON_ORDER_STATUS_CHANGE,
                    $operationEvent
                );

                if ($operationEvent->getOperation() !== $operationEvent::DO_NOTHING) {
                    $orderProductList = $order->getOrderProducts();

                    /** @var OrderProduct $orderProduct */
                    foreach ($orderProductList as $orderProduct) {
                        $productSaleElementsId = $orderProduct->getProductSaleElementsId();

                        /** @var ProductSaleElements $productSaleElements */
                        if (null !== $productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId)) {
                            $offset = 0;

                            if ($operationEvent->getOperation() == $operationEvent::INCREASE_STOCK) {
                                $offset = $orderProduct->getQuantity();
                            } elseif ($operationEvent->getOperation() == $operationEvent::DECREASE_STOCK) {
                                /* Check if we have enough stock */
                                if ($orderProduct->getQuantity() > $productSaleElements->getQuantity() && true === ConfigQuery::checkAvailableStock()) {
                                    throw new TheliaProcessException($productSaleElements->getRef() . " : Not enough stock 2");
                                }

                                $offset = -$orderProduct->getQuantity();
                            }

                            Tlog::getInstance()->addError("Product stock: " . $productSaleElements->getQuantity() . " -> " . ($productSaleElements->getQuantity() + $offset));

                            $productSaleElements
                                ->setQuantity($productSaleElements->getQuantity() + $offset)
                                ->save();
                        }
                    }
                }
            }
        }
    }
1101198
public static function get_users_in_context(userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();

        if (!$context instanceof \context_user) {
            return;
        }

        $userid = $context->instanceid;

        // Messages are in the user context.
        // For the sake of performance, there is no need to call add_from_sql for each of the below cases.
        // It is enough to add the user's context as soon as we come to the conclusion that the user has some data.
        // Also, the order of checking is sorted by the probability of occurrence (just by guess).
        // There is no need to check the message_user_actions table, as there needs to be a message in order to be a message action.
        // There is no need to check the message_conversation_actions table, as there needs to be a conversation in order to
        // be a conversation action.
        // So, checking messages table would suffice.

        $hasdata = false;
        $hasdata = $hasdata || $DB->record_exists_select('notifications', 'useridfrom = ? OR useridto = ?', [$userid, $userid]);
        $sql = "SELECT mc.id
              FROM {message_conversations} mc
              JOIN {message_conversation_members} mcm
                ON (mcm.conversationid = mc.id AND mcm.userid = :userid)
             WHERE mc.contextid IS NULL";
        $hasdata = $hasdata || $DB->record_exists_sql($sql, ['userid' => $userid]);
        $sql = "SELECT mc.id
              FROM {message_conversations} mc
              JOIN {messages} m
                ON (m.conversationid = mc.id AND m.useridfrom = :useridfrom)
             WHERE mc.contextid IS NULL";
        $hasdata = $hasdata || $DB->record_exists_sql($sql, ['useridfrom' => $userid]);
        $hasdata = $hasdata || $DB->record_exists_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid]);
        $hasdata = $hasdata || $DB->record_exists_select('message_users_blocked', 'userid = ? OR blockeduserid = ?',
                        [$userid, $userid]);
        $hasdata = $hasdata || $DB->record_exists_select('message_contact_requests', 'userid = ? OR requesteduserid = ?',
                        [$userid, $userid]);

        if ($hasdata) {
            $userlist->add_user($userid);
        }

        // Add favourite conversations.
        $component = $userlist->get_component();
        if ($component != 'core_message') {
            $userlist->set_component('core_message');
        }
        \core_favourites\privacy\provider::add_userids_for_context($userlist, 'message_conversations');
        if ($component != 'core_message') {
            $userlist->set_component($component);
        }
    }
1079063
public function getSellerAuthorizationNote(\TdbShopOrder $order, $amount, $captureNow, array $itemList = array())
    {
        $text = $this->getValue('sellerAuthorizationNote');
        $data = $this->getTemplateDataFromOrder($order);
        $data['captureNow'] = $captureNow;
        $data['transaction__totalValue'] = $amount;
        $data['transaction__items'] = $itemList;

        return $this->render($text, $data);
    }
641639
public static List<CommerceOrder> findByU_LtC_O(long userId,
		Date createDate, int orderStatus) {
		return getPersistence().findByU_LtC_O(userId, createDate, orderStatus);
	}
971566
public function updateComment( $comment, $user=null, $time = null , $notified = null )
    {
        if ( $time === null )
        {
            $time = time();
        }

        $beforeUpdating = $this->beforeUpdatingComment( $comment, $notified, $time );
        if ( $beforeUpdating !== true )
        {
            return $beforeUpdating;
        }
        $comment->store();

        $afterUpdating = $this->afterUpdatingComment( $comment, $notified, $time );
        if ( $afterUpdating !== true )
        {
            return $afterUpdating;
        }
        return true;
    }
327311
public function addComment($creditmemoIncrementId, $comment = null, $notifyCustomer = null, $includeComment = null)
    {
        return $this->__createAction('order_creditmemo.addComment', func_get_args());
    }
145164
public function addComment($invoiceIncrementId, $comment = null, $email = null, $includeComment = null)
    {
        return $this->__createAction('order_invoice.addComment', func_get_args());
    }
469632
public function save_quickgrading_changes($userid, $grade) {
        global $DB;
        $feedbackcomment = $this->get_feedback_comments($grade->id);
        $quickgradecomments = optional_param('quickgrade_comments_' . $userid, null, PARAM_RAW);
        if (!$quickgradecomments && $quickgradecomments !== '') {
            return true;
        }
        if ($feedbackcomment) {
            $feedbackcomment->commenttext = $quickgradecomments;
            return $DB->update_record('assignfeedback_comments', $feedbackcomment);
        } else {
            $feedbackcomment = new stdClass();
            $feedbackcomment->commenttext = $quickgradecomments;
            $feedbackcomment->commentformat = FORMAT_HTML;
            $feedbackcomment->grade = $grade->id;
            $feedbackcomment->assignment = $this->assignment->get_instance()->id;
            return $DB->insert_record('assignfeedback_comments', $feedbackcomment) > 0;
        }
    }
478780
public function setOrder(\Librinfo\EcommerceBundle\Entity\Order $order = null)
    {
        $this->order = $order;

        return $this;
    }
1231726
public function setOrder(\Core\Entity\Order $order = null) {
        $this->order = $order;

        return $this;
    }