# assistant/0.3.1/backend/src/Data/Repository/CommentsRepository.php

Assistant – Every Day Productivity Apps, version 0.3.1. 78 lines.

- Page: https://pluginprobe.com/plugins/assistant/0.3.1/code/backend/src/Data/Repository/CommentsRepository.php
- Raw: https://pluginprobe.com/plugins/assistant/0.3.1/raw/backend/src/Data/Repository/CommentsRepository.php
- Modified: 2020-03-25T19:33:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/assistant/0.3.1/code/backend/src/Data/Repository/CommentsRepository.php#L10-L20`.

```php
<?php


namespace FL\Assistant\Data\Repository;


use FL\Assistant\Data\Pager;
use FL\Assistant\System\Contracts\RepositoryAbstract;

/**
 * Class CommentsRepository
 * @package FL\Assistant\Data\Repository
 */
class CommentsRepository extends RepositoryAbstract {

	/**
	 * @param $id
	 * @param callable|null $transform
	 *
	 * @return array|mixed|\WP_Comment|null
	 */
	public function find( $id, callable $transform = null ) {
		$comment = get_comment( $id );
		if ( ! is_null( $transform ) ) {
			$comment = call_user_func( $transform, $comment );
		}

		return $comment;
	}

	/**
	 * @param array $args
	 * @param callable|null $transform
	 *
	 * @return array|int
	 */
	public function find_where( array $args = [], callable $transform = null ) {
		$comments = $this->query( $args )->get_comments();
		if ( ! is_null( $transform ) ) {
			$comments = array_map( $transform, $comments );
		}
		return $comments;
	}

	/**
	 * @param array $args
	 * @param callable|null $transform
	 *
	 * @return Pager
	 */
	public function paginate( array $args = [], callable $transform = null ) {
		$args['no_found_rows'] = false; // Make sure to calc the number of found rows.
		$query = $this->query( $args );

		$pager = new Pager(
			$query->get_comments(),
			$query->found_comments,
			$query->query_vars['number'],
			$query->query_vars['offset']
		);

		if ( ! is_null( $transform ) ) {
			$pager->apply_transform( $transform );
		}

		return $pager;
	}

	/**
	 * @param array $args
	 *
	 * @return \WP_Comment_Query
	 */
	public function query( array $args = [] ) {
		return new \WP_Comment_Query( $args );
	}
}

```
