It looks like you're new here. If you want to get involved, click one of these buttons!
public $belongs_to = array('companies' => array('model' => array(NAVTECH_FOLDER => 'navtech_companies_model')));
protected function _get_companies()
{
if (empty($this->_companies))
{
$this->_companies = $this->_parent_model->get_related_keys('companies', array('id' => $this->id), $this->_parent_model->has_many['companies'], 'has_many', $this->_parent_model->table_name());
}
return $this->_companies;
}
public function get_companies()
{
$this->_CI->load->module_model(NAVTECH_FOLDER, 'navtech_companies_model');
$companies = $this->_get_companies();
if (empty($companies)) return array();
$query_params = array('where_in' => array($this->_tables['navtech_companies'].'.id' => $companies));
$result = $this->_CI->navtech_companies_model->query($query_params);
return $result->result();
}
protected function _get_users()
{
if (empty($this->_users))
{
$this->_users = $this->_parent_model->get_related_keys('users', array('id' => $this->id), $this->_parent_model->has_many['users'], 'has_many', $this->_parent_model->table_name());
}
return $this->_users;
}
public function get_users()
{
$this->_CI->load->module_model(NAVTECH_FOLDER, 'navtech_users_model');
$users = $this->_get_users();
if (empty($users)) return array();
$query_params = array('where_in' => array($this->_tables['navtech_users'].'.id' => $users));
$result = $this->_CI->navtech_users_model->query($query_params);
return $result->result();
}
Comments
select * from fuel_relationships where candidate_table='navtech_companies' and foreign_table='fuel_users' and foreign_key=1
The foreign_key is the fueld_users.id. The second step is to use the returned candidate_key, which is the navtech_companies.id.
select * from fuel_relationships where candidate_table='navtech_projects' and foreign_table='fuel_companies' and foreign_key=4
Is it possible to do this in one step, and if so, how would I do it in fuel code?
function is_authorized_user() { $CI =& get_instance(); // check to see if user is logged in if (!$CI->fuel->auth->is_logged_in()) { return FALSE; } if ($CI->fuel->auth->is_super_admin()) { return TRUE; } $user_id = $CI->fuel->auth->user_data('id'); // get associated companies $companies = $this->get_companies(); foreach($companies as $company) { $users = $company->get_users(); foreach($users as $user) { if ($user->id == $user_id) { // authorized... return TRUE; } } } // not authorized return FALSE; }
$CI->load->module_model(FUEL_FOLDER, 'fuel_relationships_model'); ... $CI->fuel_relationships_model->....