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

This function builds subquery (for oracle) or comma-separated list of lessons IDs (for mysql/mssql) for SQL WHERE clause, which selects/contains all child lessons (only childs, without parent lesson). This functions prevents cycling.

Warning: currently

on oracle SQLClauseForAllSubLessons(13) returns subquery: SELECT b_learn_lesson_edges.TARGET_NODE FROM b_learn_lesson_edges START WITH b_learn_lesson_edges.SOURCE_NODE=13 CONNECT BY NOCYCLE PRIOR b_learn_lesson_edges.TARGET_NODE = b_learn_lesson_edges.SOURCE_NODE

on mysql/mssql SQLClauseForAllSubLessons(13) returns list of child lessons: 14, 16, 120, 875, 476

Any of this strings can be used in WHERE IN(...our string...) clause.

Complete example: <?php $parentLessonId = 447; $clauseChilds = CLearnHelper\SQLClauseForAllSubLessons($parentLessonId); $strSql = " SELECT * FROM b_learn_lesson WHERE ID IN ($clauseChilds) OR (ID = $parentLessonId)"; // Selects list of all childs with parentLessonId included. $CDBresult = $DB->Query ($strSql);

Аргументы
intparent lesson id
Возвращает
string for using in WHERE IN() clause: sql subquery or comma-separated list of lesson's ids.
<?php
{
const GRAPH_STATUS_NOT_SET = '1'; // status wasn't set yet (we must determine, is our tables updated to graph or not)
const GRAPH_STATUS_LEGACY = '2';
const MODULE_ID = 'learning';
const OPTION_ID = '~CLearnHelper::isUpdatedToGraph();';
const DEFAULT_VALUE = self::GRAPH_STATUS_NOT_SET; // be default
const SITE_ID = ''; // request shared options for all sites
const ACCESS_READ = 0x001;
const ACCESS_MODIFY = 0x003; // includes ACCESS_READ
public static function PatchLessonContentLinks($strContent, $contextCourseId = false)
{
static $arCourseLinksPatterns = array(
'{SELF}'
);
$argsCheck = is_string($strContent)
&& ($contextCourseId !== false)
&& ($contextCourseId > 0);
if ( ! $argsCheck )
return ($strContent);
$arCourseResolvedLinks = str_replace(
'{SELF}',
(string) ((int) $contextCourseId),
$arCourseLinksPatterns
);
$rc = str_replace(
$arCourseLinksPatterns,
$arCourseResolvedLinks,
$strContent
);
return ($rc);
}
public static function FireEvent ($eventName, $eventParams)
{
$events = GetModuleEvents('learning', $eventName);
while ($arEvent = $events->Fetch())
ExecuteModuleEventEx($arEvent, array($eventParams));
}
public static function SQLClauseForAllSubLessons ($parentLessonId)
{
if ( ! (
is_numeric($parentLessonId)
&& is_int($parentLessonId + 0)
)
)
{
throw new LearnException (
'$parentLessonId must be strictly castable to integer',
}
// MySQL & MSSQL supports "WHERE IN(...)" clause for more than 10 000 elements
$oTree = CLearnLesson::GetTree($parentLessonId, array('EDGE_SORT' => 'ASC'), array('CHECK_PERMISSIONS' => 'N'));
$arChildLessonsIds = $oTree->GetLessonsIdListInTree(); // parent lesson id isn't included
// We need escape data for SQL
$arChildLessonsIdsEscaped = array_map('intval', $arChildLessonsIds);
$sqlChildLessonsIdsList = implode (', ', $arChildLessonsIdsEscaped);
// No childs => nothing must be selected
if ($sqlChildLessonsIdsList == '')
$sqlChildLessonsIdsList = 'NULL'; // NULL != any value. NULL != NULL too.
return ($sqlChildLessonsIdsList);
}
public static function MkOperationFilter($key)
{
if(mb_substr($key, 0, 1) == "=") //Identical
{
$key = mb_substr($key, 1);
$cOperationType = "I";
}
elseif(mb_substr($key, 0, 2) == "!=") //not Identical
{
$key = mb_substr($key, 2);
$cOperationType = "NI";
}
elseif(mb_substr($key, 0, 1) == "%") //substring
{
$key = mb_substr($key, 1);
$cOperationType = "S";
}
elseif(mb_substr($key, 0, 2) == "!%") //not substring
{
$key = mb_substr($key, 2);
$cOperationType = "NS";
}
elseif(mb_substr($key, 0, 1) == "?") //logical
{
$key = mb_substr($key, 1);
$cOperationType = "?";
}
elseif(mb_substr($key, 0, 2) == "><") //between
{
$key = mb_substr($key, 2);
$cOperationType = "B";
}
elseif(mb_substr($key, 0, 3) == "!><") //not between
{
$key = mb_substr($key, 3);
$cOperationType = "NB";
}
elseif(mb_substr($key, 0, 2) == ">=") //greater or equal
{
$key = mb_substr($key, 2);
$cOperationType = "GE";
}
elseif(mb_substr($key, 0, 1) == ">") //greater
{
$key = mb_substr($key, 1);
$cOperationType = "G";
}
elseif(mb_substr($key, 0, 2) == "<=") //less or equal
{
$key = mb_substr($key, 2);
$cOperationType = "LE";
}
elseif(mb_substr($key, 0, 1) == "<") //less
{
$key = mb_substr($key, 1);
$cOperationType = "L";
}
elseif(mb_substr($key, 0, 1) == "!") // not field LIKE val
{
$key = mb_substr($key, 1);
$cOperationType = "N";
}
else
$cOperationType = "E"; // field LIKE val
return Array("FIELD"=>$key, "OPERATION"=>$cOperationType);
}
public static function FilterCreate($fname, $vals, $type, &$bFullJoin, $cOperationType=false, $bSkipEmpty = true)
{
global $DB;
if(!is_array($vals))
$vals=Array($vals);
if(count($vals)<1)
return "";
if(is_bool($cOperationType))
{
if($cOperationType===true)
$cOperationType = "N";
else
$cOperationType = "E";
}
if($cOperationType=="G")
$strOperation = ">";
elseif($cOperationType=="GE")
$strOperation = ">=";
elseif($cOperationType=="LE")
$strOperation = "<=";
elseif($cOperationType=="L")
$strOperation = "<";
else
$strOperation = "=";
$bFullJoin = false;
$bWasLeftJoin = false;
$res = Array();
for($i=0; $i<count($vals); $i++)
{
$val = $vals[$i];
if(!$bSkipEmpty || (string)$val <> '' || (is_bool($val) && $val===false))
{
switch ($type)
{
case "string_equal":
if((string)$val == '')
$res[] =
($cOperationType=="N"?"NOT":"").
"(".
$fname." IS NULL OR ".$DB->Length($fname).
"<=0)";
else
$res[] =
"(".
($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
CCourse::_Upper($fname).$strOperation.CCourse::_Upper("'".$DB->ForSql($val)."'").
($cOperationType=="N"?")":"").
")";
break;
case "string":
if($cOperationType=="?")
{
if((string)$val <> '')
$res[] = GetFilterQuery($fname, $val, "Y",array(),"N");
}
elseif((string)$val == '')
{
$res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL OR ".$DB->Length($fname)."<=0)";
}
else
{
if($strOperation=="=")
$res[] =
"(".
($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
($DB->type == "ORACLE"?CCourse::_Upper($fname)." LIKE ".CCourse::_Upper("'".$DB->ForSqlLike($val)."'")." ESCAPE '\\'" : $fname." ".($strOperation=="="?"LIKE":$strOperation)." '".$DB->ForSqlLike($val)."'").
($cOperationType=="N"?")":"").
")";
else
$res[] =
"(".
($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
($DB->type == "ORACLE"?CCourse::_Upper($fname).
" ".$strOperation." ".CCourse::_Upper("'".$DB->ForSql($val)."'")." " : $fname." ".$strOperation." '".$DB->ForSql($val)."'").
($cOperationType=="N"?")":"").
")";
}
break;
case "date":
if((string)$val == '')
$res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
else
$res[] =
"(".
($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
$fname." ".$strOperation." ".$DB->CharToDateFunction($DB->ForSql($val), "FULL").
($cOperationType=="N"?")":"").
")";
break;
case "number":
if((string)$val == '')
$res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
else
$res[] =
"(".
($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
$fname." ".$strOperation." '".DoubleVal($val).
($cOperationType=="N"?"')":"'").
")";
break;
/*
case "number_above":
if(strlen($val)<=0)
$res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
else
$res[] = ($cOperationType=="N"?" ".$fname." IS NULL OR NOT ":"")."(".$fname." ".$strOperation." '".$DB->ForSql($val)."')";
break;
*/
}
// INNER JOIN in this case
if((string)$val <> '' && $cOperationType!="N")
$bFullJoin = true;
else
$bWasLeftJoin = true;
}
}
$strResult = "";
for($i=0; $i<count($res); $i++)
{
if($i>0)
$strResult .= ($cOperationType=="N"?" AND ":" OR ");
$strResult .= $res[$i];
}
if (count($res) > 1)
$strResult = "(".$strResult.")";
if($bFullJoin && $bWasLeftJoin && $cOperationType!="N")
$bFullJoin = false;
return $strResult;
}
public static function isUpdatedToGraph()
{
if (self::getUpdatedToGraphStatus() === self::GRAPH_STATUS_UPDATED_TO_GRAPH)
return true;
else
return false;
}
public static function setUpdatedToGraphStatus($status)
{
$isSaved = COption::SetOptionString(self::MODULE_ID, self::OPTION_ID,
$status, $description, self::SITE_ID);
return ($isSaved);
}
public static function getUpdatedToGraphStatus()
{
$rc = COption::GetOptionString(self::MODULE_ID, self::OPTION_ID, self::DEFAULT_VALUE, self::SITE_ID);
// status wasn't set yet (we must determine, is our tables updated to graph or not)
if ($rc === self::DEFAULT_VALUE)
{
// Set determined mode in global options
self::setUpdatedToGraphStatus(self::GRAPH_STATUS_LEGACY);
}
$allowed_statuses = array (
self::GRAPH_STATUS_LEGACY,
self::GRAPH_STATUS_UPDATED_TO_GRAPH,
self::GRAPH_STATUS_UNDEFINED
);
if ( ! in_array($rc, $allowed_statuses, true) )
{
AddMessage2Log('Invalid COption ~CLearnHelper::isUpdatedToGraph();: `'
. $rc . '`;', 'learning');
$rc = self::GRAPH_STATUS_UNDEFINED;
}
return ($rc);
}
public static function IsBaseFilenameSafe($filename)
{
$isUnSafe = IsFileUnsafe($filename)
|| ( ! (preg_match("#^[^\\\/:*?\"\'~%<>|]+$#is", $filename) > 0) );
return ( ! $isUnSafe );
}
public static function CopyDirFiles($path_from, $path_to, $ReWrite = True, $Recursive = False)
{
if (mb_strpos($path_to."/", $path_from."/") === 0 || realpath($path_to) === realpath($path_from))
return false;
if (is_dir($path_from))
{
CheckDirPath($path_to."/");
}
elseif(is_file($path_from))
{
$p = bxstrrpos($path_to, "/");
$path_to_dir = mb_substr($path_to, 0, $p);
CheckDirPath($path_to_dir."/");
if (file_exists($path_to) && !$ReWrite)
return False;
@copy($path_from, $path_to);
if(is_file($path_to))
@chmod($path_to, BX_FILE_PERMISSIONS);
return True;
}
else
{
return True;
}
if ($handle = @opendir($path_from))
{
while (($file = readdir($handle)) !== false)
{
if ($file == "." || $file == "..")
continue;
// skip files with non-safe names
continue;
if (is_dir($path_from."/".$file) && $Recursive)
{
self::CopyDirFiles($path_from."/".$file, $path_to."/".$file, $ReWrite, $Recursive);
}
elseif (is_file($path_from."/".$file))
{
if (file_exists($path_to."/".$file) && !$ReWrite)
continue;
@copy($path_from."/".$file, $path_to."/".$file);
@chmod($path_to."/".$file, BX_FILE_PERMISSIONS);
}
}
@closedir($handle);
return true;
}
return false;
}
}
$type
Определения options.php:106
static _Upper($str)
Определения course.php:529
Определения clearnhelper.php:15
static isUpdatedToGraph()
Определения clearnhelper.php:360
const GRAPH_STATUS_UPDATED_TO_GRAPH
Определения clearnhelper.php:18
static PatchLessonContentLinks($strContent, $contextCourseId=false)
Определения clearnhelper.php:33
const ACCESS_MODIFY
Определения clearnhelper.php:27
static CopyDirFiles($path_from, $path_to, $ReWrite=True, $Recursive=False)
Определения clearnhelper.php:432
static FilterCreate($fname, $vals, $type, &$bFullJoin, $cOperationType=false, $bSkipEmpty=true)
Определения clearnhelper.php:214
const DEFAULT_VALUE
Определения clearnhelper.php:23
static IsBaseFilenameSafe($filename)
Определения clearnhelper.php:421
const GRAPH_STATUS_NOT_SET
Определения clearnhelper.php:16
const MODULE_ID
Определения clearnhelper.php:21
const OPTION_ID
Определения clearnhelper.php:22
const GRAPH_STATUS_UNDEFINED
Определения clearnhelper.php:19
const ACCESS_READ
Определения clearnhelper.php:26
static SQLClauseForAllSubLessons($parentLessonId)
Определения clearnhelper.php:108
static MkOperationFilter($key)
Определения clearnhelper.php:143
static getUpdatedToGraphStatus()
Определения clearnhelper.php:391
const GRAPH_STATUS_LEGACY
Определения clearnhelper.php:17
static FireEvent($eventName, $eventParams)
Определения clearnhelper.php:65
static setUpdatedToGraphStatus($status)
Определения clearnhelper.php:375
static GetTree( $lessonId, $arOrder=array('EDGE_SORT'=> 'asc'), $arFilter=array(), $publishProhibitionMode=true, $arSelectFields=array())
Определения clearnlesson.php:1867
Определения learnexception.php:4
const EXC_ERR_ALL_PARAMS
Определения learnexception.php:7
$filename
Определения file_edit.php:47
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
GetFilterQuery($field, $val, $procent="Y", $ex_sep=array(), $clob="N", $div_fields="Y", $clob_upper="N")
Определения filter_tools.php:383
$handle
Определения include.php:55
$p
Определения group_list_element_edit.php:23
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
global $DB
Определения cron_frame.php:29
$status
Определения session.php:10
CheckDirPath($path)
Определения tools.php:2707
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
AddMessage2Log($text, $module='', $traceDepth=6, $showArgs=false)
Определения tools.php:3941
IsFileUnsafe($name)
Определения tools.php:3016
bxstrrpos($haystack, $needle)
Определения tools.php:3292
HasScriptExtension($check_name)
Определения tools.php:2956
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</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
$val
Определения options.php:1793
const SITE_ID
Определения sonet_set_content_view.php:12