1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
clearnaccessmacroses.php
См. документацию.
1<?php
2
4{
5 public static function CanUserViewLessonAsPublic ($arParams, $allowAccessViaLearningGroups = true)
6 {
7 // Parse options (user_id from $arParams will be automaticaly resolved)
10 array(
11 'COURSE_ID' => array(
12 'type' => 'strictly_castable_to_integer',
13 'mandatory' => true
14 ),
15 'LESSON_ID' => array(
16 'type' => 'strictly_castable_to_integer',
17 'mandatory' => true
18 )
19 )
20 );
21
22 // Is it course?
23 $linkedLessonId = CCourse::CourseGetLinkedLesson($options['COURSE_ID']);
24 if ($linkedLessonId === false)
25 return (false); // Access denied
26
27 $lessonId = $options['LESSON_ID'];
28 $breakOnLessonId = $linkedLessonId; // save resources
29
30 // Is lesson included into given course?
31 $isLessonChildOfCourse = false;
32 $arOPathes = CLearnLesson::GetListOfParentPathes ($lessonId, $breakOnLessonId);
33 foreach ($arOPathes as $oPath)
34 {
35 $topLessonId = $oPath->GetTop();
36
37 if (($topLessonId !== false) && ($topLessonId == $linkedLessonId))
38 {
39 $isLessonChildOfCourse = true;
40 break;
41 }
42 }
43
44 if ( ! $isLessonChildOfCourse )
45 return (false); // Access denied
46
47 // Check permissions for course
48 $isCourseAccessible = self::CanUserViewLessonContent (array('lesson_id' => $linkedLessonId), $allowAccessViaLearningGroups);
49
50 // Permissions for all lessons/chapters in public are equivalent to course permissions
51 return ($isCourseAccessible);
52 }
53
54
59 {
60 // Parse options (user_id from $arParams will be automaticaly resolved)
62
64
65 $isAccessGranted = $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_CREATE);
66
67 return ($isAccessGranted);
68 }
69
70
76 {
77 // Parse options (user_id from $arParams will be automaticaly resolved)
80 array(
81 'parent_lesson_id' => array(
82 'type' => 'strictly_castable_to_integer',
83 'mandatory' => true
84 )
85 )
86 );
87
88 $parent_lesson_id = $options['parent_lesson_id'];
89 $user_id = $options['user_id'];
90
92
93 $isAccessGranted =
96 && $oAccess->IsLessonAccessible($parent_lesson_id, CLearnAccess::OP_LESSON_LINK_DESCENDANTS);
97
98 return ($isAccessGranted);
99 }
100
101
102 public static function CanUserEditLesson ($arParams)
103 {
104 // Parse options (user_id from $arParams will be automaticaly resolved)
106 $arParams,
107 array(
108 'lesson_id' => array(
109 'type' => 'strictly_castable_to_integer',
110 'mandatory' => true
111 )
112 )
113 );
114
116
117 $isAccessGranted = $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_WRITE)
118 || $oAccess->IsLessonAccessible($options['lesson_id'], CLearnAccess::OP_LESSON_WRITE);
119
120 return ($isAccessGranted);
121 }
122
123
124 public static function CanUserRemoveLesson ($arParams)
125 {
126 // Parse options (user_id from $arParams will be automaticaly resolved)
128 $arParams,
129 array(
130 'lesson_id' => array(
131 'type' => 'strictly_castable_to_integer',
132 'mandatory' => true
133 )
134 )
135 );
136
138
139 $isAccessGranted = $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_REMOVE)
140 || $oAccess->IsLessonAccessible($options['lesson_id'], CLearnAccess::OP_LESSON_REMOVE);
141
142 return ($isAccessGranted);
143 }
144
145
146 public static function CanUserViewLessonContent ($arParams, $allowAccessViaLearningGroups = true)
147 {
148 // Parse options (user_id from $arParams will be automaticaly resolved)
150 $arParams,
151 array(
152 'lesson_id' => array(
153 'type' => 'strictly_castable_to_integer',
154 'mandatory' => true
155 )
156 )
157 );
158
160
161 $isAccessGranted = $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_READ)
162 || $oAccess->IsLessonAccessible($options['lesson_id'], CLearnAccess::OP_LESSON_READ);
163
164
165 if ($allowAccessViaLearningGroups)
166 {
167 if ( ! $isAccessGranted )
168 {
169 $arPeriod = self::getActiveLearningGroupsPeriod($options['lesson_id'], $options['user_id']);
170
171 if ($arPeriod['IS_EXISTS'])
172 $isAccessGranted = true;
173 }
174 }
175
176 return ($isAccessGranted);
177 }
178
179
180 public static function CanUserViewLessonRelations ($arParams)
181 {
182 $isAccessGranted = false;
183
184 if (self::CanUserViewLessonContent ($arParams)
185 || self::CanUserPerformAtLeastOneRelationAction ($arParams)
186 )
187 {
188 $isAccessGranted = true; // Access granted
189 }
190
191 return ($isAccessGranted);
192 }
193
194
196 {
197 static $arPermissiveOperations = array(
202 );
203
204 // Parse options (user_id from $arParams will be automaticaly resolved)
206 $arParams,
207 array(
208 'lesson_id' => array(
209 'type' => 'strictly_castable_to_integer',
210 'mandatory' => true
211 )
212 )
213 );
214
216
217 foreach ($arPermissiveOperations as $operation)
218 {
219 if ($oAccess->IsLessonAccessible(
220 $options['lesson_id'],
221 $operation)
222 )
223 {
224 return (true); // Yeah, there is some rights for some actions with relations
225 }
226 }
227
228 return (false);
229 }
230
231
232 public static function CanUserEditLessonRights ($arParams)
233 {
234 // Parse options (user_id from $arParams will be automaticaly resolved)
236 $arParams,
237 array(
238 'lesson_id' => array(
239 'type' => 'strictly_castable_to_integer',
240 'mandatory' => true
241 )
242 )
243 );
244
246
247 $isAccessGranted = $oAccess->IsLessonAccessible(
248 $options['lesson_id'],
250 );
251
252 return ($isAccessGranted);
253 }
254
255
256 public static function CanUserViewLessonRights ($arParams)
257 {
258 $isAccessGranted = self::CanUserViewLessonContent ($arParams)
260
261 return ($isAccessGranted);
262 }
263
264
270 protected static function ParseParamsWithUser ($arParams, $arParserOptions)
271 {
272 if ( ! (is_array($arParams) && is_array($arParserOptions)) )
273 {
274 throw new LearnException(
275 'EA_LOGIC: $arParams and $arParserOptions must be arrays',
279 }
280
281 if (array_key_exists('user_id', $arParserOptions))
282 {
283 throw new LearnException(
284 'EA_LOGIC: unexpected user_id in $arParams',
288 }
289
290 $arParserOptions['user_id'] = array(
291 'type' => 'strictly_castable_to_integer',
292 'mandatory' => false,
293 'default_value' => -1 // it means, we must should use current user id
294 );
295
296 // Parse options
297 try
298 {
300 $arParams,
301 $arParserOptions
302 );
303 }
304 catch (Exception $e)
305 {
306 throw new LearnException(
307 'EA_OTHER: CLearnSharedArgManager::StaticParser() throws an exception with code: '
308 . $e->GetCode() . ' and message: ' . $e->GetMessage(),
311 }
312
313 if ($options['user_id'] === -1)
314 $options['user_id'] = self::GetCurrentUserId();
315
316 if ($options['user_id'] < 1)
317 $options['user_id'] = 0; // Not authorized user
318
319 return ($options);
320 }
321
322
323 protected static function GetCurrentUserId()
324 {
325 global $USER;
326
327 if ( ! (is_object($USER) && method_exists($USER, 'GetID')) )
328 return (0);
329
330 if ( ! $USER->IsAuthorized() )
331 return (0);
332
333 return ( (int) $USER->GetID() );
334 }
335
336
337 public static function getActiveLearningGroupsPeriod($courseLessonId, $userId)
338 {
339 static $arCache = array();
340
341 $userId = intval($userId);
342 $courseLessonId = intval($courseLessonId);
343 $cacheKey = $courseLessonId."|".$userId;
344
345 if ( ! array_key_exists($cacheKey, $arCache) )
346 {
348 array(),
349 array(
350 'ACTIVE' => 'Y',
351 'MEMBER_ID' => $userId,
352 'COURSE_LESSON_ID' => $courseLessonId,
353 'ACTIVE_DATE' => 'Y'
354 ),
355 array('ID', 'MEMBER_ID', 'ACTIVE_FROM', 'ACTIVE_TO') // $arSelect
356 );
357
358 $minActiveFrom = null;
359 $minActiveFromFound = false;
360 $minActiveFromTs = PHP_INT_MAX;
361 $maxActiveTo = null;
362 $maxActiveToFound = false;
363 $maxActiveToTs = 0;
364
365 $exists = false;
366 $arGroupsActiveFrom = array();
367 while ($ar = $rs->fetch())
368 {
369 $exists = true;
370 $arGroupsActiveFrom[$ar['ID']] = $ar['ACTIVE_FROM'];
371
372 if ($ar['ACTIVE_FROM'] === null)
373 {
374 $minActiveFrom = null;
375 $minActiveFromFound = true;
376 }
377 elseif (!$minActiveFromFound)
378 {
379 $activeFromTs = MakeTimeStamp($ar['ACTIVE_FROM']);
380 if ($activeFromTs < $minActiveFromTs)
381 {
382 $minActiveFrom = $ar['ACTIVE_FROM'];
383 $minActiveFromTs = $activeFromTs;
384 }
385 }
386
387 if ($ar['ACTIVE_TO'] === null)
388 {
389 $maxActiveTo = null;
390 $maxActiveToFound = true;
391 }
392 elseif (!$maxActiveToFound)
393 {
394 $activeToTs = MakeTimeStamp($ar['ACTIVE_TO']);
395 if ($activeToTs > $maxActiveToTs)
396 {
397 $maxActiveTo = $ar['ACTIVE_TO'];
398 $maxActiveToTs = $activeToTs;
399 }
400 }
401 }
402
403 $arPeriod = array(
404 'IS_EXISTS' => $exists,
405 'ACTIVE_FROM' => $minActiveFrom,
406 'ACTIVE_TO' => $maxActiveTo,
407 'GROUPS_ACTIVE_FROM' => $arGroupsActiveFrom
408 );
409
410 $arCache[$cacheKey] = $arPeriod;
411 }
412 else
413 $arPeriod = $arCache[$cacheKey];
414
415 return ($arPeriod);
416 }
417
418
419 public static function getActiveLearningChaptersPeriod($courseLessonId, $userId)
420 {
421 $arGroupsPeriods = self::getActiveLearningGroupsPeriod($courseLessonId, $userId);
422 if (!$arGroupsPeriods['IS_EXISTS'])
423 {
424 return false;
425 }
426
427 $arChaptersActiveFrom = array();
428 $arGroupsActiveFrom = $arGroupsPeriods['GROUPS_ACTIVE_FROM'];
429
430 $arLessons = array();
432 $courseLessonId,
433 array(),
434 array('CHECK_PERMISSIONS' => 'N'),
435 array('LESSON_ID')
436 );
437
438 $arMinChaptersActiveFromTimestamp = array();
439 while ($ar = $rs->fetch())
440 {
441 $arLessons[$ar['LESSON_ID']] = $ar['NAME'];
442 $arChaptersActiveFrom[$ar['LESSON_ID']] = null;
443 $arMinChaptersActiveFromTimestamp[$ar['LESSON_ID']] = PHP_INT_MAX;
444 }
445
446 // Get the nearest dates, when lesson can be opened
447 foreach ($arGroupsActiveFrom as $groupId => $groupActiveFrom)
448 {
449 if ($groupActiveFrom === null)
450 {
451 continue;
452 }
453
454 $arDelays = CLearningGroupLesson::getDelays($groupId, array_keys($arLessons));
455 $groupActiveFromTs = MakeTimeStamp($groupActiveFrom);
456
457 foreach ($arDelays as $lessonId => $delay)
458 {
459 $fromTs = $groupActiveFromTs + 86400 * $delay; // 24h is 86400 seconds
460
461 // search for nearest dates
462 if ($fromTs < $arMinChaptersActiveFromTimestamp[$lessonId])
463 {
464 $arChaptersActiveFrom[$lessonId] = ConvertTimeStamp($fromTs, 'FULL');
465 $arMinChaptersActiveFromTimestamp[$lessonId] = $fromTs;
466 }
467 }
468 }
469
470 return ($arChaptersActiveFrom);
471 }
472
473 public static function CanViewAdminMenu()
474 {
475 global $USER;
476
477 if ($USER->IsAdmin())
478 {
479 return true;
480 }
481
483 if (
485 && (
495 )
496 )
497 {
498 return true;
499 }
500
501 if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_CREATE))
502 {
503 return true;
504 }
505
506 $db = CCourse::GetList(
507 array(),
508 array(
509 "CHECK_PERMISSIONS" => "Y",
510 "ACCESS_OPERATIONS" =>
519 ),
520 array("nTopCount" => 1)
521 );
522
523 return $db->Fetch() !== false;
524 }
525}
$arParams
Определения access_dialog.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static CourseGetLinkedLesson($courseId)
Определения course.php:55
static GetList($arOrder=array(), $arFields=array(), $arNavParams=array())
Определения course.php:6
static GetInstance($in_userId)
Определения clearnaccess.php:171
const OP_LESSON_CREATE
Определения clearnaccess.php:139
const OP_LESSON_READ
Определения clearnaccess.php:138
const OP_LESSON_UNLINK_FROM_PARENTS
Определения clearnaccess.php:143
const OP_LESSON_MANAGE_RIGHTS
Определения clearnaccess.php:146
const OP_LESSON_WRITE
Определения clearnaccess.php:140
const OP_LESSON_LINK_DESCENDANTS
Определения clearnaccess.php:144
const OP_LESSON_UNLINK_DESCENDANTS
Определения clearnaccess.php:145
const OP_LESSON_REMOVE
Определения clearnaccess.php:141
const OP_LESSON_LINK_TO_PARENTS
Определения clearnaccess.php:142
static CanUserAddLessonToParentLesson($arParams)
Определения clearnaccessmacroses.php:75
static CanUserAddLessonWithoutParentLesson($arParams=array())
Определения clearnaccessmacroses.php:58
static GetCurrentUserId()
Определения clearnaccessmacroses.php:323
static CanUserViewLessonAsPublic($arParams, $allowAccessViaLearningGroups=true)
Определения clearnaccessmacroses.php:5
static CanUserPerformAtLeastOneRelationAction($arParams)
Определения clearnaccessmacroses.php:195
static ParseParamsWithUser($arParams, $arParserOptions)
Определения clearnaccessmacroses.php:270
static CanUserEditLessonRights($arParams)
Определения clearnaccessmacroses.php:232
static CanUserEditLesson($arParams)
Определения clearnaccessmacroses.php:102
static getActiveLearningChaptersPeriod($courseLessonId, $userId)
Определения clearnaccessmacroses.php:419
static CanViewAdminMenu()
Определения clearnaccessmacroses.php:473
static getActiveLearningGroupsPeriod($courseLessonId, $userId)
Определения clearnaccessmacroses.php:337
static CanUserViewLessonRights($arParams)
Определения clearnaccessmacroses.php:256
static CanUserRemoveLesson($arParams)
Определения clearnaccessmacroses.php:124
static CanUserViewLessonContent($arParams, $allowAccessViaLearningGroups=true)
Определения clearnaccessmacroses.php:146
static CanUserViewLessonRelations($arParams)
Определения clearnaccessmacroses.php:180
static GetListOfParentPathes($lessonId, $breakOnLessonId=false, $breakBeforeLesson=false, $arIgnoreEdges=array())
Определения clearnlesson.php:2116
static GetListOfImmediateChilds($lessonId, $arOrder=array(), $arFilter=array(), $arSelectFields=array(), $arNavParams=array())
Определения clearnlesson.php:1855
static StaticParser($arOptions, $arParseParams)
Определения clearnsharedargmanager.php:50
static getList($arOrder, $arFilter, $arSelect=array(), $arNavParams=array())
Определения group.php:169
static getDelays($learningGroupId, $arLessonsIds)
Определения grouplesson.php:249
Определения learnexception.php:4
const EXC_ERR_ALL_ACCESS_DENIED
Определения learnexception.php:8
const EXC_ERR_ALL_LOGIC
Определения learnexception.php:5
const EXC_ERR_ALL_GIVEUP
Определения learnexception.php:6
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$oAccess
Определения options.php:19
global $USER
Определения csv_new_run.php:40
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$rs
Определения action.php:82