Exemplo n.º 1
0
 public function postArticle($params)
 {
     $data = file_get_contents('php://input');
     $data = json_decode($data);
     if (!isset($data->sessionId)) {
         exit;
     }
     $usersRepo = UsersRepository::create();
     $user = $usersRepo->filterBySession($data->sessionId)->findOne();
     $userOutputObject = $user->FullObjectGeter();
     if ($data->sessionId == $userOutputObject->session && $data->id == $userOutputObject->fb_id) {
         $articleRepo = ArticlesRepository::create();
         $article = $articleRepo->filterByTitleBg($data->titleBg)->findOne();
         $articleOutputObject = $article->FullObjectGeter();
         $articleEn = $articleRepo->filterByTitle($data->titleEn)->findOne();
         $articleOutputObjectEn = $articleEn->FullObjectGeter();
         if ($articleOutputObject->title == NULL && $articleOutputObjectEn->title == NULL) {
             $link = mysqli_connect("localhost", "root", "", "algaivel");
             $sql = "INSERT INTO articles SET titleBg='{$data->titleBg}',contentBg='{$data->descBg}',articleImage='{$data->image}',title='{$data->titleEn}',content='{$data->descEn}'";
             $link->query($sql);
         } else {
             echo 'Article with the same title already exist!';
         }
         /*if( $articleOutputObject-> != NULL ){
         
         				$link = mysqli_connect("localhost", "root", "", "algaivel");
         				$sql = "UPDATE articles SET carousel=0 WHERE source='$source'";
         				$link->query($sql);
         
         			}*/
     }
 }
Exemplo n.º 2
0
 public function getCurrentArticle($parameters)
 {
     $id = $parameters[0];
     $articleRepo = ArticlesRepository::create();
     $articleRepo->filterById($id);
     $currentArticle = $articleRepo->findOne();
     if ($currentArticle->getId() != null) {
         $outPutArticleObjecgt = $currentArticle->FullObjectGeter();
         header("Content-type: application/json");
         echo json_encode((object) array("results" => $outPutArticleObjecgt));
     } else {
         header("Content-type: application/json");
         echo json_encode((object) array("results" => "Not Found"));
     }
 }
Exemplo n.º 3
0
 private function articlesSearchBG($page, $context)
 {
     $articlesRepo = ArticlesRepository::create();
     $articleIndex = $page * 9;
     if (!is_numeric($page)) {
         throw new \Exception('Invalid argument');
     }
     $articlesRepo->customOr('titleBG', $context);
     $articlesRepo->customOr('contentBG', $context);
     $articles = $articlesRepo->pagination($articleIndex, 9);
     $articlesCountObject = $articlesRepo->pagination(0, 99);
     $outPutObject = $articles->getObject();
     $pages = $this->pageCounter($articlesCountObject->getObject(), 9);
     $outPutObject->pageCount = $pages;
     return $outPutObject;
 }