C:\xampp\htdocs\landing\wp-content\plugins\totalpoll\src\Migrations\Polls\YOP\Extract.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php

namespace TotalPoll\Migrations\Polls\YOP;
defined'ABSPATH' ) && exit();


use 
TotalPoll\Contracts\Migrations\Poll\Extract as ExtractContract;
use 
TotalPoll\Contracts\Migrations\Poll\Template\Poll;

/**
 * Extract Polls.
 * @package TotalPoll\Migrations\Polls\YOP
 */
class Extract implements ExtractContract {
    
/**
     * @var \wpdb $database
     */
    
protected $database;

    
/**
     * @var array
     */
    
private $tables;

    
/**
     * Extract constructor.
     */
    
public function __construct() {
        
$this->database TotalPoll'database' );
        
$this->tables   = [
            
'polls'     => "{$this->database->prefix}yop2_polls",
            
'questions' => "{$this->database->prefix}yop2_poll_questions",
            
'answers'   => "{$this->database->prefix}yop2_poll_answers",
            
'fields'    => "{$this->database->prefix}yop2_poll_custom_fields",
            
'meta'      => "{$this->database->prefix}yop2_pollmeta",
        ];
    }

    
/**
     * Count polls.
     *
     * @return int
     */
    
public function getCount() {
        
$polls $this->getPollsIds();

        return ! empty( 
$polls ) ? countarray_diff$polls$this->getMigratedPollsIds() ) ) : 0;
    }

    
/**
     * Get polls.
     *
     * @return array
     */
    
public function getPolls() {
        
$pollsIds       array_slice$this->getPollsIds(), 0);
        
$extractedPolls   = [];

        foreach ( 
$pollsIds as $pollId ):
            
$query $this->database->prepare"SELECT poll_title, poll_start_date, poll_end_date FROM {$this->tables['polls']} WHERE ID = %d"$pollId );
            
$poll  $this->database->get_row$queryARRAY_A );

            if ( ! 
$poll ):
                continue;
            endif;

            
$query $this->database->prepare"SELECT meta_value AS options FROM {$this->tables['meta']} WHERE yop_poll_id = %d AND meta_key = %s"$pollId'options' );
            
$poll  array_merge$poll$this->database->get_row$queryARRAY_A ) );

            
$query            $this->database->prepare"SELECT question FROM {$this->tables['questions']} WHERE poll_id = %d"$pollId );
            
$poll['question'] = $this->database->get_var$query );

            
$query           $this->database->prepare"SELECT answer, answer_status, votes, answer_date, answer_modified FROM {$this->tables['answers']} WHERE poll_id = %d ORDER BY question_order"$pollId );
            
$poll['choices'] = $this->database->get_results$queryARRAY_A );

            
$query          $this->database->prepare"SELECT ID, custom_field, required, status FROM {$this->tables['fields']} WHERE poll_id = %d"$pollId );
            
$poll['fields'] = $this->database->get_results$queryARRAY_A );

            
$poll['options'] = unserialize$poll['options'] );
            
$poll['id']      = $pollId;

            
$extractedPolls[] = $poll;
        endforeach;

        return 
$extractedPolls;
    }

    
/**
     * Get options.
     */
    
public function getOptions() {
        return [];
    }

    
/**
     * Get log entries.
     *
     * @param Poll $poll
     *
     * @return array
     */
    
public function getLogEntriesPoll $poll ) {
        return [];
    }

    
/**
     * @param Poll $poll
     *
     * @return array
     */
    
public function getSubmissionsPoll $poll ) {
        return [];
    }

    
/**
     * Get polls ids array.
     *
     * @return array
     */
    
private function getPollsIds() {

        if ( 
$this->database->get_var"SHOW TABLES LIKE '{$this->tables['polls']}'" ) == $this->tables['polls'] ) :
            
$ids $this->database->get_col$this->database->prepare"SELECT ID FROM {$this->tables['polls']} WHERE poll_type = %s"'poll' ) );

            return 
array_diff$ids$this->getMigratedPollsIds() );
        endif;

        return [];
    }

    
/**
     * @return array
     */
    
public function getMigratedPollsIds() {
        return (array) 
get_option'yop_poll_migrated', [] );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586