1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
clearnhelper.php
См. документацию.
1<?php
2
15{
16 const GRAPH_STATUS_NOT_SET = '1'; // status wasn't set yet (we must determine, is our tables updated to graph or not)
20
21 const MODULE_ID = 'learning';
22 const OPTION_ID = '~CLearnHelper::isUpdatedToGraph();';
23 const DEFAULT_VALUE = self::GRAPH_STATUS_NOT_SET; // be default
24 const SITE_ID = ''; // request shared options for all sites
25
26 const ACCESS_READ = 0x001;
27 const ACCESS_MODIFY = 0x003; // includes ACCESS_READ
28
33 public static function PatchLessonContentLinks($strContent, $contextCourseId = false)
34 {
35 static $arCourseLinksPatterns = array(
36 '{SELF}'
37 );
38
39 $argsCheck = is_string($strContent)
40 && ($contextCourseId !== false)
41 && ($contextCourseId > 0);
42
43 if ( ! $argsCheck )
44 return ($strContent);
45
46 $arCourseResolvedLinks = str_replace(
47 '{SELF}',
48 (string) ((int) $contextCourseId),
49 $arCourseLinksPatterns
50 );
51
52 $rc = str_replace(
53 $arCourseLinksPatterns,
54 $arCourseResolvedLinks,
55 $strContent
56 );
57
58 return ($rc);
59 }
60
61
65 public static function FireEvent ($eventName, $eventParams)
66 {
67 $events = GetModuleEvents('learning', $eventName);
68 while ($arEvent = $events->Fetch())
69 ExecuteModuleEventEx($arEvent, array($eventParams));
70 }
71
72
108 public static function SQLClauseForAllSubLessons ($parentLessonId)
109 {
110 if ( ! (
111 is_numeric($parentLessonId)
112 && is_int($parentLessonId + 0)
113 )
114 )
115 {
116 throw new LearnException (
117 '$parentLessonId must be strictly castable to integer',
119 }
120
121 // MySQL & MSSQL supports "WHERE IN(...)" clause for more than 10 000 elements
122
123 $oTree = CLearnLesson::GetTree($parentLessonId, array('EDGE_SORT' => 'ASC'), array('CHECK_PERMISSIONS' => 'N'));
124 $arChildLessonsIds = $oTree->GetLessonsIdListInTree(); // parent lesson id isn't included
125
126 // We need escape data for SQL
127 $arChildLessonsIdsEscaped = array_map('intval', $arChildLessonsIds);
128
129 $sqlChildLessonsIdsList = implode (', ', $arChildLessonsIdsEscaped);
130
131 // No childs => nothing must be selected
132 if ($sqlChildLessonsIdsList == '')
133 $sqlChildLessonsIdsList = 'NULL'; // NULL != any value. NULL != NULL too.
134
135 return ($sqlChildLessonsIdsList);
136 }
137
138
143 public static function MkOperationFilter($key)
144 {
145 if(mb_substr($key, 0, 1) == "=") //Identical
146 {
147 $key = mb_substr($key, 1);
148 $cOperationType = "I";
149 }
150 elseif(mb_substr($key, 0, 2) == "!=") //not Identical
151 {
152 $key = mb_substr($key, 2);
153 $cOperationType = "NI";
154 }
155 elseif(mb_substr($key, 0, 1) == "%") //substring
156 {
157 $key = mb_substr($key, 1);
158 $cOperationType = "S";
159 }
160 elseif(mb_substr($key, 0, 2) == "!%") //not substring
161 {
162 $key = mb_substr($key, 2);
163 $cOperationType = "NS";
164 }
165 elseif(mb_substr($key, 0, 1) == "?") //logical
166 {
167 $key = mb_substr($key, 1);
168 $cOperationType = "?";
169 }
170 elseif(mb_substr($key, 0, 2) == "><") //between
171 {
172 $key = mb_substr($key, 2);
173 $cOperationType = "B";
174 }
175 elseif(mb_substr($key, 0, 3) == "!><") //not between
176 {
177 $key = mb_substr($key, 3);
178 $cOperationType = "NB";
179 }
180 elseif(mb_substr($key, 0, 2) == ">=") //greater or equal
181 {
182 $key = mb_substr($key, 2);
183 $cOperationType = "GE";
184 }
185 elseif(mb_substr($key, 0, 1) == ">") //greater
186 {
187 $key = mb_substr($key, 1);
188 $cOperationType = "G";
189 }
190 elseif(mb_substr($key, 0, 2) == "<=") //less or equal
191 {
192 $key = mb_substr($key, 2);
193 $cOperationType = "LE";
194 }
195 elseif(mb_substr($key, 0, 1) == "<") //less
196 {
197 $key = mb_substr($key, 1);
198 $cOperationType = "L";
199 }
200 elseif(mb_substr($key, 0, 1) == "!") // not field LIKE val
201 {
202 $key = mb_substr($key, 1);
203 $cOperationType = "N";
204 }
205 else
206 $cOperationType = "E"; // field LIKE val
207
208 return Array("FIELD"=>$key, "OPERATION"=>$cOperationType);
209 }
210
214 public static function FilterCreate($fname, $vals, $type, &$bFullJoin, $cOperationType=false, $bSkipEmpty = true)
215 {
216 global $DB;
217 if(!is_array($vals))
218 $vals=Array($vals);
219
220 if(count($vals)<1)
221 return "";
222
223 if(is_bool($cOperationType))
224 {
225 if($cOperationType===true)
226 $cOperationType = "N";
227 else
228 $cOperationType = "E";
229 }
230
231 if($cOperationType=="G")
232 $strOperation = ">";
233 elseif($cOperationType=="GE")
234 $strOperation = ">=";
235 elseif($cOperationType=="LE")
236 $strOperation = "<=";
237 elseif($cOperationType=="L")
238 $strOperation = "<";
239 else
240 $strOperation = "=";
241
242 $bFullJoin = false;
243 $bWasLeftJoin = false;
244
245 $res = Array();
246 for($i=0; $i<count($vals); $i++)
247 {
248 $val = $vals[$i];
249
250 if(!$bSkipEmpty || (string)$val <> '' || (is_bool($val) && $val===false))
251 {
252 switch ($type)
253 {
254 case "string_equal":
255 if((string)$val == '')
256 $res[] =
257 ($cOperationType=="N"?"NOT":"").
258 "(".
259 $fname." IS NULL OR ".$DB->Length($fname).
260 "<=0)";
261 else
262 $res[] =
263 "(".
264 ($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
265 CCourse::_Upper($fname).$strOperation.CCourse::_Upper("'".$DB->ForSql($val)."'").
266 ($cOperationType=="N"?")":"").
267 ")";
268 break;
269 case "string":
270 if($cOperationType=="?")
271 {
272 if((string)$val <> '')
273 $res[] = GetFilterQuery($fname, $val, "Y",array(),"N");
274 }
275 elseif((string)$val == '')
276 {
277 $res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL OR ".$DB->Length($fname)."<=0)";
278 }
279 else
280 {
281 if($strOperation=="=")
282 $res[] =
283 "(".
284 ($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
285 ($DB->type == "ORACLE"?CCourse::_Upper($fname)." LIKE ".CCourse::_Upper("'".$DB->ForSqlLike($val)."'")." ESCAPE '\\'" : $fname." ".($strOperation=="="?"LIKE":$strOperation)." '".$DB->ForSqlLike($val)."'").
286 ($cOperationType=="N"?")":"").
287 ")";
288 else
289 $res[] =
290 "(".
291 ($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
292 ($DB->type == "ORACLE"?CCourse::_Upper($fname).
293 " ".$strOperation." ".CCourse::_Upper("'".$DB->ForSql($val)."'")." " : $fname." ".$strOperation." '".$DB->ForSql($val)."'").
294 ($cOperationType=="N"?")":"").
295 ")";
296 }
297 break;
298 case "date":
299 if((string)$val == '')
300 $res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
301 else
302 $res[] =
303 "(".
304 ($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
305 $fname." ".$strOperation." ".$DB->CharToDateFunction($DB->ForSql($val), "FULL").
306 ($cOperationType=="N"?")":"").
307 ")";
308 break;
309 case "number":
310 if((string)$val == '')
311 $res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
312 else
313 $res[] =
314 "(".
315 ($cOperationType=="N"?" ".$fname." IS NULL OR NOT (":"").
316 $fname." ".$strOperation." '".DoubleVal($val).
317 ($cOperationType=="N"?"')":"'").
318 ")";
319 break;
320 /*
321 case "number_above":
322 if(strlen($val)<=0)
323 $res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
324 else
325 $res[] = ($cOperationType=="N"?" ".$fname." IS NULL OR NOT ":"")."(".$fname." ".$strOperation." '".$DB->ForSql($val)."')";
326 break;
327 */
328 }
329
330 // INNER JOIN in this case
331 if((string)$val <> '' && $cOperationType!="N")
332 $bFullJoin = true;
333 else
334 $bWasLeftJoin = true;
335 }
336 }
337
338 $strResult = "";
339 for($i=0; $i<count($res); $i++)
340 {
341 if($i>0)
342 $strResult .= ($cOperationType=="N"?" AND ":" OR ");
343 $strResult .= $res[$i];
344 }
345
346 if (count($res) > 1)
347 $strResult = "(".$strResult.")";
348
349
350 if($bFullJoin && $bWasLeftJoin && $cOperationType!="N")
351 $bFullJoin = false;
352
353 return $strResult;
354 }
355
360 public static function isUpdatedToGraph()
361 {
362 if (self::getUpdatedToGraphStatus() === self::GRAPH_STATUS_UPDATED_TO_GRAPH)
363 return true;
364 else
365 return false;
366 }
367
375 public static function setUpdatedToGraphStatus($status)
376 {
377 $description = '';
378
379 $isSaved = COption::SetOptionString(self::MODULE_ID, self::OPTION_ID,
380 $status, $description, self::SITE_ID);
381
382 return ($isSaved);
383 }
384
391 public static function getUpdatedToGraphStatus()
392 {
393
394 $rc = COption::GetOptionString(self::MODULE_ID, self::OPTION_ID, self::DEFAULT_VALUE, self::SITE_ID);
395
396 // status wasn't set yet (we must determine, is our tables updated to graph or not)
397 if ($rc === self::DEFAULT_VALUE)
398 {
399 // Set determined mode in global options
400 self::setUpdatedToGraphStatus(self::GRAPH_STATUS_LEGACY);
401 }
402
403 $allowed_statuses = array (
404 self::GRAPH_STATUS_LEGACY,
405 self::GRAPH_STATUS_UPDATED_TO_GRAPH,
406 self::GRAPH_STATUS_UNDEFINED
407 );
408
409 if ( ! in_array($rc, $allowed_statuses, true) )
410 {
411 AddMessage2Log('Invalid COption ~CLearnHelper::isUpdatedToGraph();: `'
412 . $rc . '`;', 'learning');
413
414 $rc = self::GRAPH_STATUS_UNDEFINED;
415 }
416
417 return ($rc);
418 }
419
420
421 public static function IsBaseFilenameSafe($filename)
422 {
423
424 $isUnSafe = IsFileUnsafe($filename)
426 || ( ! (preg_match("#^[^\\\/:*?\"\'~%<>|]+$#is", $filename) > 0) );
427
428 return ( ! $isUnSafe );
429 }
430
431
432 public static function CopyDirFiles($path_from, $path_to, $ReWrite = True, $Recursive = False)
433 {
434 if (mb_strpos($path_to."/", $path_from."/") === 0 || realpath($path_to) === realpath($path_from))
435 return false;
436
437 if (is_dir($path_from))
438 {
439 CheckDirPath($path_to."/");
440 }
441 elseif(is_file($path_from))
442 {
443 $p = bxstrrpos($path_to, "/");
444 $path_to_dir = mb_substr($path_to, 0, $p);
445 CheckDirPath($path_to_dir."/");
446
447 if (file_exists($path_to) && !$ReWrite)
448 return False;
449
450 @copy($path_from, $path_to);
451 if(is_file($path_to))
452 @chmod($path_to, BX_FILE_PERMISSIONS);
453
454 return True;
455 }
456 else
457 {
458 return True;
459 }
460
461 if ($handle = @opendir($path_from))
462 {
463 while (($file = readdir($handle)) !== false)
464 {
465 if ($file == "." || $file == "..")
466 continue;
467
468 // skip files with non-safe names
470 continue;
471
472 if (is_dir($path_from."/".$file) && $Recursive)
473 {
474 self::CopyDirFiles($path_from."/".$file, $path_to."/".$file, $ReWrite, $Recursive);
475 }
476 elseif (is_file($path_from."/".$file))
477 {
478 if (file_exists($path_to."/".$file) && !$ReWrite)
479 continue;
480
481 @copy($path_from."/".$file, $path_to."/".$file);
482 @chmod($path_to."/".$file, BX_FILE_PERMISSIONS);
483 }
484 }
485 @closedir($handle);
486
487 return true;
488 }
489
490 return false;
491 }
492}
$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
const SITE_ID
Определения clearnhelper.php:24
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