예제 #1
0
파일: class.php 프로젝트: akniyev/arteva.ru
	protected static function getPathToNodes($list)
	{
		$res = Location\LocationTable::getPathToMultipleNodes(
			$list, 
			array(
				'select' => (
					!!$_REQUEST['BEHAVIOUR']['PREFORMAT'] ? 
					array('ID', 'VALUE' => 'ID', 'DISPLAY' => 'NAME.NAME', 'CODE') : 
					array('ID', 'LNAME' => 'NAME.NAME', 'CODE')
				),
				'filter' => array('=NAME.LANGUAGE_ID' => LANGUAGE_ID)
			)
		);

		$pathItems = array();
		$result = array();

		while($path = $res->fetch())
		{
			// format path as required for JSON responce
			$chain = array();
			$itemId = false;

			$i = -1;
			foreach($path['PATH'] as $id => $pItem)
			{
				$i++;

				if(!$i) // we dont need for an item itself in the path chain
				{
					$itemId = $id;
					continue;
				}

				$pathItems[$pItem['ID']] = $pItem;
				$chain[] = intval($pItem['ID']);
			}

			$result['PATH'][$itemId] = $chain;
		}

		$result['PATH_ITEMS'] = $pathItems;

		return $result;
	}
예제 #2
0
	protected function obtainDataConnectors()
	{
		if(!$this->arParams['LINK_ENTITY_NAME'])
		{
			$this->errors['FATAL'][] = Loc::getMessage('SALE_SLSS_LINK_ENTITY_NAME_NOT_SET');
			return;
		}

		$class = $this->entityClass;
		$parameters = array(
			'select' => array(
				'ID',
				'CODE',
				'LEFT_MARGIN',
				'RIGHT_MARGIN',
				'SORT',
				'TYPE_ID',
				'LNAME' => 'NAME.NAME'
			),
			'filter' => array(
				'NAME.LANGUAGE_ID' => LANGUAGE_ID
			)
		);

		$linkFld = $this->useCodes ? 'CODE' : 'ID';

		$res = false;
		$points = array();

		// get locations to display
		if($this->locationsFromRequest !== false) // get from request when form save fails or smth
			$res = self::getEntityListByListOfPrimary(self::LOCATION_ENTITY_NAME, $this->locationsFromRequest, $parameters, $linkFld);
		elseif(strlen($this->arParams['ENTITY_PRIMARY'])) // get from database, if entity exists
			$res = $class::getConnectedLocations($this->arParams['ENTITY_PRIMARY'], $parameters);

		if($res !== false)
		{
			$res->addReplacedAliases(array('LNAME' => 'NAME'));

			while($item = $res->fetch())
				$points[$item['ID']] = $item;
		}


		if(!empty($points))
		{
			// same algorythm repeated on client side - fetch PATH for only visible items
			if((count($points) - static::PAGE_SIZE) > static::HUGE_TAIL_LEN)
				$pointsToGetPath = array_slice($points, 0, static::PAGE_SIZE);
			else
				$pointsToGetPath = $points;

			$res = Location\LocationTable::getPathToMultipleNodes($pointsToGetPath, array(
				'select' => array(
					//'ID',
					//'CODE',
					'LNAME' => 'NAME.NAME'
				),
				'filter' => array(
					'NAME.LANGUAGE_ID' => LANGUAGE_ID
				)
			));

			while($item = $res->Fetch())
			{
				$item['ID'] = intval($item['ID']);

				foreach($item['PATH'] as &$node)
				{
					$node['NAME'] = $node['LNAME'];
					unset($node['LNAME']);
				}

				$points[$item['ID']]['PATH'] = $item['PATH'];
			}

			foreach($points as &$location)
			{
				unset($location['LEFT_MARGIN']); // system fields should not figure in $arResult
				unset($location['RIGHT_MARGIN']); // same
			}
			unset($location);
		}

		$this->dbResult['CONNECTIONS']['LOCATION'] = $points;

		if($this->useGroups)
		{
			$parameters = array('select' => array(
					'ID',
					'CODE',
					'LNAME' => 'NAME.NAME'
				),
				'filter' => array(
					'NAME.LANGUAGE_ID' => LANGUAGE_ID
				)
			);

			$res = false;
			$points = array();

			if($this->groupsFromRequest !== false)
				$res = self::getEntityListByListOfPrimary('Bitrix\Sale\Location\GroupTable', $this->groupsFromRequest, $parameters, $linkFld);
			elseif(strlen($this->arParams['ENTITY_PRIMARY']))
				$res = $class::getConnectedGroups($this->arParams['ENTITY_PRIMARY'], $parameters);

			if($res !== false)
			{
				$res->addReplacedAliases(array('LNAME' => 'NAME'));

				while($item = $res->fetch())
				{
					$item['ID'] = intval($item['ID']);
					$points[$item['ID']] = $item;
				}
			}

			$this->dbResult['CONNECTIONS']['GROUP'] = $points;
		}
	}
예제 #3
0
	protected static function getPathToNodes($list)
	{
		$res = Location\LocationTable::getPathToMultipleNodes(
			$list, 
			array(
				'select' => array('ID', 'LNAME' => 'NAME.NAME'),
				'filter' => array('=NAME.LANGUAGE_ID' => LANGUAGE_ID)
			)
		);

		$pathNames = array();
		$result = array();

		while($path = $res->fetch())
		{
			// format path as required for JSON responce
			$chain = array();
			$itemId = false;

			$i = -1;
			foreach($path['PATH'] as $id => $pItem)
			{
				$i++;

				if(!$i) // we dont need for an item itself in the path chain
				{
					$itemId = $id;
					continue;
				}

				$pathNames[$pItem['ID']] = $pItem['LNAME'];
				$chain[] = intval($pItem['ID']);
			}

			$result['PATH'][$itemId] = $chain;
		}

		$result['PATH_NAMES'] = $pathNames;

		return $result;
	}