function getNotifyUsers($workflow_id, $user_rights) { $model =& NModel::factory($this->name); $pk = $model->primaryKey(); if ($model->get($workflow_id)) { $page_model =& $model->getLink('page_id', 'page'); $model_count = clone $model; $model_count->reset(); $parent_workflow = $model->parent_workflow ? $model->parent_workflow : $workflow_id; $workflow_steps = array(); if ($model_count->find(array('conditions' => $pk . '=' . $parent_workflow . ' OR parent_workflow=' . $parent_workflow))) { $workflow_steps =& $model_count->fetchAll(); } // we need to figure out who to email to... $notify_users = array(); if ($page_model =& $model->getLink('page_id', 'page')) { $user_model =& NModel::factory('cms_auth'); $pk = $user_model->primaryKey(); // $users = array(); $workflow_user =& NModel::factory('workflow_users'); $workflow_user->workflow_group_id = $model->workflow_group_id; $auth = new NAuth(); if ($workflow_user->find()) { $author = false; $editor = false; $approver = false; while ($workflow_user->fetch()) { if ($user_model->get($workflow_user->user_id)) { switch ($workflow_user->role) { case WORKFLOW_ROLE_AUTHOR: $author = true; break; case WORKFLOW_ROLE_EDITOR: $editor = true; break; case WORKFLOW_ROLE_APPROVER: $approver = true; break; } $users[] = clone $user_model; } $user_model->reset(); } foreach ($users as $user) { $notify_user_rights = $this->getWorkflowUserRights($page_model, $user->{$user->primaryKey()}); switch (1) { case count($workflow_steps) == 1: $rights_needed = WORKFLOW_RIGHT_EDIT + WORKFLOW_RIGHT_APPROVE; if ($notify_user_rights >= $rights_needed) { if ($author && $editor && $approver && !($notify_user_rights & WORKFLOW_RIGHT_PUBLISH)) { $notify_users[] = $user; } else { if ((!$author || !$editor || !$approver) && $notify_user_rights & WORKFLOW_RIGHT_APPROVE) { $notify_users[] = $user; } } } break; case count($workflow_steps) == 2 && $workflow_steps[1]->approved: $rights_needed = WORKFLOW_RIGHT_APPROVE + WORKFLOW_RIGHT_PUBLISH; if ($notify_user_rights >= $rights_needed) { $notify_users[] = $user; } break; } } unset($users); } if (empty($notify_users) && $user_model->get($auth->currentUserId()) && $user_model->user_level >= N_USER_ADMIN) { $notify_users[] = clone $user_model; } unset($user_model); unset($page_content_model); unset($page_model); return $notify_users; } } return false; }