Exemple #1
0
 /**
  * Helper function that sets the request data for hour reports
  *
  * @param &$array The array returned by collector
  */
 private function _add_hour_data(&$array)
 {
     static $customer_cache = array();
     if (!isset($customer_cache[$array['task']])) {
         $customer = 0;
         $customer_label = $this->_l10n->get('no customer');
         if ($array['task'] != 0) {
             $mc = new midgard_collector('org_openpsa_task', 'id', $array['task']);
             $mc->set_key_property('id');
             $mc->add_value_property('customer');
             $mc->execute();
             $customer_id = $mc->get_subkey($array['task'], 'customer');
             if ($customer_id) {
                 try {
                     $customer = new org_openpsa_contacts_group_dba($customer_id);
                     $customer_label = $customer->official;
                     $customer = $customer_id;
                 } catch (midcom_error $e) {
                 }
             }
         }
         $customer_cache[$array['task']] = $customer;
         if (!isset($this->_request_data['customers'][$customer])) {
             $this->_request_data['customers'][$customer] = $customer_label;
         }
     }
     $customer = $customer_cache[$array['task']];
     $category = 'uninvoiceable';
     if ($array['invoiceable']) {
         $category = 'invoiceable';
     }
     if (!isset($this->_request_data['hours'][$category][$customer])) {
         $this->_request_data['hours'][$category][$customer] = $array['hours'];
     } else {
         $this->_request_data['hours'][$category][$customer] += $array['hours'];
     }
     $this->_request_data['hours']['total_' . $category] += $array['hours'];
 }
Exemple #2
0
 /**
  * This is an internal helper function, which may only be called statically.
  *
  * It is used by get_all_privileges in case that there is no cache hit. It will query the
  * database and construct all necessary objects out of it.
  *
  * @param string $guid The GUID of the object for which to query ACL data.
  * @param string $type SELF or CONTENT
  * @return Array A list of midcom_core_privilege instances.
  */
 protected static function _query_privileges($guid, $type)
 {
     $result = array();
     $mc = new midgard_collector('midcom_core_privilege_db', 'objectguid', $guid);
     $mc->add_constraint('value', '<>', MIDCOM_PRIVILEGE_INHERIT);
     if ($type == 'CONTENT') {
         $mc->add_constraint('assignee', '<>', 'SELF');
     } else {
         $mc->add_constraint('assignee', '=', 'SELF');
     }
     $mc->set_key_property('guid');
     $mc->add_value_property('id');
     $mc->add_value_property('privilegename');
     $mc->add_value_property('assignee');
     $mc->add_value_property('classname');
     $mc->add_value_property('value');
     midcom_connection::set_error(MGD_ERR_OK);
     $mc->execute();
     $privileges = $mc->list_keys();
     if (!$privileges) {
         if (midcom_connection::get_error() != MGD_ERR_OK) {
             debug_add("Failed to retrieve all {$type} privileges for the Object GUID {$guid}: " . midcom_connection::get_error_string(), MIDCOM_LOG_INFO);
             debug_print_r('Result was:', $result);
             if (isset($php_errormsg)) {
                 debug_add("Error message was: {$php_errormsg}", MIDCOM_LOG_ERROR);
             }
             throw new midcom_error('Privilege collector failed to execute: ' . midcom_connection::get_error_string());
         }
         return $result;
     }
     foreach ($privileges as $privilege_guid => $value) {
         $privilege = $mc->get($privilege_guid);
         $privilege['objectguid'] = $guid;
         $privilege['guid'] = $privilege_guid;
         $privilege_object = new midcom_core_privilege($privilege);
         if (!isset($privilege_object->assignee)) {
             // Invalid privilege, skip
             continue;
         }
         $privilege_object->scope = $privilege_object->_get_scope();
         $return[] = $privilege_object;
     }
     return $return;
 }
Exemple #3
0
 /**
  * Adds a passed rule for the passed class to the querybuilder
  *
  * @param array $rule contains the rule
  * @param string $class name of the class the rule will be added to
  * @param string $person_property contains the name of the property of the
  * passed class which links to the person
  */
 function add_misc_rule(array $rule, $class, $person_property)
 {
     $persons = array(0 => -1);
     $match = $rule['match'];
     $constraint_match = "IN";
     if ($rule['match'] == '<>' || $rule['match'] == 'NOT LIKE') {
         $constraint_match = "NOT IN";
         switch ($rule['match']) {
             case '<>':
                 $match = '=';
                 break;
             case 'NOT LIKE':
                 $match = 'LIKE';
                 break;
             default:
                 $match = '=';
                 break;
         }
     }
     $mc_misc = new midgard_collector($class, 'metadata.deleted', false);
     $mc_misc->set_key_property('id');
     $mc_misc->add_constraint($rule['property'], $match, $rule['value']);
     $mc_misc->add_value_property($person_property);
     $mc_misc->execute();
     $keys = $mc_misc->list_keys();
     foreach ($keys as $key => $value) {
         // get user-id
         $persons[] = $mc_misc->get_subkey($key, $person_property);
     }
     $this->_result_mc->add_constraint('id', $constraint_match, $persons);
 }
Exemple #4
0
 /**
  * Helper function to create & recalculate existing invoice_items by tasks
  *
  * @param array $tasks array containing the task id's to recalculate for - if empty all tasks will be recalculated
  */
 public function _recalculate_invoice_items($tasks = array(), $skip_invoice_update = false)
 {
     $result_items = array();
     $result_tasks = array();
     //get hour_reports for this invoice - mc ?
     $qb_hour_reports = org_openpsa_projects_hour_report_dba::new_query_builder();
     $qb_hour_reports->add_constraint('invoice', '=', $this->id);
     if (!empty($tasks)) {
         $qb_hour_reports->add_constraint('task', 'IN', $tasks);
         //if there is a task passed it must be calculated even
         //if it doesn't have associated hour_reports
         foreach ($tasks as $task_id) {
             $result_tasks[$task_id] = 0;
         }
     }
     $hour_reports = $qb_hour_reports->execute();
     // sums up the hours of hour_reports for each task
     foreach ($hour_reports as $hour_report) {
         if (!array_key_exists($hour_report->task, $result_tasks)) {
             $result_tasks[$hour_report->task] = 0;
         }
         //only add invoiceable hour_reports
         if ($hour_report->invoiceable) {
             $result_tasks[$hour_report->task] += $hour_report->hours;
         }
     }
     foreach ($result_tasks as $task_id => $hours) {
         $invoice_item = $this->_probe_invoice_item_for_task($task_id);
         //get deliverable for this task
         $mc_task_agreement = new midgard_collector('org_openpsa_task', 'id', $task_id);
         $mc_task_agreement->set_key_property('id');
         $mc_task_agreement->add_value_property('title');
         $mc_task_agreement->add_value_property('agreement');
         $mc_task_agreement->add_constraint('agreement', '<>', 0);
         $mc_task_agreement->execute();
         $mc_task_key = $mc_task_agreement->list_keys();
         $deliverable = null;
         foreach ($mc_task_key as $key => $empty) {
             try {
                 $deliverable = new org_openpsa_sales_salesproject_deliverable_dba((int) $mc_task_agreement->get_subkey($key, 'agreement'));
                 $invoice_item->pricePerUnit = $deliverable->pricePerUnit;
                 $invoice_item->deliverable = $deliverable->id;
                 //calculate price
                 if ($deliverable->invoiceByActualUnits || $deliverable->plannedUnits == 0) {
                     $invoice_item->units = $hours;
                 } else {
                     $invoice_item->units = $deliverable->plannedUnits;
                 }
             } catch (midcom_error $e) {
                 $e->log();
                 $invoice_item->units = $hours;
             }
         }
         if ($invoice_item->description == '') {
             $invoice_item->description = $mc_task_agreement->get_subkey($task_id, 'title');
         }
         $invoice_item->skip_invoice_update = $skip_invoice_update;
         $invoice_item->update();
         $result_items[] = $invoice_item;
     }
     return $result_items;
 }