Skip to content

Commit c3db227

Browse files
committed
Extract get_sorted_questions
1 parent 0228445 commit c3db227

File tree

4 files changed

+48
-53
lines changed

4 files changed

+48
-53
lines changed

public_html/wp-content/plugins/camptix/addons/privacy.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ public function register_personal_data_exporters( $exporters ) {
4040
* @return array
4141
*/
4242
public function attendee_personal_data_exporter( $email_address, $page ) {
43-
/* @var CampTix_Plugin $camptix */
44-
global $camptix;
45-
4643
$page = (int) $page;
4744

4845
$data_to_export = array();
@@ -127,7 +124,7 @@ public function attendee_personal_data_exporter( $email_address, $page ) {
127124
}
128125
break;
129126
case 'questions':
130-
$questions = $camptix->get_sorted_questions( $post->tix_ticket_id );
127+
$questions = CampTix_Utility::get_sorted_questions( $post->tix_ticket_id );
131128
$answers = $post->tix_questions;
132129

133130
foreach ( $questions as $question ) {
@@ -327,7 +324,7 @@ public function attendee_personal_data_eraser( $email_address, $page ) {
327324
update_post_meta( $post->ID, $key, $anonymized_value );
328325
break;
329326
case 'questions':
330-
$questions = $camptix->get_sorted_questions( $post->tix_ticket_id );
327+
$questions = CampTix_Utility::get_sorted_questions( $post->tix_ticket_id );
331328
$answers = $post->tix_questions;
332329

333330
$anonymized_answers = array();

public_html/wp-content/plugins/camptix/addons/require-login.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,13 @@ protected function registering_multiple_attendees( $tickets_selected ) {
274274
* @return bool
275275
*/
276276
protected function tickets_have_questions( $tickets_selected ) {
277-
/** @var $camptix CampTix_Plugin */
278-
global $camptix;
279277
$has_questions = false;
280278

281279
foreach ( $tickets_selected as $ticket_id => $number_attendees_current_ticket ) {
282280
$number_attendees_current_ticket = absint( $number_attendees_current_ticket );
283281

284282
if ( $number_attendees_current_ticket > 0 ) {
285-
$questions = $camptix->get_sorted_questions( $ticket_id );
283+
$questions = CampTix_Utility::get_sorted_questions( $ticket_id );
286284

287285
if ( count( $questions ) >= 1 ) {
288286
$has_questions = true;

public_html/wp-content/plugins/camptix/camptix.php

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -936,46 +936,6 @@ function get_all_questions() {
936936
return $questions;
937937
}
938938

939-
/**
940-
* Takes a ticket id and returns a sorted array of questions.
941-
*
942-
* @param int $ticket_id
943-
*
944-
* @return array
945-
*/
946-
function get_sorted_questions( $ticket_id ) {
947-
$question_ids = (array) get_post_meta( $ticket_id, 'tix_question_id' );
948-
$order = (array) get_post_meta( $ticket_id, 'tix_questions_order', true );
949-
950-
// Make sure we have at least some questions
951-
if ( empty( $question_ids ) )
952-
return array();
953-
954-
$questions = get_posts( array(
955-
'post_type' => 'tix_question',
956-
'post_status' => 'publish',
957-
'posts_per_page' => -1,
958-
'post__in' => $question_ids,
959-
) );
960-
961-
$questions_with_keys = array();
962-
963-
foreach ( $questions as $question )
964-
$questions_with_keys[ $question->ID ] = $question;
965-
966-
$questions = $questions_with_keys;
967-
unset( $questions_with_keys );
968-
969-
$questions_sorted = array();
970-
foreach ( $order as $question_id )
971-
if ( isset( $questions[ $question_id ] ) )
972-
$questions_sorted[] = $questions[ $question_id ];
973-
974-
unset( $questions );
975-
976-
return $questions_sorted;
977-
}
978-
979939
/**
980940
* Fired during init, registers our new post types. $supports depends
981941
* on $this->debug, which if true, renders things like custom fields.
@@ -4400,7 +4360,7 @@ function metabox_ticket_questions() {
44004360
</div>
44014361
</div>
44024362
<?php
4403-
$questions = $this->get_sorted_questions( get_the_ID() );
4363+
$questions = CampTix_Utility::get_sorted_questions( get_the_ID() );
44044364
$i = 0;
44054365
?>
44064366
</div>
@@ -4715,7 +4675,7 @@ function metabox_attendee_info() {
47154675

47164676
// Questions
47174677
$rows[] = array( __( 'Questions', 'wordcamporg' ), '' );
4718-
$questions = $this->get_sorted_questions( $ticket_id );
4678+
$questions = CampTix_Utility::get_sorted_questions( $ticket_id );
47194679
$answers = get_post_meta( $post->ID, 'tix_questions', true );
47204680

47214681
foreach ( $questions as $question ) {
@@ -5862,7 +5822,7 @@ function form_attendee_info() {
58625822

58635823
<?php
58645824
$ticket = $this->tickets[$ticket_id];
5865-
$questions = $this->get_sorted_questions( $ticket->ID );
5825+
$questions = CampTix_Utility::get_sorted_questions( $ticket->ID );
58665826
$this->form_data['tix_attendee_info'][ $i ]['ticket_id'] = intval( $ticket->ID );
58675827
?>
58685828
<input type="hidden" name="tix_attendee_info[<?php echo esc_attr( $i ); ?>][ticket_id]" value="<?php echo intval( $ticket->ID ); ?>" />
@@ -6231,7 +6191,7 @@ function form_edit_attendee() {
62316191
$this->notice( __( 'Please note that the payment for this ticket is still pending.', 'wordcamporg' ) );
62326192

62336193
$ticket = get_post( $ticket_id );
6234-
$questions = $this->get_sorted_questions( $ticket->ID );
6194+
$questions = CampTix_Utility::get_sorted_questions( $ticket->ID );
62356195
$answers = (array) get_post_meta( $attendee->ID, 'tix_questions', true );
62366196

62376197
$ticket_info = array(
@@ -7162,7 +7122,7 @@ function form_checkout() {
71627122

71637123
$answers = array();
71647124
if ( isset( $_POST['tix_attendee_questions'][ $i ] ) ) {
7165-
$questions = $this->get_sorted_questions( $ticket->ID );
7125+
$questions = CampTix_Utility::get_sorted_questions( $ticket->ID );
71667126

71677127
foreach ( $questions as $question ) {
71687128
if ( isset( $_POST['tix_attendee_questions'][ $i ][ $question->ID ] ) ) {

public_html/wp-content/plugins/camptix/utility.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,44 @@ public static function append_currency( $amount, $options, $nbsp = true, $curren
4949

5050
return $formatted_amount;
5151
}
52+
53+
/**
54+
* Takes a ticket id and returns a sorted array of questions.
55+
*
56+
* @param int $ticket_id
57+
*
58+
* @return array
59+
*/
60+
public static function get_sorted_questions( $ticket_id ) {
61+
$question_ids = (array) get_post_meta( $ticket_id, 'tix_question_id' );
62+
$order = (array) get_post_meta( $ticket_id, 'tix_questions_order', true );
63+
64+
// Make sure we have at least some questions
65+
if ( empty( $question_ids ) )
66+
return array();
67+
68+
$questions = get_posts( array(
69+
'post_type' => 'tix_question',
70+
'post_status' => 'publish',
71+
'posts_per_page' => -1,
72+
'post__in' => $question_ids,
73+
) );
74+
75+
$questions_with_keys = array();
76+
77+
foreach ( $questions as $question )
78+
$questions_with_keys[ $question->ID ] = $question;
79+
80+
$questions = $questions_with_keys;
81+
unset( $questions_with_keys );
82+
83+
$questions_sorted = array();
84+
foreach ( $order as $question_id )
85+
if ( isset( $questions[ $question_id ] ) )
86+
$questions_sorted[] = $questions[ $question_id ];
87+
88+
unset( $questions );
89+
90+
return $questions_sorted;
91+
}
5292
}

0 commit comments

Comments
 (0)