forked from point-red/point
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
study sheet model, route, controller, test
- Loading branch information
1 parent
56bb94c
commit b58fead
Showing
10 changed files
with
489 additions
and
8 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
app/Http/Controllers/Api/Plugin/Study/StudySheetController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Plugin\Study; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Model\Master\User; | ||
use App\Model\Plugin\Study\StudySheet; | ||
use Illuminate\Http\Request; | ||
|
||
class StudySheetController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
return StudySheet::eloquentFilter($request) | ||
->fields($request->get('fields')) | ||
->where('user_id', auth()->id()) | ||
->paginate(); | ||
|
||
// search | ||
// filter | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// $request->file('video'); | ||
// $request->file('voice'); | ||
// $request->file('photo'); | ||
|
||
$validated = $request->all(); | ||
// $validated = $request->validated(); | ||
|
||
$sheet = new StudySheet(); | ||
$sheet->fill($validated); | ||
$sheet->user_id = auth()->id(); | ||
$sheet->save(); | ||
|
||
return $sheet; | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param \App\Model\Plugin\Study\StudySheet $sheet | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show(StudySheet $sheet) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param \App\Model\Plugin\Study\StudySheet $sheet | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit(StudySheet $sheet) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Model\Plugin\Study\StudySheet $sheet | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, StudySheet $sheet) | ||
{ | ||
$validated = $request->all(); | ||
// $validated = $request->validated(); | ||
$sheet->update($validated); | ||
return $sheet; | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Model\Plugin\Study\StudySheet $sheet | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(StudySheet $sheet) | ||
{ | ||
return $sheet->delete(); | ||
|
||
// delete photo from drive | ||
// delete voice from drive | ||
// delete video from drive | ||
// delete from database | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Model\Plugin\Study; | ||
|
||
use App\Model\PointModel; | ||
|
||
class StudySheet extends PointModel | ||
{ | ||
protected $connection = 'tenant'; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'started_at', | ||
'ended_at', | ||
'subject_id', | ||
'institution', | ||
'teacher', | ||
'competency', | ||
'learning_goals', | ||
'activities', | ||
'grade', | ||
'behavior', | ||
'remarks', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
class Drive | ||
{ | ||
private \Google_Client $client; | ||
private \Google\Service\Drive $service; | ||
private \Masbug\Flysystem\GoogleDriveAdapter $adapter; | ||
private \League\Flysystem\Filesystem $driver; | ||
private \Illuminate\Filesystem\FilesystemAdapter $disk; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = Google::client(); | ||
|
||
// https://github.com/masbug/flysystem-google-drive-ext#using-with-laravel-framework | ||
$this->service = new \Google\Service\Drive($this->client); | ||
$this->adapter = new \Masbug\Flysystem\GoogleDriveAdapter($this->service); | ||
$this->driver = new \League\Flysystem\Filesystem($this->adapter); | ||
$this->disk = new \Illuminate\Filesystem\FilesystemAdapter($this->driver, $this->adapter); | ||
} | ||
|
||
/** | ||
* Upload file to user's Google Drive account, set permission, get file id and path. | ||
* | ||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file | ||
* @param string $dir | ||
* @return array | ||
*/ | ||
public function store($file, $dir = '') | ||
{ | ||
if (empty($dir)) { | ||
$dir = config('services.google.drive.root'); | ||
} | ||
|
||
// Upload file to google drive, get the filename and extension | ||
$filename = $this->disk->putFile($dir, $file); | ||
|
||
// get file metadata to get the file id | ||
// file id is used to set permission and get preview link | ||
$metadata = $this->adapter->getMetadata($filename); | ||
|
||
$fileId = $metadata['id']; | ||
|
||
// set file permission to "Anyone on the internet with this link can view" | ||
// https://stackoverflow.com/a/57450358/3671954 | ||
$newPermission = new \Google\Service\Drive\Permission([ | ||
'type' => 'anyone', | ||
'role' => 'reader', | ||
'additionalRoles' => [], | ||
'withLink' => true, | ||
'value' => '' | ||
]); | ||
$this->service->permissions->create($fileId, $newPermission); | ||
|
||
return [ | ||
'id' => $fileId, | ||
'path' => implode('/', [$dir, $filename]), | ||
]; | ||
} | ||
|
||
/** | ||
* Delete existing file from user's Google Drive account. | ||
* | ||
* @param string $fileId | ||
* @return void | ||
*/ | ||
public function destroy(string $path) | ||
{ | ||
$this->disk->delete($path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
class Google | ||
{ | ||
public static function client() | ||
{ | ||
$oauthClientId = config('services.google.client_id'); | ||
$oauthClientSecret = config('services.google.client_secret'); | ||
|
||
// $client = new \Google\Client(); // newer version use this | ||
$client = new \Google_Client(); | ||
|
||
$client->setClientId($oauthClientId); | ||
$client->setClientSecret($oauthClientSecret); | ||
|
||
// get user access / refresh token | ||
|
||
return $client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
|
||
use App\Model\Plugin\Study\StudySheet; | ||
use App\Model\Plugin\Study\StudySubject; | ||
use Faker\Generator as Faker; | ||
|
||
$factory->define(StudySheet::class, function (Faker $faker) { | ||
return [ | ||
'started_at' => now()->startOfHour(), | ||
'ended_at' => function (array $attributes) { | ||
return Carbon\Carbon::make($attributes['started_at'])->addHour(); | ||
}, | ||
'institution' => $faker->text(), | ||
'teacher' => $faker->name(), | ||
'competency' => $faker->text(), | ||
'learning_goals' => $faker->text(), | ||
'activities' => $faker->text(), | ||
'grade' => $faker->numberBetween(0,100), | ||
'behavior' => $faker->randomElement(['A', 'B', 'C']), | ||
'remarks' => $faker->text(), | ||
'subject_id' => factory(StudySubject::class), | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.