Get posts from a category

@param integer $catId
@param integer $limit
@param array $moreQuerySettings
@return array<Post>
483393
public static function getByCategory($catId, $limit = false, $offset = false, $moreQuerySettings = [])
    {
        return self::getBy(Ajax::CATEGORY, $catId, $limit, $offset, $moreQuerySettings);
    }
117331
public function getLinks(int $limit = 0): array
    {
        if ($this->links === null) {
            $links = $this->attrs['links'] ?? [];
            $this->links = $this->removeInvalidOrHiddenLinks($links);
        }

        return $limit > 0 ? array_slice($this->links, 0, $limit) : $this->links;
    }
1255871
public function findNews($family, $limit = null)
    {
        $qb = $this->getQueryBuilder()
            ->orderBy('p.highlighted', 'desc')
            ->addOrderBy('p.createdAt', 'desc');

        // filter by family
        if (!is_null($family)) {
            $qb->innerJoin('p.category', 'c')
                ->innerJoin('c.parentCategory', 'pc')
                ->andWhere('pc.family = :family')
                ->setParameter('family', $family);
        }

        if (!is_null($limit)) {
            $qb->setMaxResults($limit);
        }

        return $qb->getQuery()
            ->getResult();
    }
985753
public function getItems($offset, $limit)
    {
        $this
            ->paginator
            ->getQuery()
            ->setFirstResult($offset)
            ->setMaxResults($limit)
        ;

        return iterator_to_array($this->paginator->getIterator());
    }
952574
public function getPinnedByCategoryId( $categoryId, $config = [] ) {

		$modelClass	= static::$modelClass;
		$modelTable	= $this->getModelTable();

		$config[ 'page' ]	= isset( $config[ 'page' ] ) ? $config[ 'page' ] : false;
		$config[ 'query' ]	= isset( $config[ 'query' ] ) ? $config[ 'query' ] : $modelClass::find();
		$config[ 'limit' ]	= isset( $config[ 'limit' ] ) ? $config[ 'limit' ] : 10;
		$config[ 'active' ]	= isset( $config[ 'active' ] ) ? $config[ 'active' ] : true;

		if( $config[ 'active' ] ) {

			$config[ 'query' ]->joinWith( 'activeCategories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
		}
		else {

			$config[ 'query' ]->joinWith( 'categories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
		}

		if( $config[ 'page' ] ) {

			$page	= $this->getPublicPage( $config );

			return $page->getModels();
		}

		return $config[ 'query' ]->limit( $config[ 'limit' ] )->all();
	}
28642
public function getExcerpt($limit = 50, $more = '&hellip;')
    {
        $content = strip_tags($this->getContent());
        if (strlen($content) <= $limit) {
            return $content;
        }

        $content = mb_substr($content, 0, $limit);
        $content = mb_substr($content, 0, mb_strrpos($content, ' '));

        if (! empty($more)) {
            $content .= $more;
        }

        return $content;
    }
962013
public static function getBySearch($searchQuery, $limit = false, $offset = false, $moreQuerySettings = [])
    {
        return self::getBy(Ajax::SEARCH, $searchQuery, $limit, $offset, $moreQuerySettings);
    }
506300
public function getTopTagIds(array $sourceIds = [], int $limit = null, bool $withCount = false): array
    {
        /** @var Model $model */
        $model = $this->framework->getAdapter(Model::class);

        $tagIds = $model->getRelatedValues($this->sourceTable, $this->sourceField, $sourceIds);
        $tagIds = \array_map('intval', $tagIds);

        if (0 === \count($tagIds)) {
            return [];
        }

        $helper = [];

        // Create the helper array with tag occurrences
        foreach ($tagIds as $tagId) {
            ++$helper[$tagId];
        }

        // Sort the helper array descending
        \arsort($helper);

        // Strip the count data
        if (!$withCount) {
            $helper = \array_keys($helper);
        }

        return \array_slice($helper, 0, $limit, $withCount);
    }
537975
public static function validateCategoryId($catid, $extension)
	{
		JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables');

		$categoryTable = JTable::getInstance('Category');

		$data = array();
		$data['id'] = $catid;
		$data['extension'] = $extension;

		if (!$categoryTable->load($data))
		{
			$catid = 0;
		}

		return (int) $catid;
	}
1106826
public function getPosts($limit = false, $offset = false)
    {
        if (!$limit) {
            $limit = Option::get('posts_per_page');
        }
        return Post::getByAuthor($this->ID, $limit, $offset);
    }
803774
public function selectRecentActivities($limit)
	{
		$stmt = $this->pdo->prepare(<<<EOT
SELECT 
	t1.*,
	t2.ProjectId AS "Project.ProjectId",
	t2.Name AS "Project.Name",
	t2.Description AS "Project.Description",
	t2.Created AS "Project.Created"
FROM `$this->tableName` AS t1 
LEFT JOIN Projects AS t2 ON t1.ProjectId = t2.ProjectId 
ORDER BY t1.Started DESC 
LIMIT :limit ;
EOT
		);
		$stmt->bindParam(':limit', $limit, \PDO::PARAM_INT);
		$res = $stmt->execute();

		if ($res === false) {
			return array();
		}

		$rows = $stmt->fetchAll();

		$ret = array();
		foreach ($rows as $row) {
			array_push($ret, $this->prepareEntity($row));
		}

		return $ret;
	}
1156306
def query_by_postid(postid, limit=5):
        '''
        
        '''
        recs = TabPostHist.select().where(
            TabPostHist.post_id == postid
        ).order_by(
            TabPostHist.time_update.desc()
        ).limit(limit)
        return recs
299238
public function getAllPostsOfCategory($lang, $postType, $categoryID)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postType, 'read')) {
            return $this->noPermission();
        }
        // order info
        $orderBy = (isset($_GET['order'])) ? $_GET['order'] : 'postID';
        $orderType = (isset($_GET['type'])) ? $_GET['type'] : 'DESC';

        // get postIDs from relations
        $relations = DB::table(categoriesRelationTable($postType))->where('categoryID', $categoryID)->select('postID')->get();
        $postIDs = [];
        foreach ($relations as $postID){
            $postIDs[] = $postID->postID;
        }
        // get post list
        $list = DB::table($postType)->whereIn('postID', $postIDs)->orderBy($orderBy, $orderType)->paginate(Post::$rowsPerPage);
        return Language::filterRows($list);
    }
1321245
public function findLastUpdated($limit = 5)
    {
        $query = $this->createQueryBuilder('c')
            ->orderBy('c.updatedAt', 'DESC')
            ->where('c.layout = :layout')
            ->setParameter(':layout', false)
            ->setMaxResults($limit)
            ->getQuery();

        return $query->getResult();
    }
635215
public function getAvailableParentCategoriesQueryBuilder($categoryId = null)
    {
        $queryBuilder = $this
            ->createQueryBuilder('c')
            ->where('c.root = 1');

        if (null !== $categoryId) {
            $queryBuilder
                ->andWhere('c.id <> :parent_category')
                ->setParameter('parent_category', $categoryId);
        }

        return $queryBuilder;
    }
850525
public function findEnabledAllPostsThatHaveCategoryId($catId)
    {
        $collection = $this->model->find($catId)->post->sortByDesc('updated_at');

        $filtered = $collection->filter(function ($item) {
            if ($item->enabled == 1) return true;
        });

        $filtered = $filtered->filter(function ($item) {
            $todaysDate = DatesHelper::todaysDateSetToLocalTime();
            if ($item->publish_on <= $todaysDate) return true;
        });


        // TODO: HAVE TO MANUALLY PAGINATE THE FILTERED COLLECTION :-(
        // https://laracasts.com/discuss/channels/laravel/laravel-pagination-not-working-with-array-instead-of-collection?page=1#reply-63860
        // http://www.reddit.com/r/laravel/comments/32kxn8/creating_a_paginator_manually/
        return $filtered->all();
    }
396208
public function get($limit = null, $offset = null)
    {
        if (isset($limit)) {
            $this->limit($limit, $offset);
        }

        if (false !== ($result = $this->conn->query($this->builderCache))) {
            $result->setTotalRows($this->countAllResults(true));
        }

        $this->builderCache->reset();

        return $result;
    }