[eluser]fidlet[/eluser]
I'm new at Codeigniter and PHP, and this is a bit of a convoluted issue, so please bear with me. I'm trying to set up a notification system so that when a user completes a task, the owners of the next processes are notified via email. So I'm trying to build a model that, when a step # is passed to it, it will pass back a series of email addresses belonging to the owners of the next process. I have a series of related tables:
*
process_flow: with the following fields:
process_id, and
notify_process (it identifies the next processes that are to be notified when a certain process is completed)
*
process_assignments (shows what processes are assigned to what role. There can be more than one role associated with a process, and more than one process associated with a role)
*
role_assignments (indicates what username is assigned what role. More than one user can be assigned to a role, and a user can have more than one role)
*
users (holds user data including username and email address)
So, when the step is passed to the model, the model has to
1. pick out the row(s) in
process_flow that match the step number, then
2. pick out the row(s) in
process_assignments in which the
process matches the
notify_process fields of the rows picked out in (1), then
3. pick out the rows(s) in
role_assignments in which the
role matches the
roles of the rows picked out in (2), then
4. pick out the row(s) in
users in which the
user matches the
users of the rows picked out in (3), then
5. adds the email address of these users to a variable "$emails" that is then passed back to the controller
I feel WAY out of my element here. So far, here is what's in my controller:
Code:
$step = 1;
$this->load->model('admin/queue/MNotification');
$email = $this-> MNotification ->determineEmails($step);
And, here is what's in my model:
Code:
class MNotification extends CI_Model {
function determineEmails($step) {
$email = "";
$flow_query = $this->db->get_where('process_flow', array('process_id =' => '$step')); //returns all the rows where process id = step #
if ($flow_query->num_rows() > 0)
{
foreach ($flow_query->result() as $row)
{
$data = $flow_query->row_array();
$next_query = $this->db->get_where('process_assignments', array('process =' => $data['notify_process'])); // returns all of the roles associated with the next step
if ($next_query->num_rows() > 0)
{
foreach ($flow_query->result() as $row)
{
$data = $next_query->row_array();
$user_query = $this->db->get_where('role_assignments', array('role =' => $data['role'])); // returns all of the users associated with the role
if ($user_query->num_rows() > 0)
{
foreach ($user_query->result() as $row)
{
$data = $user_query->row_array();
$email_query = $this->db->get_where('username', array('users =' => $data['username'])); // returns the row from the user table associated with the username
$user_data = $email_query->row_array();
$email = $email.";".$user_data['email'];
}
}
}
}
}
}
return $email;
}
}
Sufficed to say, it's not really working. I've been researching the documentation and the forums here to figure out how to construct this, but I don't know if I'm even on the right track. Can anyone give me some guidance?