Completed
Branch FET/asset-manager (433489)
by
unknown
32:42 queued 18:11
created
core/libraries/rest_api/RestException.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -14,54 +14,54 @@
 block discarded – undo
14 14
 class RestException extends \EE_Error
15 15
 {
16 16
 
17
-    /**
18
-     * @var array
19
-     */
20
-    protected $wp_error_data = array();
17
+	/**
18
+	 * @var array
19
+	 */
20
+	protected $wp_error_data = array();
21 21
 
22
-    protected $wp_error_code = '';
22
+	protected $wp_error_code = '';
23 23
 
24 24
 
25 25
 
26
-    public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
27
-    {
28
-        if (is_array($wp_error_data)
29
-            && isset($wp_error_data['status'])
30
-        ) {
31
-            $http_status_number = $wp_error_data['status'];
32
-        } else {
33
-            $http_status_number = 500;
34
-        }
35
-        parent::__construct(
36
-            $message,
37
-            $http_status_number,
38
-            $previous
39
-        );
40
-        $this->wp_error_data = $wp_error_data;
41
-        $this->wp_error_code = $string_code;
42
-    }
26
+	public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
27
+	{
28
+		if (is_array($wp_error_data)
29
+			&& isset($wp_error_data['status'])
30
+		) {
31
+			$http_status_number = $wp_error_data['status'];
32
+		} else {
33
+			$http_status_number = 500;
34
+		}
35
+		parent::__construct(
36
+			$message,
37
+			$http_status_number,
38
+			$previous
39
+		);
40
+		$this->wp_error_data = $wp_error_data;
41
+		$this->wp_error_code = $string_code;
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * Array of data that may have been set during the constructor, intended for WP_Error's data
48
-     *
49
-     * @return array
50
-     */
51
-    public function getData()
52
-    {
53
-        return $this->wp_error_data;
54
-    }
46
+	/**
47
+	 * Array of data that may have been set during the constructor, intended for WP_Error's data
48
+	 *
49
+	 * @return array
50
+	 */
51
+	public function getData()
52
+	{
53
+		return $this->wp_error_data;
54
+	}
55 55
 
56 56
 
57 57
 
58
-    /**
59
-     * Gets the error string
60
-     *
61
-     * @return string
62
-     */
63
-    public function getStringCode()
64
-    {
65
-        return $this->wp_error_code;
66
-    }
58
+	/**
59
+	 * Gets the error string
60
+	 *
61
+	 * @return string
62
+	 */
63
+	public function getStringCode()
64
+	{
65
+		return $this->wp_error_code;
66
+	}
67 67
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesIn40834.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,38 +10,38 @@
 block discarded – undo
10 10
 class ChangesIn40834 extends ChangesInBase
11 11
 {
12 12
 
13
-    /**
14
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
15
-     */
16
-    public function setHooks()
17
-    {
18
-        // set a hook to remove the checkout/checkout endpoints if the request
19
-        // is for lower than 4.8.33
20
-        add_filter(
21
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
22
-            array($this, 'removeResponseHeaders'),
23
-            10,
24
-            3
25
-        );
26
-    }
13
+	/**
14
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
15
+	 */
16
+	public function setHooks()
17
+	{
18
+		// set a hook to remove the checkout/checkout endpoints if the request
19
+		// is for lower than 4.8.33
20
+		add_filter(
21
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
22
+			array($this, 'removeResponseHeaders'),
23
+			10,
24
+			3
25
+		);
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     * Removes the checkin and checkout endpoints from the index for requests
31
-     * to api versions lowers than 4.8.33
32
-     *
33
-     * @param array  $response_headers
34
-     * @param Base   $controller
35
-     * @param string $requested_version
36
-     * @return array like $routes_on_this_version
37
-     */
38
-    public function removeResponseHeaders($response_headers, $controller, $requested_version)
39
-    {
40
-        if ($controller instanceof Base
41
-            && $this->appliesToVersion($requested_version)
42
-        ) {
43
-            return array();
44
-        }
45
-        return $response_headers;
46
-    }
29
+	/**
30
+	 * Removes the checkin and checkout endpoints from the index for requests
31
+	 * to api versions lowers than 4.8.33
32
+	 *
33
+	 * @param array  $response_headers
34
+	 * @param Base   $controller
35
+	 * @param string $requested_version
36
+	 * @return array like $routes_on_this_version
37
+	 */
38
+	public function removeResponseHeaders($response_headers, $controller, $requested_version)
39
+	{
40
+		if ($controller instanceof Base
41
+			&& $this->appliesToVersion($requested_version)
42
+		) {
43
+			return array();
44
+		}
45
+		return $response_headers;
46
+	}
47 47
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesIn40833.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -7,57 +7,57 @@
 block discarded – undo
7 7
 class ChangesIn40833 extends ChangesInBase
8 8
 {
9 9
 
10
-    /**
11
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
12
-     */
13
-    public function setHooks()
14
-    {
15
-        // set a hook to remove the checkout/checkout endpoints if the request
16
-        // is for lower than 4.8.33
17
-        add_filter(
18
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
19
-            array($this, 'removeCheckinRoutesEarlierThan4833'),
20
-            10,
21
-            2
22
-        );
23
-        add_filter(
24
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return',
25
-            array($this, 'dontAddHeadersFromEeNotices'),
26
-            10,
27
-            2
28
-        );
29
-    }
10
+	/**
11
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
12
+	 */
13
+	public function setHooks()
14
+	{
15
+		// set a hook to remove the checkout/checkout endpoints if the request
16
+		// is for lower than 4.8.33
17
+		add_filter(
18
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
19
+			array($this, 'removeCheckinRoutesEarlierThan4833'),
20
+			10,
21
+			2
22
+		);
23
+		add_filter(
24
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return',
25
+			array($this, 'dontAddHeadersFromEeNotices'),
26
+			10,
27
+			2
28
+		);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * Removes the checkin and checkout endpoints from the index for requests
34
-     * to api versions lowers than 4.8.33
35
-     *
36
-     * @param array  $routes_on_this_version
37
-     * @param string $version
38
-     * @return array like $routes_on_this_version
39
-     */
40
-    public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version)
41
-    {
42
-        if ($this->appliesToVersion($version)) {
43
-            unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']);
44
-        }
45
-        return $routes_on_this_version;
46
-    }
32
+	/**
33
+	 * Removes the checkin and checkout endpoints from the index for requests
34
+	 * to api versions lowers than 4.8.33
35
+	 *
36
+	 * @param array  $routes_on_this_version
37
+	 * @param string $version
38
+	 * @return array like $routes_on_this_version
39
+	 */
40
+	public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version)
41
+	{
42
+		if ($this->appliesToVersion($version)) {
43
+			unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']);
44
+		}
45
+		return $routes_on_this_version;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * We just added headers for notices in this version
51
-     *
52
-     * @param array  $headers_from_ee_notices
53
-     * @param string $requested_version
54
-     * @return array
55
-     */
56
-    public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version)
57
-    {
58
-        if ($this->appliesToVersion($requested_version)) {
59
-            return array();
60
-        }
61
-        return $headers_from_ee_notices;
62
-    }
49
+	/**
50
+	 * We just added headers for notices in this version
51
+	 *
52
+	 * @param array  $headers_from_ee_notices
53
+	 * @param string $requested_version
54
+	 * @return array
55
+	 */
56
+	public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version)
57
+	{
58
+		if ($this->appliesToVersion($requested_version)) {
59
+			return array();
60
+		}
61
+		return $headers_from_ee_notices;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Base.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -16,40 +16,40 @@
 block discarded – undo
16 16
 class Base
17 17
 {
18 18
 
19
-    /**
20
-     * @param $required_permission
21
-     * @param $attempted_calculation
22
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
23
-     */
24
-    protected static function verifyCurrentUserCan($required_permission, $attempted_calculation)
25
-    {
26
-        if (! current_user_can($required_permission)) {
27
-            throw new RestException(
28
-                'permission_denied',
29
-                sprintf(
30
-                    __(
31
-                    // @codingStandardsIgnoreStart
32
-                        'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"',
33
-                        // @codingStandardsIgnoreEnd
34
-                        'event_espresso'
35
-                    ),
36
-                    $attempted_calculation,
37
-                    EEH_Inflector::pluralize_and_lower(self::getResourceName()),
38
-                    $required_permission
39
-                )
40
-            );
41
-        }
42
-    }
19
+	/**
20
+	 * @param $required_permission
21
+	 * @param $attempted_calculation
22
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
23
+	 */
24
+	protected static function verifyCurrentUserCan($required_permission, $attempted_calculation)
25
+	{
26
+		if (! current_user_can($required_permission)) {
27
+			throw new RestException(
28
+				'permission_denied',
29
+				sprintf(
30
+					__(
31
+					// @codingStandardsIgnoreStart
32
+						'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"',
33
+						// @codingStandardsIgnoreEnd
34
+						'event_espresso'
35
+					),
36
+					$attempted_calculation,
37
+					EEH_Inflector::pluralize_and_lower(self::getResourceName()),
38
+					$required_permission
39
+				)
40
+			);
41
+		}
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * Gets the name of the resource of the called class
47
-     *
48
-     * @return string
49
-     */
50
-    public static function getResourceName()
51
-    {
52
-        $classname = get_called_class();
53
-        return substr($classname, strrpos($classname, '\\') + 1);
54
-    }
45
+	/**
46
+	 * Gets the name of the resource of the called class
47
+	 *
48
+	 * @return string
49
+	 */
50
+	public static function getResourceName()
51
+	{
52
+		$classname = get_called_class();
53
+		return substr($classname, strrpos($classname, '\\') + 1);
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
      */
24 24
     protected static function verifyCurrentUserCan($required_permission, $attempted_calculation)
25 25
     {
26
-        if (! current_user_can($required_permission)) {
26
+        if ( ! current_user_can($required_permission)) {
27 27
             throw new RestException(
28 28
                 'permission_denied',
29 29
                 sprintf(
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Datetime.php 2 patches
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -11,141 +11,141 @@
 block discarded – undo
11 11
 class Datetime extends Calculations_Base
12 12
 {
13 13
 
14
-    /**
15
-     * Calculates the total spaces available on the datetime, taking into account
16
-     * ticket limits too.
17
-     *
18
-     * @see EE_Datetime::spaces_remaining( true )
19
-     * @param array            $wpdb_row
20
-     * @param \WP_REST_Request $request
21
-     * @param Controller_Base  $controller
22
-     * @return int
23
-     * @throws \EE_Error
24
-     */
25
-    public static function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
26
-    {
27
-        if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
28
-            $dtt_obj = EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
29
-        } else {
30
-            $dtt_obj = null;
31
-        }
32
-        if ($dtt_obj instanceof EE_Datetime) {
33
-            return $dtt_obj->spaces_remaining(true);
34
-        } else {
35
-            throw new \EE_Error(
36
-                sprintf(
37
-                    __(
38
-                    // @codingStandardsIgnoreStart
39
-                        'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
40
-                        // @codingStandardsIgnoreEnd
41
-                        'event_espresso'
42
-                    ),
43
-                    $wpdb_row['Datetime.DTT_ID'],
44
-                    print_r($wpdb_row, true)
45
-                )
46
-            );
47
-        }
48
-    }
14
+	/**
15
+	 * Calculates the total spaces available on the datetime, taking into account
16
+	 * ticket limits too.
17
+	 *
18
+	 * @see EE_Datetime::spaces_remaining( true )
19
+	 * @param array            $wpdb_row
20
+	 * @param \WP_REST_Request $request
21
+	 * @param Controller_Base  $controller
22
+	 * @return int
23
+	 * @throws \EE_Error
24
+	 */
25
+	public static function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
26
+	{
27
+		if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
28
+			$dtt_obj = EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
29
+		} else {
30
+			$dtt_obj = null;
31
+		}
32
+		if ($dtt_obj instanceof EE_Datetime) {
33
+			return $dtt_obj->spaces_remaining(true);
34
+		} else {
35
+			throw new \EE_Error(
36
+				sprintf(
37
+					__(
38
+					// @codingStandardsIgnoreStart
39
+						'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
40
+						// @codingStandardsIgnoreEnd
41
+						'event_espresso'
42
+					),
43
+					$wpdb_row['Datetime.DTT_ID'],
44
+					print_r($wpdb_row, true)
45
+				)
46
+			);
47
+		}
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * Counts registrations who have checked into this datetime
53
-     *
54
-     * @param array            $wpdb_row
55
-     * @param \WP_REST_Request $request
56
-     * @param Controller_Base  $controller
57
-     * @return int
58
-     * @throws \EE_Error
59
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
60
-     */
61
-    public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
62
-    {
63
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
64
-            throw new \EE_Error(
65
-                sprintf(
66
-                    __(
67
-                    // @codingStandardsIgnoreStart
68
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
69
-                        // @codingStandardsIgnoreEnd
70
-                        'event_espresso'
71
-                    ),
72
-                    print_r($wpdb_row, true)
73
-                )
74
-            );
75
-        }
76
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
77
-        return EEM_Registration::instance()
78
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
79
-    }
51
+	/**
52
+	 * Counts registrations who have checked into this datetime
53
+	 *
54
+	 * @param array            $wpdb_row
55
+	 * @param \WP_REST_Request $request
56
+	 * @param Controller_Base  $controller
57
+	 * @return int
58
+	 * @throws \EE_Error
59
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
60
+	 */
61
+	public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
62
+	{
63
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
64
+			throw new \EE_Error(
65
+				sprintf(
66
+					__(
67
+					// @codingStandardsIgnoreStart
68
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
69
+						// @codingStandardsIgnoreEnd
70
+						'event_espresso'
71
+					),
72
+					print_r($wpdb_row, true)
73
+				)
74
+			);
75
+		}
76
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
77
+		return EEM_Registration::instance()
78
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Counts registrations who have checked out of this datetime
84
-     *
85
-     * @param array            $wpdb_row
86
-     * @param \WP_REST_Request $request
87
-     * @param Controller_Base  $controller
88
-     * @return int
89
-     * @throws \EE_Error
90
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
91
-     */
92
-    public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
93
-    {
94
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
95
-            throw new \EE_Error(
96
-                sprintf(
97
-                    __(
98
-                    // @codingStandardsIgnoreStart
99
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
100
-                        // @codingStandardsIgnoreEnd
101
-                        'event_espresso'
102
-                    ),
103
-                    print_r($wpdb_row, true)
104
-                )
105
-            );
106
-        }
107
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
108
-        return EEM_Registration::instance()
109
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
110
-    }
82
+	/**
83
+	 * Counts registrations who have checked out of this datetime
84
+	 *
85
+	 * @param array            $wpdb_row
86
+	 * @param \WP_REST_Request $request
87
+	 * @param Controller_Base  $controller
88
+	 * @return int
89
+	 * @throws \EE_Error
90
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
91
+	 */
92
+	public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
93
+	{
94
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
95
+			throw new \EE_Error(
96
+				sprintf(
97
+					__(
98
+					// @codingStandardsIgnoreStart
99
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
100
+						// @codingStandardsIgnoreEnd
101
+						'event_espresso'
102
+					),
103
+					print_r($wpdb_row, true)
104
+				)
105
+			);
106
+		}
107
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
108
+		return EEM_Registration::instance()
109
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
110
+	}
111 111
 
112 112
 
113
-    /**
114
-     * Counts the number of pending-payment registrations for this event (regardless
115
-     * of how many datetimes each registrations' ticket purchase is for)
116
-     *
117
-     * @param array            $wpdb_row
118
-     * @param \WP_REST_Request $request
119
-     * @param Controller_Base  $controller
120
-     * @return int
121
-     * @throws \EE_Error
122
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
123
-     */
124
-    public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
125
-    {
126
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
127
-            throw new \EE_Error(
128
-                sprintf(
129
-                    __(
130
-                    // @codingStandardsIgnoreStart
131
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
132
-                        // @codingStandardsIgnoreEnd
133
-                        'event_espresso'
134
-                    ),
135
-                    print_r($wpdb_row, true)
136
-                )
137
-            );
138
-        }
139
-        self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
140
-        return EEM_Registration::instance()->count(
141
-            array(
142
-                array(
143
-                    'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
144
-                    'STS_ID'                 => EEM_Registration::status_id_pending_payment,
145
-                ),
146
-            ),
147
-            'REG_ID',
148
-            true
149
-        );
150
-    }
113
+	/**
114
+	 * Counts the number of pending-payment registrations for this event (regardless
115
+	 * of how many datetimes each registrations' ticket purchase is for)
116
+	 *
117
+	 * @param array            $wpdb_row
118
+	 * @param \WP_REST_Request $request
119
+	 * @param Controller_Base  $controller
120
+	 * @return int
121
+	 * @throws \EE_Error
122
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
123
+	 */
124
+	public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
125
+	{
126
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
127
+			throw new \EE_Error(
128
+				sprintf(
129
+					__(
130
+					// @codingStandardsIgnoreStart
131
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
132
+						// @codingStandardsIgnoreEnd
133
+						'event_espresso'
134
+					),
135
+					print_r($wpdb_row, true)
136
+				)
137
+			);
138
+		}
139
+		self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
140
+		return EEM_Registration::instance()->count(
141
+			array(
142
+				array(
143
+					'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
144
+					'STS_ID'                 => EEM_Registration::status_id_pending_payment,
145
+				),
146
+			),
147
+			'REG_ID',
148
+			true
149
+		);
150
+	}
151 151
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
62 62
     {
63
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
63
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
64 64
             throw new \EE_Error(
65 65
                 sprintf(
66 66
                     __(
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
93 93
     {
94
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
94
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
95 95
             throw new \EE_Error(
96 96
                 sprintf(
97 97
                     __(
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      */
124 124
     public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
125 125
     {
126
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
126
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
127 127
             throw new \EE_Error(
128 128
                 sprintf(
129 129
                     __(
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 2 patches
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -21,391 +21,391 @@
 block discarded – undo
21 21
 class Event extends Calculations_Base
22 22
 {
23 23
 
24
-    /**
25
-     * Calculates the total spaces on the event (not subtracting sales, but taking
26
-     * sales into account; so this is the optimum sales that CAN still be achieved)
27
-     * See EE_Event::total_available_spaces( true );
28
-     *
29
-     * @param array            $wpdb_row
30
-     * @param \WP_REST_Request $request
31
-     * @param Base             $controller
32
-     * @return int
33
-     * @throws EE_Error
34
-     */
35
-    public static function optimumSalesAtStart($wpdb_row, $request, $controller)
36
-    {
37
-        $event_obj = null;
38
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
39
-            $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
40
-        }
41
-        if ($event_obj instanceof EE_Event) {
42
-            return $event_obj->total_available_spaces();
43
-        }
44
-        throw new EE_Error(
45
-            sprintf(
46
-                __(
47
-                // @codingStandardsIgnoreStart
48
-                    'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
49
-                    // @codingStandardsIgnoreEnd
50
-                    'event_espresso'
51
-                ),
52
-                $wpdb_row['Event_CPT.ID'],
53
-                print_r($wpdb_row, true)
54
-            )
55
-        );
56
-    }
57
-
58
-
59
-    /**
60
-     * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
61
-     * sales that COULD have been achieved)
62
-     * See EE_Event::total_available_spaces( true );
63
-     *
64
-     * @param array            $wpdb_row
65
-     * @param \WP_REST_Request $request
66
-     * @param Base             $controller
67
-     * @return int
68
-     * @throws EE_Error
69
-     */
70
-    public static function optimumSalesNow($wpdb_row, $request, $controller)
71
-    {
72
-        $event_obj = null;
73
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
74
-            $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
75
-        }
76
-        if ($event_obj instanceof EE_Event) {
77
-            return $event_obj->total_available_spaces(true);
78
-        }
79
-        throw new EE_Error(
80
-            sprintf(
81
-                __(
82
-                // @codingStandardsIgnoreStart
83
-                    'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
84
-                    // @codingStandardsIgnoreEnd
85
-                    'event_espresso'
86
-                ),
87
-                $wpdb_row['Event_CPT.ID'],
88
-                print_r($wpdb_row, true)
89
-            )
90
-        );
91
-    }
92
-
93
-
94
-    /**
95
-     * Like optimum_sales_now, but minus total sales so far.
96
-     * See EE_Event::spaces_remaining_for_sale( true );
97
-     *
98
-     * @param array            $wpdb_row
99
-     * @param \WP_REST_Request $request
100
-     * @param Base             $controller
101
-     * @return int
102
-     * @throws EE_Error
103
-     */
104
-    public static function spacesRemaining($wpdb_row, $request, $controller)
105
-    {
106
-        $event_obj = null;
107
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
108
-            $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
109
-        }
110
-        if ($event_obj instanceof EE_Event) {
111
-            return $event_obj->spaces_remaining_for_sale();
112
-        }
113
-        throw new EE_Error(
114
-            sprintf(
115
-                __(
116
-                // @codingStandardsIgnoreStart
117
-                    'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
118
-                    // @codingStandardsIgnoreEnd
119
-                    'event_espresso'
120
-                ),
121
-                $wpdb_row['Event_CPT.ID'],
122
-                print_r($wpdb_row, true)
123
-            )
124
-        );
125
-    }
126
-
127
-
128
-    /**
129
-     * Counts the number of approved registrations for this event (regardless
130
-     * of how many datetimes each registrations' ticket purchase is for)
131
-     *
132
-     * @param array            $wpdb_row
133
-     * @param \WP_REST_Request $request
134
-     * @param Base             $controller
135
-     * @return int
136
-     * @throws EE_Error
137
-     */
138
-    public static function spotsTaken($wpdb_row, $request, $controller)
139
-    {
140
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
141
-            throw new EE_Error(
142
-                sprintf(
143
-                    __(
144
-                    // @codingStandardsIgnoreStart
145
-                        'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
146
-                        // @codingStandardsIgnoreEnd
147
-                        'event_espresso'
148
-                    ),
149
-                    print_r($wpdb_row, true)
150
-                )
151
-            );
152
-        }
153
-        return EEM_Registration::instance()->count(
154
-            array(
155
-                array(
156
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
157
-                    'STS_ID' => EEM_Registration::status_id_approved,
158
-                ),
159
-            ),
160
-            'REG_ID',
161
-            true
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * Counts the number of pending-payment registrations for this event (regardless
168
-     * of how many datetimes each registrations' ticket purchase is for)
169
-     *
170
-     * @param array            $wpdb_row
171
-     * @param \WP_REST_Request $request
172
-     * @param Base             $controller
173
-     * @return int
174
-     * @throws EE_Error
175
-     * @throws RestException
176
-     */
177
-    public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
178
-    {
179
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
180
-            throw new EE_Error(
181
-                sprintf(
182
-                    __(
183
-                    // @codingStandardsIgnoreStart
184
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
185
-                        // @codingStandardsIgnoreEnd
186
-                        'event_espresso'
187
-                    ),
188
-                    print_r($wpdb_row, true)
189
-                )
190
-            );
191
-        }
192
-        self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
193
-        return EEM_Registration::instance()->count(
194
-            array(
195
-                array(
196
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
197
-                    'STS_ID' => EEM_Registration::status_id_pending_payment,
198
-                ),
199
-            ),
200
-            'REG_ID',
201
-            true
202
-        );
203
-    }
204
-
205
-
206
-    /**
207
-     * Counts all the registrations who have checked into one of this events' datetimes
208
-     * See EE_Event::total_available_spaces( false );
209
-     *
210
-     * @param array            $wpdb_row
211
-     * @param \WP_REST_Request $request
212
-     * @param Base             $controller
213
-     * @return int|null if permission denied
214
-     * @throws EE_Error
215
-     * @throws RestException
216
-     */
217
-    public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
218
-    {
219
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
220
-            throw new EE_Error(
221
-                sprintf(
222
-                    __(
223
-                    // @codingStandardsIgnoreStart
224
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
225
-                        // @codingStandardsIgnoreEnd
226
-                        'event_espresso'
227
-                    ),
228
-                    print_r($wpdb_row, true)
229
-                )
230
-            );
231
-        }
232
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
233
-        return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
234
-    }
235
-
236
-
237
-    /**
238
-     * Counts all the registrations who have checked out of one of this events' datetimes
239
-     * See EE_Event::total_available_spaces( false );
240
-     *
241
-     * @param array            $wpdb_row
242
-     * @param \WP_REST_Request $request
243
-     * @param Base             $controller
244
-     * @return int
245
-     * @throws EE_Error
246
-     * @throws RestException
247
-     */
248
-    public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
249
-    {
250
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
251
-            throw new EE_Error(
252
-                sprintf(
253
-                    __(
254
-                    // @codingStandardsIgnoreStart
255
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
256
-                        // @codingStandardsIgnoreEnd
257
-                        'event_espresso'
258
-                    ),
259
-                    print_r($wpdb_row, true)
260
-                )
261
-            );
262
-        }
263
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
264
-        return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
265
-    }
266
-
267
-
268
-    /**
269
-     * Gets the thumbnail image
270
-     *
271
-     * @param array            $wpdb_row
272
-     * @param \WP_REST_Request $request
273
-     * @param Base             $controller
274
-     * @return array
275
-     * @throws EE_Error
276
-     */
277
-    public static function imageThumbnail($wpdb_row, $request, $controller)
278
-    {
279
-        return self::calculateImageData($wpdb_row, 'thumbnail');
280
-    }
281
-
282
-
283
-    /**
284
-     * Gets the medium image
285
-     *
286
-     * @param array            $wpdb_row
287
-     * @param \WP_REST_Request $request
288
-     * @param Base             $controller
289
-     * @return array
290
-     * @throws EE_Error
291
-     */
292
-    public static function imageMedium($wpdb_row, $request, $controller)
293
-    {
294
-        return self::calculateImageData($wpdb_row, 'medium');
295
-    }
296
-
297
-
298
-    /**
299
-     * Gets the medium-large image
300
-     *
301
-     * @param array            $wpdb_row
302
-     * @param \WP_REST_Request $request
303
-     * @param Base             $controller
304
-     * @return array
305
-     * @throws EE_Error
306
-     */
307
-    public static function imageMediumLarge($wpdb_row, $request, $controller)
308
-    {
309
-        return self::calculateImageData($wpdb_row, 'medium_large');
310
-    }
311
-
312
-
313
-    /**
314
-     * Gets the large image
315
-     *
316
-     * @param array            $wpdb_row
317
-     * @param \WP_REST_Request $request
318
-     * @param Base             $controller
319
-     * @return array
320
-     * @throws EE_Error
321
-     */
322
-    public static function imageLarge($wpdb_row, $request, $controller)
323
-    {
324
-        return self::calculateImageData($wpdb_row, 'large');
325
-    }
326
-
327
-
328
-    /**
329
-     * Gets the post-thumbnail image
330
-     *
331
-     * @param array            $wpdb_row
332
-     * @param \WP_REST_Request $request
333
-     * @param Base             $controller
334
-     * @return array
335
-     * @throws EE_Error
336
-     */
337
-    public static function imagePostThumbnail($wpdb_row, $request, $controller)
338
-    {
339
-        return self::calculateImageData($wpdb_row, 'post-thumbnail');
340
-    }
341
-
342
-
343
-    /**
344
-     * Gets the full size image
345
-     *
346
-     * @param array            $wpdb_row
347
-     * @param \WP_REST_Request $request
348
-     * @param Base             $controller
349
-     * @return array
350
-     * @throws EE_Error
351
-     */
352
-    public static function imageFull($wpdb_row, $request, $controller)
353
-    {
354
-        return self::calculateImageData($wpdb_row, 'full');
355
-    }
356
-
357
-
358
-    /**
359
-     * Gets image specs and formats them for the display in the API,
360
-     * according to the image size requested
361
-     *
362
-     * @param array  $wpdb_row
363
-     * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
364
-     * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
365
-     * @throws EE_Error
366
-     */
367
-    protected static function calculateImageData($wpdb_row, $image_size)
368
-    {
369
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
370
-            throw new EE_Error(
371
-                sprintf(
372
-                    __(
373
-                    // @codingStandardsIgnoreStart
374
-                        'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
375
-                        // @codingStandardsIgnoreEnd
376
-                        'event_espresso'
377
-                    ),
378
-                    print_r($wpdb_row, true)
379
-                )
380
-            );
381
-        }
382
-        $EVT_ID = $wpdb_row['Event_CPT.ID'];
383
-        $attachment_id = get_post_thumbnail_id($EVT_ID);
384
-        $data = wp_get_attachment_image_src($attachment_id, $image_size);
385
-        if (! $data) {
386
-            return null;
387
-        }
388
-        $generated = true;
389
-        if (isset($data[3])) {
390
-            $generated = $data[3];
391
-        }
392
-        return array(
393
-            'url'       => $data[0],
394
-            'width'     => $data[1],
395
-            'height'    => $data[2],
396
-            'generated' => $generated,
397
-        );
398
-    }
399
-
400
-
401
-    /**
402
-     * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
403
-     *
404
-     * @param array $wpdb_row
405
-     * @return bool
406
-     */
407
-    protected static function wpdbRowHasEventId($wpdb_row)
408
-    {
409
-        return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
410
-    }
24
+	/**
25
+	 * Calculates the total spaces on the event (not subtracting sales, but taking
26
+	 * sales into account; so this is the optimum sales that CAN still be achieved)
27
+	 * See EE_Event::total_available_spaces( true );
28
+	 *
29
+	 * @param array            $wpdb_row
30
+	 * @param \WP_REST_Request $request
31
+	 * @param Base             $controller
32
+	 * @return int
33
+	 * @throws EE_Error
34
+	 */
35
+	public static function optimumSalesAtStart($wpdb_row, $request, $controller)
36
+	{
37
+		$event_obj = null;
38
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
39
+			$event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
40
+		}
41
+		if ($event_obj instanceof EE_Event) {
42
+			return $event_obj->total_available_spaces();
43
+		}
44
+		throw new EE_Error(
45
+			sprintf(
46
+				__(
47
+				// @codingStandardsIgnoreStart
48
+					'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
49
+					// @codingStandardsIgnoreEnd
50
+					'event_espresso'
51
+				),
52
+				$wpdb_row['Event_CPT.ID'],
53
+				print_r($wpdb_row, true)
54
+			)
55
+		);
56
+	}
57
+
58
+
59
+	/**
60
+	 * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
61
+	 * sales that COULD have been achieved)
62
+	 * See EE_Event::total_available_spaces( true );
63
+	 *
64
+	 * @param array            $wpdb_row
65
+	 * @param \WP_REST_Request $request
66
+	 * @param Base             $controller
67
+	 * @return int
68
+	 * @throws EE_Error
69
+	 */
70
+	public static function optimumSalesNow($wpdb_row, $request, $controller)
71
+	{
72
+		$event_obj = null;
73
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
74
+			$event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
75
+		}
76
+		if ($event_obj instanceof EE_Event) {
77
+			return $event_obj->total_available_spaces(true);
78
+		}
79
+		throw new EE_Error(
80
+			sprintf(
81
+				__(
82
+				// @codingStandardsIgnoreStart
83
+					'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
84
+					// @codingStandardsIgnoreEnd
85
+					'event_espresso'
86
+				),
87
+				$wpdb_row['Event_CPT.ID'],
88
+				print_r($wpdb_row, true)
89
+			)
90
+		);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Like optimum_sales_now, but minus total sales so far.
96
+	 * See EE_Event::spaces_remaining_for_sale( true );
97
+	 *
98
+	 * @param array            $wpdb_row
99
+	 * @param \WP_REST_Request $request
100
+	 * @param Base             $controller
101
+	 * @return int
102
+	 * @throws EE_Error
103
+	 */
104
+	public static function spacesRemaining($wpdb_row, $request, $controller)
105
+	{
106
+		$event_obj = null;
107
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
108
+			$event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
109
+		}
110
+		if ($event_obj instanceof EE_Event) {
111
+			return $event_obj->spaces_remaining_for_sale();
112
+		}
113
+		throw new EE_Error(
114
+			sprintf(
115
+				__(
116
+				// @codingStandardsIgnoreStart
117
+					'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
118
+					// @codingStandardsIgnoreEnd
119
+					'event_espresso'
120
+				),
121
+				$wpdb_row['Event_CPT.ID'],
122
+				print_r($wpdb_row, true)
123
+			)
124
+		);
125
+	}
126
+
127
+
128
+	/**
129
+	 * Counts the number of approved registrations for this event (regardless
130
+	 * of how many datetimes each registrations' ticket purchase is for)
131
+	 *
132
+	 * @param array            $wpdb_row
133
+	 * @param \WP_REST_Request $request
134
+	 * @param Base             $controller
135
+	 * @return int
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function spotsTaken($wpdb_row, $request, $controller)
139
+	{
140
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
141
+			throw new EE_Error(
142
+				sprintf(
143
+					__(
144
+					// @codingStandardsIgnoreStart
145
+						'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
146
+						// @codingStandardsIgnoreEnd
147
+						'event_espresso'
148
+					),
149
+					print_r($wpdb_row, true)
150
+				)
151
+			);
152
+		}
153
+		return EEM_Registration::instance()->count(
154
+			array(
155
+				array(
156
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
157
+					'STS_ID' => EEM_Registration::status_id_approved,
158
+				),
159
+			),
160
+			'REG_ID',
161
+			true
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Counts the number of pending-payment registrations for this event (regardless
168
+	 * of how many datetimes each registrations' ticket purchase is for)
169
+	 *
170
+	 * @param array            $wpdb_row
171
+	 * @param \WP_REST_Request $request
172
+	 * @param Base             $controller
173
+	 * @return int
174
+	 * @throws EE_Error
175
+	 * @throws RestException
176
+	 */
177
+	public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
178
+	{
179
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
180
+			throw new EE_Error(
181
+				sprintf(
182
+					__(
183
+					// @codingStandardsIgnoreStart
184
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
185
+						// @codingStandardsIgnoreEnd
186
+						'event_espresso'
187
+					),
188
+					print_r($wpdb_row, true)
189
+				)
190
+			);
191
+		}
192
+		self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
193
+		return EEM_Registration::instance()->count(
194
+			array(
195
+				array(
196
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
197
+					'STS_ID' => EEM_Registration::status_id_pending_payment,
198
+				),
199
+			),
200
+			'REG_ID',
201
+			true
202
+		);
203
+	}
204
+
205
+
206
+	/**
207
+	 * Counts all the registrations who have checked into one of this events' datetimes
208
+	 * See EE_Event::total_available_spaces( false );
209
+	 *
210
+	 * @param array            $wpdb_row
211
+	 * @param \WP_REST_Request $request
212
+	 * @param Base             $controller
213
+	 * @return int|null if permission denied
214
+	 * @throws EE_Error
215
+	 * @throws RestException
216
+	 */
217
+	public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
218
+	{
219
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
220
+			throw new EE_Error(
221
+				sprintf(
222
+					__(
223
+					// @codingStandardsIgnoreStart
224
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
225
+						// @codingStandardsIgnoreEnd
226
+						'event_espresso'
227
+					),
228
+					print_r($wpdb_row, true)
229
+				)
230
+			);
231
+		}
232
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
233
+		return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
234
+	}
235
+
236
+
237
+	/**
238
+	 * Counts all the registrations who have checked out of one of this events' datetimes
239
+	 * See EE_Event::total_available_spaces( false );
240
+	 *
241
+	 * @param array            $wpdb_row
242
+	 * @param \WP_REST_Request $request
243
+	 * @param Base             $controller
244
+	 * @return int
245
+	 * @throws EE_Error
246
+	 * @throws RestException
247
+	 */
248
+	public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
249
+	{
250
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
251
+			throw new EE_Error(
252
+				sprintf(
253
+					__(
254
+					// @codingStandardsIgnoreStart
255
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
256
+						// @codingStandardsIgnoreEnd
257
+						'event_espresso'
258
+					),
259
+					print_r($wpdb_row, true)
260
+				)
261
+			);
262
+		}
263
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
264
+		return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
265
+	}
266
+
267
+
268
+	/**
269
+	 * Gets the thumbnail image
270
+	 *
271
+	 * @param array            $wpdb_row
272
+	 * @param \WP_REST_Request $request
273
+	 * @param Base             $controller
274
+	 * @return array
275
+	 * @throws EE_Error
276
+	 */
277
+	public static function imageThumbnail($wpdb_row, $request, $controller)
278
+	{
279
+		return self::calculateImageData($wpdb_row, 'thumbnail');
280
+	}
281
+
282
+
283
+	/**
284
+	 * Gets the medium image
285
+	 *
286
+	 * @param array            $wpdb_row
287
+	 * @param \WP_REST_Request $request
288
+	 * @param Base             $controller
289
+	 * @return array
290
+	 * @throws EE_Error
291
+	 */
292
+	public static function imageMedium($wpdb_row, $request, $controller)
293
+	{
294
+		return self::calculateImageData($wpdb_row, 'medium');
295
+	}
296
+
297
+
298
+	/**
299
+	 * Gets the medium-large image
300
+	 *
301
+	 * @param array            $wpdb_row
302
+	 * @param \WP_REST_Request $request
303
+	 * @param Base             $controller
304
+	 * @return array
305
+	 * @throws EE_Error
306
+	 */
307
+	public static function imageMediumLarge($wpdb_row, $request, $controller)
308
+	{
309
+		return self::calculateImageData($wpdb_row, 'medium_large');
310
+	}
311
+
312
+
313
+	/**
314
+	 * Gets the large image
315
+	 *
316
+	 * @param array            $wpdb_row
317
+	 * @param \WP_REST_Request $request
318
+	 * @param Base             $controller
319
+	 * @return array
320
+	 * @throws EE_Error
321
+	 */
322
+	public static function imageLarge($wpdb_row, $request, $controller)
323
+	{
324
+		return self::calculateImageData($wpdb_row, 'large');
325
+	}
326
+
327
+
328
+	/**
329
+	 * Gets the post-thumbnail image
330
+	 *
331
+	 * @param array            $wpdb_row
332
+	 * @param \WP_REST_Request $request
333
+	 * @param Base             $controller
334
+	 * @return array
335
+	 * @throws EE_Error
336
+	 */
337
+	public static function imagePostThumbnail($wpdb_row, $request, $controller)
338
+	{
339
+		return self::calculateImageData($wpdb_row, 'post-thumbnail');
340
+	}
341
+
342
+
343
+	/**
344
+	 * Gets the full size image
345
+	 *
346
+	 * @param array            $wpdb_row
347
+	 * @param \WP_REST_Request $request
348
+	 * @param Base             $controller
349
+	 * @return array
350
+	 * @throws EE_Error
351
+	 */
352
+	public static function imageFull($wpdb_row, $request, $controller)
353
+	{
354
+		return self::calculateImageData($wpdb_row, 'full');
355
+	}
356
+
357
+
358
+	/**
359
+	 * Gets image specs and formats them for the display in the API,
360
+	 * according to the image size requested
361
+	 *
362
+	 * @param array  $wpdb_row
363
+	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
364
+	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
365
+	 * @throws EE_Error
366
+	 */
367
+	protected static function calculateImageData($wpdb_row, $image_size)
368
+	{
369
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
370
+			throw new EE_Error(
371
+				sprintf(
372
+					__(
373
+					// @codingStandardsIgnoreStart
374
+						'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
375
+						// @codingStandardsIgnoreEnd
376
+						'event_espresso'
377
+					),
378
+					print_r($wpdb_row, true)
379
+				)
380
+			);
381
+		}
382
+		$EVT_ID = $wpdb_row['Event_CPT.ID'];
383
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
384
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
385
+		if (! $data) {
386
+			return null;
387
+		}
388
+		$generated = true;
389
+		if (isset($data[3])) {
390
+			$generated = $data[3];
391
+		}
392
+		return array(
393
+			'url'       => $data[0],
394
+			'width'     => $data[1],
395
+			'height'    => $data[2],
396
+			'generated' => $generated,
397
+		);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
403
+	 *
404
+	 * @param array $wpdb_row
405
+	 * @return bool
406
+	 */
407
+	protected static function wpdbRowHasEventId($wpdb_row)
408
+	{
409
+		return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
410
+	}
411 411
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public static function spotsTaken($wpdb_row, $request, $controller)
139 139
     {
140
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
140
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
141 141
             throw new EE_Error(
142 142
                 sprintf(
143 143
                     __(
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      */
177 177
     public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
178 178
     {
179
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
179
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
180 180
             throw new EE_Error(
181 181
                 sprintf(
182 182
                     __(
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      */
217 217
     public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
218 218
     {
219
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
219
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
220 220
             throw new EE_Error(
221 221
                 sprintf(
222 222
                     __(
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
249 249
     {
250
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
250
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
251 251
             throw new EE_Error(
252 252
                 sprintf(
253 253
                     __(
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
      */
367 367
     protected static function calculateImageData($wpdb_row, $image_size)
368 368
     {
369
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
369
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
370 370
             throw new EE_Error(
371 371
                 sprintf(
372 372
                     __(
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
         $EVT_ID = $wpdb_row['Event_CPT.ID'];
383 383
         $attachment_id = get_post_thumbnail_id($EVT_ID);
384 384
         $data = wp_get_attachment_image_src($attachment_id, $image_size);
385
-        if (! $data) {
385
+        if ( ! $data) {
386 386
             return null;
387 387
         }
388 388
         $generated = true;
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/rpc/Checkin.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -26,124 +26,124 @@
 block discarded – undo
26 26
 class Checkin extends Base
27 27
 {
28 28
 
29
-    /**
30
-     * @param WP_REST_Request $request
31
-     * @param string          $version
32
-     * @return WP_Error|WP_REST_Response
33
-     */
34
-    public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
35
-    {
36
-        $controller = new Checkin();
37
-        return $controller->createCheckinCheckoutObject($request, $version);
38
-    }
29
+	/**
30
+	 * @param WP_REST_Request $request
31
+	 * @param string          $version
32
+	 * @return WP_Error|WP_REST_Response
33
+	 */
34
+	public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
35
+	{
36
+		$controller = new Checkin();
37
+		return $controller->createCheckinCheckoutObject($request, $version);
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * Toggles whether the user is checked in or not.
43
-     *
44
-     * @param WP_REST_Request $request
45
-     * @param string          $version
46
-     * @return WP_Error|WP_REST_Response
47
-     */
48
-    protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
49
-    {
50
-        $reg_id = $request->get_param('REG_ID');
51
-        $dtt_id = $request->get_param('DTT_ID');
52
-        $force = $request->get_param('force');
53
-        if ($force == 'true') {
54
-            $force = true;
55
-        } else {
56
-            $force = false;
57
-        }
58
-        $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
59
-        if (! $reg instanceof EE_Registration) {
60
-            return $this->sendResponse(
61
-                new WP_Error(
62
-                    'rest_registration_toggle_checkin_invalid_id',
63
-                    sprintf(
64
-                        __(
65
-                            'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
66
-                            'event_espresso'
67
-                        ),
68
-                        $reg_id
69
-                    ),
70
-                    array('status' => 422)
71
-                )
72
-            );
73
-        }
74
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
75
-            return $this->sendResponse(
76
-                new WP_Error(
77
-                    'rest_user_cannot_toggle_checkin',
78
-                    sprintf(
79
-                        __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
80
-                        $reg_id
81
-                    ),
82
-                    array('status' => 403)
83
-                )
84
-            );
85
-        }
86
-        $success = $reg->toggle_checkin_status($dtt_id, ! $force);
87
-        if ($success === false) {
88
-            // check if we know they can't check in because they're not approved and we aren't forcing
89
-            if (! $reg->is_approved() && ! $force) {
90
-                // rely on EE_Error::add_error messages to have been added to give more data about why it failed
91
-                return $this->sendResponse(
92
-                    new WP_Error(
93
-                        'rest_toggle_checkin_failed',
94
-                        __(
95
-                        // @codingStandardsIgnoreStart
96
-                            'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
97
-                            // @codingStandardsIgnoreEnd
98
-                            'event_espresso'
99
-                        )
100
-                    )
101
-                );
102
-            }
103
-            return $this->sendResponse(
104
-                new WP_Error(
105
-                    'rest_toggle_checkin_failed_not_forceable',
106
-                    __('Registration checkin failed. Please see additional error data.', 'event_espresso')
107
-                )
108
-            );
109
-        }
110
-        $checkin = EEM_Checkin::instance()->get_one(
111
-            array(
112
-                array(
113
-                    'REG_ID' => $reg_id,
114
-                    'DTT_ID' => $dtt_id,
115
-                ),
116
-                'order_by' => array(
117
-                    'CHK_timestamp' => 'DESC',
118
-                ),
119
-            )
120
-        );
121
-        if (! $checkin instanceof EE_Checkin) {
122
-            return $this->sendResponse(
123
-                new WP_Error(
124
-                    'rest_toggle_checkin_error',
125
-                    sprintf(
126
-                        __(
127
-                        // @codingStandardsIgnoreStart
128
-                            'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
129
-                            // @codingStandardsIgnoreEnd
130
-                            'event_espresso'
131
-                        ),
132
-                        $reg_id,
133
-                        $dtt_id
134
-                    )
135
-                )
136
-            );
137
-        }
138
-        $get_request = new WP_REST_Request(
139
-            'GET',
140
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
141
-        );
142
-        $get_request->set_url_params(
143
-            array(
144
-                'id' => $checkin->ID(),
145
-            )
146
-        );
147
-        return Read::handleRequestGetOne($get_request, $version, 'Checkin');
148
-    }
41
+	/**
42
+	 * Toggles whether the user is checked in or not.
43
+	 *
44
+	 * @param WP_REST_Request $request
45
+	 * @param string          $version
46
+	 * @return WP_Error|WP_REST_Response
47
+	 */
48
+	protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
49
+	{
50
+		$reg_id = $request->get_param('REG_ID');
51
+		$dtt_id = $request->get_param('DTT_ID');
52
+		$force = $request->get_param('force');
53
+		if ($force == 'true') {
54
+			$force = true;
55
+		} else {
56
+			$force = false;
57
+		}
58
+		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
59
+		if (! $reg instanceof EE_Registration) {
60
+			return $this->sendResponse(
61
+				new WP_Error(
62
+					'rest_registration_toggle_checkin_invalid_id',
63
+					sprintf(
64
+						__(
65
+							'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
66
+							'event_espresso'
67
+						),
68
+						$reg_id
69
+					),
70
+					array('status' => 422)
71
+				)
72
+			);
73
+		}
74
+		if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
75
+			return $this->sendResponse(
76
+				new WP_Error(
77
+					'rest_user_cannot_toggle_checkin',
78
+					sprintf(
79
+						__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
80
+						$reg_id
81
+					),
82
+					array('status' => 403)
83
+				)
84
+			);
85
+		}
86
+		$success = $reg->toggle_checkin_status($dtt_id, ! $force);
87
+		if ($success === false) {
88
+			// check if we know they can't check in because they're not approved and we aren't forcing
89
+			if (! $reg->is_approved() && ! $force) {
90
+				// rely on EE_Error::add_error messages to have been added to give more data about why it failed
91
+				return $this->sendResponse(
92
+					new WP_Error(
93
+						'rest_toggle_checkin_failed',
94
+						__(
95
+						// @codingStandardsIgnoreStart
96
+							'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
97
+							// @codingStandardsIgnoreEnd
98
+							'event_espresso'
99
+						)
100
+					)
101
+				);
102
+			}
103
+			return $this->sendResponse(
104
+				new WP_Error(
105
+					'rest_toggle_checkin_failed_not_forceable',
106
+					__('Registration checkin failed. Please see additional error data.', 'event_espresso')
107
+				)
108
+			);
109
+		}
110
+		$checkin = EEM_Checkin::instance()->get_one(
111
+			array(
112
+				array(
113
+					'REG_ID' => $reg_id,
114
+					'DTT_ID' => $dtt_id,
115
+				),
116
+				'order_by' => array(
117
+					'CHK_timestamp' => 'DESC',
118
+				),
119
+			)
120
+		);
121
+		if (! $checkin instanceof EE_Checkin) {
122
+			return $this->sendResponse(
123
+				new WP_Error(
124
+					'rest_toggle_checkin_error',
125
+					sprintf(
126
+						__(
127
+						// @codingStandardsIgnoreStart
128
+							'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
129
+							// @codingStandardsIgnoreEnd
130
+							'event_espresso'
131
+						),
132
+						$reg_id,
133
+						$dtt_id
134
+					)
135
+				)
136
+			);
137
+		}
138
+		$get_request = new WP_REST_Request(
139
+			'GET',
140
+			'/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
141
+		);
142
+		$get_request->set_url_params(
143
+			array(
144
+				'id' => $checkin->ID(),
145
+			)
146
+		);
147
+		return Read::handleRequestGetOne($get_request, $version, 'Checkin');
148
+	}
149 149
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             $force = false;
57 57
         }
58 58
         $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
59
-        if (! $reg instanceof EE_Registration) {
59
+        if ( ! $reg instanceof EE_Registration) {
60 60
             return $this->sendResponse(
61 61
                 new WP_Error(
62 62
                     'rest_registration_toggle_checkin_invalid_id',
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
                 )
72 72
             );
73 73
         }
74
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
74
+        if ( ! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
75 75
             return $this->sendResponse(
76 76
                 new WP_Error(
77 77
                     'rest_user_cannot_toggle_checkin',
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         $success = $reg->toggle_checkin_status($dtt_id, ! $force);
87 87
         if ($success === false) {
88 88
             // check if we know they can't check in because they're not approved and we aren't forcing
89
-            if (! $reg->is_approved() && ! $force) {
89
+            if ( ! $reg->is_approved() && ! $force) {
90 90
                 // rely on EE_Error::add_error messages to have been added to give more data about why it failed
91 91
                 return $this->sendResponse(
92 92
                     new WP_Error(
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                 ),
119 119
             )
120 120
         );
121
-        if (! $checkin instanceof EE_Checkin) {
121
+        if ( ! $checkin instanceof EE_Checkin) {
122 122
             return $this->sendResponse(
123 123
                 new WP_Error(
124 124
                     'rest_toggle_checkin_error',
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         }
138 138
         $get_request = new WP_REST_Request(
139 139
             'GET',
140
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
140
+            '/'.EED_Core_Rest_Api::ee_api_namespace.'v'.$version.'/checkins/'.$checkin->ID()
141 141
         );
142 142
         $get_request->set_url_params(
143 143
             array(
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandlerFile.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function __construct(\EEHI_File $file_helper = null)
34 34
     {
35
-        if (! $file_helper) {
35
+        if ( ! $file_helper) {
36 36
             $this->_file_helper = new \EEH_File();
37 37
         }
38 38
     }
@@ -53,28 +53,28 @@  discard block
 block discarded – undo
53 53
         try {
54 54
             $base_folder = $this->get_base_folder();
55 55
             $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
56
-                $base_folder . JobHandlerFile::temp_folder_name
56
+                $base_folder.JobHandlerFile::temp_folder_name
57 57
             );
58 58
             if ($success) {
59 59
                 $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
60
-                    $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id
60
+                    $base_folder.JobHandlerFile::temp_folder_name.DS.$job_id
61 61
                 );
62 62
             }
63 63
             if ($success) {
64
-                $filepath = $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . $filename;
64
+                $filepath = $base_folder.JobHandlerFile::temp_folder_name.DS.$job_id.DS.$filename;
65 65
                 $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
66 66
             }
67 67
             // let's add the .htaccess file so safari will open the file properly
68 68
             if ($success) {
69 69
                 $extension = \EEH_File::get_file_extension($filepath);
70 70
                 \EEH_File::write_to_file(
71
-                    $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . '.htaccess',
72
-                    'AddType ' . $filetype . ' ' . $extension,
71
+                    $base_folder.JobHandlerFile::temp_folder_name.DS.$job_id.DS.'.htaccess',
72
+                    'AddType '.$filetype.' '.$extension,
73 73
                     '.htaccess'
74 74
                 );
75 75
             }
76 76
             // those methods normally fail with an exception, but if not, let's do it
77
-            if (! $success) {
77
+            if ( ! $success) {
78 78
                 throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso'));
79 79
             }
80 80
         } catch (\EE_Error $e) {
Please login to merge, or discard this patch.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -16,111 +16,111 @@
 block discarded – undo
16 16
  */
17 17
 abstract class JobHandlerFile extends JobHandler
18 18
 {
19
-    // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
20
-    const temp_folder_name = 'batch_temp_folder';
19
+	// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
20
+	const temp_folder_name = 'batch_temp_folder';
21 21
 
22
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
23
-    /**
24
-     * @var \EEHI_File
25
-     */
26
-    protected $_file_helper = null;
22
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
23
+	/**
24
+	 * @var \EEHI_File
25
+	 */
26
+	protected $_file_helper = null;
27 27
 
28 28
 
29
-    /**
30
-     * JobHandlerFile constructor.
31
-     *
32
-     * @param \EEHI_File|null $file_helper
33
-     */
34
-    public function __construct(\EEHI_File $file_helper = null)
35
-    {
36
-        if (! $file_helper) {
37
-            $this->_file_helper = new \EEH_File();
38
-        }
39
-    }
29
+	/**
30
+	 * JobHandlerFile constructor.
31
+	 *
32
+	 * @param \EEHI_File|null $file_helper
33
+	 */
34
+	public function __construct(\EEHI_File $file_helper = null)
35
+	{
36
+		if (! $file_helper) {
37
+			$this->_file_helper = new \EEH_File();
38
+		}
39
+	}
40 40
 
41
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
42
-    /**
43
-     * Creates a file
44
-     *
45
-     * @param string $job_id
46
-     * @param string $filename
47
-     * @param string $filetype
48
-     * @return string
49
-     * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException
50
-     */
51
-    public function create_file_from_job_with_name($job_id, $filename, $filetype = 'application/ms-excel')
52
-    {
53
-        $filepath = '';
54
-        try {
55
-            $base_folder = $this->get_base_folder();
56
-            $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
57
-                $base_folder . JobHandlerFile::temp_folder_name
58
-            );
59
-            if ($success) {
60
-                $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
61
-                    $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id
62
-                );
63
-            }
64
-            if ($success) {
65
-                $filepath = $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . $filename;
66
-                $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
67
-            }
68
-            // let's add the .htaccess file so safari will open the file properly
69
-            if ($success) {
70
-                $extension = \EEH_File::get_file_extension($filepath);
71
-                \EEH_File::write_to_file(
72
-                    $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . '.htaccess',
73
-                    'AddType ' . $filetype . ' ' . $extension,
74
-                    '.htaccess'
75
-                );
76
-            }
77
-            // those methods normally fail with an exception, but if not, let's do it
78
-            if (! $success) {
79
-                throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso'));
80
-            }
81
-        } catch (\EE_Error $e) {
82
-            throw new BatchRequestException(
83
-                sprintf(
84
-                    __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
85
-                    $job_id,
86
-                    $e->getMessage()
87
-                ),
88
-                500,
89
-                $e
90
-            );
91
-        }
92
-        return $filepath;
93
-    }
41
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
42
+	/**
43
+	 * Creates a file
44
+	 *
45
+	 * @param string $job_id
46
+	 * @param string $filename
47
+	 * @param string $filetype
48
+	 * @return string
49
+	 * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException
50
+	 */
51
+	public function create_file_from_job_with_name($job_id, $filename, $filetype = 'application/ms-excel')
52
+	{
53
+		$filepath = '';
54
+		try {
55
+			$base_folder = $this->get_base_folder();
56
+			$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
57
+				$base_folder . JobHandlerFile::temp_folder_name
58
+			);
59
+			if ($success) {
60
+				$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
61
+					$base_folder . JobHandlerFile::temp_folder_name . DS . $job_id
62
+				);
63
+			}
64
+			if ($success) {
65
+				$filepath = $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . $filename;
66
+				$success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
67
+			}
68
+			// let's add the .htaccess file so safari will open the file properly
69
+			if ($success) {
70
+				$extension = \EEH_File::get_file_extension($filepath);
71
+				\EEH_File::write_to_file(
72
+					$base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . '.htaccess',
73
+					'AddType ' . $filetype . ' ' . $extension,
74
+					'.htaccess'
75
+				);
76
+			}
77
+			// those methods normally fail with an exception, but if not, let's do it
78
+			if (! $success) {
79
+				throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso'));
80
+			}
81
+		} catch (\EE_Error $e) {
82
+			throw new BatchRequestException(
83
+				sprintf(
84
+					__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
85
+					$job_id,
86
+					$e->getMessage()
87
+				),
88
+				500,
89
+				$e
90
+			);
91
+		}
92
+		return $filepath;
93
+	}
94 94
 
95
-    /**
96
-     * Gets the URL to download the file
97
-     *
98
-     * @param string $filepath
99
-     * @return string url to file
100
-     */
101
-    public function get_url_to_file($filepath)
102
-    {
103
-        return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath);
104
-    }
95
+	/**
96
+	 * Gets the URL to download the file
97
+	 *
98
+	 * @param string $filepath
99
+	 * @return string url to file
100
+	 */
101
+	public function get_url_to_file($filepath)
102
+	{
103
+		return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath);
104
+	}
105 105
 
106
-    /**
107
-     * Gets the folder which will contain the "batch_temp_folder"
108
-     *
109
-     * @return string
110
-     */
111
-    public function get_base_folder()
112
-    {
113
-        return apply_filters(
114
-            'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder',
115
-            EVENT_ESPRESSO_UPLOAD_DIR
116
-        );
117
-    }
106
+	/**
107
+	 * Gets the folder which will contain the "batch_temp_folder"
108
+	 *
109
+	 * @return string
110
+	 */
111
+	public function get_base_folder()
112
+	{
113
+		return apply_filters(
114
+			'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder',
115
+			EVENT_ESPRESSO_UPLOAD_DIR
116
+		);
117
+	}
118 118
 
119
-    public function get_base_url()
120
-    {
121
-        return apply_filters(
122
-            'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url',
123
-            EVENT_ESPRESSO_UPLOAD_URL
124
-        );
125
-    }
119
+	public function get_base_url()
120
+	{
121
+		return apply_filters(
122
+			'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url',
123
+			EVENT_ESPRESSO_UPLOAD_URL
124
+		);
125
+	}
126 126
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandler.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,5 +13,5 @@
 block discarded – undo
13 13
  */
14 14
 abstract class JobHandler implements JobHandlerInterface
15 15
 {
16
-    // so far no common methods or properties
16
+	// so far no common methods or properties
17 17
 }
Please login to merge, or discard this patch.