Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 25, 2018
2 parents ff1798b + 243d315 commit 791ae61
Show file tree
Hide file tree
Showing 39 changed files with 4,536 additions and 250 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
UNRELEASED CHANGES:

* fix settings' sidebar links and change security icon
* Set currency and timezone for new users
* Fix settings' sidebar links and change security icon
* Fix CSV import

RELEASED VERSIONS:

Expand Down
7 changes: 6 additions & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ In the interest of fostering an open and welcoming environment, we as contributo

## Our Standards

We want everyone to be able to participate to our project no matter what they are or are from, as long as you don't bring drama or something irrelevant to the project. We are here to discuss Monica, its direction and the code around Monica - that's it. We will never judge someone, no matter the differences. On the contrary, we welcome differences. We will only judge the code that is submitted, and it will never be personal.

To summarize, don't be an ass - we are here to create something good, and something that is useful for the world. Don't bring your personal story and everything will be alright.

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
Expand All @@ -16,6 +20,7 @@ Examples of behavior that contributes to creating a positive environment include

Examples of unacceptable behavior by participants include:

* Discussion about politics, culture, gender, ethnicity,...
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
Expand All @@ -30,7 +35,7 @@ Project maintainers have the right and responsibility to remove, edit, or reject

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.

## Enforcement

Expand Down
105 changes: 88 additions & 17 deletions app/Console/Commands/ImportCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

use App\Models\User\User;
use App\Models\Contact\Gender;
use App\Models\Contact\Address;
use App\Models\Contact\Contact;
use Illuminate\Console\Command;
use App\Models\Contact\ContactField;
use App\Models\Contact\ContactFieldType;

class ImportCSV extends Command
{
Expand All @@ -23,6 +26,20 @@ class ImportCSV extends Command
*/
protected $description = 'Imports CSV in Google format to user account';

/**
* The contact field email object.
*
* @var array
*/
public $contactFieldEmailId;

/**
* The contact field phone object.
*
* @var array
*/
public $contactFieldPhoneId;

/**
* Execute the console command.
*
Expand Down Expand Up @@ -112,40 +129,64 @@ private function csvToContact($data, $account_id, $gender_id)
$contact->last_name = $data[3]; // Family Name
}

if (! empty($data[28])) {
$contact->email = $data[28]; // Email 1 Value
}

if (! empty($data[42])) {
$contact->phone_number = $data[42]; // Phone 1 Value
}

$street = null;
if (! empty($data[49])) {
$contact->street = $data[49]; // address 1 street
$street = $data[49]; // address 1 street
}

$city = null;
if (! empty($data[50])) {
$contact->city = $data[50]; // address 1 city
$city = $data[50]; // address 1 city
}

$province = null;
if (! empty($data[52])) {
$contact->province = $data[52]; // address 1 region (state)
$province = $data[52]; // address 1 region (state)
}

$postalCode = null;
if (! empty($data[53])) {
$contact->postal_code = $data[53]; // address 1 postal code (zip) 53
$postalCode = $data[53]; // address 1 postal code (zip) 53
}

if (! empty($data[66])) {
$contact->job = $data[66]; // organization 1 name 66
}

// can't have empty email
if (empty($contact->email)) {
$contact->email = null;
}

$contact->setAvatarColor();
$contact->save();

if (! empty($data[28])) {
// Email 1 Value
ContactField::firstOrCreate([
'account_id' => $contact->account_id,
'contact_id' => $contact->id,
'data' => $data[28],
'contact_field_type_id' => $this->contactFieldEmailId(),
]);
}

if ($postalCode || $province || $street || $city) {
Address::firstOrCreate([
'account_id' => $contact->account_id,
'contact_id' => $contact->id,
'street' => $street,
'city' => $city,
'province' => $province,
'postal_code' => $postalCode,
]);
}

if (! empty($data[42])) {
// Phone 1 Value
ContactField::firstOrCreate([
'account_id' => $contact->account_id,
'contact_id' => $contact->id,
'data' => $data[42],
'contact_field_type_id' => $this->contactFieldPhoneId(),
]);
}

if (! empty($data[14])) {
$birthdate = new \DateTime(strtotime($data[14]));

Expand All @@ -155,4 +196,34 @@ private function csvToContact($data, $account_id, $gender_id)

$contact->updateGravatar();
}

/**
* Get the default contact field email id for the account.
*
* @return int
*/
private function contactFieldEmailId()
{
if (! $this->contactFieldEmailId) {
$contactFieldType = ContactFieldType::where('type', 'email')->first();
$this->contactFieldEmailId = $contactFieldType->id;
}

return $this->contactFieldEmailId;
}

/**
* Get the default contact field phone id for the account.
*
* @return void
*/
private function contactFieldPhoneId()
{
if (! $this->contactFieldPhoneId) {
$contactFieldType = ContactFieldType::where('type', 'phone')->first();
$this->contactFieldPhoneId = $contactFieldType->id;
}

return $this->contactFieldPhoneId;
}
}
157 changes: 152 additions & 5 deletions app/Helpers/CountriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ public static function getAll()
return CollectionHelper::sortByCollator($countries, 'country');
}

/**
* Get country name.
*
* @param string $iso code of the country
* @return string common name (localized) of the country
*/
public static function get($iso)
{
$country = Countries::where('cca2', mb_strtoupper($iso))->first();
if ($country->count() === 0) {
$country = Countries::where('alt_spellings', mb_strtoupper($iso))->first();
}
if ($country->count() === 0) {
$country = self::getCountry($iso);
if (is_null($country)) {
return '';
}

return static::getCommonNameLocale($country);
}

/**
* Find a country by the (english) name of the country.
*
* @param string $name Common name of a country
* @return string cca2 code of the country
*/
public static function find($name)
{
$country = Countries::where('name.common', $name)->first();
Expand All @@ -50,6 +59,12 @@ public static function find($name)
return $country->cca2;
}

/**
* Get the common name of country, in locale version.
*
* @param string $country
* @return string
*/
private static function getCommonNameLocale($country)
{
$locale = App::getLocale();
Expand All @@ -59,4 +74,136 @@ private static function getCommonNameLocale($country)
array_get($country, 'name.common', '')
);
}

/**
* Get country for a specific iso code.
*
* @param string $iso
* @return object the Country element
*/
public static function getCountry($iso)
{
$country = Countries::where('cca2', mb_strtoupper($iso))->first();
if ($country->count() === 0) {
$country = Countries::where('alt_spellings', mb_strtoupper($iso))->first();
}
if ($country->count() === 0) {
return;
}

return $country;
}

/**
* Get country for a specific language.
*
* @param string $locale language code (iso)
* @return object the Country element
*/
public static function getCountryFromLocale($locale)
{
$countryCode = self::getDefaultCountryFromLocale($locale);

if (is_null($countryCode)) {
$lang = LocaleHelper::getLocaleAlpha($locale);
$country = Countries::whereLanguage($lang);
if ($country->count() === 0) {
return;
}
} else {
$country = Countries::where('cca3', $countryCode);
}

return $country->first();
}

/**
* Get default country for a language.
*
* @param string $locale language code (iso)
* @return string cca3 code
*/
private static function getDefaultCountryFromLocale($locale)
{
switch (mb_strtolower($locale)) {
case 'cs':
$country = 'CZE';
break;
case 'de':
$country = 'DEU';
break;
case 'en':
$country = 'USA';
break;
case 'es':
$country = 'ESP';
break;
case 'fr':
$country = 'FRA';
break;
case 'he':
$country = 'ISR';
break;
case 'it':
$country = 'ITA';
break;
case 'nl':
$country = 'NLD';
break;
case 'pt':
$country = 'PRT';
break;
case 'ru':
$country = 'RUS';
break;
case 'zh':
$country = 'CHN';
break;
default:
$country = null;
break;
}

return $country;
}

/**
* Get default timezone for the country.
*
* @param mixed $country Country element
* @return string timezone fo this sountry
*/
public static function getDefaultTimezone($country)
{
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
// https://en.wikipedia.org/wiki/List_of_time_zones_by_country
switch ($country->cca3) {
case 'AUS':
$timezone = 'Australia/Melbourne';
break;
case 'CHN':
$timezone = 'Asia/Shanghai';
break;
case 'ESP':
$timezone = 'Europe/Madrid';
break;
case 'PRT':
$timezone = 'Europe/Lisbon';
break;
case 'RUS':
$timezone = 'Europe/Moscow';
break;
case 'CAN':
$timezone = 'America/Toronto';
break;
case 'USA':
$timezone = 'America/Chicago';
break;
default:
$timezone = $country->hydrate('timezones')->timezones->first()->zone_name;
break;
}

return $timezone;
}
}
Loading

0 comments on commit 791ae61

Please sign in to comment.