| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Http\Resources;
- use App\Http\Api\GroupApi;
- use App\Http\Api\StudioApi;
- use App\Http\Api\UserApi;
- use App\Models\Article;
- use App\Models\Channel;
- use App\Models\Collection;
- use App\Models\Project;
- use Illuminate\Contracts\Support\Arrayable;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class ShareResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param Request $request
- * @return array|Arrayable|\JsonSerializable
- */
- public function toArray($request)
- {
- // 获取资源信息
- $res_name = '';
- $owner = '';
- switch ($this->res_type) {
- case 1:
- // PCS 文档
- break;
- case 2:
- // Channel 版本
- $res = Channel::where('uid', $this->res_id)->first();
- if ($res) {
- $res_name = $res->name;
- $owner = StudioApi::getById($res->owner_uid);
- }
- break;
- case 3:
- // Article 文章
- $res = Article::where('uid', $this->res_id)->first();
- if ($res) {
- $res_name = $res->title;
- $owner = StudioApi::getById($res->owner);
- }
- break;
- case 4:
- // Collection 文集
- $res = Collection::where('uid', $this->res_id)->first();
- if ($res) {
- $res_name = $res->title;
- $owner = StudioApi::getById($res->owner);
- }
- break;
- case 5:
- // 版本片段 不支持
- break;
- case 6: // workflow
- $res = Project::where('uid', $this->res_id)->first();
- if ($res) {
- $res_name = $res->title;
- $owner = StudioApi::getById($res->owner_id);
- }
- break;
- default:
- // code...
- break;
- }
- $data = [
- 'id' => $this->id,
- 'res_id' => $this->res_id,
- 'res_type' => $this->res_type,
- 'collaborator_type' => $this->cooperator_type,
- 'power' => $this->power,
- 'res_name' => $res_name,
- 'owner' => $owner,
- 'created_at' => $this->created_at,
- 'updated_at' => $this->updated_at,
- ];
- switch ($this->cooperator_type) {
- case 0:
- // user
- $data['user'] = UserApi::getByUuid($this->cooperator_id);
- break;
- case 1:
- // code...
- $data['group'] = GroupApi::getById($this->cooperator_id);
- break;
- }
- return $data;
- }
- }
|