public function getDataBetween($from = null, $to = null)
    {
        $answerPosts = $this->getAnswerPosts($from, $to);

        $yesno = array('yes' => 0, 'no' => 0);
        $pending = array();

        foreach ($answerPosts as $post) {
            $topics = wp_get_post_terms($post->ID, 'feedback_topic');
            $feedback_topics = array();
            if (!empty($topics)) {
                foreach ($topics as $topic) {
                    $feedback_topics[] = $topic->name;
                }
            }

            $post->answer = array(
                'post_id' => get_post_meta($post->ID, 'customer_feedback_page_reference', true),
                'answer' => get_post_meta($post->ID, 'customer_feedback_answer', true),
                'comment' => get_post_meta($post->ID, 'customer_feedback_comment', true),
                'topics' => $feedback_topics
            );

            // Count yes/no
            switch ($post->answer['answer']) {
                case 'yes':
                    $yesno['yes']++;
                    break;

                case 'no':
                    $yesno['no']++;
                    break;
            }

            if ($post->post_status === 'pending') {
                $pending[] = $post;
            }
        }

        // Get the percentage ratio for $yesno
        $totalAnswers = array_sum($yesno);
        $yesnoPercent = array_map(function ($item) use ($totalAnswers) {
            if ($totalAnswers === 0) {
                return 0;
            }

            return ($item / $totalAnswers) * 100;
        }, $yesno);

        // Return array
        $data = array(
            'count' => $yesno,
            'percent' => $yesnoPercent,
            'pending' => $pending
        );

        return $data;
    }
public function getDataBetween($from = null, $to = null)
    {
        $answerPosts = $this->getAnswerPosts($from, $to);

        $yesno = array('yes' => 0, 'no' => 0);
        $pending = array();

        foreach ($answerPosts as $post) {
            $topics = wp_get_post_terms($post->ID, 'feedback_topic');
            $feedback_topics = array();
            if (!empty($topics)) {
                foreach ($topics as $topic) {
                    $feedback_topics[] = $topic->name;
                }
            }

            $post->answer = array(
                'post_id' => get_post_meta($post->ID, 'customer_feedback_page_reference', true),
                'answer' => get_post_meta($post->ID, 'customer_feedback_answer', true),
                'comment' => get_post_meta($post->ID, 'customer_feedback_comment', true),
                'topics' => $feedback_topics
            );

            // Count yes/no
            switch ($post->answer['answer']) {
                case 'yes':
                    $yesno['yes']++;
                    break;

                case 'no':
                    $yesno['no']++;
                    break;
            }

            if ($post->post_status === 'pending') {
                $pending[] = $post;
            }
        }

        // Get the percentage ratio for $yesno
        $totalAnswers = array_sum($yesno);
        $yesnoPercent = array_map(function ($item) use ($totalAnswers) {
            if ($totalAnswers === 0) {
                return 0;
            }

            return ($item / $totalAnswers) * 100;
        }, $yesno);

        // Return array
        $data = array(
            'count' => $yesno,
            'percent' => $yesnoPercent,
            'pending' => $pending
        );

        return $data;
    }
public function getDataBetween ( $ from = null , $ to = null ) { $ answerPosts = $ this -> getAnswerPosts ( $ from , $ to ) ; $ yesno = array ( 'yes' => 0 , 'no' => 0 ) ; $ pending = array ( ) ; foreach ( $ answerPosts as $ post ) { $ topics = wp_get_post_terms ( $ post -> ID , 'feedback_topic' ) ; $ feedback_topics = array ( ) ; if ( ! empty ( $ topics ) ) { foreach ( $ topics as $ topic ) { $ feedback_topics [ ] = $ topic -> name ; } } $ post -> answer = array ( 'post_id' => get_post_meta ( $ post -> ID , 'customer_feedback_page_reference' , true ) , 'answer' => get_post_meta ( $ post -> ID , 'customer_feedback_answer' , true ) , 'comment' => get_post_meta ( $ post -> ID , 'customer_feedback_comment' , true ) , 'topics' => $ feedback_topics ) ; // Count yes/no switch ( $ post -> answer [ 'answer' ] ) { case 'yes' : $ yesno [ 'yes' ] ++ ; break ; case 'no' : $ yesno [ 'no' ] ++ ; break ; } if ( $ post -> post_status === 'pending' ) { $ pending [ ] = $ post ; } } // Get the percentage ratio for $yesno $ totalAnswers = array_sum ( $ yesno ) ; $ yesnoPercent = array_map ( function ( $ item ) use ( $ totalAnswers ) { if ( $ totalAnswers === 0 ) { return 0 ; } return ( $ item / $ totalAnswers ) * 100 ; } , $ yesno ) ; // Return array $ data = array ( 'count' => $ yesno , 'percent' => $ yesnoPercent , 'pending' => $ pending ) ; return $ data ; }
Gets relevant data for the summary
@param  string $from Date from
@param  string $to   Date to
@return array        Data
Gets relevant data for the summary