<commit_before><?php

namespace App\Repositories;

use App\Definer;
use App\Project\Project;
use App\User;
use Illuminate\Http\Request;

class MemberRepository
{
    /**
     * 项目成员资源
     *
     * @param Project $project
     * @return array
     */
    public function MemberResources(Project $project)
    {
        $pl = $project->ProjectLeader;
        $sl = $project->SubLeader;
        $pms = $project->Users->all();
        $paCount = $project->Users()->where('is_admin', Definer::PROJECT_ADMIN)->count();
        $pmCount = $project->Users->count() - $paCount;
        $allCount = $pmCount + $paCount;
        if ($pl) {
            $allCount += 1;
        }
        if ($sl) {
            $allCount += 1;
            $slCount = 1;
        } else {
            $slCount = 0;
        }
        $users = User::all();

        return compact('pl', 'sl', 'pms', 'pmCount', 'allCount', 'slCount', 'users', 'paCount');
    }

    /**
     * 获取所有成员
     *
     * @param Project $project
     * @return array
     */
    public function AllMember(Project $project)
    {
        $pl = $project->ProjectLeader;
        $sl = $project->SubLeader;
        $pms = $project->Users->all();

        return compact('pl', 'sl', 'pms');
    }

    /**
     * 添加成员方法
     *
     * @param Request $request
     * @param Project $project
     * @return bool
     */
    public function AddMember(Request $request, Project $project)
    {
        $user = User::findOrFail($request->get('id'));

        if ($project->Users()->find($user->id) != null) {
            return false;
        } elseif ($user->id === $project->user_id) {
            return false;
        } elseif ($user->id === $project->sl_id) {
            return false;
        } elseif ($user->id === Definer::SUPER_ADMIN_ID) {
            return false;
        } else {
            $project->Users()->attach($user);

            return true;
        }
    }

    /**
     * 移除成员方法
     *
     * @param Project $project
     * @param User $user
     * @return bool
     */
    public function RemoveMember(Project $project, User $user)
    {
        if ($project->Users()->find($user->id) == null) {
            return false;
        } elseif ($user->id === $project->user_id) {
            return false;
        } elseif ($user->id === $project->sl_id) {
            return false;
        } elseif ($user->id === Definer::SUPER_ADMIN_ID) {
            return false;
        } else {
            $project->Users()->detach($user);

            return true;
        }
    }

    /**
     * 成员认证方法
     *
     * @param Project $project
     * @param User $user
     * @param Request $request
     * @return bool
     */
    public function Policy(Project $project, User $user, Request $request)
    {
        if ($project->Users()->find($user->id) == null) {
            return false;
        } elseif ($user->id === $project->user_id) {
            return false;
        } elseif ($user->id === $project->sl_id) {
            return false;
        } elseif ($user->id === Definer::SUPER_ADMIN_ID) {<commit_msg>BUG修正<commit_after><?php

namespace App\Repositories;

use App\Definer;
use App\Project\Project;
use App\User;
use Illuminate\Http\Request;

class MemberRepository
{
    /**
     * 项目成员资源
     *
     * @param Project $project
     * @return array
     */
    public function MemberResources(Project $project)
    {
        $pl = $project->ProjectLeader;
        $sl = $project->SubLeader;
        $pms = $project->Users->all();
        $paCount = $project->Users()->where('is_admin', Definer::PROJECT_ADMIN)->count();
        $pmCount = $project->Users->count() - $paCount;
        $allCount = $pmCount + $paCount;
        if ($pl) {
            $allCount += 1;
        }
        if ($sl) {
            $allCount += 1;
            $slCount = 1;
        } else {
            $slCount = 0;
        }
        $users = User::all();

        return compact('pl', 'sl', 'pms', 'pmCount', 'allCount', 'slCount', 'users', 'paCount');
    }

    /**
     * 获取所有成员
     *
     * @param Project $project
     * @return array
     */
    public function AllMember(Project $project)
    {
        $pl = $project->ProjectLeader;
        $sl = $project->SubLeader;
        $pms = $project->Users->all();

        return compact('pl', 'sl', 'pms');
    }

    /**
     * 添加成员方法
     *
     * @param Request $request
     * @param Project $project
     * @return bool
     */
    public function AddMember(Request $request, Project $project)
    {
        $user = User::findOrFail($request->get('id'));

        if ($project->Users()->find($user->id) != null) {
            return false;
        } elseif ($user->id === $project->user_id) {
            return false;
        } elseif ($user->id === $project->sl_id) {
            return false;
        } elseif ($user->id === Definer::SUPER_ADMIN_ID) {
            return false;
        } else {
            $project->Users()->attach($user);

            return true;
        }
    }

    /**
     * 移除成员方法
     *
     * @param Project $project
     * @param User $user
     * @return bool
     */
    public function RemoveMember(Project $project, User $user)
    {
        if ($project->Users()->find($user->id) == null) {
            return false;
        } else {
            $project->Users()->detach($user);

            return true;
        }
    }

    /**
     * 成员认证方法
     *
     * @param Project $project
     * @param User $user
     * @param Request $request
     * @return bool
     */
    public function Policy(Project $project, User $user, Request $request)
    {
        if ($project->Users()->find($user->id) == null) {
            return false;
        } elseif ($user->id === $project->user_id) {
            return false;
        } elseif ($user->id === $project->sl_id) {
            return false;
        } elseif ($user->id === Definer::SUPER_ADMIN_ID) {
{'fraction_non_alphanumeric': 0.161531914893617, 'fraction_numerical': 0.0013617021276595745, 'mean_word_length': 1.7874762808349147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6422459', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1846, 'n_words': 385}