Пример #1
0
 /**
  * @Route("/get")
  * @Method({"GET"})
  *
  * @return array
  */
 public function get(Request $request)
 {
     $posts = $this->postservice->getAllPosts();
     foreach ($posts as $post) {
         $data = ['id' => 'post_' . $post->getId(), 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/#post/' . $post->getId(), 'image' => '', 'subtype' => 'post', 'sumtext' => trim(strip_tags($post->getPreview())) . ' ' . trim(strip_tags($post->getText())), 'tags' => '"Posts"', 'body' => trim(strip_tags($post->getText())), 'date' => date('Y-m-d\\TH:i:s', $post->getDate()->getTimestamp()), 'title' => trim(strip_tags($post->getCaption()))];
         $this->allf->indexistoQueryAdd($data);
     }
     $authors = $this->service->getAllAuthors();
     foreach ($authors as $author) {
         $data = ['id' => 'author_' . $author->getId(), 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/#author/' . $author->getId() . '/posts', 'image' => '', 'subtype' => 'users', 'sumtext' => trim(strip_tags($author->getDescription())) . ' ' . trim(strip_tags($author->getInterest())), 'tags' => '"Authors"', 'body' => trim(strip_tags($author->getDescription())), 'date' => date('Y-m-d\\TH:i:s', $author->getPublicationDate()->getTimestamp()), 'title' => trim(strip_tags($author->getName()))];
         $this->allf->indexistoQueryAdd($data);
     }
     $questions = $this->questionservice->getQuestionsToSearch();
     foreach ($questions as $question) {
         $data = ['id' => 'questions_' . $question->getId(), 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/#author/' . $question->getAuthorId() . '/questions', 'image' => '', 'subtype' => 'questions', 'sumtext' => trim(strip_tags($question->getAnswer())), 'tags' => '"Questions"', 'body' => trim(strip_tags($question->getAnswer())), 'date' => date('Y-m-d\\TH:i:s', $question->getDate()->getTimestamp()), 'title' => trim(strip_tags($question->getText()))];
         $this->allf->indexistoQueryAdd($data);
     }
     return [];
 }
Пример #2
0
 /**
  * @param array $author
  * @return array
  */
 public function editInfo(array $author)
 {
     if ($this->allf->isAdmin()) {
         (int) ($authorId = $author['id']);
     } else {
         (int) ($authorId = $this->securityContext->getToken()->getUsername());
     }
     if ($authorId < 1) {
         return ['error' => true, 'errorText' => 'accessDenied'];
     }
     try {
         /** @var AuthorEntity $entity */
         $entity = $this->em->getRepository('Yasoon\\Site\\Entity\\AuthorEntity')->find($authorId);
         if (isset($author['new_pasword']) && $author['new_pasword'] != '') {
             if (md5($author['old_pasword']) == $entity->getPassword()) {
                 $entity->setPassword(md5($author['new_pasword']));
             } else {
                 return ['authorData' => false, 'message' => 'wrongPass'];
             }
         }
         isset($author['name']) && $entity->setName($author['name']);
         isset($author['email']) && $entity->setEmail($author['email']);
         isset($author['description']) && $entity->setDescription($author['description']);
         isset($author['job']) && $entity->setJob($author['job']);
         isset($author['interest']) && $entity->setInterest($author['interest']);
         isset($author['dream']) && $entity->setDream($author['dream']);
         isset($author['img']) && $entity->setImg($author['img']);
         isset($author['interviewCaption']) && $entity->setInterviewCaption($author['interviewCaption']);
         isset($author['homepage']) && $entity->setHomepage($author['homepage']);
         $entity->setDateChange(new \DateTime());
         if (isset($author['subscribed'])) {
             $entity->setSubscribed(1);
         } else {
             $entity->setSubscribed(0);
         }
         $entity = $this->em->merge($entity);
         $this->em->flush();
         $data = ['id' => 'author_' . $entity->getId(), 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/#author/' . $entity->getId() . '/posts', 'image' => '', 'subtype' => 'users', 'sumtext' => trim(strip_tags($entity->getDescription())) . ' ' . trim(strip_tags($entity->getInterest())), 'tags' => '"Authors"', 'body' => trim(strip_tags($entity->getDescription())), 'date' => date('Y-m-d\\TH:i:s', $entity->getDateChange()->getTimestamp()), 'title' => trim(strip_tags($entity->getName()))];
         $this->allf->indexistoQueryAdd($data);
         $session = new Session();
         if (!empty($session->get('reviewStatus'))) {
             $reviewId = $session->get('reviewStatus');
             $review = $this->em->getRepository('Yasoon\\Site\\Entity\\ReviewEntity')->find($reviewId);
             $review->setStatus('saved')->setAuthorId($entity->getId());
             $this->em->merge($review);
             $this->em->flush();
             $session->remove('reviewStatus');
             return ['authorData' => true, 'reviewId' => $reviewId];
         }
         return ['authorData' => true];
     } catch (\Exception $e) {
         return ['authorData' => false, 'message' => $e->getMessage()];
     }
 }
Пример #3
0
 /**
  * @param array $post
  * @return array
  */
 public function updatePost(array $dataPost, $urlImg)
 {
     $authorId = (int) $this->securityContext->getToken()->getUsername();
     /** @var PostEntity $post */
     $post = $this->em->getRepository('Yasoon\\Site\\Entity\\PostEntity')->find($dataPost['id']);
     if ($post->getAuthorId() != $authorId && !$this->allf->isAdmin()) {
         return ['error' => true, 'errorText' => 'accessDenied'];
     }
     try {
         $post->setCaption($dataPost['title'])->setPreview($dataPost['description'])->setPreviewImg($urlImg)->setText('');
         $this->em->merge($post);
         $this->em->flush();
         $tags = $this->em->getRepository('Yasoon\\Site\\Entity\\PostCategoryEntity')->createQueryBuilder('c')->leftJoin('c.post', 'p')->where('c.post_id = ' . $post->getId())->orderBy('p.date', 'desc')->getQuery()->getResult();
         foreach ($tags as $tag) {
             $exists_tags[$tag->getCategoryId()] = $tag;
         }
         if (isset($dataPost['category']) && count($dataPost['category']) > 0) {
             $saved = [];
             foreach ($dataPost['category'] as $category) {
                 if (!array_key_exists($category, $exists_tags)) {
                     $postCategoryEntity = (new PostCategoryEntity())->setPostId($post->getId())->setCategoryId($category * 1);
                     $postCategoryEntity->setPost($post);
                     $this->em->persist($postCategoryEntity);
                     $this->em->flush();
                     $saved[$postCategoryEntity->getCategoryId()] = $postCategoryEntity->getCategoryId();
                 } else {
                     $saved[$category] = $category;
                 }
             }
             foreach ($exists_tags as $tag) {
                 if (!array_key_exists($tag->getCategoryId(), $saved)) {
                     $this->em->remove($tag);
                     $this->em->flush();
                 }
             }
         } else {
             if (count($tags > 0)) {
                 foreach ($tags as $tag) {
                     $this->em->remove($tag);
                     $this->em->flush();
                 }
             }
         }
         //$questions = $post->getAnswer();
         $questions = $this->em->getRepository('Yasoon\\Site\\Entity\\PostAnswerEntity')->createQueryBuilder('a')->leftJoin('a.post', 'p')->where('a.post_id = ' . $post->getId())->orderBy('p.date', 'desc')->getQuery()->getResult();
         foreach ($questions as $question) {
             $exists_answers[$question->getQuestionId()] = $question;
         }
         //print_r($dataPost);
         if (isset($dataPost['text']) && count($dataPost['text']) > 0) {
             $saved = [];
             $i = 0;
             foreach ($dataPost['text'] as $ql) {
                 $postAnswerEntity = new PostAnswerEntity();
                 if (!array_key_exists($dataPost['interviewQuestions'][$ql['id']]['question_id'], $exists_answers)) {
                     $postAnswerEntity->setPostId($post->getId())->setQuestionId($dataPost['interviewQuestions'][$ql['id']]['question_id'] * 1)->setAnswer($ql['text'])->setLego('0');
                     $postAnswerEntity->setPost($post);
                     $postAnswerEntity->setQuestion($this->em->getReference('Yasoon\\Site\\Entity\\InterviewQuestionEntity', $dataPost['interviewQuestions'][$ql['id']]['question_id'] * 1));
                     $this->em->persist($postAnswerEntity);
                     $this->em->flush();
                     $saved[$postAnswerEntity->getQuestionId()] = $postAnswerEntity->getQuestionId();
                 } else {
                     $postAnswerEntity->setPostId($post->getId())->setQuestionId($dataPost['interviewQuestions'][$ql['id']]['question_id'] * 1)->setAnswer($ql['text'])->setLego('0');
                     $postAnswerEntity->setPost($post);
                     $postAnswerEntity->setQuestion($this->em->getReference('Yasoon\\Site\\Entity\\InterviewQuestionEntity', $dataPost['interviewQuestions'][$ql['id']]['question_id'] * 1));
                     $this->em->persist($postAnswerEntity);
                     $this->em->flush();
                     $saved[$ql['id']] = $ql['id'];
                 }
                 $i++;
             }
             foreach ($exists_answers as $ans) {
                 if (!array_key_exists($ans->getQuestionId(), $saved)) {
                     $this->em->remove($ans);
                     $this->em->flush();
                 }
             }
         } else {
             if (count($questions > 0)) {
                 foreach ($questions as $question) {
                     $this->em->remove($question);
                     $this->em->flush();
                 }
             }
         }
         $data = ['id' => 'post_' . $post->getId(), 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/#post/' . $post->getId(), 'image' => '', 'subtype' => 'post', 'sumtext' => trim(strip_tags($post->getPreview())) . ' ' . trim(strip_tags($post->getText())), 'tags' => '"Posts"', 'body' => trim(strip_tags($post->getText())), 'date' => date('Y-m-d\\TH:i:s', $post->getDate()->getTimestamp()), 'title' => trim(strip_tags($post->getCaption()))];
         $this->allf->indexistoQueryAdd($data);
     } catch (\Exception $e) {
         return ['error' => true, 'errorText' => $e->getMessage()];
     }
     return ['error' => false, 'postId' => $dataPost['id']];
 }