Added restrictions to user profile lists
This commit is contained in:
		
							parent
							
								
									66c56e9d02
								
							
						
					
					
						commit
						1d6137f7e2
					
				| 
						 | 
				
			
			@ -42,13 +42,19 @@ class EntityRepo
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the latest books added to the system.
 | 
			
		||||
     * @param $count
 | 
			
		||||
     * @param $page
 | 
			
		||||
     * @param int $count
 | 
			
		||||
     * @param int $page
 | 
			
		||||
     * @param bool $additionalQuery
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public function getRecentlyCreatedBooks($count = 20, $page = 0)
 | 
			
		||||
    public function getRecentlyCreatedBooks($count = 20, $page = 0, $additionalQuery = false)
 | 
			
		||||
    {
 | 
			
		||||
        return $this->restrictionService->enforceBookRestrictions($this->book)
 | 
			
		||||
            ->orderBy('created_at', 'desc')->skip($page * $count)->take($count)->get();
 | 
			
		||||
        $query = $this->restrictionService->enforceBookRestrictions($this->book)
 | 
			
		||||
            ->orderBy('created_at', 'desc');
 | 
			
		||||
        if ($additionalQuery !== false && is_callable($additionalQuery)) {
 | 
			
		||||
            $additionalQuery($query);
 | 
			
		||||
        }
 | 
			
		||||
        return $query->skip($page * $count)->take($count)->get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -65,13 +71,36 @@ class EntityRepo
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the latest pages added to the system.
 | 
			
		||||
     * @param $count
 | 
			
		||||
     * @param $page
 | 
			
		||||
     * @param int $count
 | 
			
		||||
     * @param int $page
 | 
			
		||||
     * @param bool $additionalQuery
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public function getRecentlyCreatedPages($count = 20, $page = 0)
 | 
			
		||||
    public function getRecentlyCreatedPages($count = 20, $page = 0, $additionalQuery = false)
 | 
			
		||||
    {
 | 
			
		||||
        return $this->restrictionService->enforcePageRestrictions($this->page)
 | 
			
		||||
            ->orderBy('created_at', 'desc')->skip($page * $count)->take($count)->get();
 | 
			
		||||
        $query = $this->restrictionService->enforcePageRestrictions($this->page)
 | 
			
		||||
            ->orderBy('created_at', 'desc');
 | 
			
		||||
        if ($additionalQuery !== false && is_callable($additionalQuery)) {
 | 
			
		||||
            $additionalQuery($query);
 | 
			
		||||
        }
 | 
			
		||||
        return $query->skip($page * $count)->take($count)->get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the latest chapters added to the system.
 | 
			
		||||
     * @param int $count
 | 
			
		||||
     * @param int $page
 | 
			
		||||
     * @param bool $additionalQuery
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public function getRecentlyCreatedChapters($count = 20, $page = 0, $additionalQuery = false)
 | 
			
		||||
    {
 | 
			
		||||
        $query = $this->restrictionService->enforceChapterRestrictions($this->chapter)
 | 
			
		||||
            ->orderBy('created_at', 'desc');
 | 
			
		||||
        if ($additionalQuery !== false && is_callable($additionalQuery)) {
 | 
			
		||||
            $additionalQuery($query);
 | 
			
		||||
        }
 | 
			
		||||
        return $query->skip($page * $count)->take($count)->get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -100,7 +129,7 @@ class EntityRepo
 | 
			
		|||
                foreach ($restrictions as $action => $value) {
 | 
			
		||||
                    $entity->restrictions()->create([
 | 
			
		||||
                        'role_id' => $roleId,
 | 
			
		||||
                        'action' => strtolower($action)
 | 
			
		||||
                        'action'  => strtolower($action)
 | 
			
		||||
                    ]);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -141,12 +141,15 @@ class UserRepo
 | 
			
		|||
    public function getRecentlyCreated(User $user, $count = 20)
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
 | 
			
		||||
                ->take($count)->get(),
 | 
			
		||||
            'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
 | 
			
		||||
                ->take($count)->get(),
 | 
			
		||||
            'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
 | 
			
		||||
                ->take($count)->get()
 | 
			
		||||
            'pages'    => $this->entityRepo->getRecentlyCreatedPages($count, 0, function ($query) use ($user) {
 | 
			
		||||
                $query->where('created_by', '=', $user->id);
 | 
			
		||||
            }),
 | 
			
		||||
            'chapters' => $this->entityRepo->getRecentlyCreatedChapters($count, 0, function ($query) use ($user) {
 | 
			
		||||
                $query->where('created_by', '=', $user->id);
 | 
			
		||||
            }),
 | 
			
		||||
            'books'    => $this->entityRepo->getRecentlyCreatedBooks($count, 0, function ($query) use ($user) {
 | 
			
		||||
                $query->where('created_by', '=', $user->id);
 | 
			
		||||
            })
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -158,9 +161,9 @@ class UserRepo
 | 
			
		|||
    public function getAssetCounts(User $user)
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(),
 | 
			
		||||
            'pages'    => $this->entityRepo->page->where('created_by', '=', $user->id)->count(),
 | 
			
		||||
            'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(),
 | 
			
		||||
            'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(),
 | 
			
		||||
            'books'    => $this->entityRepo->book->where('created_by', '=', $user->id)->count(),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,8 +26,8 @@ class ActivityService
 | 
			
		|||
     * Add activity data to database.
 | 
			
		||||
     * @param Entity $entity
 | 
			
		||||
     * @param        $activityKey
 | 
			
		||||
     * @param int    $bookId
 | 
			
		||||
     * @param bool   $extra
 | 
			
		||||
     * @param int $bookId
 | 
			
		||||
     * @param bool $extra
 | 
			
		||||
     */
 | 
			
		||||
    public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ class ActivityService
 | 
			
		|||
    /**
 | 
			
		||||
     * Adds a activity history with a message & without binding to a entity.
 | 
			
		||||
     * @param            $activityKey
 | 
			
		||||
     * @param int        $bookId
 | 
			
		||||
     * @param int $bookId
 | 
			
		||||
     * @param bool|false $extra
 | 
			
		||||
     */
 | 
			
		||||
    public function addMessage($activityKey, $bookId = 0, $extra = false)
 | 
			
		||||
| 
						 | 
				
			
			@ -88,7 +88,7 @@ class ActivityService
 | 
			
		|||
     */
 | 
			
		||||
    public function latest($count = 20, $page = 0)
 | 
			
		||||
    {
 | 
			
		||||
        $activityList =  $this->restrictionService
 | 
			
		||||
        $activityList = $this->restrictionService
 | 
			
		||||
            ->filterRestrictedEntityRelations($this->activity, 'activities', 'entity_id', 'entity_type')
 | 
			
		||||
            ->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -99,8 +99,8 @@ class ActivityService
 | 
			
		|||
     * Gets the latest activity for an entity, Filtering out similar
 | 
			
		||||
     * items to prevent a message activity list.
 | 
			
		||||
     * @param Entity $entity
 | 
			
		||||
     * @param int    $count
 | 
			
		||||
     * @param int    $page
 | 
			
		||||
     * @param int $count
 | 
			
		||||
     * @param int $page
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function entityActivity($entity, $count = 20, $page = 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -121,9 +121,10 @@ class ActivityService
 | 
			
		|||
     */
 | 
			
		||||
    public function userActivity($user, $count = 20, $page = 0)
 | 
			
		||||
    {
 | 
			
		||||
        $activity = $this->activity->where('user_id', '=', $user->id)
 | 
			
		||||
            ->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get();
 | 
			
		||||
        return $this->filterSimilar($activity);
 | 
			
		||||
        $activityList = $this->restrictionService
 | 
			
		||||
            ->filterRestrictedEntityRelations($this->activity, 'activities', 'entity_id', 'entity_type')
 | 
			
		||||
            ->orderBy('created_at', 'desc')->where('user_id', '=', $user->id)->skip($count * $page)->take($count)->get();
 | 
			
		||||
        return $this->filterSimilar($activityList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue