Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
More fixes
  • Loading branch information
asbiin committed Feb 25, 2018
commit 76c5200e716e080e6457a364674fbb59f393b41b
10 changes: 4 additions & 6 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,10 @@ public function getRemindersForMonth(int $month)
{
$startOfMonth = \Carbon\Carbon::now()->addMonthsNoOverflow($month)->startOfMonth();
$endInThreeMonths = \Carbon\Carbon::now()->addMonthsNoOverflow($month)->endOfMonth();
$reminders = auth()->user()->account->reminders()
->whereBetween('next_expected_date', [$startOfMonth, $endInThreeMonths])
->orderBy('next_expected_date', 'asc')
->get();

return $reminders;
return auth()->user()->account->reminders()
->whereBetween('next_expected_date', [$startOfMonth, $endInThreeMonths])
->orderBy('next_expected_date', 'asc')
->get();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions app/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function getContactsForAPI()
*/
public function getInfoForJournalEntry()
{
$data = [
return [
'type' => 'activity',
'id' => $this->id,
'activity_type' => (! is_null($this->type) ? $this->type->getTranslationKeyAsString() : null),
Expand All @@ -173,7 +173,5 @@ public function getInfoForJournalEntry()
'year' => $this->date_it_happened->year,
'attendees' => $this->getContactsForAPI(),
];

return $data;
}
}
17 changes: 3 additions & 14 deletions app/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,7 @@ public function getFirstProgenitor()
$offspring = Offspring::where('contact_id', $this->id)
->first();

$progenitor = self::findOrFail($offspring->is_the_child_of);

return $progenitor;
return self::findOrFail($offspring->is_the_child_of);
}

/**
Expand All @@ -1234,9 +1232,7 @@ public function getFirstPartner()
$relationship = Relationship::where('with_contact_id', $this->id)
->first();

$relationship = self::findOrFail($relationship->contact_id);

return $relationship;
return self::findOrFail($relationship->contact_id);
}

/**
Expand All @@ -1245,14 +1241,7 @@ public function getFirstPartner()
*/
public function isOwedMoney()
{
return $this
->debts()
->where('status', '=', 'inprogress')
->getResults()
->sum(function ($d) {
return $d->in_debt === 'yes' ? -$d->amount : $d->amount;
})
> 0;
return totalOutstandingDebtAmount() > 0;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions app/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getCommentAttribute($value)
*/
public function getInfoForJournalEntry()
{
$data = [
return [
'type' => 'day',
'id' => $this->id,
'rate' => $this->rate,
Expand All @@ -77,7 +77,5 @@ public function getInfoForJournalEntry()
'year' => $this->date->year,
'happens_today' => $this->date->isToday(),
];

return $data;
}
}
4 changes: 1 addition & 3 deletions app/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getPostAttribute($value)
*/
public function getInfoForJournalEntry()
{
$data = [
return [
'type' => 'activity',
'id' => $this->id,
'title' => $this->title,
Expand All @@ -76,7 +76,5 @@ public function getInfoForJournalEntry()
'month_name' => \App\Helpers\DateHelper::getShortMonth($this->created_at),
'year' => $this->created_at->year,
];

return $data;
}
}
4 changes: 1 addition & 3 deletions app/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class DateHelper
*/
public static function createDateFromFormat($date, $timezone)
{
$date = Carbon::createFromFormat('Y-m-d H:i:s', $date, $timezone);

return $date;
return Carbon::createFromFormat('Y-m-d H:i:s', $date, $timezone);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions app/Helpers/InstanceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class InstanceHelper
*/
public static function getNumberOfPaidSubscribers()
{
$paidAccounts = Account::where('stripe_id', '!=', null)->count();

return $paidAccounts;
return Account::where('stripe_id', '!=', null)->count();
}

/**
Expand All @@ -30,14 +28,12 @@ public static function getPlanInformationFromConfig(String $timePeriod)
return;
}

$planInformation = [
return [
'type' => $timePeriod,
'name' => config('monica.paid_plan_'.$timePeriod.'_friendly_name'),
'id' => config('monica.paid_plan_'.$timePeriod.'_id'),
'price' => config('monica.paid_plan_'.$timePeriod.'_price'),
'friendlyPrice' => config('monica.paid_plan_'.$timePeriod.'_price') / 100,
];

return $planInformation;
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/ActivitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function store(ActivitiesRequest $request, Contact $contact)
}

// Log a journal entry
$journalEntry = (new JournalEntry)->add($activity);
(new JournalEntry)->add($activity);

return redirect('/people/'.$contact->id)
->with('success', trans('people.activities_add_success'));
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/ApiActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function store(Request $request)
}

// Log a journal entry
$journalEntry = (new JournalEntry)->add($activity);
(new JournalEntry)->add($activity);

// Now we associate the activity with each one of the attendees
$attendeesID = $request->get('contacts');
Expand Down Expand Up @@ -167,7 +167,7 @@ public function update(Request $request, $activityId)

// Log a journal entry but need to delete the previous one first
$activity->deleteJournalEntry();
$journalEntry = (new JournalEntry)->add($activity);
(new JournalEntry)->add($activity);

// Get the attendees
$attendees = $request->get('contacts');
Expand Down
50 changes: 19 additions & 31 deletions app/Http/Controllers/Api/ApiContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,14 @@ public function store(Request $request)
// in this case, we know the month and day, but not necessarily the year
$date = \Carbon\Carbon::parse($request->get('birthdate'));

if ($request->get('birthdate_is_year_unknown') == true) {
if ($request->get('birthdate_is_year_unknown')) {
$specialDate = $contact->setSpecialDate('birthdate', 0, $date->month, $date->day);
} else {
$specialDate = $contact->setSpecialDate('birthdate', $date->year, $date->month, $date->day);
$newReminder = $specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
} else {
if ($request->get('birthdate_is_age_based') == true) {
$specialDate = $contact->setSpecialDateFromAge('birthdate', $request->input('birthdate_age'));
}
} else if ($request->get('birthdate_is_age_based')) {
$specialDate = $contact->setSpecialDateFromAge('birthdate', $request->input('birthdate_age'));
}

// first met date
Expand All @@ -156,16 +154,14 @@ public function store(Request $request)
// in this case, we know the month and day, but not necessarily the year
$date = \Carbon\Carbon::parse($request->get('first_met_date'));

if ($request->get('first_met_date_is_year_unknown') == true) {
if ($request->get('first_met_date_is_year_unknown')) {
$specialDate = $contact->setSpecialDate('first_met', 0, $date->month, $date->day);
} else {
$specialDate = $contact->setSpecialDate('first_met', $date->year, $date->month, $date->day);
$newReminder = $specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
} else {
if ($request->get('first_met_date_is_age_based') == true) {
$specialDate = $contact->setSpecialDateFromAge('first_met', $request->input('first_met_date_age'));
}
} else if ($request->get('first_met_date_is_age_based')) {
$specialDate = $contact->setSpecialDateFromAge('first_met', $request->input('first_met_date_age'));
}

// deceased date
Expand All @@ -174,16 +170,14 @@ public function store(Request $request)
// in this case, we know the month and day, but not necessarily the year
$date = \Carbon\Carbon::parse($request->get('deceased_date'));

if ($request->get('deceased_date_is_year_unknown') == true) {
if ($request->get('deceased_date_is_year_unknown')) {
$specialDate = $contact->setSpecialDate('deceased_date', 0, $date->month, $date->day);
} else {
$specialDate = $contact->setSpecialDate('deceased_date', $date->year, $date->month, $date->day);
$newReminder = $specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
} else {
if ($request->get('deceased_date_is_age_based') == true) {
$specialDate = $contact->setSpecialDateFromAge('deceased_date', $request->input('deceased_date_age'));
}
} else if ($request->get('deceased_date_is_age_based')) {
$specialDate = $contact->setSpecialDateFromAge('deceased_date', $request->input('deceased_date_age'));
}

$contact->setAvatarColor();
Expand Down Expand Up @@ -274,16 +268,14 @@ public function update(Request $request, $contactId)
// in this case, we know the month and day, but not necessarily the year
$date = \Carbon\Carbon::parse($request->get('birthdate'));

if ($request->get('birthdate_is_year_unknown') == true) {
if ($request->get('birthdate_is_year_unknown')) {
$specialDate = $contact->setSpecialDate('birthdate', 0, $date->month, $date->day);
} else {
$specialDate = $contact->setSpecialDate('birthdate', $date->year, $date->month, $date->day);
$newReminder = $specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
} else {
if ($request->get('birthdate_is_age_based') == true) {
$specialDate = $contact->setSpecialDateFromAge('birthdate', $request->input('birthdate_age'));
}
} else if ($request->get('birthdate_is_age_based')) {
$specialDate = $contact->setSpecialDateFromAge('birthdate', $request->input('birthdate_age'));
}

// first met date
Expand All @@ -293,16 +285,14 @@ public function update(Request $request, $contactId)
// in this case, we know the month and day, but not necessarily the year
$date = \Carbon\Carbon::parse($request->get('first_met_date'));

if ($request->get('first_met_date_is_year_unknown') == true) {
if ($request->get('first_met_date_is_year_unknown')) {
$specialDate = $contact->setSpecialDate('first_met', 0, $date->month, $date->day);
} else {
$specialDate = $contact->setSpecialDate('first_met', $date->year, $date->month, $date->day);
$newReminder = $specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
} else {
if ($request->get('first_met_date_is_age_based') == true) {
$specialDate = $contact->setSpecialDateFromAge('first_met', $request->input('first_met_date_age'));
}
} else if ($request->get('first_met_date_is_age_based')) {
$specialDate = $contact->setSpecialDateFromAge('first_met', $request->input('first_met_date_age'));
}

// deceased date
Expand All @@ -312,16 +302,14 @@ public function update(Request $request, $contactId)
// in this case, we know the month and day, but not necessarily the year
$date = \Carbon\Carbon::parse($request->get('deceased_date'));

if ($request->get('deceased_date_is_year_unknown') == true) {
if ($request->get('deceased_date_is_year_unknown')) {
$specialDate = $contact->setSpecialDate('deceased_date', 0, $date->month, $date->day);
} else {
$specialDate = $contact->setSpecialDate('deceased_date', $date->year, $date->month, $date->day);
$newReminder = $specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
} else {
if ($request->get('deceased_date_is_age_based') == true) {
$specialDate = $contact->setSpecialDateFromAge('deceased_date', $request->input('deceased_date_age'));
}
} else if ($request->get('deceased_date_is_age_based')) {
$specialDate = $contact->setSpecialDateFromAge('deceased_date', $request->input('deceased_date_age'));
}

$contact->logEvent('contact', $contact->id, 'update');
Expand Down Expand Up @@ -358,7 +346,7 @@ public function destroy(Request $request, $id)
}
}

if ($contactIdRowExists == true) {
if ($contactIdRowExists) {
DB::table($tableName)->where('contact_id', $contact->id)->delete();
}
}
Expand Down
13 changes: 6 additions & 7 deletions app/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApiController extends Controller
public function __construct()
{
$this->middleware(function ($request, $next) {
$apiUsage = (new ApiUsage)->log($request);
(new ApiUsage)->log($request);

if ($request->has('limit')) {
if ($request->get('limit') > config('api.max_limit_per_page')) {
Expand All @@ -40,12 +40,11 @@ public function __construct()

// make sure the JSON is well formatted if the given call sends a JSON
// TODO: there is probably a much better way to do that
if ($request->method() != 'GET' and $request->method() != 'DELETE') {
if (is_null(json_decode($request->getContent()))) {
return $this->setHTTPStatusCode(400)
->setErrorCode(37)
->respondWithError(config('api.error_codes.37'));
}
if ($request->method() != 'GET' && $request->method() != 'DELETE'
&& is_null(json_decode($request->getContent()))) {
return $this->setHTTPStatusCode(400)
->setErrorCode(37)
->respondWithError(config('api.error_codes.37'));
}

return $next($request);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Contacts/PetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function store(PetsRequest $request, Contact $contact)
]
);

return $data = [
return [
'id' => $pet->id,
'name' => $pet->name,
'pet_category_id' => $pet->pet_category_id,
Expand All @@ -93,7 +93,7 @@ public function update(PetsRequest $request, Contact $contact, Pet $pet)
]
);

return $data = [
return [
'id' => $pet->id,
'name' => $pet->name,
'pet_category_id' => $pet->pet_category_id,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function update(Request $request, Contact $contact)
->withErrors($validator);
}

if ($contact->setName($request->input('firstname'), null, $request->input('lastname')) == false) {
if (! $contact->setName($request->input('firstname'), null, $request->input('lastname'))) {
return back()
->withInput()
->withErrors('There has been a problem with saving the name.');
Expand Down
Loading