dqnqpqv3841 2016-10-27 13:13
浏览 18

检查用户是否已提交批准

I have the followin scenario: if a user has posted a message, other users are able to approve the message but not the author, which should only be able to edit or delete it.

The below if statement is supposed to work for that but it's not working.

<td>
  <?php $author = array(
    $message->user_id == $this->session->userdata('id')
  ); ?>
  <?php if($author): ?>
  <?php echo anchor('admin/messages/edit/'.$message->id.'', 'Edit', 'class="btn btn-primary"'); ?>
  <?php echo anchor('admin/messages/delete/'.$message->id.'', 'Delete', 'class="btn btn-danger"'); ?>
  <?php endif; ?>
  <?php if(!$author): ?>
  <?php echo anchor('admin/messages/approve/'.$message->id.'', 'Approve', 'class="btn btn-success"'); ?>
  <?php endif; ?>
</td>

The code below is the approve METHOD in my CONTROLLER which is supposed to check the condition before passing data to the MODEL

public function approve($id)
{
    $this->db->select('*');
    $this->db->from('approval');
    $this->db->join('messages', 'messages.id = approval.sms_id');
    $query = $this->db->get();
    $first_approval = $query->row('first_approval');
    $second_approval = $query->row('second_approval');
    $third_approval = $query->row('third_approval');

    if ($first_approval == null) {
        $data  = array(
            'first_approval' =>  $this->session->userdata('user_id')
        );

        $approval_data  = array(
            'approvals' => 'one'
        );

        $this->Message_model->some_approve($id, $approval_data);

        $this->Message_model->approve($id, $data);
        //Activity array
        $data  = array(
            'resource_id' => '',
            'type'        => 'message',
            'action'      => 'approved',
            'user_id'     => $this->session->userdata('user_id'),
            'message'     => 'Message was approved'

        );
        //Insert Activity
        $this->Activity_model->add($data);

        //isset Message
        $this->session->set_flashdata('success', 'Your approval was send');

        //Redirect
        redirect('admin/messages');

    } elseif ($second_approval == null && $this->session->userdata('user_id') != $first_approval) {

        $data  = array(
            'second_approval' =>  $this->session->userdata('user_id')
        );

        $approval_data  = array(
            'approvals' => 'two'
        );

        $this->Message_model->some_approve($id, $approval_data);

        $this->Message_model->approve($id, $data);

        //Activity array
        $data  = array(
            'resource_id' => '',
            'type'        => 'message',
            'action'      => 'approved',
            'user_id'     => $this->session->userdata('user_id'),
            'message'     => 'Message was approved'
        );

        //Insert Activity
        $this->Activity_model->add($data);

        //isset Message
        $this->session->set_flashdata('success', 'Your approval was send');

        //Redirect
        redirect('admin/messages');

    } elseif ($third_approval == null && $this->session->userdata('user_id') != $second_approval && $this->session->userdata('user_id') != $first_approval) {
        $data  = array(
            'third_approval' =>  $this->session->userdata('user_id')
        );
        $approval_data  = array(
            'status'    => 'Approved',
            'approvals' => 'three'
        );

        $this->Message_model->approve($id, $data);
        $this->Message_model->some_approve($id, $approval_data);

        //Activity array
        $data  = array(
        'resource_id' => '',
        'type'        => 'message',
        'action'      => 'approved',
        'user_id'     => $this->session->userdata('user_id'),
        'message'     => 'Message was approved'

        );

        //Insert Activity
        $this->Activity_model->add($data);

        //isset Message
        $this->session->set_flashdata('success', 'Your approval was send and the message has passed');

        //Redirect
        redirect('admin/messages');

    } elseif ($third_approval == $this->session->userdata('user_id') || $this->session->userdata('user_id') == $second_approval || $this->session->userdata('user_id') == $first_approval) {
        //isset Message
        $this->session->set_flashdata('success', 'You already have send an approval');

        //Redirect
        redirect('admin/messages');

    } else {

        $approval_data  = array(
            'status'      => 'Approved',
            'approvals'   => 'three'
        );

        $this->Message_model->some_approve($id, $approval_data);

        //isset Message
        $this->session->set_flashdata('success', 'Your approval was send and the message has already been send');

        //Redirect
        redirect('admin/messages');
    }
}

The METHODS below are working

public function approve($id, $data) {
    $this->db->where('sms_id', $id);
    $this->db->update('approval',$data);
}

public function some_approve($id, $approval_data)
{
    $this->db->where('id', $id);
    $this->db->update('messages',$approval_data);
}

The if conditions in my controller and on the buttons are the ones which I need help on because the are not showing any error but they are not working as they should

  • 写回答

1条回答 默认 最新

  • dongqu7778 2016-10-27 19:07
    关注

    Well first thing your if condition below is wrong:

    It should be something like this:

    <?php if($message->user_id && $message->user_id == $this->session->userdata('id')): ?>
    
    HTML Data
    
    <?php else:?>
    
    HTML Data
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题