C:\xampp\htdocs\landing\wp-content\plugins\totalpoll\src\Migrations\Polls\YOP\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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php

namespace TotalPoll\Migrations\Polls\YOP;
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;

class 
Transform implements TransformContract {
    public function 
transformPoll$raw ) {
        
// Create template
        
$template = new Poll();

        
// Title
        
if ( ! empty( $raw['poll_title'] ) ):
            
$template->setTitle$raw['poll_title'] );
        endif;

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

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

        if ( ! empty( 
$raw['options']['allow_multiple_answers'] ) ):
            
$question['settings']['selection']['minimum'] = absint$raw['options']['allow_multiple_answers_min_number'] );
            
$question['settings']['selection']['maximum'] = absint$raw['options']['allow_multiple_answers_number'] );
        endif;

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

        
// Fields
        
if ( ! empty( $raw['fields'] ) ):
            foreach ( 
$raw['fields'] as $field ):
                if ( 
$field['status'] !== 'active' || empty( $field['name'] ) ):
                    continue;
                endif;

                
$template->addField( [
                    
'uid'         => Misc::generateUid(),
                    
'type'        => 'text',
                    
'name'        => sanitize_title_with_dashes$field['name'] ),
                    
'label'       => $field['name'],
                    
'class'       => null,
                    
'validations' => [
                        
'filled' => $field['required'] === 'yes' ? [ 'enabled' => true ] : [],
                        
'email'  => stripos$field['name'], 'email' ) !== false ? [ 'enabled' => true ] : [],
                    ],
                    
'attributes'  => null,
                ] );
            endforeach;
        endif;

        
// Settings
        
if ( $raw['options']['blocking_voters_interval_unit'] === 'days' ):
            
$blockingUnit 1440 60;
        elseif ( 
$raw['options']['blocking_voters_interval_unit'] === 'hours' ):
            
$blockingUnit 60 60;
        else:
            
$blockingUnit 60;
        endif;

        if ( ! empty( 
$raw['options']['blocking_voters'] ) && in_array'cookie'$raw['options']['blocking_voters'] ) ):
            
$template->addSettings'vote.frequency.cookies.enabled'true );
            
$template->addSettings'vote.frequency.timeout'absint$raw['options']['blocking_voters_interval_value'] ) * $blockingUnit );
        endif;

        if ( ! empty( 
$raw['options']['blocking_voters'] ) && in_array'ip'$raw['options']['blocking_voters'] ) ):
            
$template->addSettings'vote.frequency.ip.enabled'true );
            
$template->addSettings'vote.frequency.timeout'absint$raw['options']['blocking_voters_interval_value'] ) * $blockingUnit );
        endif;

        if ( ! empty( 
$raw['options']['add_other_answers_to_default_answers'] ) && $raw['options']['add_other_answers_to_default_answers'] === 'yes' ):
            if ( ! empty( 
$raw['options']['choices']['other']['enabled'] ) ):
                
$question['settings']['allowCustomChoice'] = 'visible';

                if ( ! empty( 
$raw['options']['choices']['other']['moderation'] ) ):
                    
$question['settings']['allowCustomChoice'] = 'hidden';
                endif;
            endif;
        endif;

        if ( empty( 
$raw['options']['view_results_link'] ) ):
            
$template->addSettings'results.visibility''voters' );
        endif;

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

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

        if ( ! empty( 
$raw['options']['view_results_type'] ) ):
            
$votesExpression '';
            if ( 
$raw['options']['view_results_type'] === 'votes-number' || $raw['options']['view_results_type'] === 'votes-number-and-percentages' ):
                
$votesExpression '{{votesWithLabel}} ';
            endif;
            if ( 
$raw['options']['view_results_type'] === 'percentages' || $raw['options']['view_results_type'] === 'votes-number-and-percentages' ):
                
$votesExpression .= '({{votesPercentage}})';
            endif;

            
$template->addSettings'results.votes.format'$votesExpression );
        endif;

        if ( ! empty( 
$raw['options']['vote_permisions'] ) && in_array'registered'$raw['options']['vote_permisions'] ) ):
            
$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['options']['sorting_results'] ) ):
            
$template->addSettings'choices.sort.direction'$raw['options']['sorting_results_direction'] );

            if ( 
$raw['options']['sorting_results'] === 'as_defined' ):
                
$template->addSettings'choices.sort.field''position' );
            elseif ( 
$raw['options']['sorting_results'] === 'alphabetical' ):
                
$template->addSettings'choices.sort.field''label' );
            elseif ( 
$raw['options']['sorting_results'] === 'votes' ):
                
$template->addSettings'choices.sort.field''votes' );
            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']['bar_background'] ) ):
            
$template->addSettings'design.custom.votesbar.colors.start''#' $raw['options']['bar_background'] );
            
$template->addSettings'design.custom.votesbar.colors.end''#' $raw['options']['bar_background'] );
        endif;

        
$template->addQuestion$question );


        return 
$template;
    }

    
/**
     * @param $raw
     *
     * @return mixed|void
     */
    
public function transformOptions$raw ) {
        
$template = new Options();

        return 
$template;
    }

    
/**
     * @param $raw
     *
     * @return mixed|void
     */
    
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