コード例 #1
0
ファイル: viewer.php プロジェクト: nemein/openpsa
 /**
  * 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();
             }
         }
     }
 }
コード例 #2
0
ファイル: dbaTest.php プロジェクト: nemein/openpsa
 public function testCRUD()
 {
     $relatedto = new org_openpsa_relatedto_dba();
     midcom::get('auth')->request_sudo('org.openpsa.relatedto');
     $stat = $relatedto->create();
     $this->assertTrue($stat);
     $this->assertEquals($relatedto->status, org_openpsa_relatedto_dba::SUSPECTED);
     $relatedto->status = org_openpsa_relatedto_dba::CONFIRMED;
     $stat = $relatedto->update();
     $this->assertTrue($stat);
     $this->assertEquals($relatedto->status, org_openpsa_relatedto_dba::CONFIRMED);
     $stat = $relatedto->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
コード例 #3
0
ファイル: plugin.php プロジェクト: nemein/openpsa
 /**
  * Parses relatedto information from request, returning either
  * existing matching relatedtos or prefilled new ones for creation
  */
 public static function get2relatedto()
 {
     $ret = array();
     if (!array_key_exists('org_openpsa_relatedto', $_REQUEST)) {
         return $ret;
     }
     foreach ($_REQUEST['org_openpsa_relatedto'] as $rel_array) {
         $rel = new org_openpsa_relatedto_dba();
         foreach ($rel_array as $k => $v) {
             $rel->{$k} = $v;
         }
         if ($guid = $rel->check_db()) {
             $rel = new org_openpsa_relatedto_dba($guid);
         }
         $ret[] = $rel;
     }
     return $ret;
 }
コード例 #4
0
ファイル: interfaces.php プロジェクト: nemein/openpsa
 /**
  * Support for contacts person merge
  */
 function org_openpsa_contacts_duplicates_merge_person(&$person1, &$person2, $mode)
 {
     switch ($mode) {
         case 'all':
             break;
         case 'future':
             // Relatedto does not have future references so we have nothing to transfer...
             return true;
             break;
         default:
             // Mode not implemented
             debug_add("mode {$mode} not implemented", MIDCOM_LOG_ERROR);
             return false;
             break;
     }
     $qb = org_openpsa_relatedto_dba::new_query_builder();
     $qb->begin_group('OR');
     $qb->add_constraint('fromGuid', '=', $person2->guid);
     $qb->add_constraint('toGuid', '=', $person2->guid);
     $qb->end_group();
     $links = $qb->execute();
     if ($links === false) {
         // QB Error
         return false;
     }
     foreach ($links as $link) {
         if ($link->fromGuid == $person2->guid) {
             debug_add("Transferred link->fromGuid #{$link->id} to person #{$person1->id} (from {$link->fromGuid})");
             $link->fromGuid = $person1->guid;
         }
         if ($link->toGuid == $person2->guid) {
             debug_add("Transferred link->toGuid #{$link->id} to person #{$person1->id} (from {$link->toGuid})");
             $link->toGuid = $person1->guid;
         }
     }
     // TODO: Check for duplicates and remove those (also from the links array...)
     // Save updates to remaining links
     foreach ($links as $link) {
         if (!$link->update()) {
             // Failure updating
             return false;
         }
     }
     // TODO: 1.8 metadata format support
     // All done
     return true;
 }
コード例 #5
0
ファイル: dba.php プロジェクト: nemein/openpsa
 /**
  * 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;
 }
コード例 #6
0
ファイル: migrate_to_90beta.php プロジェクト: nemein/openpsa
                $item->invoice = $invoice->id;
                $item->task = $task->id;
                $item->deliverable = $task->agreement;
                $item->pricePerUnit = 0;
                $item->units = 1;
                $item->description = $task->title . ' (auto-generated)';
                $item->create();
            }
        }
        $relatedto->delete();
    }
}
$deliverable_qb = org_openpsa_sales_salesproject_deliverable_dba::new_query_builder();
$deliverables = $deliverable_qb->execute();
foreach ($deliverables as $deliverable) {
    $relatedto_qb = org_openpsa_relatedto_dba::new_query_builder();
    $relatedto_qb->add_constraint('toGuid', '=', $deliverable->guid);
    $relatedto_qb->add_constraint('fromClass', '=', 'org_openpsa_invoices_invoice_dba');
    $relatedtos = $relatedto_qb->execute();
    if (sizeof($relatedtos) == 0) {
        echo "Deliverable " . $deliverable->title . " has no invoice relatedtos, skipping\n";
        flush();
    }
    foreach ($relatedtos as $relatedto) {
        $invoice = new org_openpsa_invoices_invoice_dba($relatedto->fromGuid);
        $items = $invoice->get_invoice_items();
        if (sizeof($items) == 0) {
            echo "Invoice " . $invoice->get_label() . " has no items, creating one for deliverable\n";
            flush();
            $item = new org_openpsa_invoices_invoice_item_dba();
            $item->invoice = $invoice->id;
コード例 #7
0
ファイル: schedulerTest.php プロジェクト: nemein/openpsa
 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();
 }
コード例 #8
0
ファイル: reporthours.php プロジェクト: nemein/openpsa
 /**
  * Search for events withing configured timeframe and if
  * they have confirmed relatedtos to tasks reports hours
  * for each participant (who is task resource) towards
  * said task.
  */
 public function _on_execute()
 {
     debug_add('_on_execute called');
     $root_event = org_openpsa_calendar_interface::find_root_event();
     if (!is_object($root_event)) {
         debug_add('calendar root event not found', MIDCOM_LOG_WARN);
         return;
     }
     if (!class_exists('org_openpsa_relatedto_dba')) {
         debug_add('relatedto library could not be loaded', MIDCOM_LOG_WARN);
         return;
     }
     if (!midcom::get('componentloader')->load_graceful('org.openpsa.projects')) {
         debug_add('org.openpsa.projects could not be loaded', MIDCOM_LOG_WARN);
         return;
     }
     if (!midcom::get('auth')->request_sudo('org.openpsa.calendar')) {
         $msg = "Could not get sudo, aborting operation, see error log for details";
         $this->print_error($msg);
         debug_add($msg, MIDCOM_LOG_ERROR);
         return;
     }
     $qb = org_openpsa_calendar_event_participant_dba::new_query_builder();
     // Event must be directly under openpsa calendar root event
     $qb->add_constraint('eid.up', '=', $root_event->id);
     // Member type must not be resource
     $qb->add_constraint('orgOpenpsaObtype', '<>', ORG_OPENPSA_OBTYPE_EVENTRESOURCE);
     // Event must have ended
     $qb->add_constraint('eid.end', '<', time());
     // Event can be at most week old
     // TODO: make max age configurable
     /* TODO: store a timestamp of last process in root event and use whichever
                 is nearer, though it has the issue with creating events after the fact
                 (which can happen when synchronizing from other systems for example)
        */
     $qb->add_constraint('eid.start', '>', time() - 24 * 3600 * 7);
     // Must not have hours reported already
     $qb->add_constraint('hoursReported', '=', 0);
     $eventmembers = $qb->execute();
     if (!is_array($eventmembers) || count($eventmembers) < 1) {
         midcom::get('auth')->drop_sudo();
         return;
     }
     // keyed by id
     $seen_events = array();
     // keyed by guid
     $seen_tasks = array();
     // keyed by guid
     $event_links = array();
     foreach ($eventmembers as $member) {
         // Bulletproofing: prevent duplicating hour reports
         $member->hoursReported = time();
         if (!$member->update(false)) {
             $msg = "Could not set hoursReported on member #{$member->id} (event #{$member->eid}), errstr: " . midcom_connection::get_error_string() . " skipping this member";
             $this->print_error($msg);
             debug_add($msg, MIDCOM_LOG_ERROR);
             continue;
         }
         //Avoid multiple loads of same event
         if (!isset($seen_events[$member->eid])) {
             $seen_events[$member->eid] = new org_openpsa_calendar_event_dba($member->eid);
         }
         $event =& $seen_events[$member->eid];
         // Avoid multiple queries of events links
         if (!isset($event_links[$event->guid])) {
             $qb2 = org_openpsa_relatedto_dba::new_query_builder();
             $qb2->add_constraint('fromGuid', '=', $event->guid);
             $qb2->add_constraint('fromComponent', '=', 'org.openpsa.calendar');
             $qb2->add_constraint('toComponent', '=', 'org.openpsa.projects');
             $qb2->add_constraint('toClass', '=', 'org_openpsa_projects_task_dba');
             $qb2->add_constraint('status', '=', org_openpsa_relatedto_dba::CONFIRMED);
             $event_links[$event->guid] = $qb2->execute();
         }
         $links =& $event_links[$event->guid];
         // These checks are done here (in stead of few lines above) on purpose
         if (!is_array($links) || count($links) < 1) {
             continue;
         }
         foreach ($links as $link) {
             //Avoid multiple loads of same task
             if (!isset($seen_tasks[$link->toGuid])) {
                 $seen_tasks[$link->toGuid] = new org_openpsa_projects_task_dba($link->toGuid);
             }
             $task =& $seen_tasks[$link->toGuid];
             debug_add("processing task #{$task->id} ({$task->title}) for person #{$member->uid} from event #{$event->id} ({$event->title})");
             // Make sure the person we found is a resource in this particular task
             $task->get_members();
             if (!isset($task->resources[$member->uid])) {
                 debug_add("person #{$member->uid} is not a *resource* in task #{$task->id}, skipping");
                 continue;
             }
             if (!org_openpsa_projects_interface::create_hour_report($task, $member->uid, $event, 'org.openpsa.calendar')) {
                 // MidCOM error log is filled in the method, here we just display error
                 $this->print_error("Failed to create hour_report to task #{$task->id} for person #{$member->uid} from event #{$event->id}");
                 // Failed to create hour_report, unset hoursReported so that we might have better luck next time
                 // PONDER: This might be an issue in case be have multiple tasks linked and only one of them fails... figure out a more granular way to flag reported hours ?
                 $member->hoursReported = 0;
                 if (!$member->update(false)) {
                     $msg = "Could not UNSET hoursReported on member #{$member->id} (event #{$member->eid}), errstr: " . midcom_connection::get_error_string();
                     $this->print_error($msg);
                     debug_add($msg, MIDCOM_LOG_WARN);
                 }
             }
         }
     }
     midcom::get('auth')->drop_sudo();
     debug_add('done');
     return;
 }
コード例 #9
0
ファイル: relatedto.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $response = new midcom_response_xml();
     try {
         $relation = new org_openpsa_relatedto_dba($args[0]);
         $response->result = $relation->delete();
         $response->status = 'Last message: ' . midcom_connection::get_error_string();
     } catch (midcom_error $e) {
         $response->result = false;
         $response->status = "Object '{$args[0]}' could not be loaded, error:" . $e->getMessage();
     }
     return $response;
 }