Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
group.php
1<?php
3
8
9class Group implements Feature
10{
11 const MODULE_ID = "blog";
12 const QUEUE_OPTION = "BlogGroupQueue";
13 const CHECKER_OPTION = "BlogGroupChecker_";
14 const STEPPER_OPTION = "BlogGroupStepper_";
15 const STEPPER_CLASS = GroupStepper::class;
16 const ERROR_OPTION = "BlogGroupError_";
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 $blogPostIds = $this->getBlogPostIdsByGroupId($groupId);
30 if (!$blogPostIds)
31 {
32 return;
33 }
34
35 $this->addToQueue($copiedGroupId);
36
37 Option::set(self::MODULE_ID, self::CHECKER_OPTION.$copiedGroupId, "Y");
38
39 $queueOption = [
40 "executiveUserId" => $this->executiveUserId,
41 "groupId" => $groupId,
42 "copiedGroupId" => $copiedGroupId,
43 "features" => $this->features
44 ];
45 Option::set(self::MODULE_ID, self::STEPPER_OPTION.$copiedGroupId, serialize($queueOption));
46
47 $agent = \CAgent::getList([], [
48 "MODULE_ID" => self::MODULE_ID,
49 "NAME" => GroupStepper::class."::execAgent();"
50 ])->fetch();
51 if (!$agent)
52 {
53 GroupStepper::bind(1);
54 }
55 }
56
57 private function getBlogPostIdsByGroupId($groupId)
58 {
59 $blogPostIds = [];
60
61 $queryObject = \CBlogPost::getList([], ["SOCNET_GROUP_ID" => $groupId]);
62 while ($blogPost = $queryObject->fetch())
63 {
64 $blogPostIds[] = $blogPost["ID"];
65 }
66
67 return $blogPostIds;
68 }
69
70 // use it if need attach posts to another group
71 private function attachGroupToPost($groupIdToCopy, $copiedGroupId)
72 {
73 $blogPosts = $this->getBlogPosts($groupIdToCopy);
74
75 foreach ($blogPosts as $blogPost)
76 {
77 $sonetRights = $this->getSonetBlogPostRights($blogPost["ID"]);
78 $sonetRights[] = "SG".$copiedGroupId;
79 $newBlogPostRights = ["SG".$copiedGroupId];
81 [
82 "POST_ID" => $blogPost["ID"],
83 "BLOG_ID" => $blogPost["BLOG_ID"],
84 "SITE_ID" => SITE_ID,
85 "SONET_RIGHTS" => $sonetRights,
86 "NEW_RIGHTS" => $newBlogPostRights,
87 "USER_ID" => $this->executiveUserId
88 ],
89 []
90 );
91 }
92
93 return new Result();
94 }
95
96 private function getBlogPosts($groupId)
97 {
98 $blogPosts = [];
99
100 $queryObject = \CBlogPost::getList([], ["SOCNET_GROUP_ID" => $groupId]);
101 while ($blogPost = $queryObject->fetch())
102 {
103 $blogPosts[] = $blogPost;
104 }
105
106 return $blogPosts;
107 }
108
109 private function getSonetBlogPostRights($blogPostId)
110 {
111 $currentRights = [];
112
113 foreach (\CBlogPost::getSocNetPerms($blogPostId) as $type => $val)
114 {
115 foreach ($val as $id => $values)
116 {
117 if ($type != "U")
118 {
119 $currentRights[] = $type.$id;
120 }
121 else
122 {
123 $currentRights[] = (in_array("US".$id, $values) ? "UA" : $type.$id);
124 }
125 }
126 }
127
128 return $currentRights;
129 }
130
131 private function addToQueue(int $copiedGroupId)
132 {
133 $option = Option::get(self::MODULE_ID, self::QUEUE_OPTION, "");
134 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
135 $option = (is_array($option) ? $option : []);
136
137 $option[] = $copiedGroupId;
138 Option::set(self::MODULE_ID, self::QUEUE_OPTION, serialize($option));
139 }
140}
__construct($executiveUserId=0, array $features=[])
Definition group.php:21
copy($groupId, $copiedGroupId)
Definition group.php:27
static processBlogPostShare($fields, $params)