| @@ -1,112 +1,112 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace FL\Assistant\Controllers; | |
| 4 | - | |
| 5 | -use FL\Assistant\System\Contracts\ControllerAbstract; | |
| 6 | -use WP_REST_Server; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * REST API logic for content count data. | |
| 10 | - */ | |
| 11 | -class CountsController extends ControllerAbstract { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * Register routes. | |
| 15 | - */ | |
| 16 | - public function register_routes() { | |
| 17 | - $this->route( | |
| 18 | - '/counts', [ | |
| 19 | - [ | |
| 20 | - 'methods' => WP_REST_Server::READABLE, | |
| 21 | - 'callback' => [ $this, 'all' ], | |
| 22 | - 'permission_callback' => function () { | |
| 23 | - return is_user_logged_in(); | |
| 24 | - }, | |
| 25 | - ], | |
| 26 | - ] | |
| 27 | - ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * Returns all counts for the site. | |
| 32 | - * | |
| 33 | - * @todo move this to data service and call data service | |
| 34 | - */ | |
| 35 | - public function all( $request ) { | |
| 36 | - $routes = [ | |
| 37 | - '/fl-assistant/v1/posts/count' => function ( $response ) { | |
| 38 | - $return = []; | |
| 39 | - foreach ( $response as $type => $data ) { | |
| 40 | - $return[ 'content/' . $type ] = $data->total; | |
| 41 | - } | |
| 42 | - | |
| 43 | - return $return; | |
| 44 | - }, | |
| 45 | - '/fl-assistant/v1/terms/count' => function ( $response ) { | |
| 46 | - $return = []; | |
| 47 | - foreach ( $response as $type => $count ) { | |
| 48 | - $return[ 'taxonomy/' . $type ] = $count; | |
| 49 | - } | |
| 50 | - | |
| 51 | - return $return; | |
| 52 | - }, | |
| 53 | - '/fl-assistant/v1/attachments/count' => function ( $response ) { | |
| 54 | - $return = []; | |
| 55 | - foreach ( $response as $type => $count ) { | |
| 56 | - $return[ 'attachment/' . $type ] = $count; | |
| 57 | - } | |
| 58 | - | |
| 59 | - return $return; | |
| 60 | - }, | |
| 61 | - '/fl-assistant/v1/comments/count' => function ( $response ) { | |
| 62 | - $return = []; | |
| 63 | - foreach ( $response as $type => $count ) { | |
| 64 | - $return[ 'comment/' . $type ] = $count; | |
| 65 | - } | |
| 66 | - | |
| 67 | - return $return; | |
| 68 | - }, | |
| 69 | - '/fl-assistant/v1/users/count' => function ( $response ) { | |
| 70 | - $return = []; | |
| 71 | - foreach ( $response as $type => $count ) { | |
| 72 | - $return[ 'role/' . $type ] = $count; | |
| 73 | - } | |
| 74 | - | |
| 75 | - return $return; | |
| 76 | - }, | |
| 77 | - '/fl-assistant/v1/updates/count' => function ( $response ) { | |
| 78 | - $return = []; | |
| 79 | - foreach ( $response as $type => $count ) { | |
| 80 | - $return[ 'update/' . $type ] = $count; | |
| 81 | - } | |
| 82 | - | |
| 83 | - return $return; | |
| 84 | - }, | |
| 85 | - '/fl-assistant/v1/notifications/count' => function ( $response ) { | |
| 86 | - $return = []; | |
| 87 | - foreach ( $response as $type => $count ) { | |
| 88 | - $return[ 'notification/' . $type ] = $count; | |
| 89 | - } | |
| 90 | - | |
| 91 | - return $return; | |
| 92 | - }, | |
| 93 | - '/fl-assistant/v1/labels/count' => function ( $response ) { | |
| 94 | - $return = []; | |
| 95 | - foreach ( $response as $type => $count ) { | |
| 96 | - $return[ 'label/' . $type ] = $count; | |
| 97 | - } | |
| 98 | - | |
| 99 | - return $return; | |
| 100 | - }, | |
| 101 | - ]; | |
| 102 | - | |
| 103 | - $requests = array_reduce( array_keys( $routes ), 'rest_preload_api_request', [] ); | |
| 104 | - $counts = []; | |
| 105 | - | |
| 106 | - foreach ( $requests as $route => $request ) { | |
| 107 | - $counts = array_merge( $counts, $routes[ $route ]( $request['body'] ) ); | |
| 108 | - } | |
| 109 | - | |
| 110 | - return $counts; | |
| 111 | - } | |
| 112 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace FL\Assistant\Controllers; | |
| 4 | + | |
| 5 | +use FL\Assistant\System\Contracts\ControllerAbstract; | |
| 6 | +use WP_REST_Server; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * REST API logic for content count data. | |
| 10 | + */ | |
| 11 | +class CountsController extends ControllerAbstract { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Register routes. | |
| 15 | + */ | |
| 16 | + public function register_routes() { | |
| 17 | + $this->route( | |
| 18 | + '/counts', [ | |
| 19 | + [ | |
| 20 | + 'methods' => WP_REST_Server::READABLE, | |
| 21 | + 'callback' => [ $this, 'all' ], | |
| 22 | + 'permission_callback' => function () { | |
| 23 | + return is_user_logged_in(); | |
| 24 | + }, | |
| 25 | + ], | |
| 26 | + ] | |
| 27 | + ); | |
| 28 | + } | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Returns all counts for the site. | |
| 32 | + * | |
| 33 | + * @todo move this to data service and call data service | |
| 34 | + */ | |
| 35 | + public function all( $request ) { | |
| 36 | + $routes = [ | |
| 37 | + '/fl-assistant/v1/posts/count' => function ( $response ) { | |
| 38 | + $return = []; | |
| 39 | + foreach ( $response as $type => $data ) { | |
| 40 | + $return[ 'content/' . $type ] = $data->total; | |
| 41 | + } | |
| 42 | + | |
| 43 | + return $return; | |
| 44 | + }, | |
| 45 | + '/fl-assistant/v1/terms/count' => function ( $response ) { | |
| 46 | + $return = []; | |
| 47 | + foreach ( $response as $type => $count ) { | |
| 48 | + $return[ 'taxonomy/' . $type ] = $count; | |
| 49 | + } | |
| 50 | + | |
| 51 | + return $return; | |
| 52 | + }, | |
| 53 | + '/fl-assistant/v1/attachments/count' => function ( $response ) { | |
| 54 | + $return = []; | |
| 55 | + foreach ( $response as $type => $count ) { | |
| 56 | + $return[ 'attachment/' . $type ] = $count; | |
| 57 | + } | |
| 58 | + | |
| 59 | + return $return; | |
| 60 | + }, | |
| 61 | + '/fl-assistant/v1/comments/count' => function ( $response ) { | |
| 62 | + $return = []; | |
| 63 | + foreach ( $response as $type => $count ) { | |
| 64 | + $return[ 'comment/' . $type ] = $count; | |
| 65 | + } | |
| 66 | + | |
| 67 | + return $return; | |
| 68 | + }, | |
| 69 | + '/fl-assistant/v1/users/count' => function ( $response ) { | |
| 70 | + $return = []; | |
| 71 | + foreach ( $response as $type => $count ) { | |
| 72 | + $return[ 'role/' . $type ] = $count; | |
| 73 | + } | |
| 74 | + | |
| 75 | + return $return; | |
| 76 | + }, | |
| 77 | + '/fl-assistant/v1/updates/count' => function ( $response ) { | |
| 78 | + $return = []; | |
| 79 | + foreach ( $response as $type => $count ) { | |
| 80 | + $return[ 'update/' . $type ] = $count; | |
| 81 | + } | |
| 82 | + | |
| 83 | + return $return; | |
| 84 | + }, | |
| 85 | + '/fl-assistant/v1/notifications/count' => function ( $response ) { | |
| 86 | + $return = []; | |
| 87 | + foreach ( $response as $type => $count ) { | |
| 88 | + $return[ 'notification/' . $type ] = $count; | |
| 89 | + } | |
| 90 | + | |
| 91 | + return $return; | |
| 92 | + }, | |
| 93 | + '/fl-assistant/v1/labels/count' => function ( $response ) { | |
| 94 | + $return = []; | |
| 95 | + foreach ( $response as $type => $count ) { | |
| 96 | + $return[ 'label/' . $type ] = $count; | |
| 97 | + } | |
| 98 | + | |
| 99 | + return $return; | |
| 100 | + }, | |
| 101 | + ]; | |
| 102 | + | |
| 103 | + $requests = array_reduce( array_keys( $routes ), 'rest_preload_api_request', [] ); | |
| 104 | + $counts = []; | |
| 105 | + | |
| 106 | + foreach ( $requests as $route => $request ) { | |
| 107 | + $counts = array_merge( $counts, $routes[ $route ]( $request['body'] ) ); | |
| 108 | + } | |
| 109 | + | |
| 110 | + return $counts; | |
| 111 | + } | |
| 112 | +} | |