Codeigniter |获取尚未进行项目开发的用户

时间:2019-03-01 01:56:30

标签: php html mysql database codeigniter

我有一个网站,管理员可以在其中添加/分配用户到项目。我尝试了很多不同的东西,最新的是它在某种程度上可以工作..但不是根据需要:

在ProjectDetails页面上,有一个下拉列表,用于将用户添加到特定的Project。但是此下拉列表仅显示根本没有在任何其他项目中注册的用户。但是必须能够同时在多个项目中注册/添加用户。我需要显示此信息视图(ProjectDetails)中的下拉列表仅针对尚未在该特定项目中注册的用户

查看:

<? 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>';

}
}

?>

控制器:

  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;
}
	
}

型号:

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;
}

0 个答案:

没有答案