18 private $executiveUserId;
19 private $features = [];
21 public function __construct($executiveUserId = 0, array $features = [])
23 $this->executiveUserId = $executiveUserId;
24 $this->features = $features;
27 public function copy($groupId, $copiedGroupId)
29 $blogPostIds = $this->getBlogPostIdsByGroupId($groupId);
35 $this->addToQueue($copiedGroupId);
37 Option::set(self::MODULE_ID, self::CHECKER_OPTION.$copiedGroupId,
"Y");
40 "executiveUserId" => $this->executiveUserId,
41 "groupId" => $groupId,
42 "copiedGroupId" => $copiedGroupId,
43 "features" => $this->features
45 Option::set(self::MODULE_ID, self::STEPPER_OPTION.$copiedGroupId, serialize($queueOption));
47 $agent = \CAgent::getList([], [
48 "MODULE_ID" => self::MODULE_ID,
49 "NAME" => GroupStepper::class.
"::execAgent();"
53 GroupStepper::bind(1);
57 private function getBlogPostIdsByGroupId($groupId)
61 $queryObject = \CBlogPost::getList([], [
"SOCNET_GROUP_ID" => $groupId]);
62 while ($blogPost = $queryObject->fetch())
64 $blogPostIds[] = $blogPost[
"ID"];
71 private function attachGroupToPost($groupIdToCopy, $copiedGroupId)
73 $blogPosts = $this->getBlogPosts($groupIdToCopy);
75 foreach ($blogPosts as $blogPost)
77 $sonetRights = $this->getSonetBlogPostRights($blogPost[
"ID"]);
78 $sonetRights[] =
"SG".$copiedGroupId;
79 $newBlogPostRights = [
"SG".$copiedGroupId];
82 "POST_ID" => $blogPost[
"ID"],
83 "BLOG_ID" => $blogPost[
"BLOG_ID"],
85 "SONET_RIGHTS" => $sonetRights,
86 "NEW_RIGHTS" => $newBlogPostRights,
87 "USER_ID" => $this->executiveUserId
96 private function getBlogPosts($groupId)
100 $queryObject = \CBlogPost::getList([], [
"SOCNET_GROUP_ID" => $groupId]);
101 while ($blogPost = $queryObject->fetch())
103 $blogPosts[] = $blogPost;
109 private function getSonetBlogPostRights($blogPostId)
113 foreach (\CBlogPost::getSocNetPerms($blogPostId) as $type => $val)
115 foreach ($val as $id => $values)
119 $currentRights[] = $type.$id;
123 $currentRights[] = (in_array(
"US".$id, $values) ?
"UA" : $type.$id);
128 return $currentRights;
131 private function addToQueue(
int $copiedGroupId)
133 $option = Option::get(self::MODULE_ID, self::QUEUE_OPTION,
"");
134 $option = ($option !==
"" ? unserialize($option, [
'allowed_classes' =>
false]) : []);
135 $option = (is_array($option) ? $option : []);
137 $option[] = $copiedGroupId;
138 Option::set(self::MODULE_ID, self::QUEUE_OPTION, serialize($option));
__construct($executiveUserId=0, array $features=[])
copy($groupId, $copiedGroupId)