authorsModel = new AuthorsModel(); } public function getData() { $topAuthorsByViews = $this->authorsModel->getAuthorsByViewsPerPost($this->args); $parsedData = $this->parseData($topAuthorsByViews); $data = $this->prepareResult($parsedData); return $data; } protected function parseData($data) { $parsedData = []; if ($data) { foreach ($data as $author) { $parsedData[] = [ 'x' => $author->total_views, 'y' => $author->total_posts, 'img' => esc_url(get_avatar_url($author->id)), 'author' => esc_html($author->name) ]; } } return $parsedData; } protected function prepareResult($data) { $this->initChartData(); $this->setChartDatasets($data); $this->setChartLabels([ 'chart' => sprintf(esc_html__('Views/Published %s', 'wp-statistics'),Helper::getPostTypeName($this->args['post_type'])), 'yAxis' => sprintf(esc_html__('Published %s', 'wp-statistics'), Helper::getPostTypeName($this->args['post_type'])), 'xAxis' => sprintf(esc_html__('%s Views', 'wp-statistics'), Helper::getPostTypeName($this->args['post_type'], true)) ]); return $this->getChartData(); } }