/** * static function to return all tickets belonging to the specified project * * @param Codebase_Request $request * @param string $project_permalink * @return array A collection Codebase_Model_Ticket objects * @static * @access public */ public static function get_tickets_for_project(Codebase_Request $request, $project_permalink) { $tickets = array(); $paged_tickets = array(); $page = 1; $path = '/' . $project_permalink . '/tickets'; $request->add_param('page', $page); while (count($paged_tickets = self::get_objects_for_path($request, 'Codebase_Model_Ticket', $path)) > 0) { $tickets = array_merge($tickets, $paged_tickets); $page++; $request->add_param('page', $page); } // sort the tickets into priority order usort($tickets, 'Codebase_Model_Ticket::sort'); return $tickets; }
/** * static function to return objects of the specified class at the specified * API path, shouldn't be used directly but rather implemented by child * classes. * * @param Codebase_Request $request * @param string $class_name The class of the objects to instantiate and return * @param string $path The uri path to make the Codebase API call to * @return array A collection Codebase_Model objects * @static * @access protected */ protected static function get_objects_for_path(Codebase_Request $request, $class_name, $path) { // check that the supplied class name is a sub class of Codebase_Model (and therefore this class) if (!is_subclass_of($class_name, 'Codebase_Model')) { throw new Codebase_Exception('The supplied class name must be a sub class of Codebase_Model'); } $objects = array(); try { $response = $request->get($path); $response_data = self::parse_response($response); foreach ($response_data as $object_data) { $objects[] = new $class_name($request, $object_data); } } catch (Codebase_Exception $e) { // something went wrong with the request $objects = array(); } return $objects; }