проблема в нескольких блочных комментариях, но одиночный комментарий успешно заблокирован - PullRequest
0 голосов
/ 03 декабря 2018

Проблема множественная, когда я блокирую несколько комментариев, это не работает.если я заблокирую один комментарий, это будет работать успешно.Пожалуйста, прочитайте мой HTML & PHP код и сообщите мне решение этой проблемы.

HTML-код для флажка

 <input class="allCheck" type="checkbox" name="check12[]" value="<?php
         echo $d['ID']; ?>" />

PHP контроллер: Здесьопределить два метода для dataAccess

public function multipleBlockAction() {

    $request = $this->request;
    $arrdatas = array();
    $commentsValues = $request->getPost("check12");

    $sizeOfvalue = sizeof($commentsValues) - 1;

    for ($x = 0; $x <= $sizeOfvalue; $x++) {

        $checkOneByOne = $commentsValues[$x];

        $commentdata = $this->_commentservice->getCommentById($checkOneByOne);

        foreach ($commentdata as $ucdata) {

            $arrdatas = $ucdata->toArray();
            $arrdatas['Status'] = '2';
            $arrdatas['Block_DateTime'] = date('Y-m-d H:i:s');

            $result = $this->_commentservice->totrashcomment($arrdatas);

            if (is_object($result)) {
                $result = $result->getMessages();
                $this->logErrorMessage($result);
            foreach ($result as $res) {
                $this->flash->error($res);
            }
            } else {
                $this->flashSession->success('<div  class="alert alert-success text-center">Comment is Blocked successfully</div>');
                $previous = $this->session->get('previous_url');
                return $this->response->redirect($previous);
            }



        }

    }

} 

getCommentById : я упомянул об этом методе, и он вызывает контроллер.

public function getCommentById($comid) {
        try {
            $transaction = $this->_transaction->get();
            $this->_userComment->setTransaction($transaction);
            $result = $this->_userComment->find("ID = '{$comid}'");
            return $result;
        } catch (TxFailed $e) {
            return $this->_userComment;
        }
    }

totrashcomment : этот метод также вызывает контроллер

public function totrashcomment($data) {
        //print_r();
        try {

            $transaction = $this->_transaction->get();
            $this->_userComment->setTransaction($transaction);

            $conditions = "Unique_ID = {$data['Unique_ID']} and MainComment = '1'";
            $data1 = $this->_userComment->find(array($conditions))->toArray();
            if (count($data1) > 0) {
                return;
            } else {
                if ($this->_userComment->save($data) == false) {
                    $transaction->rollback('comment not updated');
                }
            }
            //Everything goes fine, let's commit the transaction
            $transaction->commit();
        } catch (TxFailed $e) {
            return $this->_userComment;
        }
    }
...