/** * Get all parties with a given roles */ public static function find_by_role($entity_data, $role) { $search_results = array(); // Get the role $role_type = EntityAPI::get_by_code('roletype', strtoupper($role)); // Process only if we got a valid response from the call above if (isset($role_type['id']) && isset($role_type['entity_code'])) { $party_ids = array(); // Search for all the party role type associations with the given role $party_roles = EntityAPI::find_by_criteria('partyrole', array('role' => $role_type['id'])); // Loop throug all the return party roles // and push the party id into list of parties foreach ($party_roles as $party_role) { array_push($party_ids, $party_role['party']); } // Doing all this shit cause I am not good at SQL :-( if (!empty($party_ids)) { $results = EntityAPI::find_by_ids_and_criteria('party', $party_ids); foreach ($results as $key => $party_data) { foreach ($party_roles as $party_role) { if ($party_data['id'] == $party_role['party']) { array_push($search_results, $party_data); } } } } } return $search_results; }
/** * */ public static function do_create_organization($entity_data) { $party_type = EntityAPI::get_by_code('partytype', PartyAPI::$non_individual_party_type); if (!isset($party_type['id'])) { return EntityAPIUtils::init_error($entity_data, 'Party type is required'); } // Create the party role $party_data = self::do_create_party($party_data, $party_type); if ($party_data['has_errors']) { return $party_data; } $organization_data = PartyGroupAPI::do_create_party_group($party_data, $entity_data); if (!isset($organization_data['id'])) { return EntityAPIUtils::init_error($party_data, 'Organization creation failed'); } return $party_data; }