/** * List all tasks, optionally filtered by status */ private function _handler_list_all($args) { // Default to open tasks list if none specified if (!isset($args[1]) || empty($args[1])) { $this->_request_data['view_identifier'] = 'open'; $args[1] = 'open'; } switch ($args[1]) { case 'agreement': if (!$args[2]) { throw new midcom_error('Invalid arguments for agreement filter'); } $agreement_id = (int) $args[2]; $this->_request_data['agreement'] = $agreement_id; $deliverable = org_openpsa_sales_salesproject_deliverable_dba::get_cached($agreement_id); $title = sprintf($this->_l10n->get('tasks for agreement %s'), $deliverable->title); midcom::get('head')->set_pagetitle($title); $this->add_breadcrumb("", $title); $this->_qb->add_constraint('agreement', '=', $deliverable->id); $this->_provider->add_order('end', 'DESC'); break; case 'all': case 'both': $args[1] = 'all'; $this->_provider->add_order('end', 'DESC'); break; case 'open': $this->set_active_leaf($this->_topic->id . ':tasks_open'); $this->_qb->add_constraint('status', '<', org_openpsa_projects_task_status_dba::CLOSED); $this->_provider->add_order('end'); break; case 'closed': $this->set_active_leaf($this->_topic->id . ':tasks_closed'); $this->_qb->add_constraint('status', '=', org_openpsa_projects_task_status_dba::CLOSED); $this->_provider->add_order('end', 'DESC'); break; case 'current': $this->_qb->add_constraint('status', 'IN', array(org_openpsa_projects_task_status_dba::ACCEPTED, org_openpsa_projects_task_status_dba::STARTED, org_openpsa_projects_task_status_dba::REJECTED, org_openpsa_projects_task_status_dba::REOPENED)); $this->_provider->add_order('end'); break; case 'invoiceable': $this->set_active_leaf($this->_topic->id . ':tasks_invoiceable'); $this->_qb->add_constraint('invoiceableHours', '>', 0); $this->_provider->add_order('end'); break; case 'invoiced': $this->set_active_leaf($this->_topic->id . ':tasks_invoiced'); $this->_qb->add_constraint('invoicedHours', '>', 0); $this->_provider->add_order('end', 'DESC'); break; default: throw new midcom_error("Filter {$args[1]} not recognized"); } $qf = new org_openpsa_core_queryfilter('org_openpsa_task_list_' . $args[1]); $qf->add_filter(new org_openpsa_core_filter('priority', '<=', $this->_request_data['priority_array'])); $date_filter = new org_openpsa_core_filter('timeframe'); $date_filter->set('mode', 'timeframe'); $date_filter->set('helptext', $this->_l10n->get("timeframe")); $date_filter->set('fieldname', array('start' => 'start', 'end' => 'end')); $qf->add_filter($date_filter); $qf->apply_filters($this->_qb); $this->_request_data["qf"] = $qf; $this->_request_data['table-heading'] = $args[1] . ' tasks'; $this->_request_data['view'] = 'grid'; }
/** * This function will determine the correct type of midgard_query_builder that * has to be created. It will also call the _on_prepare_new_query_builder event handler. * * @param string $classname The name of the class for which you want to create a query builder. * @return midcom_core_querybuilder The initialized instance of the query builder. * @see midcom_core_querybuilder */ function new_query_builder($classname) { $qb = new midcom_core_querybuilder($classname); $qb->initialize(); return $qb; }
public function get_objects() { $qb = new midcom_core_querybuilder($this->_real_class); if (!empty($this->_orders)) { //Reset offset/limit, otherwise sorting won't work properly $limit = $this->_limit; $offset = $this->_offset; $this->_offset = 0; $this->_limit = 0; $qb->set_limit($limit); $qb->set_offset($offset); } $this->execute(); $guids = $this->list_keys(); if (!empty($this->_orders)) { $this->_offset = $offset; $this->_limit = $limit; } if (sizeof($guids) == 0) { return array(); } $qb->hide_invisible = $this->hide_invisible; $qb->add_constraint('guid', 'IN', array_keys($guids)); foreach ($this->_orders as $order) { $qb->add_order($order['field'], $order['direction']); } return $qb->execute(); }