1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ilearngraphrelation.php
См. документацию.
1<?php
2
13{
24 public static function Link ($parentNodeId, $childNodeId, $arProperties);
25
35 public static function Unlink ($parentNodeId, $childNodeId);
36
60 public static function SetProperty ($parentNodeId, $childNodeId, $propertyName, $value);
61
74 public static function GetProperty ($parentNodeId, $childNodeId, $propertyName);
75
112 public static function ListImmediateNeighbours ($nodeId);
113
123 public static function ListImmediateParents ($nodeId);
124
134 public static function ListImmediateChilds ($nodeId);
135}
136
147{
148 // For bitmask:
149 const NBRS_IMDT_PARENTS = 0x1; // immediate parent neighbours
150 const NBRS_IMDT_CHILDS = 0x2; // immediate child neighbours
151
152 private static $arNodesCache = array();
153 private static $nodesCached = 0;
154
155
156 public static function ListImmediateParents ($nodeId)
157 {
158 return (self::_ListImmediateNeighbours ($nodeId, self::NBRS_IMDT_PARENTS));
159 }
160
161 public static function ListImmediateChilds ($nodeId)
162 {
163 return (self::_ListImmediateNeighbours ($nodeId, self::NBRS_IMDT_CHILDS));
164 }
165
166 public static function ListImmediateNeighbours ($nodeId)
167 {
168 return (self::_ListImmediateNeighbours ($nodeId, self::NBRS_IMDT_PARENTS | self::NBRS_IMDT_CHILDS));
169 }
170
171 protected static function _ListImmediateNeighbours ($nodeId, $bitmaskSearchMode)
172 {
173 global $DB;
174
175 $arWhere = array();
176
177 // List parents?
178 if ($bitmaskSearchMode & self::NBRS_IMDT_PARENTS)
179 $arWhere[] = "TARGET_NODE='" . (int) ($nodeId + 0) . "'";
180
181 // List childs?
182 if ($bitmaskSearchMode & self::NBRS_IMDT_CHILDS)
183 $arWhere[] = "SOURCE_NODE='" . (int) ($nodeId + 0) . "'";
184
185 // Prepare string for query
186 $sqlWhere = implode (' OR ', $arWhere);
187
188 if ($sqlWhere == '')
189 {
190 throw new LearnException ('EA_PARAMS: nothing to search (check search mode bitmask);',
192 }
193
194 if ( ! array_key_exists($sqlWhere, self::$arNodesCache) )
195 {
196 // Get graph edge
197 $rc = $DB->Query (
198 "SELECT SOURCE_NODE, TARGET_NODE, SORT
199 FROM b_learn_lesson_edges
200 WHERE " . $sqlWhere,
201 $ignore_errors = true);
202
203 if ($rc === false)
205
206 $result = array();
207
208 // Postprocessing of result
209 while ($arData = $rc->Fetch())
210 {
211 $result[] = array (
212 'SOURCE_NODE' => $arData['SOURCE_NODE'],
213 'TARGET_NODE' => $arData['TARGET_NODE'],
214 'PARENT_LESSON' => $arData['SOURCE_NODE'],
215 'CHILD_LESSON' => $arData['TARGET_NODE'],
216 'SORT' => (int) $arData['SORT']
217 );
218 }
219
220 // limit static cache size to 1024 nodes
221 if (self::$nodesCached < 1024)
222 {
223 ++self::$nodesCached;
224 self::$arNodesCache[$sqlWhere] = $result;
225 }
226 }
227 else
228 $result = self::$arNodesCache[$sqlWhere];
229
230
231 return ($result);
232 }
233
234 public static function Link ($parentNodeId, $childNodeId, $arProperties)
235 {
236 global $DB;
237
238 // reset static cache
239 self::$arNodesCache = array();
240 self::$nodesCached = 0;
241
242 $args_check = is_array($arProperties) // must be an array
243 && (count($arProperties) === 1)
244 && ($parentNodeId > 0)
245 && ($childNodeId > 0);
246
247 // Only SORT allowed
248 $args_check = $args_check && isset ($arProperties['SORT']);
249
250 // check SORT admitted range: number
251 if (isset($arProperties['SORT']))
252 $args_check = $args_check && is_numeric ($arProperties['SORT']) && is_int ($arProperties['SORT'] + 0);
253 else
254 $args_check = false;
255
256 if ( ! $args_check )
257 {
258 throw new LearnException (
259 'EA_PARAMS: ' . $parentNodeId . ' / ' . $childNodeId . ' / ' . var_export($arProperties, true),
261 }
262
263 // normalize & sanitize
264 {
265 $sort = (int) ($arProperties['SORT'] + 0);
266
267 $parentNodeId += 0;
268 $childNodeId += 0;
269 }
270
271 // Create graph edge
272 $rc = $DB->Query (
273 "INSERT INTO b_learn_lesson_edges (SOURCE_NODE, TARGET_NODE, SORT)
274 VALUES ('" . $parentNodeId . "', '" . $childNodeId . "', '" . $sort . "')",
275 $ignore_errors = true);
276
277 if ($rc === false)
278 throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_LINK);
279 }
280
281 public static function Unlink ($parentNodeId, $childNodeId)
282 {
283 global $DB;
284
285 // reset static cache
286 self::$arNodesCache = array();
287 self::$nodesCached = 0;
288
289 $args_check = ($parentNodeId > 0) && ($childNodeId > 0);
290
291 if ( ! $args_check )
292 throw new LearnException ('EA_PARAMS', LearnException::EXC_ERR_GR_UNLINK);
293
294 $parentNodeId += 0;
295 $childNodeId += 0;
296
297 // Remove graph edge
298 $rc = $DB->Query (
299 "DELETE FROM b_learn_lesson_edges
300 WHERE SOURCE_NODE = '" . $parentNodeId . "'
301 AND TARGET_NODE = '" . $childNodeId . "'",
302 $ignore_errors = true);
303
304 if ($rc === false)
305 throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_GR_UNLINK);
306
307 if ($rc->AffectedRowsCount() == 0)
308 throw new LearnException ('EA_NOT_EXISTS', LearnException::EXC_ERR_GR_UNLINK);
309 }
310
311 public static function SetProperty ($parentNodeId, $childNodeId, $propertyName, $value)
312 {
313 global $DB;
314
315 // reset static cache
316 self::$arNodesCache = array();
317 self::$nodesCached = 0;
318
319 $args_check = ($parentNodeId > 0) && ($childNodeId > 0)
320 && ( in_array ($propertyName, array('SORT'), true) );
321
322 if ($propertyName === 'SORT')
323 {
324 // check SORT admitted range: number
325 $args_check = $args_check && is_numeric ($value) && is_int ($value + 0);
326 }
327
328 if ( ! $args_check )
330
331 $parentNodeId += 0;
332 $childNodeId += 0;
333
334 switch ($propertyName)
335 {
336 case 'SORT':
337 $value = (int) ($value + 0);
338
339 $arFields = array ('SORT' => "'" . $value . "'");
340 break;
341
342 default:
343 throw new LearnException ('EA_PARAMS: unknown property name: '
345 break;
346 }
347
348 // Update graph edge
349 $rc = $DB->Update ('b_learn_lesson_edges', $arFields,
350 "WHERE SOURCE_NODE='" . $parentNodeId . "'
351 AND TARGET_NODE='" . $childNodeId . "'", __LINE__, false,
352 false); // we must halt on errors due to bug in CDatabase::Update();
353
358 if ($rc === false)
360
361 /*
362 This is not correctly, because there is can be update to value, which already set in db. And not affected rows will be.
363 Consistent check of existence of relation needs transaction with one more sql-prerequest,
364 so don't check it because of perfomance penalties and DB::transactions problems. :(
365 if ($rc->AffectedRowsCount() == 0)
366 throw new LearnException ('EA_NOT_EXISTS', LearnException::EXC_ERR_GR_SET_PROPERTY);
367 */
368 }
369
370 public static function GetProperty ($parentNodeId, $childNodeId, $propertyName)
371 {
372 global $DB;
373
374 $args_check = ($parentNodeId > 0) && ($childNodeId > 0)
375 && ( in_array ($propertyName, array('SORT'), true) );
376
377 if ( ! $args_check )
379
380 $parentNodeId += 0;
381 $childNodeId += 0;
382
383 // Prepare DB field name
384 switch ($propertyName)
385 {
386 case 'SORT':
387 $field = 'SORT';
388 break;
389
390 default:
391 throw new LearnException ('EA_PARAMS: unknown property name: '
393 break;
394 }
395
396 // Get graph edge
397 $rc = $DB->Query (
398 "SELECT " . $field . "
399 FROM b_learn_lesson_edges
400 WHERE SOURCE_NODE='" . $parentNodeId . "'
401 AND TARGET_NODE='" . $childNodeId . "'",
402 $ignore_errors = true);
403
404 if ($rc === false)
406
407 if ( ! (($arData = $rc->Fetch()) && isset($arData[$field])) )
408 throw new LearnException ('EA_NOT_EXISTS', LearnException::EXC_ERR_GR_GET_PROPERTY);
409
410 // Postprocessing of result
411 switch ($propertyName)
412 {
413 case 'SORT':
414 $rc = (int) $arData[$field];
415 break;
416
417 default:
418 throw new LearnException ('EA_PARAMS: unknown property name: '
420 break;
421 }
422
423 return ($rc);
424 }
425}
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
Определения learnexception.php:4
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
</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