Пример #1
0
 /**
  * This is what Datamanager calls to actually create a group
  */
 public function &dm2_create_callback(&$datamanager)
 {
     $this->_group = new org_openpsa_contacts_group_dba();
     if ($this->_type == 'organization' && $this->_parent_group) {
         $this->_group->owner = (int) $this->_parent_group->id;
     } else {
         $root_group = org_openpsa_contacts_interface::find_root_group();
         $this->_group->owner = (int) $root_group->id;
     }
     $this->_group->name = time();
     if (!$this->_group->create()) {
         debug_print_r('We operated on this object:', $this->_group);
         throw new midcom_error("Failed to create a new group. Error: " . midcom_connection::get_error_string());
     }
     return $this->_group;
 }
Пример #2
0
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('org.openpsa.contacts');
     $group = new org_openpsa_contacts_group_dba();
     $time = time();
     $group->name = 'TEST NAME' . $time;
     $stat = $group->create();
     $this->assertFalse($stat);
     $group->name = 'TEST-NAME' . $time;
     $stat = $group->create();
     $this->assertTrue($stat);
     $this->register_object($group);
     $this->assertEquals('TEST-NAME' . $time, $group->get_label());
     $this->assertEquals(org_openpsa_core_acl::ACCESS_PUBLIC, $group->orgOpenpsaAccesstype);
     $group->official = 'TEST OFFICIAL';
     $stat = $group->update();
     $this->assertTrue($stat);
     $this->assertEquals('TEST OFFICIAL', $group->get_label());
     $stat = $group->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Пример #3
0
 private function _get_group($autocreate = false)
 {
     if ($this->_group) {
         return $this->_group;
     }
     $qb = org_openpsa_contacts_list_dba::new_query_builder();
     $qb->add_constraint('person', '=', $this->_user->guid);
     $results = $qb->execute();
     if (sizeof($results) == 0) {
         if ($autocreate) {
             $this->_group = new org_openpsa_contacts_list_dba();
             $this->_group->person = $this->_user->guid;
             midcom::get('auth')->request_sudo('org.openpsa.contacts');
             $this->_group->create();
             $this->_group->set_privilege('midgard:owner', $this->_user->id, MIDCOM_PRIVILEGE_ALLOW);
             midcom::get('auth')->drop_sudo();
         } else {
             return false;
         }
     } else {
         $this->_group = $results[0];
     }
     return $this->_group;
 }
Пример #4
0
 private function _import_subscribers_organization($subscriber)
 {
     $organization = null;
     if (array_key_exists('official', $subscriber['organization']) && $subscriber['organization']['official']) {
         // Perform a simple check for existing organization. More complicated duplicate checking is best left to the o.o.contacts duplicate checker
         $qb = org_openpsa_contacts_group_dba::new_query_builder();
         if (array_key_exists('company_id', $this->_schemadbs['organization']['default']->fields) && array_key_exists('company_id', $subscriber['organization']) && $subscriber['organization']['company_id']) {
             // Imported data has a company id, we use that instead of name
             $qb->add_constraint($this->_schemadbs['organization']['default']->fields['company_id']['storage']['location'], '=', $subscriber['organization']['company_id']);
         } else {
             // Seek by official name
             $qb->add_constraint('official', '=', $subscriber['organization']['official']);
             if (array_key_exists('city', $this->_schemadbs['organization']['default']->fields) && array_key_exists('city', $subscriber['organization']) && $subscriber['organization']['city']) {
                 // Imported data has a city, we use also that for matching
                 $qb->add_constraint($this->_schemadbs['organization']['default']->fields['city']['storage']['location'], '=', $subscriber['organization']['city']);
             }
         }
         $organizations = $qb->execute_unchecked();
         if (count($organizations) > 0) {
             // Match found, use it
             // Use first match
             $organization = array_shift($organizations);
         }
     }
     if (!$organization) {
         // We didn't have person matching the email in DB. Create a new one.
         $organization = new org_openpsa_contacts_group_dba();
         if (!$organization->create()) {
             $this->_request_data['new_objects']['organization'] =& $organization;
             debug_add("Failed to create organization, reason " . midcom_connection::get_error_string());
             return null;
         }
     }
     if (!$this->_datamanager_process('organization', $subscriber, $organization)) {
         return null;
     }
     return $organization;
 }