Commit 6a0fa12f authored by John Punzalan's avatar John Punzalan

Update news form

parent c018e35d
......@@ -215,7 +215,7 @@ class Esi_Management_Admin {
add_submenu_page( $this->plugin_name, __( 'Media', 'esi' ), __( 'Media', 'esi' ), 'manage_options', 'esi-management-media', array( $plugin_admin_media, 'plugin_page' ) );
$plugin_admin_company = new Esi_Management_Entity( $this->plugin_name, $this->version );
add_submenu_page( $this->plugin_name, __( 'entity', 'esi' ), __( 'entity', 'esi' ), 'manage_options', 'esi-management-entity', array( $plugin_admin_company, 'plugin_page' ) );
add_submenu_page( $this->plugin_name, __( 'Entity', 'esi' ), __( 'Entity', 'esi' ), 'manage_options', 'esi-management-entity', array( $plugin_admin_company, 'plugin_page' ) );
$plugin_admin_investment = new Esi_Management_Investment( $this->plugin_name, $this->version );
add_submenu_page( $this->plugin_name, __( 'Investment', 'esi' ), __( 'Investment', 'esi' ), 'manage_options', 'esi-management-investment', array( $plugin_admin_investment, 'plugin_page' ) );
......
......@@ -35,7 +35,7 @@ class Esi_Management_News_Form {
}
$errors = array();
$page_url = admin_url( 'admin.php?page=esi-management-news&action=new' );
$page_url = admin_url( 'admin.php?page=esi-management-news' );
$field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
$title = isset( $_POST['title'] ) ? sanitize_text_field( $_POST['title'] ) : '';
......@@ -51,6 +51,7 @@ class Esi_Management_News_Form {
$industry_id = isset( $_POST['radar_industry'] ) ? $_POST['radar_industry'] : array();
$function_id = isset( $_POST['radar_function'] ) ? $_POST['radar_function'] : array();
$technology_ids = isset( $_POST['technology_sub_id'] ) ? $_POST['technology_sub_id'] : array();
$post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : '';
......@@ -118,6 +119,7 @@ class Esi_Management_News_Form {
'region_id' => $region_id,
'industry_id' => $industry_id,
'function_id' => $function_id,
'technology_ids' => $technology_ids,
'post_id' => $post_id
);
......@@ -128,6 +130,8 @@ class Esi_Management_News_Form {
$fields['id'] = $field_id;
$insert_id = esi_insert_new( $fields );
}
if ( is_wp_error( $insert_id ) ) {
$redirect_to = add_query_arg( array( 'message' => 'error' ), $page_url );
......
......@@ -103,6 +103,8 @@ function esi_insert_new( $args = array() ) {
unset( $args['industry_id'] );
$function_id = $args['function_id'];
unset( $args['function_id'] );
$technology_ids = $args['technology_ids'];
unset( $args['technology_ids'] );
$radar_industry_id = esi_get_radar_by_industry($industry_id);
$radar_function_id = esi_get_radar_by_function($function_id);
......@@ -122,6 +124,7 @@ function esi_insert_new( $args = array() ) {
esi_save_news_radar($row_id, $radar_id);
esi_save_news_industry($row_id, $industry_id);
esi_save_news_function($row_id, $function_id);
esi_save_list_technology_news($row_id, $technology_ids);
return $row_id;
}
......@@ -130,6 +133,7 @@ function esi_insert_new( $args = array() ) {
esi_save_news_radar($row_id, $radar_id);
esi_save_news_industry($row_id, $industry_id);
esi_save_news_function($row_id, $function_id);
esi_save_list_technology_news($row_id, $technology_ids);
// do update method here
if ( $wpdb->update( $table_name, $args, array( 'id' => $row_id ) ) ) {
......@@ -306,3 +310,34 @@ function esi_get_list_technology( $id = 0 ) {
return $arrSelectedTechnology;
}
function esi_save_list_technology_news ( $newsid = 0, $technologyids = array() ) {
global $wpdb;
// Delete all current join from liaison table
$wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'esi_technology_news WHERE news_id = %d', $newsid));
// Insert new news_id technology_id relation
foreach ($technologyids as $technology_id) {
$wpdb->insert(
$wpdb->prefix . "esi_technology_news",
array(
'technology_id' => $technology_id,
'news_id' => intval($newsid)
));
}
}
function esi_get_list_technology_news ( $newsid = 0 ) {
global $wpdb;
$query = $wpdb->get_results("
SELECT id, name
FROM " . $wpdb->prefix . "esi_technology
INNER JOIN " . $wpdb->prefix . "esi_technology_news
ON " . $wpdb->prefix . "esi_technology.id = " . $wpdb->prefix . "esi_technology_news.technology_id
WHERE news_id = " . $newsid . "
");
return $query;
}
......@@ -43,6 +43,7 @@ $investorArray = esi_get_investor_array($item->investment_id);
$industries = array();
$functions = array();
$radars_news = array();
$selectedTechnologies = array();
$radars_news[] = esi_get_radar_by_news($id);
if ($radars_news) {
......@@ -55,6 +56,7 @@ $industry_news[] = esi_get_industry_by_news($id);
$function_news[] = esi_get_function_by_news($id);
$technologies = esi_get_list_technology();
$selectedTechnologies = esi_get_list_technology_news($id);
add_thickbox();
?>
......@@ -134,7 +136,7 @@ add_thickbox();
</tr>
<tr class="row-entity-id">
<th scope="row">
<label for="entity_id"><?php _e( 'entity', 'esi' ); ?></label>
<label for="entity_id"><?php _e( 'Entity', 'esi' ); ?></label>
</th>
<td>
<select id="entity_id" name="entity_id" style="float:left">
......@@ -208,6 +210,9 @@ add_thickbox();
</th>
<td>
<select id="technology_sub_id" name="technology_sub_id[]" class="join_sub_data_select" multiple="multiple">
<?php foreach ($selectedTechnologies as $activetechnology): ?>
<option value='<?= $activetechnology->id ?>' selected><?= $activetechnology->name ?></option>
<?endforeach;?>
</select><br />
</td>
</tr>
......@@ -252,7 +257,11 @@ add_thickbox();
<input type="hidden" name="post_id" value="<?php echo ($item)?$item->post_id:''; ?>">
<?php wp_nonce_field( '' ); ?>
<?php submit_button( __( 'Add new', 'esi' ), 'primary', 'submit new' ); ?>
<?php if ($_GET['action'] == 'edit'): ?>
<?php submit_button( __( 'Update News', 'esi' ), 'primary', 'submit new' ); ?>
<?php else: ?>
<?php submit_button( __( 'Add News', 'esi' ), 'primary', 'submit new' ); ?>
<?php endif; ?>
</form>
</div>
......
......@@ -218,6 +218,7 @@ class Esi_Management {
$this->loader->add_action( 'wp_ajax_esi_radar_ajax_action', $plugin_admin, 'esi_radar_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_industries_ajax_action', $plugin_admin, 'esi_industries_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_technologies_ajax_action', $plugin_admin, 'esi_technologies_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_technologies_ajax_action', $plugin_admin, 'esi_technologies_ajax_callback' );
// Add radars field to user form
// $this->loader->add_action('show_user_profile', $plugin_admin, 'esi_custom_user_profile_fields');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment