Mapper.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Reviews\Translations; |
| 4 | |
| 5 | class Mapper { |
| 6 | |
| 7 | private $wpdb; |
| 8 | |
| 9 | public function __construct( \wpdb $wpdb ) { |
| 10 | $this->wpdb = $wpdb; |
| 11 | } |
| 12 | |
| 13 | public function registerMissingReviewStrings() { |
| 14 | foreach ( $this->getUnregisteredReviews() as $review ) { |
| 15 | FrontEndHooks::registerReviewString( $review ); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public function countMissingReviewStrings() { |
| 20 | return count( $this->getUnregisteredReviews() ); |
| 21 | } |
| 22 | |
| 23 | private function getUnregisteredReviews() { |
| 24 | $sql = " |
| 25 | SELECT c.comment_ID, |
| 26 | c.comment_post_ID, |
| 27 | c.comment_content, |
| 28 | c.comment_type, |
| 29 | tr.language_code, |
| 30 | st.name, |
| 31 | st.value |
| 32 | FROM {$this->wpdb->comments} AS c |
| 33 | LEFT JOIN {$this->wpdb->prefix}icl_translations AS tr |
| 34 | ON tr.element_id = c.comment_post_ID AND tr.element_type = 'post_product' |
| 35 | LEFT JOIN {$this->wpdb->prefix}icl_strings AS st |
| 36 | ON c.comment_content = st.value |
| 37 | AND st.context = '" . FrontEndHooks::CONTEXT . "' |
| 38 | LEFT JOIN {$this->wpdb->comments} AS review_parent |
| 39 | ON review_parent.comment_ID = c.comment_post_ID and review_parent.comment_type = '" . FrontEndHooks::COMMENT_TYPE_REVIEW . "' |
| 40 | WHERE st.name IS null |
| 41 | AND (c.comment_type = '" . FrontEndHooks::COMMENT_TYPE_REVIEW . "' OR (c.comment_type = '" . FrontEndHooks::COMMENT_TYPE_REPLY . "' AND review_parent.comment_id is not null)) |
| 42 | "; |
| 43 | |
| 44 | return (array) $this->wpdb->get_results( $sql ); |
| 45 | } |
| 46 | } |
| 47 |