| 1 |
<?php |
| 2 |
|
| 3 |
class Qcformbuilder_Forms_API_Response_Factory { |
| 4 |
|
| 5 |
/** |
| 6 |
* Form not found error response |
| 7 |
* |
| 8 |
* @since unknown |
| 9 |
* |
| 10 |
* @return Qcformbuilder_Forms_API_Error |
| 11 |
*/ |
| 12 |
public static function error_form_not_found(){ |
| 13 |
return new Qcformbuilder_Forms_API_Error( 'form-not-found', __( 'Form not found', 'qcformbuilder-forms' ) ); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Form not created error response |
| 18 |
* |
| 19 |
* @since 1.8.0 |
| 20 |
* |
| 21 |
* @return Qcformbuilder_Forms_API_Error |
| 22 |
*/ |
| 23 |
public static function error_form_not_created(){ |
| 24 |
return new Qcformbuilder_Forms_API_Error( 'form-not-created', __( 'Form not created', 'qcformbuilder-forms' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Entry not found error response |
| 29 |
* |
| 30 |
* @since unknown |
| 31 |
* |
| 32 |
* @return Qcformbuilder_Forms_API_Error |
| 33 |
*/ |
| 34 |
public static function error_entry_not_found(){ |
| 35 |
return new Qcformbuilder_Forms_API_Error( 'form-entry-not-found', __( 'Form entry not found', 'qcformbuilder-forms' ) ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Entry data response |
| 40 |
* |
| 41 |
* @since unknown |
| 42 |
* |
| 43 |
* @param $data |
| 44 |
* @param null $total |
| 45 |
* @param bool $total_pages |
| 46 |
* @return Qcformbuilder_Forms_API_Response |
| 47 |
*/ |
| 48 |
public static function entry_data($data, $total = null, $total_pages = false ){ |
| 49 |
if( null === $total ){ |
| 50 |
$total = count( $data ); |
| 51 |
} |
| 52 |
|
| 53 |
$response = new Qcformbuilder_Forms_API_Response( $data, 200, array() ); |
| 54 |
$response->set_total_header( $total ); |
| 55 |
if ( is_numeric( $total_pages ) ) { |
| 56 |
$response->set_total_pages_header( $total_pages ); |
| 57 |
} |
| 58 |
|
| 59 |
return $response; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* Response for general settings |
| 65 |
* |
| 66 |
* @since 1.7.3 |
| 67 |
* |
| 68 |
* @param array $style_includes Style includes settings |
| 69 |
* @param bool $cdn_enable Is CDN enabled? |
| 70 |
* @param int $status Optional. Status code. Default is 200 |
| 71 |
* @return Qcformbuilder_Forms_API_Response |
| 72 |
*/ |
| 73 |
public static function general_settings_response($style_includes, $cdn_enable, $status = 200 ) |
| 74 |
{ |
| 75 |
|
| 76 |
return new Qcformbuilder_Forms_API_Response( [ |
| 77 |
'styleIncludes' => $style_includes, |
| 78 |
'cdnEnable' => $cdn_enable |
| 79 |
], $status, array() ); |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
} |