Example #1
0
 /**
  * @param $review_id
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function deleteReview($review_id)
 {
     try {
         $authorId = (int) $this->securityContext->getToken()->getUsername();
         if (!is_int($authorId)) {
             return ['error' => true, 'errorText' => 'accessDenied'];
         }
         $review = $this->em->getRepository('Yasoon\\Site\\Entity\\ReviewEntity')->find($review_id);
         if (!$review) {
             return ['error' => true, 'errorText' => 'notFound'];
         }
         if ($review->getAuthorId() != $authorId && !$this->allf->isAdmin()) {
             return ['error' => true, 'errorText' => 'accessDenied'];
         }
         $this->em->remove($review);
         $this->em->flush();
         $review_like = $this->em->getRepository('Yasoon\\Site\\Entity\\ReviewLikesEntity')->createQueryBuilder('l')->where('l.review_id = ' . $review_id)->getQuery()->getResult();
         foreach ($review_like as $like) {
             $this->em->remove($like);
             $this->em->flush();
         }
         //            $friends = $this->em->getRepository('Yasoon\Site\Entity\AuthorEntity')->find($authorId)->getWriters();
         //
         //            foreach($friends as $friend)
         //            {
         //                $timeline =  $this->em->createQueryBuilder()
         //                    ->select('t')
         //                    ->from('Yasoon\Site\Entity\TimelineEntity', 't')
         //                    ->where('t.author_id = :aid')
         //                    ->setParameter('aid', $friend->getId())
         //                    ->getQuery()->getResult();
         //                if (count($timeline) < 1 || !is_object($timeline[0])) {
         //                    $timeline = (new TimelineEntity())
         //                        ->setAuthorId($friend->getId())
         //                        ->setPostsCount('0')
         //                        ->setQuestionsCount('0')
         //                        ->setAnswersCount('0');
         //
         //                    $this->em->persist($timeline);
         //                    $this->em->flush();
         //                }
         //                else
         //                {
         //                    if($timeline[0]->getPostsCount() > 0)
         //                    {
         //                        $timeline[0]->setPostsCount(($timeline[0]->getPostsCount()*1) - 1);
         //                        $this->em->merge($timeline[0]);
         //                        $this->em->flush();
         //                    }
         //                }
         //            }
         $data = json_encode(['_id' => 'review_' . $review_id]);
         $batchDataBody = '[' . $data . ']';
         $this->allf->indexistoQueryDelete($batchDataBody);
     } catch (\Exception $e) {
         return ['error' => true, 'errorText' => $e->getMessage()];
     }
     return ['error' => false, 'errorText' => ''];
 }
Example #2
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 [];
 }
Example #3
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()];
     }
 }