dongxiang3648 2019-03-01 01:56
浏览 20

Codeigniter | 获取尚未加入项目的用户

I have a site where admin can add/assign users to projects. I have tried a lot of different stuff and the latest is that it works to some extent.. but not as needed:

On ProjectDetails page there is a dropdown-list which is used to add users to specific Project. BUT this drowdown-list shows only users who are not registered in any other projects at all.But Users must be able to be registered/added in multiple projects at same time. What I need is to show this dropdown list in View (ProjectDetails) only with users who are not already registered in this specific project

View:

<? if ( $level == "9" ) { ?>
<?php

$tVAR555 = count($allUsers_NotInProject);
//print_r($testVAR555)."<br><br>";

if ($tVAR555 < 1) {
   echo "";
}

else {

echo '
<div class="dropdown button editPP_J">
  <i class="add user icon"></i>
  <span class="text">Add user</span>
  <div class="menu">
    <div class="header">
      Add user to project
    </div>
';

foreach ($allUsers_NotInProject as $rows) {

   echo '<div class="item"> <p> Username: <strong>'.$rows->username.'</strong> </p> ';

   echo form_open('Project/addParticipant', 'class="form" id="addPP"');

   echo form_hidden('user_id',  $rows->user_id);
   echo form_hidden('Project_ID', $this->uri->segment(3));

   echo '
      <button type="submit" class="uBfB" id="addPP_SB"> Add 
      </button> 
   ';

   echo form_close();

   echo '</div><hr> ';
}

echo '</div></div>';

}
}

?>

Controller:

  public function projectDetails($Project_ID) {

  $this->is_logged_in();
  $loggedInUserID = $this->auth_user_id;

  $Project_ID = $this->uri->segment(3);

  $data['loggedInUserID'] = $this->auth_user_id;


  /* Tested different approaches for fetching data from DB */
  $data['projectParticipants'] = 
       $this->projectModel->getAllProjects_Participants($Project_ID);
   
  /* Tested different approaches for fetching data from DB */
  $data['projectUsers2'] = 
      $this->projectModel->get_projParts($Project_ID);

  /* Tested different approaches for fetching data from DB */
  $data['allUsers_NotInProject'] = 
     $this->projectModel->getAllUsers_NotInProject();


  $res = $this->projectModel->getProjectDetails($Project_ID);

  foreach ($res->result_array() as $projectDetail) {
         $data['rProjectID'] = $projectDetail['Project_ID'];
     $data['rProjectName'] = $projectDetail['Name'];
     $data['rProjectCreatedAt'] = $projectDetail['created_at'];
  }

  if( $this->verify_role('admin,manager') ) {

     if( $this->is_role('manager') ) {
        $data['level'] = "6";
     }
     if( $this->is_role('admin') ) {
        $data['level'] = "9";
     }

     $html = $this->load->view('header', $data, TRUE);
     $html .= $this->load->view('projectDetails', $data, TRUE);
     $html .= $this->load->view('footer', $data, TRUE);

     echo $html;
}
    
}

Model:

public function getAllProjects_Participants($Project_ID){
    $query = $this->db->query("
           SELECT * FROM Participants, users WHERE  
           Participants.user_id = users.user_id AND 
           Participants.Project_ID = $Project_ID
      ");
    return $query->result_array();
}


public function get_projParts($Project_ID) {
    $this->db->select('*');
    $this->db->from('Participants');
    $this->db->join('Users', 'Participants.user_id = Users.user_id');
    $this->db->where('Project_ID', $Project_ID);

    $query = $this->db->get();
    return $query->result();
}


public function getAllUsers_NotInProject() {
    $query = $this->db->query
       ("
          SELECT * FROM users
            WHERE user_id NOT IN (
              SELECT DISTINCT(user_id) from Participants
            )
       ");

    return $query->result();
}


public function getProjectDetails($Project_ID) {
    $query2 = $this->db->query
        ("
          SELECT * FROM Projects 
          WHERE Projects.Project_ID = $Project_ID
        ");

    $res  = $query2;
    return $res;
}

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来