芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/Models/Task.php
$mentionTask * @property-read int|null $mention_task_count * @property-read \Illuminate\Database\Eloquent\Collection
$mentionUser * @property-read int|null $mention_user_count * @property-read \Illuminate\Database\Eloquent\Collection
$mentionTask * @property-read \Illuminate\Database\Eloquent\Collection
$mentionUser * @mixin \Eloquent */ class Task extends BaseModel { use Notifiable, SoftDeletes; use CustomFieldsTrait; use HasCompany; protected $casts = [ 'due_date' => 'datetime', 'completed_on' => 'datetime', 'start_date' => 'datetime', ]; protected $appends = ['due_on', 'create_on']; protected $guarded = ['id']; protected $with = ['company:id,date_format']; const CUSTOM_FIELD_MODEL = 'App\Models\Task'; public function project(): BelongsTo { return $this->belongsTo(Project::class, 'project_id')->withTrashed(); } public function activeProject(): BelongsTo { return $this->belongsTo(Project::class, 'project_id'); } public function label(): HasMany { return $this->hasMany(TaskLabel::class, 'task_id'); } public function boardColumn(): BelongsTo { return $this->belongsTo(TaskboardColumn::class, 'board_column_id'); } public function users(): BelongsToMany { return $this->belongsToMany(User::class, 'task_users')->withoutGlobalScope(ActiveScope::class)->using(TaskUser::class); } public function taskUsers(): HasMany { return $this->hasMany(TaskUser::class, 'task_id'); } public function activeUsers(): BelongsToMany { return $this->belongsToMany(User::class, 'task_users')->using(TaskUser::class); } public function labels(): BelongsToMany { return $this->belongsToMany(TaskLabelList::class, 'task_labels', 'task_id', 'label_id'); } public function createBy(): BelongsTo { return $this->belongsTo(User::class, 'created_by')->withoutGlobalScope(ActiveScope::class); } public function addedByUser(): BelongsTo { return $this->belongsTo(User::class, 'added_by')->withoutGlobalScope(ActiveScope::class); } public function category(): BelongsTo { return $this->belongsTo(TaskCategory::class, 'task_category_id'); } public function subtasks(): HasMany { return $this->hasMany(SubTask::class, 'task_id'); } public function history(): HasMany { return $this->hasMany(TaskHistory::class, 'task_id')->orderBy('id', 'desc'); } public function completedSubtasks(): HasMany { return $this->hasMany(SubTask::class, 'task_id')->where('sub_tasks.status', 'complete'); } public function incompleteSubtasks(): HasMany { return $this->hasMany(SubTask::class, 'task_id')->where('sub_tasks.status', 'incomplete'); } public function comments(): HasMany { return $this->hasMany(TaskComment::class, 'task_id')->orderBy('id', 'desc'); } public function notes(): HasMany { return $this->hasMany(TaskNote::class, 'task_id')->orderBy('id', 'desc'); } public function files(): HasMany { return $this->hasMany(TaskFile::class, 'task_id')->orderBy('id', 'desc'); } public function activeTimer(): HasOne { return $this->hasOne(ProjectTimeLog::class, 'task_id') ->whereNull('project_time_logs.end_time'); } public function userActiveTimer(): HasOne { return $this->hasOne(ProjectTimeLog::class, 'task_id') ->whereNull('project_time_logs.end_time') ->where('project_time_logs.user_id', user()->id); } public function activeTimerAll(): HasMany { return $this->hasMany(ProjectTimeLog::class, 'task_id') ->whereNull('project_time_logs.end_time'); } public function timeLogged(): HasMany { return $this->hasMany(ProjectTimeLog::class, 'task_id'); } public function approvedTimeLogs(): HasMany { return $this->hasMany(ProjectTimeLog::class, 'task_id')->where('project_time_logs.approved', 1)->orderBy('project_time_logs.start_time', 'desc'); } public function recurrings(): HasMany { return $this->hasMany(Task::class, 'recurring_task_id'); } public function milestone(): BelongsTo { return $this->belongsTo(ProjectMilestone::class, 'milestone_id'); } public function scopePending($query) { $taskBoardColumn = TaskboardColumn::completeColumn(); return $query->where('tasks.board_column_id', '<>', $taskBoardColumn->id); } /** * @return string */ public function getDueOnAttribute() { if (is_null($this->due_date)) { return ''; } return $this->due_date->format($this->company->date_format); } public function getCreateOnAttribute() { if (is_null($this->start_date)) { return ''; } return $this->start_date->format($this->company->date_format); } public function getIsTaskUserAttribute() { if (user()) { return $this->taskUsers->where('user_id', user()->id)->first(); } } public function getTotalEstimatedMinutesAttribute() { $hours = $this->estimate_hours; $minutes = $this->estimate_minutes; return ($hours * 60) + $minutes; } /** * @param int $projectId * @param null $userID * @return \Illuminate\Support\Collection */ public static function projectOpenTasks($projectId, $userID = null) { $taskBoardColumn = TaskboardColumn::completeColumn(); $projectTask = Task::join('task_users', 'task_users.task_id', '=', 'tasks.id') ->where('tasks.board_column_id', '<>', $taskBoardColumn->id) ->select('tasks.*'); if ($userID) { $projectIssue = $projectTask->where('task_users.user_id', '=', $userID); } $projectIssue = $projectTask->where('project_id', $projectId) ->get(); return $projectIssue; } public static function projectCompletedTasks($projectId) { $taskBoardColumn = TaskboardColumn::completeColumn(); return Task::where('tasks.board_column_id', $taskBoardColumn->id) ->where('project_id', $projectId) ->get(); } public static function projectTasks($projectId, $userID = null, $onlyPublic = null, $withoutDueDate = null) { $projectTask = Task::with('boardColumn') ->leftJoin('task_users', 'task_users.task_id', '=', 'tasks.id') ->where('project_id', $projectId) ->select('tasks.*'); if ($userID) { $projectIssue = $projectTask->where('task_users.user_id', '=', $userID); } if ($withoutDueDate) { $projectIssue = $projectTask->whereNotNull('tasks.due_date'); } if ($onlyPublic != null) { $projectIssue = $projectTask->where( function ($q) { $q->where('is_private', 0); if (auth()->user()) { $q->orWhere('created_by', user()->id); } } ); } $projectIssue = $projectTask->select('tasks.*'); $projectIssue = $projectTask->orderBy('start_date', 'asc'); $projectIssue = $projectTask->groupBy('tasks.id'); $projectIssue = $projectTask->get(); return $projectIssue; } public static function projectLogTimeTasks($projectId, $userID = null, $onlyPublic = null, $withoutDueDate = null) { $projectTask = Task::with('boardColumn') ->leftJoin('task_users', 'task_users.task_id', '=', 'tasks.id') ->where('project_id', $projectId) ->select('tasks.*'); if ($userID) { $projectIssue = $projectTask->where('task_users.user_id', '=', $userID); } if ($withoutDueDate) { $projectIssue = $projectTask->whereNotNull('tasks.due_date'); } if ($onlyPublic != null) { $projectIssue = $projectTask->where( function ($q) { $q->where('is_private', 0); if (auth()->user()) { $q->orWhere('created_by', user()->id); } } ); } // Get tasks related to selected project and selected project manager $viewTaskPermission = user()->permission('view_tasks'); $addTimelogPermission = user()->permission('add_timelogs'); if ($viewTaskPermission == 'both') { $projectTask->where(function ($query) use ($addTimelogPermission) { if ($addTimelogPermission == 'all') { $query->where('tasks.added_by', user()->id); } $query->orWhere('task_users.user_id', user()->id); }); } $projectIssue = $projectTask->select('tasks.*'); $projectIssue = $projectTask->orderBy('start_date'); $projectIssue = $projectTask->groupBy('tasks.id'); $projectIssue = $projectTask->get(); return $projectIssue; } /** * @return bool */ public function pinned() { $pin = Pinned::where('user_id', user()->id)->where('task_id', $this->id)->first(); if (!is_null($pin)) { return true; } return false; } public static function timelogTasks($projectId = null) { $viewTaskPermission = user()->permission('view_tasks'); $addTimelogPermission = user()->permission('add_timelogs'); if ($viewTaskPermission != 'none' && $addTimelogPermission != 'none') { $tasks = Task::select('tasks.id', 'tasks.heading') ->join('task_users', 'task_users.task_id', '=', 'tasks.id'); if (!is_null($projectId)) { $tasks->where('tasks.project_id', '=', $projectId); } if ($viewTaskPermission == 'both') { $tasks->where(function ($query) use ($addTimelogPermission) { if ($addTimelogPermission == 'all') { $query->where('tasks.added_by', user()->id); } $query->orWhere('task_users.user_id', user()->id); }); } if ($viewTaskPermission == 'added' && $addTimelogPermission == 'all') { $tasks->where('tasks.added_by', user()->id); } if ($viewTaskPermission == 'owned') { $tasks->where('task_users.user_id', user()->id); } return $tasks->groupBy('tasks.id')->get(); } } public function breakMinutes() { return ProjectTimeLogBreak::taskBreakMinutes($this->id); } public function mentionUser(): BelongsToMany { return $this->belongsToMany(User::class, 'mention_users')->withoutGlobalScope(ActiveScope::class)->using(MentionUser::class); } public function mentionTask(): HasMany { return $this->hasMany(MentionUser::class, 'task_id'); } public static function projectTaskCount($projectID) { $task = Task::where('project_id', $projectID)->orderBy('id', 'desc')->first(); if ($task) { $taskID = explode('-', $task->task_short_code); $taskCode = array_pop($taskID); return (int)$taskCode; } return 0; } }