function get($criteria = null, $order = null) { $sql = "SELECT tasks.*, CONCAT(users.first_name, ' ', users.last_name) AS assigned_to_name\n FROM tasks\n LEFT JOIN users ON users.id = tasks.assigned_to"; if (isset($criteria) && is_numeric($criteria)) { $sql .= " WHERE tasks.id = {$criteria}"; $task = parent::get_one($sql); $this->update_status(); return $task; } else { $sql = $this->add_criteria($sql, $criteria); $sql = $this->modify_sql_for_user_type($sql); $sql = $this->add_order_by($sql, $order); $tasks = parent::get($sql); foreach ($tasks as &$task) { //create the invoice $task_object = new Task($task); //todo: i don't think this makes any sense because the invoice status will already be updated when I create the invoice using new Invoice //store the current task status as it exists in the database $old_status = $task_object->status_text; //update the task status $task_object->update_status(); //if the old status and the new status do not match, then we need to save this task back to the database. if ($old_status != (string) $task_object->status_text) { //todo:make sure this isn't saving each time $task_object->save(false); } //we need to add the status text back the task array, since we're sending the array to the client, //not the object $task['status_text'] = $task_object->status_text; } return $tasks; } }
function get($criteria = null) { if (is_numeric($criteria)) { $sql = $this->generate_base_sql_for_get() . " WHERE files.id = {$criteria}"; return parent::get_one($sql); } else { //if we're not getting a specific file, the base get function is fine return parent::get($this->modify_sql_for_user_type('')); } }
function get($criteria = null) { if (is_numeric($criteria)) { $sql = "SELECT clients.*, CONCAT(users.first_name, ' ', users.last_name) AS primary_contact_name\n FROM clients\n LEFT JOIN users on clients.primary_contact_id = users.id\n WHERE clients.id = {$criteria}"; $client = parent::get_one($sql); $client['primary_contact_image'] = User::get_profile_image($client['primary_contact_id'], true); return $client; } else { if (!current_user()->is('admin')) { return false; } //if we're not getting a specific file, the base get function is fine return parent::get($criteria); } }
function get($criteria = null) { if (is_numeric($criteria)) { //if we are getting a specific user, we want to get their role info //TODO: this only selects the first role. Need to change this if multiple roles are ever applied to one user //TODO: there should be a standard way to do this //TODO: this is including the username, password, salt in the user object - big no no $sql = "SELECT users.* FROM users\n WHERE users.id = '{$criteria}'"; $params = parent::get_one($sql); $params->profile_image = $this->get_profile_image($params->id, false); return $params; } else { return array(); } }
function get($criteria = null) { $sql = "SELECT projects.*, clients.name AS client_name\n FROM projects\n LEFT JOIN clients ON projects.client_id = clients.id"; if (is_numeric($criteria)) { $sql .= ' WHERE projects.id = ' . $criteria; $project = parent::get_one($sql); $this->import_parameters($project); $this->update_status(); $project['status_text'] = $this->status_text; return $project; } else { $sql = $this->add_criteria($sql, $criteria); $sql = $this->add_criteria($sql, 'is_template = 0'); //if the user isn't an admin, we'll need to filter for projects that this user has access to. $sql = $this->modify_sql_for_user_type($sql); $projects = parent::get($sql); foreach ($projects as &$project) { //create the invoice $project_object = new Project($project); //todo: i don't think this makes any sense because the invoice status will already be updated when I create the invoice using new Invoice //store the current project status as it exists in the database $old_status = $project_object->status_text; $old_expected_progress = $project_object->expected_progress; $project_object->clear_params(); //update the project status $project_object->update_status(); //if the old status and the new status do not match, then we need to save this task back to the database. if ($old_status != (string) $project_object->status_text || $old_expected_progress != (int) $project_object->expected_progress) { //todo:make sure this isn't saving each time //todo: I only want to update the expected progress if we're retreiving a single project. Not when we're getting the list $project_object->save(false); } //we need to add the status text back the task array, since we're sending the array to the client, //not the object $project['status_text'] = $project_object->status_text; } return $projects; //return parent::get($sql); } }