20 private $blogCommentCopier =
null;
22 private $features = [];
23 private $changedRights = [];
35 $this->blogCommentCopier = $blogCommentCopier;
45 $this->features = $features;
55 $this->changedRights = $changedRights;
67 $blogPostId = \CBlogPost::add($fields);
71 $this->addCategory($blogPostId, $fields);
72 $this->addNotify($blogPostId, $fields);
76 $this->result->addError(
new Error(
"Blog post hasn't been added", self::BLOG_POST_COPY_ERROR));
82 public function update($blogPostId, array $fields)
84 return \CBlogPost::update($blogPostId, $fields);
96 $queryObject = \CBlogPost::getlist([], [
"ID" => $entityId],
false,
false, [
"*"]);
98 return (($fields = $queryObject->fetch()) ? $fields : []);
110 $blogPostId = $fields[
"ID"];
112 $fields[
"SOCNET_RIGHTS"] = $this->getSocnetRights($blogPostId);
114 unset($fields[
"ID"]);
129 $this->
copyUfFields($entityId, $copiedEntityId, $this->ufEntityObject);
133 if (in_array(
"comments", $this->features))
135 $results[] = $this->copyComments($entityId, $copiedEntityId);
149 $copyManager =
new Manager([$voteId]);
151 if (in_array(
"voteResult", $this->features))
153 $copyManager->setResetVotingResult(
false);
156 $result = $copyManager->startCopy();
158 return $this->getCopiedVoteId($voteId,
$result->getData());
163 $queryObject = \CBlogPost::getlist([], [
"ID" => $blogPostId],
false,
false, [
"DETAIL_TEXT"]);
165 if ($fields = $queryObject->fetch())
167 return [
"DETAIL_TEXT", $fields[
"DETAIL_TEXT"]];
171 return [
"DETAIL_TEXT",
""];
175 private function addCategory($blogPostId, array $fields)
177 if (!empty($fields[
"CATEGORY_ID"]))
179 \CBlogPostCategory::deleteByPostID($blogPostId);
181 $categoryIds = explode(
",", $fields[
"CATEGORY_ID"]);
182 foreach ($categoryIds as $categoryId)
184 \CBlogPostCategory::add([
185 "BLOG_ID" => $fields[
"BLOG_ID"],
186 "POST_ID" => $blogPostId,
187 "CATEGORY_ID" => $categoryId
193 private function getSocnetRights($blogPostId)
197 $prevSocnetRights = \CBlogPost::getSocNetPerms($blogPostId,
false);
199 foreach ($prevSocnetRights as $entityPrefix => $entities)
201 foreach ($entities as $entityId => $rights)
203 if ($entityPrefix !=
"SG")
205 $socnetRights[$entityId] = $entityPrefix.$entityId;
210 if ($this->changedRights)
212 foreach ($this->changedRights as $entityPrefix => $entitiesRatio)
214 foreach ($entitiesRatio as $oldEntityId => $newEntityId)
216 $socnetRights[$newEntityId] = $entityPrefix.$newEntityId;
221 return ($socnetRights ? $socnetRights : []);
224 private function copyComments($blogPostId, $copiedBlogPostId)
226 $containerCollection =
new ContainerCollection();
228 $queryObject = \CBlogComment::getList([], [
"POST_ID" => $blogPostId],
false,
false, [
"ID"]);
229 while ($blogPostComment = $queryObject->fetch())
231 $container =
new Container($blogPostComment[
"ID"]);
232 $container->setParentId($copiedBlogPostId);
233 $containerCollection[] = $container;
236 if (!$containerCollection->isEmpty())
238 return $this->blogCommentCopier->copy($containerCollection);
244 private function addNotify($blogPostId, $fields)
246 $fields[
"ID"] = $blogPostId;
248 $pathToPost = \COption::getOptionString(
"socialnetwork",
"userblogpost_page",
249 "/company/personal/user/#user_id#/blog/#post_id#/", SITE_ID);
250 $pathToSmile = \COption::getOptionString(
"socialnetwork",
"smile_page",
false, SITE_ID);
254 "UserID" => $fields[
"AUTHOR_ID"],
255 "allowVideo" => \COption::getOptionString(
"blog",
"allow_video",
"Y"),
256 "PATH_TO_SMILE" => $pathToSmile,
257 "PATH_TO_POST" => $pathToPost,
258 "user_id" => $fields[
"AUTHOR_ID"],
259 "NAME_TEMPLATE" => \CSite::getNameFormat(
false),
263 $logId = \CBlogPost::notify($fields, [], $paramsNotify);
268 $logFields = [
"EVENT_ID" => $eventId];
271 $logFields[
"TAG"] = $post->getTags();
273 \CSocNetLog::update($logId, $logFields);
277 private function getCopiedVoteId($voteId, array
$result)
282 if (array_key_exists($voteId, $value))
284 $copiedVoteId = $value[$voteId];
288 return $copiedVoteId;
setChangedRights($changedRights)
getFields(Container $container, $entityId)
setBlogCommentCopier(EntityCopier $blogCommentCopier)
setFeatures(array $features)
update($blogPostId, array $fields)
add(Container $container, array $fields)
copyChildren(Container $container, $entityId, $copiedEntityId)
const BLOG_POST_COPY_ERROR
prepareFieldsToCopy(Container $container, array $fields)
static getById($postId=0, $params=array())
copyUfFields(int $entityId, int $copiedEntityId, string $ufObject)
getResult(array $results=[])