Commit 860a9c59 authored by John Punzalan's avatar John Punzalan

Add Ability in Entity

parent 4469d04b
......@@ -55,6 +55,7 @@ class Esi_Management_Entity_Form {
$total_raised = isset( $_POST['total-raised'] ) ? (int)sanitize_text_field( $_POST['total-raised'] ) : '';
$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'] ) : '';
if ($is_investor == "on") {
$is_investor = 1;
......@@ -113,6 +114,7 @@ class Esi_Management_Entity_Form {
}
esi_save_list_entity_technology($fields['id'], $technology_ids);
esi_save_list_entity_ability($fields['id'], $ability_ids);
if($is_ajax){
return $fields;
......
......@@ -298,4 +298,55 @@ function esi_save_list_entity_technology( $entityid = 0, $technologyids = array(
'entity_id' => intval($entityid)
));
}
}
/**
* Fetch technologies array
*
* @param int $entity_id
* @param array $ability_ids
*
* @return array
*/
function esi_save_list_entity_ability( $entity_id = 0, $ability_ids = array() ) {
global $wpdb;
// Delete all current join from liaison table
$wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'esi_ability_entity WHERE entity_id = %d', $entityid));
// Insert new news_id ability_id relation
foreach ($ability_ids as $ability_id) {
$wpdb->insert(
$wpdb->prefix . "esi_ability_entity",
array(
'ability_id' => $ability_id,
'entity_id' => intval($entity_id)
));
}
}
/**
* Fetch technologies array
*
* @param int $id
*
* @return array
*/
function esi_get_list_selected_entity_ability( $id = 0, $output = 'object' ) {
global $wpdb;
// Get Selected technology mapping
$arrSelectedTechnology = $wpdb->get_results("SELECT * FROM " .$wpdb->prefix . "esi_ability_entity WHERE entity_id = " . $id, OBJECT_K);
if ($output == 'array') {
$array = array();
foreach ($arrSelectedTechnology as $selected) {
$array [] = $selected->ability_id;
}
$arrSelectedTechnology = $array;
}
return $arrSelectedTechnology;
}
\ No newline at end of file
......@@ -22,6 +22,8 @@ $technologies = esi_get_all_list_technology();
$technologies_selected = esi_get_list_selected_entity_technology($id, 'array');
$investment_type = esi_get_all_investment_type(array('number' => 10000));
$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');
add_thickbox();
?>
......@@ -200,6 +202,18 @@ add_thickbox();
</select><br />
</td>
</tr>
<tr class="row-ability-id">
<th scope="row">
<label for="ability_id"><?php _e( 'Ability', 'esi' ); ?></label>
</th>
<td>
<select id="ability_id" class="chosen-select" name="ability_id[]" multiple="multiple">
<?php foreach ($abilities as $ability) : ?>
<option value="<?= $ability->id ?>" <?= (in_array($ability->id, $abilities_selected)) ? "selected='selected'" : ""?>><?= $ability->name ?></option>
<?php endforeach; ?>
</select><br />
</td>
</tr>
</tbody>
</table>
......
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