Skip to content

Commit

Permalink
Created school model. This fixes #31. (#32)
Browse files Browse the repository at this point in the history
* created school model. This fixes #31.

* fixed school factory
  • Loading branch information
MelonSmasher committed Jun 8, 2017
1 parent d1394ab commit fa0f054
Show file tree
Hide file tree
Showing 33 changed files with 1,650 additions and 16 deletions.
75 changes: 75 additions & 0 deletions app/Events/Api/Account/AssignedSchool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Events\Api\Account;

use App\Http\Models\API\Account;
use App\Http\Models\API\School;
use Illuminate\Support\Facades\Log;
use App\Events\Event;
use Illuminate\Support\Facades\Redis;
use Krucas\Settings\Facades\Settings;


class AssignedSchool extends Event
{
/**
* AssignedSchool constructor.
* @param Account $account
* @param School $school
*/
public function __construct(Account $account, School $school)
{
$info = [
'account_id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true),
'school_id' => $school->id,
'school_code' => $school->code,
'school_label' => $school->label
];

Log::info('Account assigned School:', $info);

if ($user = auth()->user()) {

if (Settings::get('broadcast-events', false)) {

$account->primary_duty = $account->primaryDuty;
$trans = $account->toArray();
$trans['name_full'] = $account->format_full_name(true);
unset($trans['password']);
$trans['username'] = strtolower($trans['username']);

$data_to_secure = json_encode([
'data' => [
'account' => $account,
'school' => $school->toArray()
],
'conf' => [
'ldap' => ldap_config()
]
]);

$secure_data = encrypt_broadcast_data($data_to_secure);

$message = [
'event' => 'assigned',
'type' => 'school',
'to' => 'account',
'encrypted' => $secure_data
];

Redis::publish('events', json_encode($message));
}

history()->log(
'Assignment',
'enrolled ' . $account->format_full_name() . ' in school: "' . $school->label . '"',
$account->id,
'university',
'bg-olive'
);
}
}
}
75 changes: 75 additions & 0 deletions app/Events/Api/Account/UnassignedSchool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Events\Api\Account;

use App\Http\Models\API\Account;
use App\Http\Models\API\School;
use Illuminate\Support\Facades\Log;
use App\Events\Event;
use Illuminate\Support\Facades\Redis;
use Krucas\Settings\Facades\Settings;


class UnassignedSchool extends Event
{
/**
* UnassignedCourse constructor.
* @param Account $account
* @param School $school
*/
public function __construct(Account $account, School $school)
{
$info = [
'account_id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true),
'school_id' => $school->id,
'school_code' => $school->code,
'school_label' => $school->label
];

Log::info('Account removed from School:', $info);

if ($user = auth()->user()) {

if (Settings::get('broadcast-events', false)) {

$account->primary_duty = $account->primaryDuty;
$trans = $account->toArray();
$trans['name_full'] = $account->format_full_name(true);
unset($trans['password']);
$trans['username'] = strtolower($trans['username']);

$data_to_secure = json_encode([
'data' => [
'account' => $account,
'school' => $school->toArray()
],
'conf' => [
'ldap' => ldap_config()
]
]);

$secure_data = encrypt_broadcast_data($data_to_secure);

$message = [
'event' => 'unassigned',
'type' => 'school',
'to' => 'account',
'encrypted' => $secure_data
];

Redis::publish('events', json_encode($message));
}

history()->log(
'Assignment',
'removed ' . $account->format_full_name() . ' from school: "' . $school->label . '"',
$account->id,
'university',
'bg-yellow'
);
}
}
}
2 changes: 1 addition & 1 deletion app/Events/Api/LoadStatus/LoadStatusCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(LoadStatus $loadStatus)
'LoadStatus',
'created a new load status: ' . $loadStatus->label,
$loadStatus->id,
'fa-university',
'cubes',
'bg-green'
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Events/Api/LoadStatus/LoadStatusDestroyed.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(LoadStatus $loadStatus)
'LoadStatus',
'destroyed a load status: ' . $loadStatus->label,
$loadStatus->id,
'fa-university',
'cubes',
'bg-red'
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Events/Api/LoadStatus/LoadStatusRestored.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Events\Api\LoadStatus;

use App\Http\Models\API\Course;
use App\Http\Models\API\LoadStatus;
use App\Events\Event;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Log;
Expand All @@ -12,7 +12,7 @@ class LoadStatusRestored extends Event
{

/**
* CourseRestored constructor.
* LoadStatusRestored constructor.
* @param LoadStatus $loadStatus
*/
public function __construct(LoadStatus $loadStatus)
Expand Down Expand Up @@ -51,7 +51,7 @@ public function __construct(LoadStatus $loadStatus)
'LoadStatus',
'restored a load status: ' . $loadStatus->label() . '.',
$loadStatus->id,
'fa-university',
'cubes',
'bg-lime'
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Events/Api/LoadStatus/LoadStatusUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(LoadStatus $loadStatus)
'LoadStatus',
'updated the load status: ' . $loadStatus->label() . '.',
$loadStatus->id,
'fa-university',
'cubes',
'bg-lime'
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Events/Api/LoadStatus/LoadStatusViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(LoadStatus $loadStatus)
'LoadStatus',
'viewed ' . $loadStatus->label . '.',
$loadStatus->id,
'fa-university',
'cubes',
'bg-aqua'
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Events/Api/LoadStatus/LoadStatusesViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public function __construct($loadStatusIds = [])
'LoadStatus',
'viewed ' . count($loadStatusIds) . ' load statuses',
$user->id,
'fa-university',
'cubes',
'bg-aqua'
);

}

Log::info($user_name . ' viewed ' . count($loadStatusIds) . ' courses', $loadStatusIds);
Log::info($user_name . ' viewed ' . count($loadStatusIds) . ' schools', $loadStatusIds);
}
}
56 changes: 56 additions & 0 deletions app/Events/Api/School/SchoolCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Events\Api\School;

use App\Http\Models\API\School;
use Illuminate\Support\Facades\Log;
use App\Events\Event;
use Illuminate\Support\Facades\Redis;
use Krucas\Settings\Facades\Settings;

class SchoolCreated extends Event
{
/**
* SchoolCreated constructor.
* @param School $school
*/
public function __construct(School $school)
{
Log::info('School Created:', [
'id' => $school->id,
'code' => $school->code,
'label' => $school->label
]);

if ($user = auth()->user()) {

if (Settings::get('broadcast-events', false)) {

$data_to_secure = json_encode([
'data' => $school->toArray(),
'conf' => [
'ldap' => ldap_config()
]
]);

$secure_data = encrypt_broadcast_data($data_to_secure);

$message = [
'event' => 'created',
'type' => 'school',
'encrypted' => $secure_data
];

Redis::publish('events', json_encode($message));
}

history()->log(
'School',
'created a new school: ' . $school->label,
$school->id,
'university',
'bg-green'
);
}
}
}
56 changes: 56 additions & 0 deletions app/Events/Api/School/SchoolDestroyed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Events\Api\School;

use App\Http\Models\API\School;
use Krucas\Settings\Facades\Settings;
use Illuminate\Support\Facades\Log;
use App\Events\Event;
use Illuminate\Support\Facades\Redis;

class SchoolDestroyed extends Event
{
/**
* SchoolDestroyed constructor.
* @param School $school
*/
public function __construct(School $school)
{
Log::info('School Destroyed:', [
'id' => $school->id,
'code' => $school->code,
'label' => $school->label
]);

if ($user = auth()->user()) {

if (Settings::get('broadcast-events', false)) {

$data_to_secure = json_encode([
'data' => $school->toArray(),
'conf' => [
'ldap' => ldap_config()
]
]);

$secure_data = encrypt_broadcast_data($data_to_secure);

$message = [
'event' => 'deleted',
'type' => 'school',
'encrypted' => $secure_data
];

Redis::publish('events', json_encode($message));
}

history()->log(
'School',
'destroyed a school: ' . $school->label,
$school->id,
'university',
'bg-red'
);
}
}
}

0 comments on commit fa0f054

Please sign in to comment.