Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
UNRELEASED CHANGES:

* Add ability to create custom genders
* Add Annual plan for the .com site
* Fix avatar being invalid in the Contact API call
* DB_PREFIX is now blank in .env.example
Expand Down
37 changes: 22 additions & 15 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,8 @@
use DB;
use Laravel\Cashier\Billable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property User $user
* @property Collection|Activity[] $activities
* @property Collection|ActitivyStatistic[] $activityStatistics
* @property Collection|Contact[] $contacts
* @property Collection|Invitation[] $invitations
* @property Collection|Debt[] $debts
* @property Collection|Entry[] $entries
* @property Collection|Gift[] $gifts
* @property Collection|Event[] $events
* @property Collection|Note[] $notes
* @property Collection|Reminder[] $reminders
* @property Collection|Task[] $tasks
*/
class Account extends Model
{
use Billable;
Expand Down Expand Up @@ -274,6 +259,16 @@ public function days()
return $this->hasMany('App\Day');
}

/**
* Get the Genders records associated with the account.
*
* @return HasMany
*/
public function genders()
{
return $this->hasMany('App\Gender');
}

/**
* Check if the account can be downgraded, based on a set of rules.
*
Expand Down Expand Up @@ -427,6 +422,18 @@ public function populateContactFieldTypeTable($ignoreMigratedTable = false)
}
}

/**
* Populates the default genders in a new account.
*
* @return void
*/
public function populateDefaultGendersTable()
{
Gender::create(['name' => trans('app.gender_male'), 'account_id' => $this->id]);
Gender::create(['name' => trans('app.gender_female'), 'account_id' => $this->id]);
Gender::create(['name' => trans('app.gender_none'), 'account_id' => $this->id]);
}

/**
* Get the reminders for the month given in parameter.
* - 0 means current month
Expand Down
12 changes: 11 additions & 1 deletion app/Console/Commands/ImportCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public function handle()

$this->info("Importing CSV file $file to user {$user->id}");

// create special gender for this import
// we don't know which gender all the contacts are, so we need to create a special status for them, as we
// can't guess whether they are men, women or else.
$gender = new Gender;
$gender->account_id = $user->account_id;
$gender->name = 'vCard';
$gender->save();

$row = 0;
$imported = 0;
if (($handle = fopen($file, 'r')) !== false) {
Expand All @@ -73,7 +81,7 @@ public function handle()
}

$contact = new Contact();
$contact->account_id = $user->id;
$contact->account_id = $user->account_id;

// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
Expand Down Expand Up @@ -123,6 +131,8 @@ public function handle()
$contact->email = null;
}

$contact->gender_id = $gender->id;

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

Expand Down
12 changes: 11 additions & 1 deletion app/Console/Commands/ImportVCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use App\User;
use App\Gender;
use App\Address;
use App\Contact;
use App\Country;
Expand All @@ -28,6 +29,7 @@ class ImportVCards extends Command
* @var string
*/
protected $description = 'Imports contacts from vCard files for a specific user';
protected $gender;

/**
* Create a new command instance.
Expand Down Expand Up @@ -74,6 +76,14 @@ public function handle(Filesystem $filesystem)

$skippedContacts = 0;

// create special gender for this import
// we don't know which gender all the contacts are, so we need to create a special status for them, as we
// can't guess whether they are men, women or else.
$this->gender = new Gender;
$this->gender->account_id = $user->account_id;
$this->gender->name = 'vCard';
$this->gender->save();

collect($matches[0])->map(function ($vcard) {
return Reader::read($vcard);
})->each(function (VCard $vcard) use ($user, $skippedContacts) {
Expand Down Expand Up @@ -103,7 +113,7 @@ public function handle(Filesystem $filesystem)
$contact->first_name = $this->formatValue($vcard->NICKNAME);
}

$contact->gender = 'none';
$contact->gender_id = $this->gender->id;
$contact->job = $this->formatValue($vcard->ORG);

$contact->setAvatarColor();
Expand Down
12 changes: 11 additions & 1 deletion app/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Contact extends Model
'first_name',
'middle_name',
'last_name',
'gender',
'gender_id',
'account_id',
'is_partial',
'job',
Expand Down Expand Up @@ -106,6 +106,16 @@ public function account()
return $this->belongsTo('App\Account');
}

/**
* Get the gender of the contact.
*
* @return HasOne
*/
public function gender()
{
return $this->belongsTo('App\Gender');
}

/**
* Get the activity records associated with the contact.
*
Expand Down
65 changes: 65 additions & 0 deletions app/Gender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Gender extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
];

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'account_id',
];

/**
* Get the account record associated with the gift.
*
* @return BelongsTo
*/
public function account()
{
return $this->belongsTo(Account::class);
}

/**
* Get the contact records associated with the gift.
*
* @return BelongsTo
*/
public function contacts()
{
return $this->hasMany(Contact::class);
}

/**
* Get the name of the gender.
*
* @param string $value
* @return string
*/
public function getNameAttribute($value)
{
return $value;
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/ApiContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function store(Request $request)
$validator = Validator::make($request->all(), [
'first_name' => 'required|max:50',
'last_name' => 'nullable|max:100',
'gender' => 'required',
'gender_id' => 'integer|required',
'birthdate' => 'nullable|date',
'birthdate_is_age_based' => 'boolean',
'birthdate_is_year_unknown' => 'boolean',
Expand Down Expand Up @@ -103,7 +103,7 @@ public function store(Request $request)
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
'job',
'company',
'food_preferencies',
Expand Down Expand Up @@ -210,7 +210,7 @@ public function update(Request $request, $contactId)
$validator = Validator::make($request->all(), [
'first_name' => 'required|max:50',
'last_name' => 'nullable|max:100',
'gender' => 'required',
'gender_id' => 'integer|required',
'birthdate' => 'nullable|date',
'birthdate_is_age_based' => 'nullable|boolean',
'birthdate_is_year_unknown' => 'nullable|boolean',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected function create(array $data)
$user->save();

$account->populateContactFieldTypeTable();
$account->populateDefaultGendersTable();

// send me an alert
dispatch(new SendNewUserAlert($user));
Expand Down
12 changes: 7 additions & 5 deletions app/Http/Controllers/Contacts/KidsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function create(Contact $contact)
{
return view('people.dashboard.kids.add')
->withContact($contact)
->withKid(new Contact);
->withKid(new Contact)
->withGenders(auth()->user()->account->genders);
}

/**
Expand All @@ -51,7 +52,7 @@ public function store(KidsRequest $request, Contact $contact)
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
])
+ [
'account_id' => $contact->account_id,
Expand All @@ -66,7 +67,7 @@ public function store(KidsRequest $request, Contact $contact)
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
])
+ [
'account_id' => $contact->account_id,
Expand Down Expand Up @@ -126,7 +127,8 @@ public function edit(Contact $contact, Contact $kid)
{
return view('people.dashboard.kids.edit')
->withContact($contact)
->withKid($kid);
->withKid($kid)
->withGenders(auth()->user()->account->genders);
}

/**
Expand All @@ -143,7 +145,7 @@ public function update(KidsRequest $request, Contact $contact, Contact $kid)
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
])
+ [
'account_id' => $contact->account_id,
Expand Down
12 changes: 7 additions & 5 deletions app/Http/Controllers/Contacts/RelationshipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function create(Contact $contact)
{
return view('people.relationship.add')
->withContact($contact)
->withPartner(new Contact);
->withPartner(new Contact)
->withGenders(auth()->user()->account->genders);
}

/**
Expand All @@ -50,7 +51,7 @@ public function store(RelationshipsRequest $request, Contact $contact)
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
])
+ [
'account_id' => $contact->account_id,
Expand All @@ -65,7 +66,7 @@ public function store(RelationshipsRequest $request, Contact $contact)
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
])
+ [
'account_id' => $contact->account_id,
Expand Down Expand Up @@ -125,7 +126,8 @@ public function edit(Contact $contact, Contact $partner)
{
return view('people.relationship.edit')
->withContact($contact)
->withPartner($partner);
->withPartner($partner)
->withGenders(auth()->user()->account->genders);
}

/**
Expand All @@ -142,7 +144,7 @@ public function update(RelationshipsRequest $request, Contact $contact, Contact
$request->only([
'first_name',
'last_name',
'gender',
'gender_id',
])
+ [
'account_id' => $contact->account_id,
Expand Down
Loading