Example #1
0
 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);
     }
 }