Esempio n. 1
0
 /**
  * Function to process the notify date in the passed formdata of the datamanger
  * creates/edits/deletes the corresponding at_entry if needed
  *
  * @param array $formdata The Formdata of the datamanager containing the notify_date
  * @param org_openpsa_sales_salesproject_deliverable_dba $deliverable The current deliverable
  */
 public function process_notify_date($formdata, org_openpsa_sales_salesproject_deliverable_dba $deliverable)
 {
     //check if there is already an at_entry
     $mc_entry = org_openpsa_relatedto_dba::new_collector('toGuid', $deliverable->guid);
     $mc_entry->add_constraint('fromClass', '=', 'midcom_services_at_entry_dba');
     $mc_entry->add_constraint('toClass', '=', 'org_openpsa_sales_salesproject_deliverable_dba');
     $mc_entry->add_constraint('toExtra', '=', 'notify_at_entry');
     $entry_keys = $mc_entry->get_values('fromGuid');
     //check date
     if (!$formdata['notify']->is_empty()) {
         $notification_entry = null;
         if (count($entry_keys) == 0) {
             $notification_entry = new midcom_services_at_entry_dba();
             $notification_entry->create();
             //relatedto from notifcation to deliverable
             org_openpsa_relatedto_plugin::create($notification_entry, 'midcom.services.at', $deliverable, 'org.openpsa.sales', false, array('toExtra' => 'notify_at_entry'));
         } else {
             //get guid of at_entry
             foreach ($entry_keys as $key => $entry) {
                 //check if related at_entry exists
                 try {
                     $notification_entry = new midcom_services_at_entry_dba($entry);
                 } catch (midcom_error $e) {
                     //relatedto links to a non-existing at_entry - so create a new one an link to it
                     $notification_entry = new midcom_services_at_entry_dba();
                     $notification_entry->create();
                     $relatedto = new org_openpsa_relatedto_dba($key);
                     $relatedto->fromGuid = $notification_entry->guid;
                     $relatedto->update();
                 }
                 break;
             }
         }
         $notification_entry->start = $formdata['notify']->value->format('U');
         $notification_entry->method = 'new_notification_message';
         $notification_entry->component = 'org.openpsa.sales';
         $notification_entry->arguments = array('deliverable' => $deliverable->guid);
         $notification_entry->update();
     } else {
         //void date - so delete existing at_entrys for this notify_date
         foreach ($entry_keys as $key => $empty) {
             try {
                 $notification_entry = new midcom_services_at_entry_dba($mc_entry->get_subkey($key, 'fromGuid'));
                 //check if related at_entry exists & delete it
                 $notification_entry->delete();
             } catch (midcom_error $e) {
                 $e->log();
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Check database for essentially same relatedto object and returns GUID if found
  */
 function check_db($check_status = true)
 {
     $mc = org_openpsa_relatedto_dba::new_collector('toGuid', $this->toGuid);
     $mc->add_constraint('fromClass', '=', $this->fromClass);
     $mc->add_constraint('toClass', '=', $this->toClass);
     $mc->add_constraint('fromGuid', '=', $this->fromGuid);
     $mc->add_constraint('fromComponent', '=', $this->fromComponent);
     $mc->add_constraint('toComponent', '=', $this->toComponent);
     if ($check_status) {
         $mc->add_constraint('status', '=', $this->status);
     }
     $mc->set_limit(1);
     $mc->execute();
     $ret = $mc->list_keys();
     if (is_array($ret) && count($ret) > 0) {
         return key($ret);
     }
     return false;
 }
Esempio n. 3
0
 public function testCreate_task()
 {
     $organization = $this->create_object('org_openpsa_contacts_group_dba');
     $manager = $this->create_object('midcom_db_person');
     $member = $this->create_object('midcom_db_person');
     $group = $this->create_object('org_openpsa_products_product_group_dba');
     $product_attributes = array('productGroup' => $group->id, 'code' => 'TEST-' . __CLASS__ . time());
     $product = $this->create_object('org_openpsa_products_product_dba', $product_attributes);
     $salesproject_attributes = array('owner' => $manager->id, 'customer' => $organization->id);
     $salesproject = $this->create_object('org_openpsa_sales_salesproject_dba', $salesproject_attributes);
     $member_attributes = array('person' => $member->id, 'objectGuid' => $salesproject->guid, 'role' => ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER);
     $this->create_object('org_openpsa_contacts_role_dba', $member_attributes);
     $deliverable_attributes = array('salesproject' => $salesproject->id, 'product' => $product->id, 'description' => 'TEST DESCRIPTION', 'plannedUnits' => 15);
     $deliverable = $this->create_object('org_openpsa_sales_salesproject_deliverable_dba', $deliverable_attributes);
     $start = time();
     $end = $start + 30 * 24 * 60 * 60;
     $title = 'TEST TITLE';
     $start_cmp = mktime(0, 0, 0, date('n', $start), date('j', $start), date('Y', $start));
     $end_cmp = mktime(23, 59, 59, date('n', $end), date('j', $end), date('Y', $end));
     $scheduler = new org_openpsa_invoices_scheduler($deliverable);
     midcom::get('auth')->request_sudo('org.openpsa.invoices');
     $task = $scheduler->create_task($start, $end, $title);
     $this->assertTrue(is_a($task, 'org_openpsa_projects_task_dba'));
     $this->register_object($task);
     $this->assertEquals($deliverable->id, $task->agreement);
     $this->assertEquals($salesproject->customer, $task->customer);
     $this->assertEquals($title, $task->title);
     $this->assertEquals($deliverable->description, $task->description);
     $this->assertEquals($start_cmp, $task->start);
     $this->assertEquals($end_cmp, $task->end);
     $this->assertEquals($deliverable->plannedUnits, $task->plannedHours);
     $this->assertEquals($salesproject->owner, $task->manager);
     $this->assertTrue($task->hoursInvoiceableDefault);
     $mc = org_openpsa_relatedto_dba::new_collector('fromGuid', $task->guid);
     $mc->add_value_property('toGuid');
     $mc->execute();
     $keys = $mc->list_keys();
     $this->assertEquals(1, sizeof($keys));
     $product_guid = $mc->get_subkey(key($keys), 'toGuid');
     $this->assertEquals($product->guid, $product_guid);
     $salesproject->get_members();
     $task->get_members();
     $this->assertEquals($salesproject->contacts, $task->contacts);
     $project = new org_openpsa_projects_project($task->project);
     $this->assertTrue(!empty($project->guid));
     $this->register_object($project);
     $project->get_members();
     $this->assertEquals($salesproject->contacts, $project->contacts);
     $this->assertEquals($salesproject->owner, $project->manager);
     $task->priority = 4;
     $task->manager = $member->id;
     $task->update();
     $task->add_members('resources', array($member->id));
     $task->refresh();
     $task2 = $scheduler->create_task($start, $end, $title, $task);
     $this->register_object($task2);
     $task2->get_members();
     $task->get_members();
     $this->assertEquals(4, $task2->priority);
     $this->assertEquals($member->id, $task2->manager);
     $this->assertEquals($task->resources, $task2->resources);
     midcom::get('auth')->drop_sudo();
 }
Esempio n. 4
0
 /**
  * Default method for getting object's relatedtos (outbound ie fromGuid == $obj->guid)
  *
  * Components handlers may need to override this to account
  * for specific object types and possible traversing of their children
  */
 private function _get_object_links_out(&$arr, $obj)
 {
     if (!is_object($obj) || !is_array($arr)) {
         return false;
     }
     $mc = org_openpsa_relatedto_dba::new_collector('fromGuid', $obj->guid);
     $mc->add_value_property('toGuid');
     $mc->add_value_property('toClass');
     $mc->add_value_property('toComponent');
     $mc->add_value_property('status');
     $mc->add_constraint('status', '<>', org_openpsa_relatedto_dba::NOTRELATED);
     $mc->execute();
     $links = $mc->list_keys();
     if (!is_array($links)) {
         return false;
     }
     foreach ($links as $guid => $link) {
         //TODO: check for duplicates ?
         $to_arr = array('link' => false, 'other_obj' => false, 'sort_time' => false);
         $to_arr['link'] = array('guid' => $guid, 'component' => $mc->get_subkey($guid, 'toComponent'), 'class' => $mc->get_subkey($guid, 'toClass'), 'status' => $mc->get_subkey($guid, 'status'));
         try {
             $to_arr['other_obj'] = midcom::get('dbfactory')->get_object_by_guid($mc->get_subkey($guid, 'toGuid'));
         } catch (midcom_error $e) {
             continue;
         }
         $to_arr['sort_time'] = $this->_get_object_links_sort_time($to_arr['other_obj']);
         $arr[] = $to_arr;
     }
     return true;
 }