Esempio n. 1
0
 public function voting(Voting $voting, VotingList $votingList, VotingIp $votingIp, Request $request)
 {
     $this->data['voting'] = $voting->getActive();
     // Витягую всі назви голосуванн
     $this->data['voting_list'] = $votingList->getActive();
     // Витягую весь список голосуванн
     if ($request->isMethod('post')) {
         $browser_name = $_SERVER['HTTP_USER_AGENT'];
         // Записую в зміну назву браузера для проведення статистики
         $voting_id_form = \Input::get('voting_value');
         // Записую значення з форми
         $getVotingId = $votingList->getVotingIpCheck($voting_id_form);
         //Витягую ід де воно дорівнює значення з форми
         $voting_id = $getVotingId->voting_id;
         //записую ід в зміну
         $people_ip = $_SERVER['REMOTE_ADDR'];
         $getAddress = $votingIp->getActiveCheck($voting_id, $people_ip);
         // Витягую всі ip адреси та індифікатори голосування для перевірки
         if ($getAddress) {
             /* $this->data['errorIp'] = 'Ви уже голосували';*/
             return Response::json(['success' => false, 'errors' => trans('translation.З_вашої_ip_уже_голосували')]);
         } else {
             $votingIp->insertTable($voting_id, $people_ip, $browser_name);
             // передаю значення для запису таблиць
             $getVoting = $votingList->getVoting($voting_id_form);
             // передаю значення з форми в модель
             $addCount = $getVoting->count + 1;
             \DB::table('votingList')->WHERE('id', '=', $voting_id_form)->UPDATE(['count' => $addCount]);
             // перезаписую дані з додаванням 1
             /* --------------------------------------------------------------
                  Calculates the percentage of the vote
                -----------------------------------------------------------------*/
             $sumVotingList = $votingList->sumVotingList($voting_id);
             // витягуємо суму чисел з певним ід
             $voting->upSumVotingList($voting_id, $sumVotingList);
             //оновлюємо поле з сумою
             /* --------------------------------------------------------------
                  Calculates the percentage of the vote
                -----------------------------------------------------------------*/
             /*$this->data['success'] = 'Ви успішно проголосували';*/
             return Response::json(['success' => trans('translation.Ви_успішно_проголосували')]);
         }
     }
     return view('pages.voting', $this->data);
 }
Esempio n. 2
0
 public function listCategory(CategorySong $categorySong, IndexComment $indexComment, Voting $voting, VotingList $votingList, VotingIp $votingIp)
 {
     /**-------------------------------------------------------------
      * Add a comment to the category list
      * ----------------------------------------------------------------**/
     if ($this->request->has('body')) {
         $validator = IndexComment::validate(\Input::all());
         if ($validator->fails()) {
             return \Response::json(['success' => false, 'errors' => $validator->errors()->toArray()]);
         } else {
             $indexComment = new indexComment();
             $indexComment->name = $this->request->get('name');
             $indexComment->email = $this->request->get('email');
             $indexComment->body = $this->request->get('body');
             $indexComment->date = date("Y-m-d h:i:s");
             $indexComment->save();
             return \Response::json(['success' => trans('translation.Ваш_коментар_успішно_добавлений')]);
         }
     }
     /**-------------------------------------------------------------
      * End of adding comments to the list of categories
      * ----------------------------------------------------------------**/
     /**-------------------------------------------------------------
      * Sort the list of categories
      * ----------------------------------------------------------------**/
     if (isset($_POST['sort'])) {
         $input = \Input::all();
         $sort = $input['sort'];
         $sortBy = $input['sortBy'];
         $this->data['category'] = $categorySong->sortCategory($sort, $sortBy);
     } else {
         $this->data['category'] = $categorySong->getActive();
     }
     /**-------------------------------------------------------------
      * End sort the list of categories
      * ----------------------------------------------------------------**/
     /**-------------------------------------------------------------
      * Voting
      * ----------------------------------------------------------------**/
     $this->data['voting'] = $voting->getActive();
     $this->data['voting_list'] = $votingList->getActive();
     $this->data['votingIp'] = $votingIp->getActive();
     if ($this->request->has('voting_id')) {
         $browser_name = $_SERVER['HTTP_USER_AGENT'];
         // Writes to change the name of the browser for statistics
         $voting_id_form = \Input::get('voting_value');
         // Writing values from form
         $getVotingId = $votingList->getVotingIpCheck($voting_id_form);
         //Retrieves the ID where it is mentioned on the form
         $voting_id = $getVotingId->voting_id;
         //Id record in change
         $people_ip = $_SERVER['REMOTE_ADDR'];
         $getAddress = $votingIp->getActiveCheck($voting_id, $people_ip);
         // Extracts all the ip addresses and indicators vote for testing
         if ($getAddress) {
             return \Response::json(['success' => false, 'errors' => trans('translation.З_вашої_ip_уже_голосували')]);
         } else {
             $votingIp->insertTable($voting_id, $people_ip, $browser_name);
             // transfer values to record tables
             $getVoting = $votingList->getVoting($voting_id_form);
             // transfer value from the model form
             $addCount = $getVoting->count + 1;
             $votingList->upVotingListCount($voting_id_form, $addCount);
             /** --------------------------------------------------------------
              *  Calculates the percentage of the vote
              * -----------------------------------------------------------------*/
             $sumVotingList = $votingList->sumVotingList($voting_id);
             // take out a certain sum of Eid
             $voting->upSumVotingList($voting_id, $sumVotingList);
             //update the field with the amount
             /** --------------------------------------------------------------
              *  Calculates the percentage of the vote
              * -----------------------------------------------------------------*/
             return \Response::json(['success' => trans('translation.Ви_успішно_проголосували')]);
         }
     }
     /**-------------------------------------------------------------
      * End of voting
      * ----------------------------------------------------------------**/
     /**-------------------------------------------------------------
      * Extracts the most popular and newest category
      * ----------------------------------------------------------------**/
     $this->data['most_popular'] = $categorySong->most_popular();
     $this->data['last_add'] = $categorySong->last_add();
     /**-------------------------------------------------------------
      * End extracts the most popular and newest category
      * ----------------------------------------------------------------**/
     $this->data['getComments'] = $indexComment->getActive();
     return view('song.listCategory', $this->data);
 }