• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/ilearngraphrelation.php
  • Класс: CLearnGraphRelation
  • Вызов: CLearnGraphRelation::_ListImmediateNeighbours
static function _ListImmediateNeighbours ($nodeId, $bitmaskSearchMode)
{
	global $DB;

	$arWhere = array();

	// List parents?
	if ($bitmaskSearchMode & self::NBRS_IMDT_PARENTS)
		$arWhere[] = "TARGET_NODE='" . (int) ($nodeId + 0) . "'";

	// List childs?
	if ($bitmaskSearchMode & self::NBRS_IMDT_CHILDS)
		$arWhere[] = "SOURCE_NODE='" . (int) ($nodeId + 0) . "'";

	// Prepare string for query
	$sqlWhere = implode (' OR ', $arWhere);

	if ($sqlWhere == '')
	{
		throw new LearnException ('EA_PARAMS: nothing to search (check search mode bitmask);',
			LearnException::EXC_ERR_GR_GET_NEIGHBOURS | LearnException::EXC_ERR_ALL_LOGIC);
	}

	if ( ! array_key_exists($sqlWhere, self::$arNodesCache) )
	{
		// Get graph edge
		$rc = $DB->Query (
			"SELECT SOURCE_NODE, TARGET_NODE, SORT
			FROM b_learn_lesson_edges
			WHERE " . $sqlWhere,
			$ignore_errors = true);

		if ($rc === false)
			throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_GET_NEIGHBOURS);

		$result = array();

		// Postprocessing of result
		while ($arData = $rc->Fetch())
		{
			$result[] = array (
				'SOURCE_NODE'   => $arData['SOURCE_NODE'],
				'TARGET_NODE'   => $arData['TARGET_NODE'],
				'PARENT_LESSON' => $arData['SOURCE_NODE'],
				'CHILD_LESSON'  => $arData['TARGET_NODE'],
				'SORT'          => (int) $arData['SORT']
			);
		}

		// limit static cache size to 1024 nodes
		if (self::$nodesCached < 1024)
		{
			++self::$nodesCached;
			self::$arNodesCache[$sqlWhere] = $result;
		}
	}
	else
		$result = self::$arNodesCache[$sqlWhere];


	return ($result);
}