1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
C:/bitrix/modules/learning/classes/general/ilearngraphrelation.php

Lists immediate neighbours.

Аргументы
integerid of node
Возвращает
array of immediate neighbours (empty array if there is no neighbours)

<?php $arNeighbours = ThisClass::ListImmediateNeighbours (1); var_dump ($arNeighbours); ?>

output: array(2) { [0]=> array(4) { ["SOURCE_NODE"]=> int(1) ["TARGET_NODE"]=> int(2) ["SORT"]=> int(500) } [1]=> array(4) { ["SOURCE_NODE"]=> int(4) ["TARGET_NODE"]=> int(1) ["SORT"]=> int(500) } }

<?php
{
public static function Link ($parentNodeId, $childNodeId, $arProperties);
public static function Unlink ($parentNodeId, $childNodeId);
public static function SetProperty ($parentNodeId, $childNodeId, $propertyName, $value);
public static function GetProperty ($parentNodeId, $childNodeId, $propertyName);
public static function ListImmediateNeighbours ($nodeId);
public static function ListImmediateParents ($nodeId);
public static function ListImmediateChilds ($nodeId);
}
{
// For bitmask:
const NBRS_IMDT_PARENTS = 0x1; // immediate parent neighbours
const NBRS_IMDT_CHILDS = 0x2; // immediate child neighbours
private static $arNodesCache = array();
private static $nodesCached = 0;
public static function ListImmediateParents ($nodeId)
{
return (self::_ListImmediateNeighbours ($nodeId, self::NBRS_IMDT_PARENTS));
}
public static function ListImmediateChilds ($nodeId)
{
return (self::_ListImmediateNeighbours ($nodeId, self::NBRS_IMDT_CHILDS));
}
public static function ListImmediateNeighbours ($nodeId)
{
return (self::_ListImmediateNeighbours ($nodeId, self::NBRS_IMDT_PARENTS | self::NBRS_IMDT_CHILDS));
}
protected 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);',
}
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);
// 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);
}
public static function Link ($parentNodeId, $childNodeId, $arProperties)
{
global $DB;
// reset static cache
self::$arNodesCache = array();
self::$nodesCached = 0;
$args_check = is_array($arProperties) // must be an array
&& (count($arProperties) === 1)
&& ($parentNodeId > 0)
&& ($childNodeId > 0);
// Only SORT allowed
$args_check = $args_check && isset ($arProperties['SORT']);
// check SORT admitted range: number
if (isset($arProperties['SORT']))
$args_check = $args_check && is_numeric ($arProperties['SORT']) && is_int ($arProperties['SORT'] + 0);
else
$args_check = false;
if ( ! $args_check )
{
throw new LearnException (
'EA_PARAMS: ' . $parentNodeId . ' / ' . $childNodeId . ' / ' . var_export($arProperties, true),
}
// normalize & sanitize
{
$sort = (int) ($arProperties['SORT'] + 0);
$parentNodeId += 0;
$childNodeId += 0;
}
// Create graph edge
$rc = $DB->Query (
"INSERT INTO b_learn_lesson_edges (SOURCE_NODE, TARGET_NODE, SORT)
VALUES ('" . $parentNodeId . "', '" . $childNodeId . "', '" . $sort . "')",
$ignore_errors = true);
if ($rc === false)
throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_LINK);
}
public static function Unlink ($parentNodeId, $childNodeId)
{
global $DB;
// reset static cache
self::$arNodesCache = array();
self::$nodesCached = 0;
$args_check = ($parentNodeId > 0) && ($childNodeId > 0);
if ( ! $args_check )
throw new LearnException ('EA_PARAMS', LearnException::EXC_ERR_GR_UNLINK);
$parentNodeId += 0;
$childNodeId += 0;
// Remove graph edge
$rc = $DB->Query (
"DELETE FROM b_learn_lesson_edges
WHERE SOURCE_NODE = '" . $parentNodeId . "'
AND TARGET_NODE = '" . $childNodeId . "'",
$ignore_errors = true);
if ($rc === false)
throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_UNLINK);
if ($rc->AffectedRowsCount() == 0)
throw new LearnException ('EA_NOT_EXISTS', LearnException::EXC_ERR_GR_UNLINK);
}
public static function SetProperty ($parentNodeId, $childNodeId, $propertyName, $value)
{
global $DB;
// reset static cache
self::$arNodesCache = array();
self::$nodesCached = 0;
$args_check = ($parentNodeId > 0) && ($childNodeId > 0)
&& ( in_array ($propertyName, array('SORT'), true) );
if ($propertyName === 'SORT')
{
// check SORT admitted range: number
$args_check = $args_check && is_numeric ($value) && is_int ($value + 0);
}
if ( ! $args_check )
throw new LearnException ('EA_PARAMS', LearnException::EXC_ERR_GR_SET_PROPERTY);
$parentNodeId += 0;
$childNodeId += 0;
switch ($propertyName)
{
case 'SORT':
$value = (int) ($value + 0);
$arFields = array ('SORT' => "'" . $value . "'");
break;
default:
throw new LearnException ('EA_PARAMS: unknown property name: '
break;
}
// Update graph edge
$rc = $DB->Update ('b_learn_lesson_edges', $arFields,
"WHERE SOURCE_NODE='" . $parentNodeId . "'
AND TARGET_NODE='" . $childNodeId . "'", __LINE__, false,
false); // we must halt on errors due to bug in CDatabase::Update();
if ($rc === false)
throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_SET_PROPERTY);
/*
This is not correctly, because there is can be update to value, which already set in db. And not affected rows will be.
Consistent check of existence of relation needs transaction with one more sql-prerequest,
so don't check it because of perfomance penalties and DB::transactions problems. :(
if ($rc->AffectedRowsCount() == 0)
throw new LearnException ('EA_NOT_EXISTS', LearnException::EXC_ERR_GR_SET_PROPERTY);
*/
}
public static function GetProperty ($parentNodeId, $childNodeId, $propertyName)
{
global $DB;
$args_check = ($parentNodeId > 0) && ($childNodeId > 0)
&& ( in_array ($propertyName, array('SORT'), true) );
if ( ! $args_check )
throw new LearnException ('EA_PARAMS', LearnException::EXC_ERR_GR_GET_PROPERTY);
$parentNodeId += 0;
$childNodeId += 0;
// Prepare DB field name
switch ($propertyName)
{
case 'SORT':
$field = 'SORT';
break;
default:
throw new LearnException ('EA_PARAMS: unknown property name: '
break;
}
// Get graph edge
$rc = $DB->Query (
"SELECT " . $field . "
FROM b_learn_lesson_edges
WHERE SOURCE_NODE='" . $parentNodeId . "'
AND TARGET_NODE='" . $childNodeId . "'",
$ignore_errors = true);
if ($rc === false)
throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_GET_PROPERTY);
if ( ! (($arData = $rc->Fetch()) && isset($arData[$field])) )
throw new LearnException ('EA_NOT_EXISTS', LearnException::EXC_ERR_GR_GET_PROPERTY);
// Postprocessing of result
switch ($propertyName)
{
case 'SORT':
$rc = (int) $arData[$field];
break;
default:
throw new LearnException ('EA_PARAMS: unknown property name: '
break;
}
return ($rc);
}
}
const NBRS_IMDT_PARENTS
Определения ilearngraphrelation.php:149
static GetProperty($parentNodeId, $childNodeId, $propertyName)
Определения ilearngraphrelation.php:370
static SetProperty($parentNodeId, $childNodeId, $propertyName, $value)
Определения ilearngraphrelation.php:311
static Link($parentNodeId, $childNodeId, $arProperties)
Определения ilearngraphrelation.php:234
static ListImmediateNeighbours($nodeId)
Определения ilearngraphrelation.php:166
static Unlink($parentNodeId, $childNodeId)
Определения ilearngraphrelation.php:281
static ListImmediateChilds($nodeId)
Определения ilearngraphrelation.php:161
const NBRS_IMDT_CHILDS
Определения ilearngraphrelation.php:150
static ListImmediateParents($nodeId)
Определения ilearngraphrelation.php:156
static _ListImmediateNeighbours($nodeId, $bitmaskSearchMode)
Определения ilearngraphrelation.php:171
const EXC_ERR_GR_SET_PROPERTY
Определения learnexception.php:14
const EXC_ERR_GR_GET_NEIGHBOURS
Определения learnexception.php:16
const EXC_ERR_GR_UNLINK
Определения learnexception.php:13
const EXC_ERR_ALL_LOGIC
Определения learnexception.php:5
const EXC_ERR_GR_LINK
Определения learnexception.php:12
const EXC_ERR_GR_GET_PROPERTY
Определения learnexception.php:15
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
static GetProperty($parentNodeId, $childNodeId, $propertyName)
static SetProperty($parentNodeId, $childNodeId, $propertyName, $value)
static Link($parentNodeId, $childNodeId, $arProperties)
static ListImmediateNeighbours($nodeId)
static Unlink($parentNodeId, $childNodeId)
static ListImmediateChilds($nodeId)
static ListImmediateParents($nodeId)
global $DB
Определения cron_frame.php:29
$value
Определения Param.php:39
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644