Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
group.php
1<?php
3
8
9class Group implements Feature
10{
11 const MODULE_ID = "photogallery";
12 const QUEUE_OPTION = "PhotogalleryGroupQueue";
13 const CHECKER_OPTION = "PhotogalleryGroupChecker_";
14 const STEPPER_OPTION = "PhotogalleryGroupStepper_";
15 const STEPPER_CLASS = GroupStepper::class;
16 const ERROR_OPTION = "PhotogalleryGroupError_";
17
18 private $executiveUserId;
19 private $features = [];
20
21 public function __construct($executiveUserId = 0, array $features = [])
22 {
23 $this->executiveUserId = $executiveUserId;
24 $this->features = $features;
25 }
26
27 public function copy($groupId, $copiedGroupId)
28 {
29 if (!Loader::includeModule("iblock") || !Loader::includeModule("socialnetwork"))
30 {
31 return;
32 }
33
34 $this->addToQueue($copiedGroupId);
35
36 Option::set(self::MODULE_ID, self::CHECKER_OPTION.$copiedGroupId, "Y");
37
38 $sectionName = $this->getSectionName($groupId);
39 $parentSectionId = $this->getParentSectionId($groupId, $sectionName);
40 $newSectionName = $this->getNewSectionName($copiedGroupId);
41 if (!$parentSectionId)
42 {
43 return;
44 }
45
46 $queueOption = [
47 "copiedGroupId" => $copiedGroupId,
48 "parentSectionId" => $parentSectionId,
49 "newSectionName" => $newSectionName,
50 ];
51 Option::set(self::MODULE_ID, self::STEPPER_OPTION.$copiedGroupId, serialize($queueOption));
52
53 $agent = \CAgent::getList([], [
54 "MODULE_ID" => self::MODULE_ID,
55 "NAME" => GroupStepper::class."::execAgent();"
56 ])->fetch();
57 if (!$agent)
58 {
59 GroupStepper::bind(1);
60 }
61 }
62
63 private function getParentSectionId($groupId, $sectionName)
64 {
65 $parentSectionId = 0;
66
67 $res = \CIBlockSection::getList([], ["NAME" => $sectionName, "SOCNET_GROUP_ID" => $groupId], false, ["ID"]);
68 if ($section = $res->fetch())
69 {
70 $parentSectionId = $section["ID"];
71 }
72
73 return $parentSectionId;
74 }
75
76 private function getSectionName($groupId)
77 {
78 $fields = \CSocNetGroup::getByID($groupId);
79 return Loc::getMessage("GROUP_FEATURE_SECTION_NAME_PREFIX").$fields["NAME"];
80 }
81
82 private function getNewSectionName($copiedGroupId)
83 {
84 $fields = \CSocNetGroup::getByID($copiedGroupId);
85 return Loc::getMessage("GROUP_FEATURE_SECTION_NAME_PREFIX").$fields["NAME"];
86 }
87
88 private function addToQueue(int $copiedGroupId)
89 {
90 $option = Option::get(self::MODULE_ID, self::QUEUE_OPTION, "");
91 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
92 $option = (is_array($option) ? $option : []);
93
94 $option[] = $copiedGroupId;
95 Option::set(self::MODULE_ID, self::QUEUE_OPTION, serialize($option));
96 }
97}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct($executiveUserId=0, array $features=[])
Definition group.php:21
copy($groupId, $copiedGroupId)
Definition group.php:27