Beispiel #1
0
/**
 * Get the departement group name from the postal code
 * @return a string that contains the departement group name
 */
function get_departemental_group_name_from_postalcode($country, $postalcode)
{
    if ($country == 'France') {
        $departements = get_departement_data();
        $depnum = get_departement_number_from_postal_code($postalcode);
        if ($depnum) {
            return "{$depnum} - " . $departements[$depnum];
        }
    }
    return false;
}
Beispiel #2
0
/**
 * Create all local groups
 */
function create_local_groups()
{
    // first, creates country groups
    $countrygroup_guid = array();
    $options["type"] = 'group';
    $options["limit"] = NULL;
    $options["metadata_name_value_pairs"][] = array("name" => 'grouptype', "value" => 'local');
    $options["metadata_name_value_pairs"][] = array("name" => 'localtype', "value" => 'national');
    $existing_countrygroups = elgg_get_entities_from_metadata($options);
    $country_data = get_country_data();
    foreach ($country_data as $country) {
        if (!is_group_name_existing($country, $existing_countrygroups)) {
            $group = new ElggGroup();
            $group->name = $country;
            $group->description = "";
            $group->grouptype = 'local';
            $group->localtype = 'national';
            $group->membership = ACCESS_PUBLIC;
            $group->access_id = ACCESS_LOGGED_IN;
            $group->save();
            $countrygroup_guid[$country] = $group->guid;
        }
    }
    // then, creates departement groups
    $depgroup_guids = array();
    $options["type"] = 'group';
    $options["limit"] = NULL;
    $options["metadata_name_value_pairs"][] = array("name" => 'grouptype', "value" => 'local');
    $options["metadata_name_value_pairs"][] = array("name" => 'localtype', "value" => 'departemental');
    $existing_depgroups = elgg_get_entities_from_metadata($options);
    $departements_data = get_departement_data();
    foreach ($departements_data as $num => $name) {
        $groupname = $num . " - " . $name;
        if (!is_group_name_existing($groupname, $existing_depgroups)) {
            $group = new ElggGroup();
            $group->name = $groupname;
            $group->description = "";
            $group->grouptype = 'local';
            $group->localtype = 'departemental';
            $group->membership = ACCESS_PUBLIC;
            $group->access_id = ACCESS_LOGGED_IN;
            $group->save();
            $depgroup_guids[$num] = $group->guid;
        }
    }
    // finally, creates region groups
    $options["metadata_name_value_pairs"] = array(array('name' => 'grouptype', 'value' => 'local', 'operand' => '=', 'case_sensitive' => TRUE), array('name' => 'localtype', 'value' => 'regional', 'operand' => '=', 'case_sensitive' => TRUE));
    $existing_region_groups = elgg_get_entities_from_metadata($options);
    $regions_data = get_region_data();
    foreach ($regions_data as $name => $dep_nums) {
        if (!is_group_name_existing($name, $existing_region_groups)) {
            $group = new ElggGroup();
            $group->name = $name;
            $group->grouptype = 'local';
            $group->localtype = 'regional';
            $group->membership = ACCESS_PUBLIC;
            $group->access_id = ACCESS_LOGGED_IN;
            $group->save();
            //add relationship with departement groups
            foreach ($dep_nums as $num) {
                $depgroup = get_entity($depgroup_guids[$num]);
                if ($depgroup) {
                    $group->addRelationship($depgroup->guid, 'child');
                    $depgroup->addRelationship($group->guid, 'parent');
                    $depgroup->save();
                }
            }
            // add relationship with country group
            $countrygroup = get_entity($countrygroup_guid['France']);
            if ($countrygroup) {
                $countrygroup->addRelationship($group->guid, 'child');
                $group->addRelationship($countrygroup->guid, 'parent');
                $countrygroup->save();
            }
            $group->save();
        }
    }
}