예제 #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
 /**
  * Shorthand for creating a relatedto object.
  *
  * The <i>from</i> object is something that is related to the <em>to</em>
  * object.
  * For example, if a task is created under a sales project, that task is
  * the from object, and the sales project the to object.
  *
  * @param object &$from_obj The from object
  * @param string $from_component The from component name
  * @param object &$to_obj The to object
  * @param string $to_component The to component name
  * @param int $status The status of the relation
  * @param array $extra Array with the possible extra-properties
  * @return mixed The newly-created relatedto object or false on failure
  */
 public static function create(&$from_obj, $from_component, &$to_obj, $to_component, $status = false, $extra = false)
 {
     if (!is_object($from_obj) || !is_object($to_obj)) {
         return false;
     }
     if (!$status) {
         $status = org_openpsa_relatedto_dba::CONFIRMED;
     }
     $rel = new org_openpsa_relatedto_dba();
     $rel->fromClass = get_class($from_obj);
     $rel->toClass = get_class($to_obj);
     $rel->fromGuid = $from_obj->guid;
     $rel->toGuid = $to_obj->guid;
     $rel->fromComponent = $from_component;
     $rel->toComponent = $to_component;
     $rel->status = $status;
     if ($guid = $rel->check_db(false)) {
         $db_rel = new org_openpsa_relatedto_dba($guid);
         debug_add("A relation from {$rel->fromClass} #{$rel->fromGuid} to {$rel->toClass} #{$rel->toGuid} already exists, returning this one instead");
         if ($db_rel->status < $rel->status) {
             $db_rel->status = $rel->status;
             $db_rel->update();
         }
         return $db_rel;
     }
     if (!empty($extra)) {
         foreach ($extra as $extra_key => $extra_value) {
             $rel->{$extra_key} = $extra_value;
         }
     }
     if (!$rel->create()) {
         debug_add("failed to create link from {$rel->fromClass} #{$rel->fromGuid} to {$rel->toClass} #{$rel->toGuid}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_WARN);
         return false;
     }
     return $rel;
 }