Commit 72beaa9b authored by John Punzalan's avatar John Punzalan

Update Entity

parent 3417eb92
......@@ -56,6 +56,8 @@ class Esi_Management_Entity_Form {
$latest_round_type = isset( $_POST['latest-round-type'] ) ? (int)sanitize_text_field( $_POST['latest-round-type'] ) : '';
$technology_ids = isset( $_POST['technology_id'] ) ? ( $_POST['technology_id'] ) : '';
$ability_ids = isset( $_POST['ability_id'] ) ? ( $_POST['ability_id'] ) : '';
$industry_ids = isset( $_POST['industry_id'] ) ? ( $_POST['industry_id'] ) : '';
$industry_sub_ids = isset( $_POST['industry_sub_id'] ) ? ( $_POST['industry_sub_id'] ) : '';
if ($is_investor == "on") {
$is_investor = 1;
......@@ -113,8 +115,11 @@ class Esi_Management_Entity_Form {
$insert_id = esi_insert_entity( $fields );
}
$industry_ids = array_merge($industry_ids, $industry_sub_ids);
esi_save_list_entity_technology($fields['id'], $technology_ids);
esi_save_list_entity_ability($fields['id'], $ability_ids);
esi_save_list_entity_industry($fields['id'], $industry_ids);
if($is_ajax){
return $fields;
......
......@@ -191,32 +191,25 @@ function esi_get_list_industry( $id = 0 ) {
return $arrSelectedIndustry;
}
/**
* Fetch technologies array
* Fetch industry
*
* @param int $id
*
* @return array
*/
function esi_get_list_selected_entity_industry( $id = 0, $output = 'object' ) {
function esi_get_industry( $id = 0 ) {
global $wpdb;
// Get Selected technology mapping
$arrSelectedTechnology = $wpdb->get_results("SELECT * FROM " .$wpdb->prefix . "esi_technology_entity WHERE entity_id = " . $id, OBJECT_K);
if ($output == 'array') {
$array = array();
foreach ($arrSelectedTechnology as $selected) {
$array [] = $selected->technology_id;
}
$arrSelectedTechnology = $array;
}
// Get Selected industry mapping
$item = $wpdb->get_results("SELECT * FROM " .$wpdb->prefix . "esi_industry WHERE id = " . $id . " ORDER BY name ASC");
return $arrSelectedTechnology;
return $item;
}
/**
* Fetch technologies array
*
......@@ -349,4 +342,56 @@ function esi_get_list_selected_entity_ability( $id = 0, $output = 'object' ) {
}
return $arrSelectedTechnology;
}
\ No newline at end of file
}
/**
* Fetch technologies array
*
* @param int $id
*
* @return array
*/
function esi_get_list_selected_entity_industry( $id = 0, $output = 'object' ) {
global $wpdb;
// Get Selected technology mapping
$arrSelectedIndustry = $wpdb->get_results("SELECT * FROM " .$wpdb->prefix . "esi_entity_industry WHERE entity_id = " . $id, ARRAY_A);
if ($output == 'array') {
$array = array();
foreach ($arrSelectedIndustry as $selected) {
$array [] = $selected['industry_id'];
}
$arrSelectedIndustry = $array;
}
return $arrSelectedIndustry;
}
/**
* Save industries array
*
* @param int $entity_id
* @param array $industry_ids
*
* @return array
*/
function esi_save_list_entity_industry( $entity_id = 0, $industry_ids = array()) {
global $wpdb;
// Delete all current join from liaison table
$wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'esi_entity_industry WHERE entity_id = %d', $entity_id));
// Insert new news_id ability_id relation
foreach ($industry_ids as $industry_id) {
$wpdb->insert(
$wpdb->prefix . "esi_entity_industry",
array(
'industry_id' => $industry_id,
'entity_id' => intval($entity_id)
));
}
}
......@@ -25,6 +25,9 @@ $entities = esi_get_all_entity(array('number' => 10000));
$abilities = esi_get_all_ability(array('number' => 10000));
$abilities_selected = esi_get_list_selected_entity_ability($id, 'array');
$industries_selected = esi_get_list_selected_entity_industry($id, 'array');
add_thickbox();
?>
......@@ -177,7 +180,7 @@ add_thickbox();
<select id="industry_id" name="industry_id[]">
<option value="0">Select an industry</option>
<?php foreach ($industries as $industry) : ?>
<option value="<?= $industry->id ?>"><?= $industry->name ?></option>
<option value="<?= $industry->id ?>" <?= (in_array($industry->id, $industries_selected)? 'selected="selected"':'') ?> ><?= $industry->name ?></option>
<?php endforeach; ?>
</select><br />
</td>
......@@ -187,6 +190,10 @@ add_thickbox();
</th>
<td>
<select id="industry_sub_id" name="industry_sub_id[]" multiple="multiple">
<?php foreach ($industries_selected as $industry_selected) : ?>
<?php $current_industry = esi_get_industry($industry_selected);?>
<option value="<?= $industry_selected ?>" selected="selected" > <?= $current_industry[0]->name; ?></option>
<?php endforeach; ?>esi_get_industry
</select><br />
</td>
</tr>
......
......@@ -306,7 +306,7 @@ add_thickbox();
<label for="investor"><?php _e( 'Investor', 'esi' ); ?></label>
</th>
<td>
<select id="investor" name="investor[]" data-placeholder="Choose a entity..." multiple="" class="chosen-select">
<select id="investor" name="investor[]" data-placeholder="Choose a entity..." multiple="" class="chosen-select" required="required" >
<?php foreach ($companies as $entity) : ?>
<option value="<?= $entity->id ?>" <?= (isset($investorArray) && in_array($entity->id, $investorArray))?'selected="selected"':'' ?>><?= $entity->name ?></option>
<?php endforeach; ?>
......
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