コード例 #1
0
ファイル: roleTest.php プロジェクト: nemein/openpsa
 public function testCRUD()
 {
     $salesproject = $this->create_object('org_openpsa_sales_salesproject_dba');
     $person1 = $this->create_object('midcom_db_person');
     $person2 = $this->create_object('midcom_db_person');
     midcom::get('auth')->request_sudo('org.openpsa.contacts');
     $member1 = new org_openpsa_contacts_role_dba();
     $member1->objectGuid = $salesproject->guid;
     $member1->person = $person1->id;
     $member1->role = ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER;
     $stat = $member1->create();
     $this->assertTrue($stat);
     $this->register_object($member1);
     $this->assertEquals(ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER, $member1->role);
     $this->assertEquals(array($person1->id => true), $salesproject->contacts);
     $stat = $member1->delete();
     $this->assertTrue($stat);
     $stat = org_openpsa_contacts_role_dba::add($salesproject->guid, $person2->id, ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER);
     $this->assertTrue($stat);
     $qb = org_openpsa_contacts_role_dba::new_query_builder();
     $qb->add_constraint('objectGuid', '=', $salesproject->guid);
     $this->assertEquals(1, $qb->count());
     $members = $qb->execute();
     $member2 = $members[0];
     $this->assertEquals(ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER, $member2->role);
     $this->assertEquals($person2->id, $member2->person);
     $salesproject->refresh();
     $this->assertEquals(array($person2->id => true), $salesproject->contacts);
     $stat = $member2->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
コード例 #2
0
ファイル: resource.php プロジェクト: nemein/openpsa
 /**
  * Helper function that adds a member to parents if necessary
  *
  * @param org_openpsa_projects_task_dba $object The object for which we search the parent
  */
 function add_resource_to_parent(&$object)
 {
     $parent = $object->get_parent();
     if (!$parent) {
         return;
     }
     if (is_a($parent, 'org_openpsa_projects_project')) {
         org_openpsa_contacts_role_dba::add($parent->guid, $this->person, $this->orgOpenpsaObtype);
         return;
     }
     $mc = self::new_collector('task', $parent->id);
     $mc->add_constraint('orgOpenpsaObtype', '=', $this->orgOpenpsaObtype);
     $mc->add_constraint('person', '=', $this->person);
     $mc->execute();
     if ($mc->count() > 0) {
         //Resource is already present, aborting
         return;
     }
     $new_resource = new org_openpsa_projects_task_resource_dba();
     $new_resource->person = $this->person;
     $new_resource->orgOpenpsaObtype = $this->orgOpenpsaObtype;
     $new_resource->task = $parent->id;
     $new_resource->create();
 }
コード例 #3
0
ファイル: salesproject.php プロジェクト: nemein/openpsa
 /**
  * Populates contacts as resources lists
  */
 function get_members()
 {
     if (!$this->id) {
         return false;
     }
     $this->_contacts = array();
     $mc = org_openpsa_contacts_role_dba::new_collector('objectGuid', $this->guid);
     $mc->add_constraint('role', '=', ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER);
     $members = $mc->get_values('person');
     foreach ($members as $member) {
         $this->_contacts[$member] = true;
     }
     if ($this->customerContact) {
         $this->_contacts[$this->customerContact] = true;
     }
     return true;
 }
コード例 #4
0
ファイル: project.php プロジェクト: nemein/openpsa
 /**
  * Populates contacts as resources lists
  */
 function get_members()
 {
     if (!$this->guid) {
         return false;
     }
     if (!is_array($this->contacts)) {
         $this->contacts = array();
     }
     if (!is_array($this->resources)) {
         $this->resources = array();
     }
     $mc = org_openpsa_contacts_role_dba::new_collector('objectGuid', $this->guid);
     $mc->add_value_property('role');
     $mc->add_value_property('person');
     $mc->add_constraint('role', '<>', ORG_OPENPSA_OBTYPE_PROJECTPROSPECT);
     $mc->execute();
     $ret = $mc->list_keys();
     if (is_array($ret) && count($ret) > 0) {
         foreach ($ret as $guid => $empty) {
             switch ($mc->get_subkey($guid, 'role')) {
                 case ORG_OPENPSA_OBTYPE_PROJECTCONTACT:
                     $varName = 'contacts';
                     break;
                 default:
                     //fall-trough intentional
                 //fall-trough intentional
                 case ORG_OPENPSA_OBTYPE_PROJECTRESOURCE:
                     $varName = 'resources';
                     break;
             }
             $this->{$varName}[$mc->get_subkey($guid, 'person')] = true;
         }
     }
     return true;
 }
コード例 #5
0
ファイル: interfaces.php プロジェクト: nemein/openpsa
 /**
  * Used by org_openpsa_relatedto_find_suspects to in case the given object is a person
  */
 private function _org_openpsa_relatedto_find_suspects_person(&$object, &$defaults, &$links_array)
 {
     $seen_sp = array();
     $mc = org_openpsa_contacts_role_dba::new_collector('role', ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER);
     $mc->add_constraint('person', '=', array_keys($object->id));
     $guids = $mc->get_values('objectGuid');
     if (!empty($guids)) {
         $qb = org_openpsa_sales_salesproject_dba::new_query_builder();
         $qb->add_constraint('status', '=', org_openpsa_sales_salesproject_dba::STATUS_ACTIVE);
         $qb->add_constraint('guid', 'IN', $guids);
         $qbret = @$qb->execute();
         if (is_array($qbret)) {
             foreach ($qbret as $salesproject) {
                 if (isset($seen_sp[$salesproject->id])) {
                     //Only process one salesproject once (someone might be both resource and contact for example)
                     continue;
                 }
                 $seen_sp[$salesproject->id] = true;
                 $to_array = array('other_obj' => false, 'link' => false);
                 $link = new org_openpsa_relatedto_dba();
                 org_openpsa_relatedto_suspect::defaults_helper($link, $defaults, $this->_component, $salesproject);
                 $to_array['other_obj'] = $salesproject;
                 $to_array['link'] = $link;
                 $links_array[] = $to_array;
             }
         }
     }
     $qb2 = org_openpsa_sales_salesproject_dba::new_query_builder();
     $qb2->add_constraint('owner', '=', $object->id);
     $qb2->add_constraint('status', '=', org_openpsa_sales_salesproject_dba::STATUS_ACTIVE);
     $qb2ret = @$qb2->execute();
     if (is_array($qb2ret)) {
         foreach ($qb2ret as $sp) {
             if (isset($seen_sp[$sp->id])) {
                 //Only process one task once (someone might be both resource and contact for example)
                 continue;
             }
             $seen_sp[$sp->id] = true;
             $to_array = array('other_obj' => false, 'link' => false);
             $link = new org_openpsa_relatedto_dba();
             org_openpsa_relatedto_suspect::defaults_helper($link, $defaults, $this->_component, $sp);
             $to_array['other_obj'] = $sp;
             $to_array['link'] = $link;
             $links_array[] = $to_array;
         }
     }
 }