wpdb->get_var( $this->wpdb->prepare( " SELECT COUNT(*) FROM {$this->wpdb->prefix}icl_core_status ct JOIN {$this->wpdb->prefix}icl_string_status st ON ct.rid = st.rid JOIN {$this->wpdb->prefix}icl_string_translations t ON st.string_translation_id = t.id WHERE ct.rid = %d AND t.status < %d ", $job_arr['id'], ICL_TM_COMPLETE ) ) ? true : $in_progress_status; } public function jobs_union_table_sql_filter( $sql_statements, $args ) { return $this->get_jobs_table_sql_part( $sql_statements, $args ); } /** * @param string $table * * @return string */ public function filter_tm_post_job_table( $table ) { return " (SELECT ID, post_type FROM {$table} UNION ALL SELECT ID, NULL as post_type FROM {$this->wpdb->prefix}icl_string_packages) "; } private function get_jobs_table_sql_part( $sql_statements, $args ) { $sql_statements[] = "SELECT st.translator_id, st.id AS job_id, 'string' AS element_type_prefix, st.batch_id FROM {$this->wpdb->prefix}icl_string_translations st JOIN {$this->wpdb->prefix}icl_strings s ON s.id = st.string_id " . $this->build_string_where( $args ); return $sql_statements; } /** * @param array $args * string_where * translator_id * from * to * status * service * * @return string */ private function build_string_where( $args ) { $string_where = isset( $args['string_where'] ) ? $args['string_where'] : ''; $translator_id = isset( $args['translator_id'] ) ? $args['translator_id'] : ''; $from = isset( $args['from'] ) ? $args['from'] : ''; $to = isset( $args['to'] ) ? $args['to'] : ''; $status = isset( $args['status'] ) ? $args['status'] : ''; $service = isset( $args['service'] ) ? $args['service'] : false; $wheres = array(); $where_args = array(); if ( true === (bool) $from ) { $wheres[] = 's.language = %s'; $where_args[] = $from; } if ( true === (bool) $to ) { $wheres[] = 'st.language = %s'; $where_args[] = $to; } if ( $status ) { $wheres[] = 'st.status = %d'; $where_args[] = ICL_TM_IN_PROGRESS === (int) $status ? ICL_TM_WAITING_FOR_TRANSLATOR : $status; } $service = ! $service && is_numeric( $translator_id ) ? 'local' : $service; $service = 'local' !== $service && false !== strpos( $translator_id, 'ts-' ) ? substr( $translator_id, 3 ) : $service; if ( 'local' === $service ) { $wheres[] = 'st.translator_id = %s'; $where_args[] = $translator_id; } if ( false !== $service ) { $wheres[] = 'st.translation_service = %s'; $where_args[] = $service; } if ( count( $wheres ) > 0 && count( $wheres ) === count( $where_args ) ) { $where_sql = implode( ' AND ', $wheres ); $string_where = 'WHERE ' . $this->wpdb->prepare( $where_sql, $where_args ); } return $string_where; } }