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.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / tutor-droip / backend / ElementGenerator / RatingGenerator.php
tutor / tutor-droip / backend / ElementGenerator Last commit date
ActionBoxGenerator.php 1 year ago AnnouncementsGenerator.php 1 year ago CourseMetaGenerator.php 1 year ago CourseThumbnailGenerator.php 1 year ago ElementGenerator.php 1 year ago GradebookGenerator.php 1 year ago InstructorGenerator.php 1 year ago LessonGenerator.php 1 year ago Preview.php 1 year ago QnAGenerator.php 1 year ago RatingGenerator.php 1 year ago ResourcesGenerator.php 1 year ago ShareGenerator.php 1 year ago TopicsGenerator.php 1 year ago WishListGenerator.php 1 year ago
RatingGenerator.php
207 lines
1 <?php
2 /**
3 * Preview script for html markup generator
4 *
5 * @package tutor-droip-elements
6 */
7
8 namespace TutorLMSDroip\ElementGenerator;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * Class Rating genrator
16 *
17 * @package TutorLMSDroip\ElementGenerator
18 */
19 trait RatingGenerator {
20
21 /**
22 * Generate Rating elements
23 *
24 * @return string
25 */
26 private function generate_rating_elements() {
27 $ele_name = $this->element['name'];
28 $course_id = isset( $this->options['post'] ) ? $this->options['post']->ID : get_the_ID();
29 $show_course_ratings = apply_filters( 'tutor_show_course_ratings', true, $course_id );
30 if ( ! $show_course_ratings ) {
31 return '';
32 }
33
34 switch ( $this->element['name'] ) {
35 case TDE_APP_PREFIX . '-rating-active-icon':
36 $current_rating = 0;
37 if ( isset( $this->options['my_rating_input_generator'] ) && $this->options['my_rating_input_generator'] === true ) {
38 $current_rating = 5;
39 } elseif ( isset( $this->options['componentType'], $this->options['comment'] ) && $this->options['componentType'] === 'comments' ) {
40 $current_rating = get_comment_meta( $this->options['comment']->comment_ID, 'tutor_rating', true );
41 } else {
42 $course_rating = tutor_utils()->get_course_rating( $course_id );
43 $current_rating = number_format( $course_rating->rating_avg, 2, '.', '' );
44 }
45
46 $html = '';
47 for ( $i = 1; $i <= 5; $i++ ) {
48 if ( $i <= round( (int) $current_rating ) ) {
49 $html .= $this->generate_common_element();
50 }
51 }
52 return $html;
53
54 case TDE_APP_PREFIX . '-rating-inactive-icon':
55 $current_rating = 0;
56 if ( isset( $this->options['my_rating_input_generator'] ) && $this->options['my_rating_input_generator'] === true ) {
57 $current_rating = 0;
58 } elseif ( isset( $this->options['componentType'], $this->options['comment'] ) && $this->options['componentType'] === 'comments' ) {
59 $current_rating = get_comment_meta( $this->options['comment']->comment_ID, 'tutor_rating', true );
60 } else {
61 $course_rating = tutor_utils()->get_course_rating( $course_id );
62 $current_rating = number_format( $course_rating->rating_avg, 2, '.', '' );
63 }
64
65 $html = '';
66 for ( $i = 1; $i <= 5; $i++ ) {
67 if ( $i > round( (int) $current_rating ) ) {
68 $html .= $this->generate_common_element();
69 }
70 }
71 return $html;
72
73 case TDE_APP_PREFIX . '-rating-avarage-count':
74 if ( isset( $this->options['tutor_review_avg_count'] ) ) {
75 $settings = isset( $this->properties['settings'] ) ? $this->properties['settings'] : array();
76 $template = isset( $settings['template'] ) ? $settings['template'] : '{{avarage}}';
77 $html = str_replace( '{{avarage}}', $this->options['tutor_review_avg_count'], $template );
78
79 return $this->generate_common_element( false, $html );
80 } else {
81 $course_id = isset( $this->options['post'] ) ? $this->options['post']->ID : get_the_ID();
82 $course_rating = tutor_utils()->get_course_rating( $course_id );
83 $settings = isset( $this->properties['settings'] ) ? $this->properties['settings'] : array();
84 $template = isset( $settings['template'] ) ? $settings['template'] : '{{avarage}}';
85 $html = str_replace( '{{avarage}}', $course_rating->rating_avg, $template );
86 return $this->generate_common_element( false, $html );
87 }
88
89 case TDE_APP_PREFIX . '-rating-total-count':
90 if ( isset( $this->options['tutor_review_summery_value'] ) ) {
91 $settings = isset( $this->properties['settings'] ) ? $this->properties['settings'] : array();
92 $template = isset( $settings['template'] ) ? $settings['template'] : '{{avarage}}';
93 $html = str_replace( '{{count}}', $this->options['tutor_review_summery_value'], $template );
94
95 return $this->generate_common_element( false, $html );
96 } else {
97 $course_rating = tutor_utils()->get_course_rating( $course_id );
98 $settings = isset( $this->properties['settings'] ) ? $this->properties['settings'] : array();
99 $template = isset( $settings['template'] ) ? $settings['template'] : '{{avarage}}';
100 $html = str_replace( '{{count}}', $course_rating->rating_count, $template );
101 return $this->generate_common_element( false, $html );
102 }
103 }
104 }
105
106 /**
107 * Generate Review elements
108 *
109 * @return string
110 */
111 private function generate_review_elements() {
112 $ele_name = $this->element['name'];
113 $course_id = isset( $this->options['post'] ) ? $this->options['post']->ID : get_the_ID();
114 $show_course_ratings = apply_filters( 'tutor_show_course_ratings', true, $course_id );
115 if ( ! $show_course_ratings ) {
116 return '';
117 }
118 switch ( $this->element['name'] ) {
119 case TDE_APP_PREFIX . '-rating-empty':
120 $reviews = $this->get_tutor_reviews();
121 if ( ! is_array( $reviews ) || ! count( $reviews ) ) {
122 return $this->generate_common_element();
123 } else {
124 return '';
125 }
126
127 case TDE_APP_PREFIX . '-rating-not-empty':
128 $reviews = $this->get_tutor_reviews();
129 if ( ! is_array( $reviews ) || ! count( $reviews ) ) {
130 return '';
131 } else {
132 // $this->options['tutor_reviews'] = $reviews;
133 return $this->generate_common_element();
134 }
135
136 case TDE_APP_PREFIX . '-rating-summery':
137 $course_rating = tutor_utils()->get_course_rating( $course_id );
138
139 $html = '';
140 $child = $this->element['children'][0];
141 foreach ( $course_rating->count_by_value as $key => $value ) {
142 $rating_count_percent = ( $value > 0 ) ? ( $value * 100 ) / $course_rating->rating_count : 0;
143 $html .= call_user_func(
144 $this->generate_child_element_with_new_id,
145 $this->elements,
146 $this->style_blocks,
147 $child,
148 array_merge(
149 $this->options,
150 array(
151 'tutor_review_summery_index' => $key,
152 'tutor_review_summery_value' => $value,
153 'tutor_review_count_percent' => $rating_count_percent,
154 'tutor_review_avg_count' => $value, // TODO: need to recheck avarage count.
155 )
156 )
157 );
158 }
159 return $this->generate_common_element( false, $html );
160
161 case TDE_APP_PREFIX . '-rating-summery-item-index':
162 return $this->generate_common_element( false, $this->options['tutor_review_summery_index'] );
163
164 case TDE_APP_PREFIX . '-rating-summery-item-progress':
165 $id = $this->element['id'];
166 $per = $this->options['tutor_review_count_percent'];
167 $html = "<style>[data-droip='$id']{width: $per% !important;}</style>" . $this->generate_common_element( false );
168 return $html;
169
170 case TDE_APP_PREFIX . '-review-add-edit':
171 // TODO: check user can review or not. if not return "";.
172 $my_rating = tutor_utils()->get_reviews_by_user( 0, 0, 150, false, $course_id, array( 'approved', 'hold' ) );
173 if ( ! $my_rating || !$course_id) {
174 return '';
175 }
176 $this->options['my_rating'] = $my_rating;
177 $this->options['my_rating_input_generator'] = true;
178 $children_html = $this->generate_child_elements();
179 $active_rating = $my_rating ? $my_rating->rating : 0;
180 $review_id = $my_rating ? $my_rating->comment_ID : null;
181 $children_html .= "<input type='hidden' name='course_id' value='$course_id' />";
182 $children_html .= "<input type='hidden' name='review_id' value='$review_id' />";
183 return "<div $this->attributes data-ele_name='$ele_name' data-active_rating='$active_rating'>$children_html</div>";
184
185 case TDE_APP_PREFIX . '-review-text-input':
186 $my_rating = $this->options['my_rating'];
187 $html = stripslashes( $my_rating ? $my_rating->comment_content : '' );
188 return $this->generate_common_element( false, $html );
189
190 }
191 }
192
193 /**
194 * Get Tutor Reviews
195 *
196 * @return array
197 */
198 private function get_tutor_reviews() {
199 $per_page = tutor_utils()->get_option( 'pagination_per_page', 10 );
200 $offset = 0;// TODO: need to check tutor functionality.
201 $current_user_id = get_current_user_id();
202 $course_id = isset( $this->options['post'] ) ? $this->options['post']->ID : get_the_ID();
203 $reviews = tutor_utils()->get_course_reviews( $course_id, $offset, $per_page, false, array( 'approved' ), $current_user_id );
204 return $reviews;
205 }
206 }
207