Migrate to organization
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
APP_ENV=local
|
||||
APP_DEBUG=true
|
||||
APP_KEY=SomeRandomString
|
||||
APP_URL=http://localhost
|
||||
APP_LOG=daily
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=monica
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
DB_TEST_DATABASE=monica_test
|
||||
DB_TEST_USERNAME=homestead
|
||||
DB_TEST_PASSWORD=secret
|
||||
|
||||
CACHE_DRIVER=database
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
FACEBOOK_CLIENT_ID=
|
||||
FACEBOOK_CLIENT_SECRET_ID=
|
||||
FACEBOOK_REDIRECT_URL=
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
APP_ENV=testing
|
||||
APP_KEY=base64:NTrXToqFZJlv48dgPc+kNpc3SBt333TfDnF1mDShsBg=
|
||||
|
||||
DB_CONNECTION=testing
|
||||
DB_TEST_HOST=127.0.0.1
|
||||
DB_TEST_DATABASE=monica
|
||||
DB_TEST_USERNAME=root
|
||||
DB_TEST_PASSWORD=
|
||||
|
||||
CACHE_DRIVER=array
|
||||
SESSION_DRIVER=array
|
||||
QUEUE_DRIVER=sync
|
||||
@@ -0,0 +1,3 @@
|
||||
* text=auto
|
||||
*.css linguist-vendored
|
||||
*.scss linguist-vendored
|
||||
@@ -0,0 +1,8 @@
|
||||
/vendor
|
||||
/resources/vendor
|
||||
/node_modules
|
||||
/public/storage
|
||||
Homestead.yaml
|
||||
Homestead.json
|
||||
.env
|
||||
monica.sublime-workspace
|
||||
@@ -0,0 +1,94 @@
|
||||
options:
|
||||
formatter: stylish
|
||||
files:
|
||||
include: '**/*.s+(a|c)ss'
|
||||
rules:
|
||||
# Extends
|
||||
extends-before-mixins: 1
|
||||
extends-before-declarations: 1
|
||||
placeholder-in-extend: 1
|
||||
|
||||
# Mixins
|
||||
mixins-before-declarations: 1
|
||||
|
||||
# Line Spacing
|
||||
one-declaration-per-line: 1
|
||||
empty-line-between-blocks: 1
|
||||
single-line-per-selector: 1
|
||||
|
||||
# Disallows
|
||||
no-attribute-selectors: 0
|
||||
no-color-hex: 0
|
||||
no-color-keywords: 1
|
||||
no-color-literals: 0
|
||||
no-combinators: 0
|
||||
no-css-comments: 1
|
||||
no-debug: 1
|
||||
no-disallowed-properties: 0
|
||||
no-duplicate-properties: 1
|
||||
no-empty-rulesets: 1
|
||||
no-extends: 0
|
||||
no-ids: 1
|
||||
no-important: 1
|
||||
no-invalid-hex: 1
|
||||
no-mergeable-selectors: 1
|
||||
no-misspelled-properties: 1
|
||||
no-qualifying-elements: 1
|
||||
no-trailing-whitespace: 1
|
||||
no-trailing-zero: 1
|
||||
no-transition-all: 1
|
||||
no-universal-selectors: 0
|
||||
no-url-protocols: 1
|
||||
no-vendor-prefixes: 1
|
||||
no-warn: 1
|
||||
property-units: 0
|
||||
|
||||
# Nesting
|
||||
force-attribute-nesting: 3
|
||||
force-element-nesting: 1
|
||||
force-pseudo-nesting: 1
|
||||
|
||||
# Name Formats
|
||||
class-name-format: 1
|
||||
function-name-format: 1
|
||||
id-name-format: 0
|
||||
mixin-name-format: 1
|
||||
placeholder-name-format: 1
|
||||
variable-name-format: 1
|
||||
|
||||
# Style Guide
|
||||
attribute-quotes: 1
|
||||
bem-depth: 0
|
||||
border-zero: 1
|
||||
brace-style: 1
|
||||
clean-import-paths: 1
|
||||
empty-args: 1
|
||||
hex-length: 1
|
||||
hex-notation: 1
|
||||
indentation: 1
|
||||
leading-zero: 1
|
||||
nesting-depth:
|
||||
- 1
|
||||
-
|
||||
max-depth: 5
|
||||
property-sort-order: 1
|
||||
pseudo-element: 1
|
||||
quotes: 1
|
||||
shorthand-values: 1
|
||||
url-quotes: 1
|
||||
variable-for-property: 1
|
||||
zero-unit: 1
|
||||
|
||||
# Inner Spacing
|
||||
space-after-comma: 1
|
||||
space-before-colon: 1
|
||||
space-after-colon: 1
|
||||
space-before-brace: 1
|
||||
space-before-bang: 1
|
||||
space-after-bang: 1
|
||||
space-between-parens: 1
|
||||
space-around-operator: 1
|
||||
|
||||
# Final Items
|
||||
trailing-semicolon: 1
|
||||
final-newline: 1
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
services:
|
||||
- mysql
|
||||
|
||||
before_script:
|
||||
- cp .env.travis .env
|
||||
- mysql -e 'create database monica;'
|
||||
- composer self-update
|
||||
- composer install --no-interaction
|
||||
|
||||
script:
|
||||
- php artisan migrate --env=testing --no-interaction -vvv
|
||||
- php artisan db:seed --env=testing --no-interaction -vvv
|
||||
- vendor/bin/phpunit
|
||||
@@ -0,0 +1,45 @@
|
||||
## Contributing
|
||||
|
||||
First off, thank you for considering contributing to Monica. We need people like
|
||||
you to make Monica the best tool it can be.
|
||||
|
||||
### 1. Where do I go from here?
|
||||
|
||||
If you've noticed a bug or have a question, [make an issue](https://github.com/djaiss/monica/issues/new),
|
||||
we'll try to answer it as fast as possible.
|
||||
|
||||
### 2. Fork & create a branch
|
||||
|
||||
If this is something you think you can fix, then
|
||||
[fork Monica](https://help.github.com/articles/fork-a-repo)
|
||||
and create a branch with a descriptive name.
|
||||
|
||||
A good branch name would be (where issue #325 is the ticket you're working on):
|
||||
|
||||
```sh
|
||||
git checkout -b 325-add-japanese-translations
|
||||
```
|
||||
|
||||
### 3. Get the test suite running
|
||||
|
||||
Make sure you follow the [readme's instructions](https://github.com/djaiss/monica#setup-the-testing-environment)
|
||||
on how to setup the test suite.
|
||||
|
||||
#### 4. Did you find a bug?
|
||||
|
||||
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/djaiss/monica/issues).
|
||||
|
||||
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/djaiss/monica/issues/new).
|
||||
Be sure to include a **title and clear description**, as much relevant
|
||||
information as possible, and a **code sample** or an **executable test case**
|
||||
demonstrating the expected behavior that is not occurring.
|
||||
|
||||
### 5. Implement your fix or feature
|
||||
|
||||
At this point, you're ready to make your changes! Feel free to ask for help;
|
||||
everyone is a beginner at first :smile_cat:
|
||||
|
||||
### 6. What can I contribute to?
|
||||
|
||||
Even the simplest change is appreciated. It can be a typo error, translating the
|
||||
application in a new language, fix a bug. No change is too small.
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Régis Freyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,2 @@
|
||||
web: vendor/bin/heroku-php-nginx -C nginx_app.conf /public
|
||||
queue: php artisan queue:work --sleep=3 --tries=3
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Account extends Model
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\ActivityType;
|
||||
use App\Helpers\DateHelper;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Events\Activity\ActivityCreated;
|
||||
use App\Events\Activity\ActivityDeleted;
|
||||
use App\Events\Activity\ActivityUpdated;
|
||||
|
||||
class Activity extends Model
|
||||
{
|
||||
protected $table = 'activities';
|
||||
|
||||
protected $dates = ['date_it_happened'];
|
||||
|
||||
protected $events = [
|
||||
'created' => ActivityCreated::class,
|
||||
'updated' => ActivityUpdated::class,
|
||||
'deleted' => ActivityDeleted::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the description for this activity.
|
||||
*
|
||||
* @return string or null
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (is_null($this->description)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date the activity happened.
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getDateItHappened()
|
||||
{
|
||||
return $this->date_it_happened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key of the title of the activity.
|
||||
*
|
||||
* @return string or null
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
$activityType = ActivityType::find($this->activity_type_id);
|
||||
|
||||
return $activityType->key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityStatistic extends Model
|
||||
{
|
||||
protected $table = 'activity_statistics';
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\ActivityTypeGroup;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityType extends Model
|
||||
{
|
||||
protected $table = 'activity_types';
|
||||
|
||||
public function getTranslationKeyAsString()
|
||||
{
|
||||
return trans('people.activity_type_'.$this->key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityTypeGroup extends Model
|
||||
{
|
||||
protected $table = 'activity_type_groups';
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Statistic;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CalculateStatistics extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monica:calculatestatistics';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Calculate general usage statistics';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$statistic = new Statistic;
|
||||
$statistic->number_of_users = DB::table('users')->count();
|
||||
$statistic->number_of_contacts = DB::table('contacts')->count();
|
||||
$statistic->number_of_notes = DB::table('notes')->count();
|
||||
$statistic->number_of_reminders = DB::table('reminders')->count();
|
||||
$statistic->number_of_tasks = DB::table('tasks')->count();
|
||||
$statistic->number_of_kids = DB::table('kids')->count();
|
||||
$statistic->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Kid;
|
||||
use App\Note;
|
||||
use App\Task;
|
||||
use App\Contact;
|
||||
use App\Reminder;
|
||||
use App\SignificantOther;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class EncryptAllTheThings extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monica:encryptallthethings';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'ONE TIME USE ONLY - Encrypt all the data in the database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
// CONTACTS
|
||||
//
|
||||
$contacts = Contact::all();
|
||||
foreach ($contacts as $contact) {
|
||||
// if (!is_null($contact->first_name)) {
|
||||
// $contact->first_name = encrypt($contact->first_name);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->middle_name)) {
|
||||
// $contact->middle_name = encrypt($contact->middle_name);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->last_name)) {
|
||||
// $contact->last_name = encrypt($contact->last_name);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->street)) {
|
||||
// $contact->street = encrypt($contact->street);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->city)) {
|
||||
// $contact->city = encrypt($contact->city);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->province)) {
|
||||
// $contact->province = encrypt($contact->province);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->postal_code)) {
|
||||
// $contact->postal_code = encrypt($contact->postal_code);
|
||||
// }
|
||||
|
||||
// if (!is_null($contact->food_preferencies)) {
|
||||
// $contact->food_preferencies = encrypt($contact->food_preferencies);
|
||||
// }
|
||||
|
||||
if (! is_null($contact->email)) {
|
||||
$contact->email = encrypt($contact->email);
|
||||
}
|
||||
|
||||
$contact->save();
|
||||
}
|
||||
|
||||
//
|
||||
// KIDS
|
||||
//
|
||||
// $kids = Kid::all();
|
||||
// foreach ($kids as $kid) {
|
||||
// if (!is_null($kid->first_name)) {
|
||||
// $kid->first_name = encrypt($kid->first_name);
|
||||
// }
|
||||
|
||||
// $kid->save();
|
||||
// }
|
||||
|
||||
//
|
||||
// NOTES
|
||||
//
|
||||
// $notes = Note::all();
|
||||
// foreach ($notes as $note) {
|
||||
// if (!is_null($note->title)) {
|
||||
// $note->title = encrypt($note->title);
|
||||
// }
|
||||
|
||||
// if (!is_null($note->body)) {
|
||||
// $note->body = encrypt($note->body);
|
||||
// }
|
||||
|
||||
// $note->save();
|
||||
// }
|
||||
|
||||
//
|
||||
// PEOPLES
|
||||
//
|
||||
// $peoples = People::all();
|
||||
// foreach ($peoples as $people) {
|
||||
// if (!is_null($people->sortable_name)) {
|
||||
// $people->sortable_name = encrypt($people->sortable_name);
|
||||
// }
|
||||
|
||||
// $people->save();
|
||||
// }
|
||||
|
||||
//
|
||||
// REMINDERS
|
||||
//
|
||||
// $reminders = Reminder::all();
|
||||
// foreach ($reminders as $reminder) {
|
||||
// if (!is_null($reminder->title)) {
|
||||
// $reminder->title = encrypt($reminder->title);
|
||||
// }
|
||||
|
||||
// if (!is_null($reminder->description)) {
|
||||
// $reminder->description = encrypt($reminder->description);
|
||||
// }
|
||||
|
||||
// $reminder->save();
|
||||
// }
|
||||
|
||||
//
|
||||
// SIGNIFICANT OTHER
|
||||
//
|
||||
// $significantOthers = SignificantOther::all();
|
||||
// foreach ($significantOthers as $significantOther) {
|
||||
// if (!is_null($significantOther->first_name)) {
|
||||
// $significantOther->first_name = encrypt($significantOther->first_name);
|
||||
// }
|
||||
|
||||
// $significantOther->save();
|
||||
// }
|
||||
|
||||
//
|
||||
// TASKS
|
||||
//
|
||||
// $tasks = Task::all();
|
||||
// foreach ($tasks as $task) {
|
||||
// if (!is_null($task->title)) {
|
||||
// $task->title = encrypt($task->title);
|
||||
// }
|
||||
|
||||
// if (!is_null($task->description)) {
|
||||
// $task->description = encrypt($task->description);
|
||||
// }
|
||||
|
||||
// $task->save();
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
|
||||
class Inspire extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'inspire';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Display an inspiring quote';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Note;
|
||||
use App\Activity;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MigrateActivities extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monica:migrateactivities';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'One time use only';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$notes = Note::where('type', 'activity')
|
||||
->where('deleted_at', null)
|
||||
->get();
|
||||
|
||||
foreach ($notes as $note) {
|
||||
$activity = new Activity;
|
||||
$activity->account_id = $note->account_id;
|
||||
$activity->people_id = $note->people_id;
|
||||
$activity->activity_type_id = $note->activity_type_id;
|
||||
$activity->description = $note->body;
|
||||
$activity->date_it_happened = $note->activity_date;
|
||||
$activity->user_id_of_the_writer = $note->author_id;
|
||||
$activity->created_at = $note->created_at;
|
||||
$activity->updated_at = $note->updated_at;
|
||||
$activity->save();
|
||||
}
|
||||
|
||||
foreach ($notes as $note) {
|
||||
$note->forceDelete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Contact;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MigratePeopleInformation extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monica:migratecontacts';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'One time use only. Remove encrypt for first/last names';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$contacts = Contact::all();
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
$contact->first_name = decrypt($contact->first_name);
|
||||
|
||||
if (! is_null($contact->middle_name)) {
|
||||
$contact->middle_name = decrypt($contact->middle_name);
|
||||
}
|
||||
|
||||
if (! is_null($contact->last_name)) {
|
||||
$contact->last_name = decrypt($contact->last_name);
|
||||
}
|
||||
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ResetTestDB extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monica:resetdb';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Reset the testing database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (env('APP_ENV') == 'local') {
|
||||
DB::table('tasks')->delete();
|
||||
DB::table('significant_others')->delete();
|
||||
DB::table('reminders')->delete();
|
||||
DB::table('peoples')->delete();
|
||||
DB::table('notes')->delete();
|
||||
DB::table('kids')->delete();
|
||||
DB::table('important_dates')->delete();
|
||||
DB::table('gifts')->delete();
|
||||
DB::table('entities')->delete();
|
||||
DB::table('contacts')->delete();
|
||||
DB::table('accounts')->delete();
|
||||
|
||||
$this->info('Test database has been reset');
|
||||
} else {
|
||||
$this->info('Can\'t execute this command in this environment');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Log;
|
||||
use App\User;
|
||||
use App\Account;
|
||||
use App\Contact;
|
||||
use App\Reminder;
|
||||
use Carbon\Carbon;
|
||||
use App\Jobs\SendReminderEmail;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Jobs\SetNextReminderDate;
|
||||
|
||||
class SendNotifications extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monica:sendnotifications';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Send notifications about reminders';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$reminders = Reminder::orderBy('next_expected_date', 'asc')->get();
|
||||
|
||||
foreach ($reminders as $reminder) {
|
||||
$contact = Contact::findOrFail($reminder->contact_id);
|
||||
$account = Account::findOrFail($contact->account_id);
|
||||
$user = User::where('account_id', $account->id)->first();
|
||||
$date = $reminder->next_expected_date->setTimezone($user->timezone);
|
||||
|
||||
if ($date->isToday()) {
|
||||
Log::info($reminder->id);
|
||||
dispatch(new SendReminderEmail($reminder, $user));
|
||||
dispatch(new SetNextReminderDate($reminder, $user));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
// Commands\Inspire::class,
|
||||
'App\Console\Commands\ResetTestDB',
|
||||
'App\Console\Commands\SendNotifications',
|
||||
'App\Console\Commands\CalculateStatistics',
|
||||
//'App\Console\Commands\EncryptAllTheThings'
|
||||
//'App\Console\Commands\MigrateActivities'
|
||||
'App\Console\Commands\MigratePeopleInformation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('monica:sendnotifications')->hourly();
|
||||
$schedule->command('monica:calculatestatistics')->daily();
|
||||
}
|
||||
}
|
||||
+912
@@ -0,0 +1,912 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Auth;
|
||||
use App\Note;
|
||||
use App\Account;
|
||||
use App\Country;
|
||||
use App\Reminder;
|
||||
use Carbon\Carbon;
|
||||
use App\ReminderType;
|
||||
use App\Helpers\DateHelper;
|
||||
use Gmopx\LaravelOWM\LaravelOWM;
|
||||
use App\Events\Contact\ContactCreated;
|
||||
use App\Events\Contact\ContactUpdated;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Contact extends Model
|
||||
{
|
||||
protected $dates = [
|
||||
'birthdate',
|
||||
];
|
||||
|
||||
protected $events = [
|
||||
'created' => ContactCreated::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the complete name of the contact.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCompleteName()
|
||||
{
|
||||
$completeName = $this->first_name;
|
||||
|
||||
if (! is_null($this->middle_name)) {
|
||||
$completeName = $completeName.' '.$this->middle_name;
|
||||
}
|
||||
|
||||
if (! is_null($this->last_name)) {
|
||||
$completeName = $completeName.' '.$this->last_name;
|
||||
}
|
||||
|
||||
return $completeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first name of the contact.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
if (is_null($this->first_name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->first_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middle name of the contact.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMiddleName()
|
||||
{
|
||||
if (is_null($this->middle_name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->middle_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last name of the contact.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
if (is_null($this->last_name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the initials of the contact, used for avatars.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInitials()
|
||||
{
|
||||
$initials = $this->getFirstName()[0];
|
||||
|
||||
if (! is_null($this->getMiddleName())) {
|
||||
$initial = $this->getMiddleName()[0];
|
||||
$initials .= $initial;
|
||||
}
|
||||
|
||||
if (! is_null($this->getLastName())) {
|
||||
$initial = $this->getLastName()[0];
|
||||
$initials .= $initial;
|
||||
}
|
||||
|
||||
return $initials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date of the last activity done by this contact.
|
||||
*
|
||||
* @return string 'Oct 29, 1981'
|
||||
*/
|
||||
public function getLastActivityDate($timezone)
|
||||
{
|
||||
$activity = Activity::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->orderBy('date_it_happened', 'desc')
|
||||
->first();
|
||||
|
||||
if (count($activity) == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$last_activity_date = DateHelper::createDateFromFormat($activity->date_it_happened, $timezone);
|
||||
|
||||
return DateHelper::getShortDate($last_activity_date, 'en');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last talked to date.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastCalled($timezone)
|
||||
{
|
||||
if (is_null($this->last_talked_to)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$lastTalkedTo = DateHelper::createDateFromFormat($this->last_talked_to, $timezone)->diffForHumans();
|
||||
|
||||
return $lastTalkedTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the birthdate of the contact.
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getBirthdate()
|
||||
{
|
||||
if (is_null($this->birthdate)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->birthdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the age of the contact in years, or returns null if the birthdate
|
||||
* is not set.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAge()
|
||||
{
|
||||
if (is_null($this->birthdate)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$age = $this->birthdate->diffInYears(Carbon::now());
|
||||
|
||||
return $age;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phone number as a string.
|
||||
*
|
||||
* @return string or null
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
if (is_null($this->phone_number)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->phone_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the birthdate as a full sentence ('Born on Oct 29, 1981'),
|
||||
* or as an approximation if this is the case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function isBirthdateApproximate()
|
||||
{
|
||||
return $this->is_birthdate_approximate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the address in a format like 'Lives in Scranton, MS'.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPartialAddress()
|
||||
{
|
||||
$address = $this->getCity();
|
||||
|
||||
if (is_null($address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! is_null($this->getProvince())) {
|
||||
$address = $address.', '.$this->getProvince();
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the street of the contact.
|
||||
* @return string or null
|
||||
*/
|
||||
public function getStreet()
|
||||
{
|
||||
if (is_null($this->street)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->street);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the province of the contact.
|
||||
* @return string or null
|
||||
*/
|
||||
public function getProvince()
|
||||
{
|
||||
if (is_null($this->province)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->province);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the postal code of the contact.
|
||||
* @return string or null
|
||||
*/
|
||||
public function getPostalCode()
|
||||
{
|
||||
if (is_null($this->postal_code)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->postal_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the country of the contact.
|
||||
* @return string or null
|
||||
*/
|
||||
public function getCountryName()
|
||||
{
|
||||
$country = null;
|
||||
|
||||
if (! is_null($this->country_id)) {
|
||||
$country = Country::findOrFail($this->country_id);
|
||||
$country = $country->country;
|
||||
}
|
||||
|
||||
return $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the city.
|
||||
* @return string
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
if (is_null($this->city)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->city);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the countryID of the contact.
|
||||
* @return string or null
|
||||
*/
|
||||
public function getCountryID()
|
||||
{
|
||||
return $this->country_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the country ISO of the contact.
|
||||
* @return string or null
|
||||
*/
|
||||
public function getCountryISO()
|
||||
{
|
||||
$country = Country::find($this->country_id);
|
||||
|
||||
if (count($country) == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $country->iso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an URL for Google Maps for the address.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGoogleMapAddress()
|
||||
{
|
||||
$address = $this->getFullAddress();
|
||||
$address = urlencode($address);
|
||||
|
||||
return "https://www.google.ca/maps/place/{$address}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last updated date.
|
||||
*
|
||||
* @return string Y-m-d
|
||||
*/
|
||||
public function getLastUpdated()
|
||||
{
|
||||
$user = User::where('account_id', $this->account_id)->first();
|
||||
$lastUpdated = DateHelper::createDateFromFormat($this->updated_at, $user->timezone);
|
||||
|
||||
return $lastUpdated->format('Y/m/d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of reminders.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumberOfReminders()
|
||||
{
|
||||
return $this->number_of_reminders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of kids.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumberOfKids()
|
||||
{
|
||||
return $this->number_of_kids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of activities.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumberOfActivities()
|
||||
{
|
||||
return $this->number_of_activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of gifts, regardless of ideas or offered.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumberOfGifts()
|
||||
{
|
||||
return $this->number_of_gifts_ideas + $this->number_of_gifts_offered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the email address or returns null if undefined.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
if (is_null($this->email)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current Significant Other, if it exists, or return null otherwise.
|
||||
*
|
||||
* @return SignificantOther
|
||||
*/
|
||||
public function getCurrentSignificantOther()
|
||||
{
|
||||
$significantOther = SignificantOther::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->where('status', 'active')
|
||||
->first();
|
||||
|
||||
return $significantOther;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notes for this contact. Return an empty collection if no notes.
|
||||
*
|
||||
* @return Notes
|
||||
*/
|
||||
public function getNotes()
|
||||
{
|
||||
$notes = Note::where('contact_id', $this->id)
|
||||
->where('account_id', $this->account_id)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return $notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of notes for this contact.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumberOfNotes()
|
||||
{
|
||||
return $this->number_of_notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kids, if any, as a collection.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getKids()
|
||||
{
|
||||
$kids = Kid::where('account_id', $this->account_id)
|
||||
->where('child_of_contact_id', $this->id)
|
||||
->get();
|
||||
|
||||
return $kids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the food preferencies or return null if not defined.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFoodPreferencies()
|
||||
{
|
||||
if (is_null($this->food_preferencies)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->food_preferencies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default color of the avatar if no picture is present.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAvatarColor()
|
||||
{
|
||||
return $this->default_avatar_color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default avatar color for this object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAvatarColor()
|
||||
{
|
||||
$colors = [
|
||||
'#fdb660',
|
||||
'#93521e',
|
||||
'#bd5067',
|
||||
'#b3d5fe',
|
||||
'#ff9807',
|
||||
'#709512',
|
||||
'#5f479a',
|
||||
'#e5e5cd',
|
||||
];
|
||||
$randomColorChosen = $colors[mt_rand(0, count($colors) - 1)];
|
||||
|
||||
$this->default_avatar_color = $randomColorChosen;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event in the Event table about this contact.
|
||||
*
|
||||
* @param string $objectType Contact, Activity, Kid,...
|
||||
* @param int $objectId ID of the object
|
||||
* @param string $natureOfOperation 'add', 'edit', 'delete'
|
||||
* @return int Id of the created event
|
||||
*/
|
||||
public function logEvent($objectType, $objectId, $natureOfOperation)
|
||||
{
|
||||
$event = new Event;
|
||||
$event->account_id = $this->account_id;
|
||||
$event->contact_id = $this->id;
|
||||
$event->object_type = $objectType;
|
||||
$event->object_id = $objectId;
|
||||
$event->nature_of_operation = $natureOfOperation;
|
||||
$event->save();
|
||||
|
||||
return $event->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a significant other.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $gender
|
||||
* @param bool $birthdate_approximate
|
||||
* @param string $birthdate
|
||||
* @param int $age
|
||||
* @return int
|
||||
*/
|
||||
public function addSignificantOther($firstname, $lastname, $gender, $birthdate_approximate, $birthdate, $age, $timezone)
|
||||
{
|
||||
$significantOther = new SignificantOther;
|
||||
$significantOther->account_id = $this->account_id;
|
||||
$significantOther->contact_id = $this->id;
|
||||
$significantOther->first_name = encrypt(ucfirst($firstname));
|
||||
if (! is_null($lastname)) {
|
||||
$significantOther->last_name = encrypt(ucfirst($lastname));
|
||||
}
|
||||
$significantOther->gender = $gender;
|
||||
$significantOther->is_birthdate_approximate = $birthdate_approximate;
|
||||
$significantOther->status = 'active';
|
||||
if ($birthdate_approximate == 'true') {
|
||||
$year = Carbon::now()->subYears($age)->year;
|
||||
$birthdate = Carbon::createFromDate($year, 1, 1);
|
||||
$significantOther->birthdate = $birthdate;
|
||||
} else {
|
||||
$birthdate = Carbon::createFromFormat('Y-m-d', $birthdate);
|
||||
$significantOther->birthdate = $birthdate;
|
||||
}
|
||||
$significantOther->save();
|
||||
|
||||
return $significantOther->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the information about the Significant other.
|
||||
*
|
||||
* @param int $significantOtherId
|
||||
* @param string $firstname
|
||||
* @param string $lastname
|
||||
* @param string $gender
|
||||
* @param string $birthdate_approximate
|
||||
* @param string $birthdate
|
||||
* @param int $age
|
||||
* @param string $timezone
|
||||
* @return Response
|
||||
*/
|
||||
public function editSignificantOther($significantOtherId, $firstname, $lastname, $gender, $birthdate_approximate, $birthdate, $age, $timezone)
|
||||
{
|
||||
$significantOther = SignificantOther::findOrFail($significantOtherId);
|
||||
|
||||
$significantOther->first_name = encrypt(ucfirst($firstname));
|
||||
|
||||
if (is_null($lastname)) {
|
||||
$significantOther->last_name = null;
|
||||
} else {
|
||||
$significantOther->last_name = encrypt(ucfirst($lastname));
|
||||
}
|
||||
|
||||
$significantOther->gender = $gender;
|
||||
$significantOther->is_birthdate_approximate = $birthdate_approximate;
|
||||
$significantOther->status = 'active';
|
||||
|
||||
if ($birthdate_approximate == 'true') {
|
||||
$year = Carbon::now()->subYears($age)->year;
|
||||
$birthdate = Carbon::createFromDate($year, 1, 1);
|
||||
$significantOther->birthdate = $birthdate;
|
||||
} else {
|
||||
$birthdate = Carbon::createFromFormat('Y-m-d', $birthdate);
|
||||
$significantOther->birthdate = $birthdate;
|
||||
}
|
||||
|
||||
$significantOther->save();
|
||||
|
||||
return $significantOther->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the significant other.
|
||||
*/
|
||||
public function deleteSignificantOther($significantOtherId)
|
||||
{
|
||||
$significantOther = SignificantOther::findOrFail($significantOtherId);
|
||||
$significantOther->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the name of the contact.
|
||||
*
|
||||
* @param string $firstName
|
||||
* @param string $middleName
|
||||
* @param string $lastName
|
||||
* @return bool
|
||||
*/
|
||||
public function updateName($firstName, $middleName, $lastName)
|
||||
{
|
||||
if ($firstName == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->first_name = encrypt($firstName);
|
||||
|
||||
if (! is_null($middleName)) {
|
||||
$this->middle_name = encrypt($middleName);
|
||||
}
|
||||
|
||||
if (! is_null($lastName)) {
|
||||
$this->last_name = encrypt($lastName);
|
||||
}
|
||||
$this->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the name of the contact.
|
||||
*
|
||||
* @param string $foodPreferencies
|
||||
* @return void
|
||||
*/
|
||||
public function updateFoodPreferencies($foodPreferencies)
|
||||
{
|
||||
if ($foodPreferencies == '') {
|
||||
$this->food_preferencies = null;
|
||||
} else {
|
||||
$this->food_preferencies = encrypt($foodPreferencies);
|
||||
}
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a kid.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $gender
|
||||
* @param bool $birthdate_approximate
|
||||
* @param string $birthdate
|
||||
* @param int $age
|
||||
* @return int the Kid ID
|
||||
*/
|
||||
public function addKid($name, $gender, $birthdate_approximate, $birthdate, $age, $timezone)
|
||||
{
|
||||
$kid = new Kid;
|
||||
$kid->account_id = $this->account_id;
|
||||
$kid->child_of_contact_id = $this->id;
|
||||
$kid->first_name = encrypt(ucfirst($name));
|
||||
$kid->gender = $gender;
|
||||
$kid->is_birthdate_approximate = $birthdate_approximate;
|
||||
|
||||
if ($birthdate_approximate == 'true') {
|
||||
$year = Carbon::now()->subYears($age)->year;
|
||||
$birthdate = Carbon::createFromDate($year, 1, 1);
|
||||
$kid->birthdate = $birthdate;
|
||||
} else {
|
||||
$birthdate = Carbon::createFromFormat('Y-m-d', $birthdate);
|
||||
$kid->birthdate = $birthdate;
|
||||
}
|
||||
|
||||
$kid->save();
|
||||
|
||||
return $kid->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a kid.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $gender
|
||||
* @param bool $birthdate_approximate
|
||||
* @param string $birthdate
|
||||
* @param int $age
|
||||
* @return int the Kid ID
|
||||
*/
|
||||
public function editKid($kidId, $name, $gender, $birthdate_approximate, $birthdate, $age, $timezone)
|
||||
{
|
||||
$kid = Kid::findOrFail($kidId);
|
||||
$kid->first_name = encrypt(ucfirst($name));
|
||||
$kid->gender = $gender;
|
||||
$kid->is_birthdate_approximate = $birthdate_approximate;
|
||||
|
||||
if ($birthdate_approximate == 'true') {
|
||||
$year = Carbon::now()->subYears($age)->year;
|
||||
$birthdate = Carbon::createFromDate($year, 1, 1);
|
||||
$kid->birthdate = $birthdate;
|
||||
} else {
|
||||
$birthdate = Carbon::createFromFormat('Y-m-d', $birthdate);
|
||||
$kid->birthdate = $birthdate;
|
||||
}
|
||||
|
||||
$kid->save();
|
||||
|
||||
return $kid->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the kid.
|
||||
*/
|
||||
public function deleteKid($kidId)
|
||||
{
|
||||
$kid = Kid::findOrFail($kidId);
|
||||
$kid->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a note.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public function addNote($body)
|
||||
{
|
||||
$note = new Note;
|
||||
$note->account_id = $this->account_id;
|
||||
$note->contact_id = $this->id;
|
||||
$note->body = encrypt($body);
|
||||
$note->save();
|
||||
|
||||
return $note->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the note.
|
||||
*/
|
||||
public function deleteNote($noteId)
|
||||
{
|
||||
$note = Note::findOrFail($noteId);
|
||||
$note->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the activities, if any.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActivities()
|
||||
{
|
||||
$activities = Activity::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->orderBy('date_it_happened', 'desc')
|
||||
->get();
|
||||
|
||||
return $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh statistics about activities
|
||||
* TODO: unit test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function calculateActivitiesStatistics()
|
||||
{
|
||||
// Delete the Activities statistics table for this contact
|
||||
$activitiesStatistics = ActivityStatistic::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->get();
|
||||
|
||||
foreach ($activitiesStatistics as $activityStatistic) {
|
||||
$activityStatistic->delete();
|
||||
}
|
||||
|
||||
// Create the statistics again
|
||||
foreach ($this->getActivities() as $activity) {
|
||||
$year = $activity->date_it_happened->year;
|
||||
|
||||
// Check to see if there is a year for this activity already
|
||||
$activityStatistic = ActivityStatistic::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->where('year', $year)
|
||||
->first();
|
||||
|
||||
if (count($activityStatistic) == 0) {
|
||||
|
||||
// Year does not exist, create the record
|
||||
$activityStatistic = new ActivityStatistic;
|
||||
$activityStatistic->account_id = $this->account_id;
|
||||
$activityStatistic->contact_id = $this->id;
|
||||
$activityStatistic->year = $year;
|
||||
$activityStatistic->count = 1;
|
||||
$activityStatistic->save();
|
||||
|
||||
} else {
|
||||
|
||||
// Year does exist, increment the record
|
||||
$activityStatistic->count = $activityStatistic->count + 1;
|
||||
$activityStatistic->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statistics for the contact
|
||||
* TODO: add unit test.
|
||||
*
|
||||
* @param int $contactId
|
||||
*/
|
||||
public function getActivitiesStats()
|
||||
{
|
||||
$statistics = ActivityStatistic::where('contact_id', $this->id)
|
||||
->orderBy('year', 'desc')
|
||||
->get();
|
||||
|
||||
return $statistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the reminders, if any.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getReminders()
|
||||
{
|
||||
$reminders = Reminder::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->orderBy('next_expected_date', 'asc')
|
||||
->get();
|
||||
|
||||
return $reminders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the gifts, if any.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getGifts()
|
||||
{
|
||||
return Gift::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the gifts offered, if any.
|
||||
*/
|
||||
public function getGiftsOffered()
|
||||
{
|
||||
return Gift::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->where('has_been_offered', 'true')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the gift ideas, if any.
|
||||
*/
|
||||
public function getGiftIdeas()
|
||||
{
|
||||
return Gift::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->where('is_an_idea', 'true')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the tasks in the in progress state, if any.
|
||||
*/
|
||||
public function getTasksInProgress()
|
||||
{
|
||||
return Task::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->where('status', 'inprogress')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the tasks in the in progress state, if any.
|
||||
*/
|
||||
public function getCompletedTasks()
|
||||
{
|
||||
return Task::where('account_id', $this->account_id)
|
||||
->where('contact_id', $this->id)
|
||||
->where('status', 'completed')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL of the avatar with the given size
|
||||
* @param int $size
|
||||
* @return string
|
||||
*/
|
||||
public function getAvatarURL($size)
|
||||
{
|
||||
$original_avatar_url = Storage::disk('public')->url($this->avatar_file_name);
|
||||
$avatar_filename = pathinfo($original_avatar_url, PATHINFO_FILENAME);
|
||||
$avatar_extension = pathinfo($original_avatar_url, PATHINFO_EXTENSION);
|
||||
$resized_avatar = 'avatars/'.$avatar_filename.'_'.$size.'.'.$avatar_extension;
|
||||
|
||||
return Storage::disk('public')->url($resized_avatar);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Country extends Model
|
||||
{
|
||||
protected $table = 'countries';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Entry extends Model
|
||||
{
|
||||
protected $table = 'entries';
|
||||
|
||||
public function getPost()
|
||||
{
|
||||
if (is_null($this->post)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->post);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
if (is_null($this->title)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Auth;
|
||||
use App\Reminder;
|
||||
use App\Helpers\DateHelper;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
public function getDescription()
|
||||
{
|
||||
if ($this->nature_of_operation == 'create') {
|
||||
$description = 'You added ';
|
||||
}
|
||||
|
||||
if ($this->nature_of_operation == 'update') {
|
||||
$description = 'You updated ';
|
||||
}
|
||||
|
||||
// You added a reminder about John Doe
|
||||
if ($this->object_type == 'reminder') {
|
||||
$reminder = Reminder::findOrFail($this->object_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Activity;
|
||||
|
||||
use App\Activity;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class ActivityCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $activity;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Activity $activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Activity;
|
||||
|
||||
use App\Activity;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class ActivityDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $activity;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Activity $activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Activity;
|
||||
|
||||
use App\Activity;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class ActivityUpdated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $activity;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Activity $activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Contact;
|
||||
|
||||
use App\Contact;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class ContactCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $contact;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Contact $contact)
|
||||
{
|
||||
$this->contact = $contact;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
abstract class Event
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Gift;
|
||||
|
||||
use App\Gift;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class GiftCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $gift;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Gift $gift)
|
||||
{
|
||||
$this->gift = $gift;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Gift;
|
||||
|
||||
use App\Gift;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class GiftDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $gift;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Gift $gift)
|
||||
{
|
||||
$this->gift = $gift;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Kid;
|
||||
|
||||
use App\Kid;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class KidCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $kid;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Kid $kid)
|
||||
{
|
||||
$this->kid = $kid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Kid;
|
||||
|
||||
use App\Kid;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class KidDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $kid;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Kid $kid)
|
||||
{
|
||||
$this->kid = $kid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Kid;
|
||||
|
||||
use App\Kid;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class KidUpdated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $kid;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Kid $kid)
|
||||
{
|
||||
$this->kid = $kid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Note;
|
||||
|
||||
use App\Note;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class NoteCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $note;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Note $note)
|
||||
{
|
||||
$this->note = $note;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Note;
|
||||
|
||||
use App\Note;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class NoteDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $note;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Note $note)
|
||||
{
|
||||
$this->note = $note;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Reminder;
|
||||
|
||||
use App\Reminder;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class ReminderCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $reminder;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Reminder $reminder)
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Reminder;
|
||||
|
||||
use App\Reminder;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class ReminderDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $reminder;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Reminder $reminder)
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\SignificantOther;
|
||||
|
||||
use App\SignificantOther;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class SignificantOtherCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $significantOther;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param SignificantOther $contact
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SignificantOther $significantOther)
|
||||
{
|
||||
$this->significantOther = $significantOther;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\SignificantOther;
|
||||
|
||||
use App\SignificantOther;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class SignificantOtherDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $significantOther;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param SignificantOther $contact
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SignificantOther $significantOther)
|
||||
{
|
||||
$this->significantOther = $significantOther;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\SignificantOther;
|
||||
|
||||
use App\SignificantOther;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class SignificantOtherUpdated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $significantOther;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SignificantOther $significantOther)
|
||||
{
|
||||
$this->significantOther = $significantOther;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Task;
|
||||
|
||||
use App\Task;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class TaskCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Task $task)
|
||||
{
|
||||
$this->task = $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Task;
|
||||
|
||||
use App\Task;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class TaskDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Task $task)
|
||||
{
|
||||
$this->task = $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Task;
|
||||
|
||||
use App\Task;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class TaskUpdated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Task $task)
|
||||
{
|
||||
$this->task = $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
ValidationException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $e)
|
||||
{
|
||||
parent::report($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $e
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Events\Gift\GiftCreated;
|
||||
use App\Events\Gift\GiftDeleted;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Gift extends Model
|
||||
{
|
||||
protected $dates = [
|
||||
'date_offered',
|
||||
];
|
||||
|
||||
protected $events = [
|
||||
'created' => GiftCreated::class,
|
||||
'deleted' => GiftDeleted::class,
|
||||
];
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (is_null($this->name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->name);
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
if (is_null($this->url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->url);
|
||||
}
|
||||
|
||||
public function getComment()
|
||||
{
|
||||
if (is_null($this->comment)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->comment);
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
if (is_null($this->value_in_dollars)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->value_in_dollars;
|
||||
}
|
||||
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->created_at;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class DateHelper
|
||||
{
|
||||
/**
|
||||
* Creates a Carbon object.
|
||||
*
|
||||
* @param string date
|
||||
* @param string timezone
|
||||
* @return Carbon
|
||||
*/
|
||||
public static function createDateFromFormat($date, $timezone)
|
||||
{
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s', $date, $timezone);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a date according to the timezone of the user, in a short format
|
||||
* like "Oct 29, 1981".
|
||||
*
|
||||
* @param Carbon $date
|
||||
* @return string
|
||||
*/
|
||||
public static function getShortDate($date, $locale)
|
||||
{
|
||||
$date = new Date($date);
|
||||
|
||||
switch ($locale) {
|
||||
case 'en':
|
||||
Date::setLocale('en');
|
||||
$format = 'M d, Y';
|
||||
break;
|
||||
case 'fr':
|
||||
Date::setLocale('fr');
|
||||
$format = 'd M Y';
|
||||
break;
|
||||
default:
|
||||
Date::setLocale('en');
|
||||
$format = 'M d, Y';
|
||||
break;
|
||||
}
|
||||
|
||||
return $date->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a date and the time according to the timezone of the user, in a short format
|
||||
* like "Oct 29, 1981 19:32".
|
||||
*
|
||||
* @param Carbon $date
|
||||
* @return string
|
||||
*/
|
||||
public static function getShortDateWithTime($date, $locale)
|
||||
{
|
||||
$date = new Date($date);
|
||||
|
||||
switch ($locale) {
|
||||
case 'en':
|
||||
Date::setLocale('en');
|
||||
$format = 'M d, Y H:i';
|
||||
break;
|
||||
case 'fr':
|
||||
Date::setLocale('fr');
|
||||
$format = 'd M Y H:i';
|
||||
break;
|
||||
default:
|
||||
Date::setLocale('en');
|
||||
$format = 'M d, Y H:i';
|
||||
}
|
||||
|
||||
return $date->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the next date an event will occur.
|
||||
* @param Carbon
|
||||
* @param string
|
||||
* @param int
|
||||
* @return Carbon
|
||||
*/
|
||||
public static function calculateNextOccuringDate($date, $frequency_type, $frequency_number)
|
||||
{
|
||||
if ($frequency_type == 'week') {
|
||||
$date->addWeeks($frequency_number);
|
||||
}
|
||||
if ($frequency_type == 'month') {
|
||||
$date->addMonths($frequency_number);
|
||||
}
|
||||
if ($frequency_type == 'year') {
|
||||
$date->addYears($frequency_number);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the age given a date and the fact that the date is an
|
||||
* approximation or not.
|
||||
*
|
||||
* @param Carbon $date [description]
|
||||
* @param string $approximation 'true' or 'false'
|
||||
* @return string
|
||||
*/
|
||||
public static function getAgeAsString($date, $approximation)
|
||||
{
|
||||
Carbon::setLocale(Auth::user()->locale);
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s', $date, Auth::user()->timezone);
|
||||
$age = $date->diffInYears(Carbon::now());
|
||||
|
||||
if ($age < 1) {
|
||||
$ageInMonths = self::createDateFromFormat($date, Auth::user()->timezone)->diffInMonths(Carbon::now());
|
||||
|
||||
if ($approximation == 'true') {
|
||||
// returns Approx. 3 months old
|
||||
return trans('people.age_approximate_in_months', ['age' => $ageInMonths]);
|
||||
} else {
|
||||
// returns 3 month old (Oct 29, 1981)
|
||||
$html = '<span class="age-date">('.self::getShortDate($date, Auth::user()->locale).')</span>';
|
||||
|
||||
return trans('people.age_exact_in_months', ['age' => $ageInMonths, 'html' => $html]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($approximation == 'true') {
|
||||
// returns Approx. 3 years old
|
||||
return trans('people.age_approximate_in_years', ['age' => $age]);
|
||||
} else {
|
||||
// returns 23 years old (Oct 29, 1981)
|
||||
$html = '<span class="age-date">('.self::getShortDate($date, Auth::user()->locale).')</span>';
|
||||
|
||||
return trans('people.age_exact_in_years', ['age' => $age, 'html' => $html]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class RandomHelper
|
||||
{
|
||||
/**
|
||||
* Generate a random string of characters.
|
||||
*
|
||||
* @param int length The length of the desired string
|
||||
* @return string A random string of characters
|
||||
*/
|
||||
public static function generateString($length)
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0987654321'.time();
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
|
||||
for ($i = $length; $i > 0; $i--) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/dashboard';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use App\User;
|
||||
use Socialite;
|
||||
use Validator;
|
||||
use App\Account;
|
||||
use App\Helpers\RandomHelper;
|
||||
use App\Jobs\SendNewUserAlert;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/dashboard';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'last_name' => 'required|max:255',
|
||||
'first_name' => 'required|max:255',
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
$user = new User;
|
||||
$user->first_name = $data['first_name'];
|
||||
$user->last_name = $data['last_name'];
|
||||
$user->email = $data['email'];
|
||||
$user->password = bcrypt($data['password']);
|
||||
$user->timezone = 'America/New_York';
|
||||
$user->save();
|
||||
|
||||
// create a new account
|
||||
$account = new Account;
|
||||
$account->api_key = RandomHelper::generateString(30);
|
||||
$account->save();
|
||||
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
||||
// send me an alert
|
||||
dispatch(new SendNewUserAlert($user));
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user to the Facebook authentication page.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function redirectToProvider()
|
||||
{
|
||||
return Socialite::driver('facebook')->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the user information from Facebook.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handleProviderCallback()
|
||||
{
|
||||
$user = Socialite::driver('facebook')->user();
|
||||
|
||||
// Is there a user already registered?
|
||||
$userObject = User::where('email', $user->getEmail())->first();
|
||||
|
||||
if (count($userObject) == 0) {
|
||||
$userObject = new User;
|
||||
$userObject->first_name = 'Facebook';
|
||||
$userObject->last_name = 'User';
|
||||
$userObject->email = $user->getEmail();
|
||||
$userObject->timezone = 'America/New_York';
|
||||
$userObject->save();
|
||||
|
||||
// create a new account
|
||||
$account = new Account;
|
||||
$account->api_key = RandomHelper::generateString(30);
|
||||
$account->save();
|
||||
|
||||
$userObject->account_id = $account->id;
|
||||
$userObject->access_token = $user->token;
|
||||
$userObject->save();
|
||||
|
||||
// send me an alert
|
||||
dispatch(new SendNewUserAlert($userObject));
|
||||
}
|
||||
|
||||
Auth::login($userObject);
|
||||
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use App\Event;
|
||||
use Validator;
|
||||
use App\Contact;
|
||||
use App\Reminder;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Requests;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$lastUpdatedContacts = Contact::where('account_id', Auth::user()->account_id)
|
||||
->orderBy('updated_at', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
// List of events
|
||||
$events = Event::where('account_id', Auth::user()->account_id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(30)
|
||||
->get();
|
||||
|
||||
if (count($events) == 0) {
|
||||
return view('dashboard.blank');
|
||||
}
|
||||
|
||||
$eventsArray = collect();
|
||||
|
||||
foreach ($events as $event) {
|
||||
$contact = Contact::findOrFail($event->contact_id);
|
||||
|
||||
$eventsArray->push([
|
||||
'id' => $event->id,
|
||||
'date' => $event->created_at,
|
||||
'object_type' => $event->object_type,
|
||||
'object_id' => $event->object_id,
|
||||
'contact_id' => $contact->id,
|
||||
'contact_complete_name' => $contact->getCompleteName(),
|
||||
'nature_of_operation' => $event->nature_of_operation,
|
||||
]);
|
||||
}
|
||||
|
||||
// List of upcoming reminders
|
||||
$thirtyDaysFromNow = Carbon::now()->addDays(30);
|
||||
$upcomingReminders = Reminder::where('account_id', Auth::user()->account_id)
|
||||
->where('next_expected_date', '<', $thirtyDaysFromNow)
|
||||
->get();
|
||||
|
||||
$data = [
|
||||
'events' => $eventsArray,
|
||||
'lastUpdatedContacts' => $lastUpdatedContacts,
|
||||
'upcomingReminders' => $upcomingReminders,
|
||||
];
|
||||
|
||||
return view('dashboard.index', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use App\Entry;
|
||||
use Validator;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Requests;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class JournalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$entries = Entry::where('account_id', Auth::user()->account_id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$data = [
|
||||
'entries' => $entries,
|
||||
];
|
||||
|
||||
return view('journal.index', $data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return view('journal.add');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the journal entry
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'entry' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors($validator);
|
||||
}
|
||||
|
||||
$entry = new Entry;
|
||||
$entry->account_id = Auth::user()->account_id;
|
||||
$entry->post = encrypt($request->input('entry'));
|
||||
|
||||
if ($request->input('title') != '') {
|
||||
$entry->title = encrypt($request->input('title'));
|
||||
}
|
||||
|
||||
$entry->save();
|
||||
|
||||
return redirect()->route('journal.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the reminder.
|
||||
*/
|
||||
public function deleteEntry(Request $request, $entryId)
|
||||
{
|
||||
$entry = Entry::findOrFail($entryId);
|
||||
|
||||
if ($entry->account_id != Auth::user()->account_id) {
|
||||
return redirect()->route('people.index');
|
||||
}
|
||||
|
||||
$entry->delete();
|
||||
$request->session()->flash('success', trans('journal.entry_delete_success'));
|
||||
|
||||
return redirect('/journal');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\User;
|
||||
use App\Statistic;
|
||||
use App\Http\Requests;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MarketingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('marketing/homepage');
|
||||
}
|
||||
|
||||
public function release()
|
||||
{
|
||||
return view('marketing/release');
|
||||
}
|
||||
|
||||
public function privacy()
|
||||
{
|
||||
return view('marketing/privacy');
|
||||
}
|
||||
|
||||
public function statistics()
|
||||
{
|
||||
$statistics = Statistic::orderBy('id', 'desc')->get();
|
||||
$data = [
|
||||
'statistics' => $statistics,
|
||||
];
|
||||
|
||||
return view('marketing/statistics', $data);
|
||||
}
|
||||
|
||||
public function getMails()
|
||||
{
|
||||
$users = User::all();
|
||||
foreach ($users as $user) {
|
||||
echo $user->email.'<br>';
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use App\Kid;
|
||||
use App\Note;
|
||||
use App\Task;
|
||||
use App\Event;
|
||||
use Validator;
|
||||
use App\Account;
|
||||
use App\Contact;
|
||||
use App\Activity;
|
||||
use App\Reminder;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Requests;
|
||||
use App\SignificantOther;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helpers\RandomHelper;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('settings.index');
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email' => 'required|email|max:2083',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect('/settings')
|
||||
->withInput()
|
||||
->withErrors($validator);
|
||||
}
|
||||
|
||||
$email = $request->input('email');
|
||||
$timezone = $request->input('timezone');
|
||||
$layout = $request->input('layout');
|
||||
$locale = $request->input('locale');
|
||||
|
||||
Auth::user()->email = $email;
|
||||
Auth::user()->timezone = $timezone;
|
||||
Auth::user()->fluid_container = $layout;
|
||||
Auth::user()->metric = $layout;
|
||||
Auth::user()->locale = $locale;
|
||||
Auth::user()->save();
|
||||
|
||||
return redirect('settings')->with('status', 'Profile updated!');
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
// get the account id
|
||||
$accountID = Auth::user()->account_id;
|
||||
|
||||
// delete all reminders
|
||||
$reminders = Reminder::where('account_id', $accountID)->get();
|
||||
foreach ($reminders as $reminder) {
|
||||
$reminder->forceDelete();
|
||||
}
|
||||
|
||||
// delete contacts
|
||||
$contacts = Contact::where('account_id', $accountID)->get();
|
||||
foreach ($contacts as $contact) {
|
||||
$contact->forceDelete();
|
||||
}
|
||||
|
||||
// delete kids
|
||||
$kids = Kid::where('account_id', $accountID)->get();
|
||||
foreach ($kids as $kid) {
|
||||
$kid->forceDelete();
|
||||
}
|
||||
|
||||
// delete notes
|
||||
$notes = Note::where('account_id', $accountID)->get();
|
||||
foreach ($notes as $note) {
|
||||
$note->forceDelete();
|
||||
}
|
||||
|
||||
// delete significant others
|
||||
$significantOthers = SignificantOther::where('account_id', $accountID)->get();
|
||||
foreach ($significantOthers as $significantOther) {
|
||||
$significantOther->forceDelete();
|
||||
}
|
||||
|
||||
// delete tasks
|
||||
$tasks = Task::where('account_id', $accountID)->get();
|
||||
foreach ($tasks as $task) {
|
||||
$task->forceDelete();
|
||||
}
|
||||
|
||||
// delete activities
|
||||
$activities = Activity::where('account_id', $accountID)->get();
|
||||
foreach ($activities as $activity) {
|
||||
$activity->forceDelete();
|
||||
}
|
||||
|
||||
// delete events
|
||||
$events = Event::where('account_id', $accountID)->get();
|
||||
foreach ($events as $event) {
|
||||
$event->forceDelete();
|
||||
}
|
||||
|
||||
// delete account
|
||||
$account = Account::find($accountID);
|
||||
$account->delete();
|
||||
|
||||
Auth::user()->delete();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\CheckLocale::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->guest()) {
|
||||
if ($request->ajax() || $request->wantsJson()) {
|
||||
return response('Unauthorized.', 401);
|
||||
} else {
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Auth;
|
||||
use Closure;
|
||||
|
||||
class CheckLocale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
\App::setLocale(Auth::user()->locale);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
|
||||
|
||||
class EncryptCookies extends BaseEncrypter
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
|
||||
class VerifyCsrfToken extends BaseVerifier
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
abstract class Request extends FormRequest
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
Route::get('/', 'MarketingController@index');
|
||||
|
||||
Auth::routes();
|
||||
|
||||
Route::get('/password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
|
||||
|
||||
Route::get('/changelog', 'MarketingController@release');
|
||||
Route::get('/privacy', 'MarketingController@privacy');
|
||||
Route::get('/statistics', 'MarketingController@statistics');
|
||||
|
||||
Route::get('auth/facebook', 'Auth\RegisterController@redirectToProvider');
|
||||
Route::get('auth/facebook/callback', 'Auth\RegisterController@handleProviderCallback');
|
||||
|
||||
Route::group(['middleware' => 'auth'], function () {
|
||||
|
||||
//Route::resource('people', 'PeopleController');
|
||||
Route::get('/logout', 'Auth\LoginController@logout');
|
||||
|
||||
Route::get('/dashboard/', ['as' => 'dashboard', 'uses' => 'DashboardController@index']);
|
||||
|
||||
Route::group(['as' => 'people'], function () {
|
||||
Route::get('/people/', ['as' => '.index', 'uses' => 'PeopleController@index']);
|
||||
Route::get('/people/add', ['as' => '.create', 'uses' => 'PeopleController@create']);
|
||||
Route::post('/people/', 'PeopleController@store');
|
||||
|
||||
// Dashboard
|
||||
Route::get('/people/{people}', ['as' => '.show', 'uses' => 'PeopleController@show']);
|
||||
Route::get('/people/{people}/edit', ['as' => '.edit', 'uses' => 'PeopleController@edit']);
|
||||
Route::post('/people/{people}/update', 'PeopleController@update');
|
||||
Route::get('/people/{people}/delete', ['as' => '.delete', 'uses' => 'PeopleController@delete']);
|
||||
|
||||
// Notes
|
||||
Route::get('/people/{people}/note/add', 'PeopleController@addNote');
|
||||
Route::post('/people/{people}/note/save', 'PeopleController@storeNote');
|
||||
|
||||
// Food preferencies
|
||||
Route::get('/people/{people}/food', ['as' => '.food', 'uses' => 'PeopleController@editFoodPreferencies']);
|
||||
Route::post('/people/{people}/food/save', 'PeopleController@updateFoodPreferencies');
|
||||
|
||||
// Kid
|
||||
Route::get('/people/{people}/kid/add', ['as' => '.dashboard.kid.add', 'uses' => 'PeopleController@addKid']);
|
||||
Route::post('/people/{people}/kid/store', 'PeopleController@storeKid');
|
||||
Route::get('/people/{people}/kid/{kid}/edit', ['as' => '.dashboard.kid.edit', 'uses' => 'PeopleController@editKid']);
|
||||
Route::post('/people/{people}/kid/{kid}/save', 'PeopleController@updateKid');
|
||||
Route::get('/people/{people}/kid/{kid}/delete', 'PeopleController@deleteKid');
|
||||
|
||||
// Significant other
|
||||
Route::get('/people/{people}/significantother/add', ['as' => '.dashboard.significantother.add', 'uses' => 'PeopleController@addSignificantOther']);
|
||||
Route::post('/people/{people}/significantother/store', 'PeopleController@storeSignificantOther');
|
||||
Route::get('/people/{people}/significantother/{significantother}/edit', ['as' => '.dashboard.significantother.edit', 'uses' => 'PeopleController@editSignificantOther']);
|
||||
Route::post('/people/{people}/significantother/{significantother}/save', 'PeopleController@updateSignificantOther');
|
||||
Route::get('/people/{people}/significantother/{significantother}/delete', 'PeopleController@deleteSignificantOther');
|
||||
|
||||
Route::post('/people/{people}/notes/store', 'PeopleController@storeNote');
|
||||
Route::get('/people/{people}/notes/{note}/delete', 'PeopleController@deleteNote');
|
||||
|
||||
// Activities
|
||||
Route::get('/people/{people}/activities', ['as' => '.activities', 'uses' => 'PeopleController@activities']);
|
||||
Route::get('/people/{people}/activities/add', ['as' => '.activities.add', 'uses' => 'PeopleController@addActivity']);
|
||||
Route::post('/people/{people}/activities/store', 'PeopleController@storeActivity');
|
||||
Route::get('/people/{people}/activities/{activity}/edit', ['as' => '.activities.edit', 'uses' => 'PeopleController@editActivity']);
|
||||
Route::post('/people/{people}/activities/{activityId}/save', 'PeopleController@updateActivity');
|
||||
Route::get('/people/{people}/activities/{activityId}/delete', 'PeopleController@deleteActivity');
|
||||
|
||||
// Reminders
|
||||
Route::get('/people/{people}/reminders', ['as' => '.reminders', 'uses' => 'PeopleController@reminders']);
|
||||
Route::get('/people/{people}/reminders/add', ['as' => '.reminders.add', 'uses' => 'PeopleController@addReminder']);
|
||||
Route::post('/people/{people}/reminders/store', 'PeopleController@storeReminder');
|
||||
Route::get('/people/{people}/reminders/{reminderId}/edit', ['as' => '.reminders.edit', 'uses' => 'PeopleController@editReminder']);
|
||||
Route::post('/people/{people}/reminders/{reminderId}/save', 'PeopleController@updateReminder');
|
||||
Route::get('/people/{people}/reminders/{reminderId}/delete', 'PeopleController@deleteReminder');
|
||||
|
||||
// Tasks
|
||||
Route::get('/people/{people}/tasks', ['as' => '.tasks', 'uses' => 'PeopleController@tasks']);
|
||||
Route::get('/people/{people}/tasks/add', ['as' => '.tasks.add', 'uses' => 'PeopleController@addTask']);
|
||||
Route::post('/people/{people}/tasks/store', 'PeopleController@storeTask');
|
||||
Route::get('/people/{people}/tasks/{taskId}/toggle', 'PeopleController@toggleTask');
|
||||
Route::get('/people/{people}/tasks/{taskId}/delete', 'PeopleController@deleteTask');
|
||||
|
||||
// Gifts
|
||||
Route::get('/people/{people}/gifts', ['as' => '.gifts', 'uses' => 'PeopleController@gifts']);
|
||||
Route::get('/people/{people}/gifts/add', ['as' => '.gifts.add', 'uses' => 'PeopleController@addGift']);
|
||||
Route::post('/people/{people}/gifts/store', 'PeopleController@storeGift');
|
||||
Route::get('/people/{people}/gifts/{giftId}/delete', 'PeopleController@deleteGift');
|
||||
});
|
||||
|
||||
Route::group(['as' => 'journal'], function () {
|
||||
Route::get('/journal', ['as' => '.index', 'uses' => 'JournalController@index']);
|
||||
Route::get('/journal/add', ['as' => '.create', 'uses' => 'JournalController@add']);
|
||||
Route::post('/journal/create', ['as' => '.create', 'uses' => 'JournalController@save']);
|
||||
Route::get('/journal/{entryId}/delete', ['as' => '.delete', 'uses' => 'JournalController@deleteEntry']);
|
||||
});
|
||||
|
||||
Route::group(['as' => 'settings'], function () {
|
||||
Route::get('/settings', ['as' => '.index', 'uses' => 'SettingsController@index']);
|
||||
Route::get('/settings/delete', ['as' => '.delete', 'uses' => 'SettingsController@delete']);
|
||||
Route::post('/settings/save', 'SettingsController@save');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
||||
abstract class Job
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queueable Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This job base class provides a central location to place any logic that
|
||||
| is shared across all of your jobs. The trait included with the class
|
||||
| provides access to the "onQueue" and "delay" queue helper methods.
|
||||
|
|
||||
*/
|
||||
|
||||
use Queueable;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Contact;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Intervention\Image\Facades\Image as Image;
|
||||
|
||||
class ResizeAvatars implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $contact;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Contact $contact)
|
||||
{
|
||||
$this->contact = $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->contact->has_avatar == 'true') {
|
||||
|
||||
$avatar_file = Storage::disk('public')->get($this->contact->avatar_file_name);
|
||||
$avatar_path = Storage::disk('public')->url($this->contact->avatar_file_name);
|
||||
$avatar_filename_without_extension = pathinfo($avatar_path, PATHINFO_FILENAME);
|
||||
$avatar_extension = pathinfo($avatar_path, PATHINFO_EXTENSION);
|
||||
|
||||
$size = 110;
|
||||
$avatar_cropped_path = 'avatars/'.$avatar_filename_without_extension.'_'.$size.'.'.$avatar_extension;
|
||||
$avatar = Image::make($avatar_file);
|
||||
$avatar->fit($size);
|
||||
Storage::disk('public')->put($avatar_cropped_path, $avatar->stream());
|
||||
|
||||
$size = 174;
|
||||
$avatar_cropped_path = 'avatars/'.$avatar_filename_without_extension.'_'.$size.'.'.$avatar_extension;
|
||||
$avatar = Image::make($avatar_file);
|
||||
$avatar->fit($size);
|
||||
Storage::disk('public')->put($avatar_cropped_path, $avatar->stream());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\User;
|
||||
use App\Mail\NewUserAlert;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class SendNewUserAlert implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Mail::to('regis@monicahq.com')->send(new NewUserAlert($this->user));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\User;
|
||||
use App\Reminder;
|
||||
use Carbon\Carbon;
|
||||
use App\Mail\UserReminded;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class SendReminderEmail implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $reminder;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Reminder $reminder, User $user)
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Mail::to($this->user->email)->send(new UserReminded($this->reminder, $this->user));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\User;
|
||||
use App\Reminder;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class SetNextReminderDate implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $reminder;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Reminder $reminder, User $user)
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->reminder->frequency_type == 'one_time') {
|
||||
$this->reminder->delete();
|
||||
} else {
|
||||
$frequencyType = $this->reminder->frequency_type;
|
||||
$frequencyNumber = $this->reminder->frequency_number;
|
||||
$startDate = $this->reminder->next_expected_date;
|
||||
$this->reminder->calculateNextExpectedDate($startDate, $frequencyType, $frequencyNumber);
|
||||
$this->reminder->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Gift;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Events\Kid\KidCreated;
|
||||
use App\Events\Kid\KidDeleted;
|
||||
use App\Events\Kid\KidUpdated;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Kid extends Model
|
||||
{
|
||||
protected $dates = ['birthdate'];
|
||||
|
||||
protected $events = [
|
||||
'created' => KidCreated::class,
|
||||
'updated' => KidUpdated::class,
|
||||
'deleted' => KidDeleted::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets the age of the kid in years, or returns null if the birthdate
|
||||
* is not set.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAge()
|
||||
{
|
||||
if (is_null($this->birthdate)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$age = $this->birthdate->diffInYears(Carbon::now());
|
||||
|
||||
return $age;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the birthdate of the kid.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBirthdate()
|
||||
{
|
||||
if (is_null($this->birthdate)) {
|
||||
return Carbon::now()->format('Y-m-d');
|
||||
}
|
||||
|
||||
return $this->birthdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first name of the kid.
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
if (is_null($this->first_name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decrypt($this->first_name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Activity\ActivityDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class DecreaseActivitiesStatistics
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ActivityDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityDeleted $event)
|
||||
{
|
||||
$contact = Contact::find($event->activity->contact_id);
|
||||
$contact->calculateActivitiesStatistics();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Activity\ActivityDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class DecreaseNumberOfActivities
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ActivityDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityDeleted $event)
|
||||
{
|
||||
$contact = Contact::find($event->activity->contact_id);
|
||||
$contact->number_of_activities = $contact->number_of_activities - 1;
|
||||
|
||||
if ($contact->number_of_activities < 1) {
|
||||
$contact->number_of_activities = 0;
|
||||
}
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Activity\ActivityCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class IncreaseActivitiesStatistics
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute all the statistics for all the activities of the contact.
|
||||
* This is triggered everytime an activity is created, updated or deleted.
|
||||
*
|
||||
*
|
||||
* @param ActivityUpdated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityCreated $event)
|
||||
{
|
||||
$contact = Contact::find($event->activity->contact_id);
|
||||
$contact->calculateActivitiesStatistics();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Activity\ActivityCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class IncrementNumberOfActivities
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ActivityCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityCreated $event)
|
||||
{
|
||||
$contact = Contact::find($event->activity->contact_id);
|
||||
$contact->number_of_activities = $contact->number_of_activities + 1;
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Activity\ActivityCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogActivityCreatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ActivityCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityCreated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->activity->account_id;
|
||||
$eventToSave->contact_id = $event->activity->contact_id;
|
||||
$eventToSave->object_type = 'activity';
|
||||
$eventToSave->object_id = $event->activity->id;
|
||||
$eventToSave->nature_of_operation = 'create';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Activity\ActivityUpdated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogActivityUpdatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ActivityUpdated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityUpdated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->activity->account_id;
|
||||
$eventToSave->contact_id = $event->activity->contact_id;
|
||||
$eventToSave->object_type = 'activity';
|
||||
$eventToSave->object_id = $event->activity->id;
|
||||
$eventToSave->nature_of_operation = 'update';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Activity\ActivityDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class RemoveAllActivityEvents
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ActivityDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityDeleted $event)
|
||||
{
|
||||
$events = Event::where('contact_id', $event->activity->contact_id)
|
||||
->where('account_id', $event->activity->account_id)
|
||||
->where('object_type', 'activity')
|
||||
->where('object_id', $event->activity->id)
|
||||
->get();
|
||||
|
||||
foreach ($events as $event) {
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Activity;
|
||||
|
||||
use App\Contact;
|
||||
use App\Activity;
|
||||
use App\ActivityStatistic;
|
||||
use App\Events\Activity\ActivityUpdated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class UpdateActivitiesStatistics
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute all the statistics for all the activities of the contact.
|
||||
* This is triggered everytime an activity is created, updated or deleted.
|
||||
*
|
||||
*
|
||||
* @param ActivityUpdated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ActivityUpdated $event)
|
||||
{
|
||||
$contact = Contact::find($event->activity->contact_id);
|
||||
$contact->calculateActivitiesStatistics();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Contact;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Contact\ContactCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogContactCreatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ContactCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ContactCreated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->contact->account_id;
|
||||
$eventToSave->contact_id = $event->contact->id;
|
||||
$eventToSave->object_type = 'contact';
|
||||
$eventToSave->object_id = $event->contact->id;
|
||||
$eventToSave->nature_of_operation = 'create';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Contact;
|
||||
|
||||
use App\Events\Contact\ContactCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class SetAvatarColor
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ContactCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ContactCreated $event)
|
||||
{
|
||||
$event->contact->setAvatarColor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Gift;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Gift\GiftDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class DecreaseNumberOfGifts
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param GiftDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(GiftDeleted $event)
|
||||
{
|
||||
$contact = Contact::find($event->gift->contact_id);
|
||||
|
||||
if ($event->gift->is_an_idea == 'true') {
|
||||
$contact->number_of_gifts_ideas = $contact->number_of_gifts_ideas - 1;
|
||||
|
||||
if ($contact->number_of_gifts_ideas < 1) {
|
||||
$contact->number_of_gifts_ideas = 0;
|
||||
}
|
||||
} else {
|
||||
$contact->number_of_gifts_offered = $contact->number_of_gifts_offered - 1;
|
||||
|
||||
if ($contact->number_of_gifts_offered < 1) {
|
||||
$contact->number_of_gifts_offered = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Gift;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Gift\GiftCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class IncrementNumberOfGifts
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param GitCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(GiftCreated $event)
|
||||
{
|
||||
$contact = Contact::find($event->gift->contact_id);
|
||||
|
||||
if ($event->gift->is_an_idea == 'true') {
|
||||
$contact->number_of_gifts_ideas = $contact->number_of_gifts_ideas + 1;
|
||||
} else {
|
||||
$contact->number_of_gifts_offered = $contact->number_of_gifts_offered + 1;
|
||||
}
|
||||
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Gift;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Gift\GiftCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogGiftCreatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param GitCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(GiftCreated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->gift->account_id;
|
||||
$eventToSave->contact_id = $event->gift->contact_id;
|
||||
$eventToSave->object_type = 'gift';
|
||||
$eventToSave->object_id = $event->gift->id;
|
||||
$eventToSave->nature_of_operation = 'create';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Gift;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Gift\GiftDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class RemoveAllGiftEvents
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param GiftDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(GiftDeleted $event)
|
||||
{
|
||||
$events = Event::where('contact_id', $event->gift->contact_id)
|
||||
->where('account_id', $event->gift->account_id)
|
||||
->where('object_type', 'gift')
|
||||
->where('object_id', $event->gift->id)
|
||||
->get();
|
||||
|
||||
foreach ($events as $event) {
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Kid;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Kid\KidDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class DecreaseNumberOfKids
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param KidDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(KidDeleted $event)
|
||||
{
|
||||
$contact = Contact::find($event->kid->child_of_contact_id);
|
||||
$contact->number_of_kids = $contact->number_of_kids - 1;
|
||||
|
||||
if ($contact->number_of_kids < 1) {
|
||||
$contact->number_of_kids = 0;
|
||||
$contact->has_kids = 'false';
|
||||
}
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Kid;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Kid\KidCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class IncrementNumberOfKids
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param KidCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(KidCreated $event)
|
||||
{
|
||||
$contact = Contact::find($event->kid->child_of_contact_id);
|
||||
$contact->has_kids = 'true';
|
||||
$contact->number_of_kids = $contact->number_of_kids + 1;
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Kid;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Kid\KidCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogKidCreatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param KidCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(KidCreated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->kid->account_id;
|
||||
$eventToSave->contact_id = $event->kid->child_of_contact_id;
|
||||
$eventToSave->object_type = 'kid';
|
||||
$eventToSave->object_id = $event->kid->id;
|
||||
$eventToSave->nature_of_operation = 'create';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Kid;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Kid\KidUpdated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogKidUpdatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param KidUpdated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(KidUpdated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->kid->account_id;
|
||||
$eventToSave->contact_id = $event->kid->child_of_contact_id;
|
||||
$eventToSave->object_type = 'kid';
|
||||
$eventToSave->object_id = $event->kid->id;
|
||||
$eventToSave->nature_of_operation = 'update';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Kid;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Kid\KidDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class RemoveAllKidEvents
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param SignificantOtherDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(KidDeleted $event)
|
||||
{
|
||||
$events = Event::where('contact_id', $event->kid->child_of_contact_id)
|
||||
->where('account_id', $event->kid->account_id)
|
||||
->where('object_type', 'kid')
|
||||
->where('object_id', $event->kid->id)
|
||||
->get();
|
||||
|
||||
foreach ($events as $event) {
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Note;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Note\NoteDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class DecreaseNumberOfNotes
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param NoteDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(NoteDeleted $event)
|
||||
{
|
||||
$contact = Contact::find($event->note->contact_id);
|
||||
$contact->number_of_notes = $contact->number_of_notes - 1;
|
||||
|
||||
if ($contact->number_of_notes < 1) {
|
||||
$contact->number_of_notes = 0;
|
||||
}
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Note;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Note\NoteCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class IncrementNumberOfNotes
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param NoteCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(NoteCreated $event)
|
||||
{
|
||||
$contact = Contact::find($event->note->contact_id);
|
||||
$contact->number_of_notes = $contact->number_of_notes + 1;
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Note;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Note\NoteCreated;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogNoteCreatedEvent
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param NoteCreated $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(NoteCreated $event)
|
||||
{
|
||||
$eventToSave = new Event;
|
||||
$eventToSave->account_id = $event->note->account_id;
|
||||
$eventToSave->contact_id = $event->note->contact_id;
|
||||
$eventToSave->object_type = 'note';
|
||||
$eventToSave->object_id = $event->note->id;
|
||||
$eventToSave->nature_of_operation = 'update';
|
||||
$eventToSave->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Note;
|
||||
|
||||
use App\Event;
|
||||
use App\Events\Note\NoteDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class RemoveAllNoteEvents
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param NoteDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(NoteDeleted $event)
|
||||
{
|
||||
$events = Event::where('contact_id', $event->note->contact_id)
|
||||
->where('account_id', $event->note->account_id)
|
||||
->where('object_type', 'note')
|
||||
->where('object_id', $event->note->id)
|
||||
->get();
|
||||
|
||||
foreach ($events as $event) {
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Reminder;
|
||||
|
||||
use App\Contact;
|
||||
use App\Events\Reminder\ReminderDeleted;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class DecreaseNumberOfReminders
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ReminderDeleted $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ReminderDeleted $event)
|
||||
{
|
||||
$contact = Contact::find($event->reminder->contact_id);
|
||||
$contact->number_of_reminders = $contact->number_of_reminders - 1;
|
||||
|
||||
if ($contact->number_of_reminders < 1) {
|
||||
$contact->number_of_reminders = 0;
|
||||
}
|
||||
$contact->save();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user