예제 #1
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();
 }
예제 #2
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;
 }