| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package WPDataProjects\Project |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPDataProjects\Project { |
| 10 |
|
| 11 |
use WPDataProjects\Parent_Child\WPDP_Parent_Form; |
| 12 |
use WPDataAccess\WPDA; |
| 13 |
|
| 14 |
/** |
| 15 |
* Class WPDP_Project_Project_Form extends WPDP_Parent_Form |
| 16 |
* |
| 17 |
* @see WPDP_Parent_Form |
| 18 |
* |
| 19 |
* @author Peter Schulz |
| 20 |
* @since 2.0.0 |
| 21 |
*/ |
| 22 |
class WPDP_Project_Project_Form extends WPDP_Parent_Form { |
| 23 |
|
| 24 |
/** |
| 25 |
* WPDP_Project_Project_Form constructor |
| 26 |
* |
| 27 |
* @param $schema_name |
| 28 |
* @param $table_name |
| 29 |
* @param $wpda_list_columns |
| 30 |
* @param array $args |
| 31 |
* @param array $relationship |
| 32 |
*/ |
| 33 |
public function __construct( $schema_name, $table_name, $wpda_list_columns, array $args = array(), array $relationship = array() ) { |
| 34 |
// Add column labels. |
| 35 |
$args['column_headers'] = array( |
| 36 |
'project_id' => __( 'Project ID', 'wp-data-access' ), |
| 37 |
'project_name' => __( 'Project Name', 'wp-data-access' ), |
| 38 |
'project_description' => __( 'Project Description', 'wp-data-access' ), |
| 39 |
'add_to_menu' => __( 'Add To Menu', 'wp-data-access' ), |
| 40 |
'menu_name' => __( 'Menu Name', 'wp-data-access' ), |
| 41 |
'project_sequence' => __( 'Seq#', 'wp-data-access' ), |
| 42 |
); |
| 43 |
|
| 44 |
$args['edit_form_class'] = 'WPDataProjects\\Project\\WPDP_Project_Page_Form'; |
| 45 |
|
| 46 |
if ( isset( $args['mode'] ) ) { |
| 47 |
$mode = $args['mode']; |
| 48 |
} else { |
| 49 |
wp_die( __( 'ERROR: Wrong arguments [missing mode]', 'wp-data-access' ) ); |
| 50 |
} |
| 51 |
|
| 52 |
if ( 'view' === $mode ) { |
| 53 |
$args['list_form_class'] = 'WPDataProjects\\Project\\WPDP_Project_Page_List_View'; |
| 54 |
} else { |
| 55 |
$args['list_form_class'] = 'WPDataProjects\\Project\\WPDP_Project_Page_List'; |
| 56 |
} |
| 57 |
|
| 58 |
parent::__construct( $schema_name, $table_name, $wpda_list_columns, $args, $relationship ); |
| 59 |
|
| 60 |
$this->title = 'Project'; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Overwrites method show to add debug info |
| 65 |
* |
| 66 |
* This debug info can be helpful in case of project page structure errors |
| 67 |
* |
| 68 |
* @param bool $allow_save |
| 69 |
* @param string $add_param |
| 70 |
*/ |
| 71 |
public function show( $allow_save = true, $add_param = '' ) { |
| 72 |
if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) && isset( $_REQUEST['project_id'] ) ) { |
| 73 |
$project_id = sanitize_text_field( wp_unslash( $_REQUEST['project_id'] ) ); // input var okay. |
| 74 |
global $wpdb; |
| 75 |
$project_page_table_name = $wpdb->prefix . 'wpda_project_page'; |
| 76 |
$pages = $wpdb->get_results( |
| 77 |
$wpdb->prepare( |
| 78 |
" select * from `%1s` where project_id = %d and add_to_menu = 'Yes' order by page_sequence", // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders |
| 79 |
array( |
| 80 |
WPDA::remove_backticks( $project_page_table_name ), |
| 81 |
$project_id, |
| 82 |
) |
| 83 |
), |
| 84 |
'ARRAY_A' |
| 85 |
); // phpcs:ignore Standard.Category.SniffName.ErrorCode |
| 86 |
|
| 87 |
$project_info = ''; |
| 88 |
$first_page = true; |
| 89 |
foreach ( $pages as $page ) { |
| 90 |
$wpdp = new WPDP_Project( $project_id, $page['page_id'] ); |
| 91 |
if ( null === $wpdp->get_project() ) { |
| 92 |
wp_die( __( 'Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' ) ); |
| 93 |
} |
| 94 |
if ( ! $first_page ) { |
| 95 |
$project_info .= '<br/><br/>'; |
| 96 |
} |
| 97 |
$project_info .= "Project $project_id, page {$page['page_id']}:<br/>"; |
| 98 |
$project_info .= json_encode( $wpdp->get_project() ); |
| 99 |
$first_page = false; |
| 100 |
} |
| 101 |
?> |
| 102 |
<style> |
| 103 |
#overlay_project { |
| 104 |
height: 400px; |
| 105 |
width: 600px; |
| 106 |
position: fixed; |
| 107 |
display: none; |
| 108 |
top: 50%; |
| 109 |
left: 50%; |
| 110 |
transform: translate(-50%, -50%); |
| 111 |
-ms-transform: translate(-50%, -50%); |
| 112 |
right: 0; |
| 113 |
bottom: 0; |
| 114 |
background-color: #f9f9f9; |
| 115 |
opacity: .95; |
| 116 |
border: 1px solid #ccc; |
| 117 |
cursor: pointer; |
| 118 |
z-index: 1000; |
| 119 |
} |
| 120 |
|
| 121 |
#overlay_project_text { |
| 122 |
height: 360px; |
| 123 |
width: 400px; |
| 124 |
padding: 10px; |
| 125 |
position: relative; |
| 126 |
top: 50%; |
| 127 |
left: 235px; |
| 128 |
transform: translate(-50%, -50%); |
| 129 |
-ms-transform: translate(-50%, -50%); |
| 130 |
color: black; |
| 131 |
overflow-y: auto; |
| 132 |
background-color: white; |
| 133 |
border: 1px solid #ccc; |
| 134 |
} |
| 135 |
</style> |
| 136 |
<div id="overlay_project"> |
| 137 |
<div id="overlay_project_text"> |
| 138 |
<?php echo $project_info; // phpcs:ignore WordPress.Security.EscapeOutput ?> |
| 139 |
</div> |
| 140 |
<div style="position: absolute; bottom: 0; right: 0; padding-right: 5px; padding-bottom: 10px;"> |
| 141 |
<a id="button-copy-clipboard" href="javascript:void(0)" class="button button-secondary" |
| 142 |
style="text-align:center;width:145px;" |
| 143 |
data-clipboard-text="<?php echo str_replace( '<br/>', "\n", str_replace( '"', '"', $project_info ) ); // phpcs:ignore WordPress.Security.EscapeOutput ?>"> |
| 144 |
<span class="material-icons wpda_icon_on_button">content_copy</span> |
| 145 |
<?php echo __( 'Copy to clipboard', 'wp-data-access' ); ?> |
| 146 |
</a> |
| 147 |
<br/> |
| 148 |
<div style="height: 5px;"></div> |
| 149 |
<a href="javascript:void(0)" class="button button-primary" |
| 150 |
style="text-align:center;width:145px;" |
| 151 |
onclick="jQuery('#overlay_project').hide()"> |
| 152 |
<span class="material-icons wpda_icon_on_button">cancel</span> |
| 153 |
<?php echo __( 'Close', 'wp-data-access' ); ?> |
| 154 |
</a> |
| 155 |
</div> |
| 156 |
</div> |
| 157 |
<div style="float:right;text-align:right;"> |
| 158 |
<a href="javascript:void(0);" onclick="jQuery('#overlay_project').show()" class="button">DEBUG</a> |
| 159 |
</div> |
| 160 |
<script type='text/javascript'> |
| 161 |
jQuery(function () { |
| 162 |
var sql_to_clipboard = new ClipboardJS('#button-copy-clipboard'); |
| 163 |
sql_to_clipboard.on('success', function (e) { |
| 164 |
jQuery.notify('<?php echo __( 'Info copied to clipboard!', 'wp-data-access' ); ?>','info'); |
| 165 |
}); |
| 166 |
sql_to_clipboard.on('error', function (e) { |
| 167 |
jQuery.notify('<?php echo __( 'Could not copy info to clipboard!', 'wp-data-access' ); ?>','error'); |
| 168 |
}); |
| 169 |
}); |
| 170 |
</script> |
| 171 |
<?php |
| 172 |
} |
| 173 |
|
| 174 |
parent::show( $allow_save, $add_param ); |
| 175 |
|
| 176 |
if ( 'new' !== $this->action_posted || $this->child_request ) { |
| 177 |
?> |
| 178 |
<script type='text/javascript'> |
| 179 |
jQuery(function () { |
| 180 |
jQuery('#show_more_less_button').show(); |
| 181 |
}); |
| 182 |
</script> |
| 183 |
<?php |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Overwrite method |
| 189 |
* |
| 190 |
* @param bool $set_back_form_values |
| 191 |
*/ |
| 192 |
public function prepare_items( $set_back_form_values = false ) { |
| 193 |
parent::prepare_items( $set_back_form_values ); |
| 194 |
|
| 195 |
$column_index = $this->get_item_index( 'project_description' ); |
| 196 |
$this->form_items[ $column_index ]->set_item_class( 'row-show-less-more' ); |
| 197 |
|
| 198 |
$column_index = $this->get_item_index( 'project_sequence' ); |
| 199 |
$this->form_items[ $column_index ]->set_item_class( 'row-show-less-more' ); |
| 200 |
} |
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
|