# assistant/0.3.1/backend/src/Controllers/NotationsController.php

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

- Page: https://pluginprobe.com/plugins/assistant/0.3.1/code/backend/src/Controllers/NotationsController.php
- Raw: https://pluginprobe.com/plugins/assistant/0.3.1/raw/backend/src/Controllers/NotationsController.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/Controllers/NotationsController.php#L10-L20`.

```php
<?php

namespace FL\Assistant\Controllers;

use FL\Assistant\Data\Repository\NotationsRepository;
use FL\Assistant\System\Contracts\ControllerAbstract;
use WP_REST_Server;

/**
 * REST API logic for notations.
 */
class NotationsController extends ControllerAbstract {

	/**
	 * @var NotationsRepository
	 */
	protected $notations;

	/**
	 * NotationsController constructor.
	 *
	 * @param NotationsRepository $notations
	 */
	public function __construct( NotationsRepository $notations ) {
		$this->notations = $notations;
	}

	/**
	 * Register routes.
	 */
	public function register_routes() {
		$this->route(
			'/notations/delete-where-meta', [
				[
					'methods'             => WP_REST_Server::CREATABLE,
					'callback'            => [ $this, 'delete_notation' ],
					'permission_callback' => function () {
						return current_user_can( 'edit_others_posts' );
					},
				],
			]
		);
	}

	/**
	 * Deletes notations.
	 *
	 * @param \WP_REST_Request $request
	 *
	 * @return mixed|\WP_REST_Response
	 */
	public function delete_notation( \WP_REST_Request $request ) {
		$meta      = $request->get_params();
		$notations = $this->notations->get_by_meta( $meta );

		foreach ( $notations as $notation ) {
			if ( ! current_user_can( 'edit_post', $notation['id'] ) ) {
				return rest_ensure_response(
					[
						'error' => true,
					]
				);
			}
			wp_delete_post( $notation['id'] );
		}

		return rest_ensure_response(
			[
				'success' => true,
			]
		);
	}
}

```
