C:\xampp\htdocs\landing\wp-content\plugins\totalpoll\src\Migrations\Polls\WPPolls\Transform.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php

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


use 
TotalPoll\Contracts\Migrations\Poll\Transform as TransformContract;
use 
TotalPoll\Migrations\Polls\Templates\LogEntry;
use 
TotalPoll\Migrations\Polls\Templates\Options;
use 
TotalPoll\Migrations\Polls\Templates\Poll;
use 
TotalPoll\Migrations\Polls\Templates\Submission;
use 
TotalPollVendors\TotalCore\Helpers\Misc;

/**
 * Transform Poll.
 * @package TotalPoll\Migrations\Polls\WPPolls
 */
class Transform implements TransformContract {
    
/**
     * Transform poll.
     *
     * @param array $raw
     *
     * @return Poll
     */
    
public function transformPoll$raw ) {
        
// Create template
        
$template = new Poll();

        
// Title
        
$template->setTitle$raw['question'] );

        
$template->setId$raw['id'] );

        
// Question
        
$question = [
            
'uid'      => Misc::generateUid(),
            
'content'  => $raw['question'],
            
'settings' => [
                
'selection' => [
                    
'minimum' => 1,
                    
'maximum' => 1,
                ],
            ],
            
'choices'  => [],
        ];

        if ( ! empty( 
$raw['multiple'] ) ):
            
$question['settings']['selection']['maximum'] = absint$raw['multiple'] );
        endif;

        foreach ( 
$raw['choices'] as $choice ):
            
$question['choices'][] = [
                
'uid'           => Misc::generateUid(),
                
'votes'         => $choice['votes'],
                
'votesOverride' => $choice['votes'],
                
'visibility'    => true,
                
'type'          => 'text',
                
'label'         => wp_unslash$choice['label'] ),
            ];
        endforeach;

        
$template->addQuestion$question );

        
// Settings
        
if ( ! empty( $raw['options']['poll_logging_method'] ) ):
            if ( ! empty( 
$raw['options']['poll_cookielog_expiry'] ) ):
                
$template->addSettings'vote.frequency.timeout'absint$raw['options']['poll_cookielog_expiry'] ) );
            endif;

            if ( 
$raw['options']['poll_logging_method'] == || $raw['options']['poll_logging_method'] == ):
                
$template->addSettings'vote.frequency.cookies.enabled'true );
            endif;

            if ( 
$raw['options']['poll_logging_method'] == || $raw['options']['poll_logging_method'] == ):
                
$template->addSettings'vote.frequency.ip.enabled'true );
            endif;
        endif;

        if ( ! empty( 
$raw['options']['poll_allowtovote'] ) && $raw['options']['poll_allowtovote'] == ):
            
$roles = [];
            foreach ( 
get_editable_roles() as $role => $details ):
                
$roles[] = $role;
            endforeach;

            
$template->addSettings'vote.limitations.membership.enabled'true );
            
$template->addSettings'vote.limitations.membership.roles'$roles );
        endif;

        if ( ! empty( 
$raw['start_date'] ) ):
            
$template->addSettings'vote.limitations.period.enabled'true );
            
$template->addSettings'vote.limitations.period.start'$raw['start_date'] );
        endif;

        if ( ! empty( 
$raw['end_date'] ) ):
            
$template->addSettings'vote.limitations.period.enabled'true );
            
$template->addSettings'vote.limitations.period.end'$raw['end_date'] );
        endif;

        if ( ! empty( 
$raw['options']['poll_ans_sortby'] ) ):
            
$template->addSettings'choices.sort.direction'$raw['options']['poll_ans_sortorder'] );

            if ( 
$raw['options']['poll_ans_sortby'] === 'polla_aid' ):
                
$template->addSettings'choices.sort.field''position' );
            elseif ( 
$raw['options']['poll_ans_sortby'] === 'polla_answers' ):
                
$template->addSettings'choices.sort.field''label' );
            elseif ( 
$raw['options']['poll_ans_sortby'] === 'RAND()' ):
                
$template->addSettings'choices.sort.field''random' );
            endif;
        endif;

        if ( ! empty( 
$raw['options']['poll_ans_result_sortby'] ) ):
            
$template->addSettings'results.sort.direction'$raw['options']['poll_ans_result_sortorder'] );

            if ( 
$raw['options']['poll_ans_result_sortby'] === 'polla_votes' ):
                
$template->addSettings'results.sort.field''votes' );
            elseif ( 
$raw['options']['poll_ans_result_sortby'] === 'polla_aid' ):
                
$template->addSettings'results.sort.field''position' );
            elseif ( 
$raw['options']['poll_ans_result_sortby'] === 'polla_answers' ):
                
$template->addSettings'results.sort.field''label' );
            elseif ( 
$raw['options']['poll_ans_result_sortby'] === 'RAND()' ):
                
$template->addSettings'results.sort.field''random' );
            endif;
        endif;

        
// Design
        
$template->addSettings'design.template''basic-template' );
        
$defaults TotalPoll'modules.repository' )->getDefaults'basic-template' ) ?: [];
        
$template->addSettings'design.custom'$defaults );

        if ( ! empty( 
$raw['options']['poll_bar_bg'] ) ):
            
$template->addSettings'design.custom.votesbar.colors.start''#' $raw['options']['poll_bar_bg'] );
            
$template->addSettings'design.custom.votesbar.colors.end''#' $raw['options']['poll_bar_bg'] );
        endif;

        if ( ! empty( 
$raw['options']['poll_bar_border'] ) ):
            
$template->addSettings'design.custom.votesbar.colors.border''#' $raw['options']['poll_bar_border'] );
        endif;

        return 
$template;
    }

    
/**
     * Transform options.
     *
     * @param array $raw
     *
     * @return Options
     */
    
public function transformOptions$raw ) {
        
// Create template
        
$template = new Options();

        return 
$template;
    }

    
/**
     * Transform log.
     *
     * @param array $raw
     *
     * @return LogEntry
     */
    
public function transformLog$raw ) {
        
// Create template
        
$template = new LogEntry();

        
// Attributes
        
foreach ( $raw as $key => $value ):
            
$template$key ] = $value;
        endforeach;

        return 
$template;
    }

    
/**
     * @param $raw
     *
     * @return Submission
     */
    
public function transformSubmission$raw ) {
        
// Create template
        
$template = new Submission();

        
// Attributes
        
foreach ( $raw as $key => $value ):
            
$template$key ] = $value;
        endforeach;

        return 
$template;
    }
}
x

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