WIP: Near to finish

This commit is contained in:
Jose Gonzalez 2020-03-30 19:03:55 +02:00
parent fa372656f4
commit c2d81238d6

View File

@ -131,11 +131,14 @@ class ModuleTemplates extends HTML
$this->id_np = get_parameter('id_np', -1);
$this->name = get_parameter('name', '');
$this->description = get_parameter('description', '');
$this->pen = get_parameter('pen', '');
$pensList = get_parameter('pen', []);
// Separate all PENs received.
$this->pen = explode(',', $pensList);
$this->offset = get_parameter('offset', 0);
$this->ajaxController = $ajax_controller;
$this->ncGroup = get_parameter('ncgroup', -1);
$this->ncFilter = get_parameter('ncfilter', '');
return $this;
}
@ -205,19 +208,15 @@ class ModuleTemplates extends HTML
/**
* Undocumented function
* Save or Update the data received.
*
* @return void
*/
public function processData()
{
// This data is sent always
$name = get_parameter('name', '');
$description = get_parameter('description', '');
$pensList = get_parameter('pen', '');
// Get action if is needed.
$action = get_parameter('submit_button', '');
// Evaluate the modules allowed
// Evaluate the modules allowed.
if (!empty($action)) {
$numberComponent = [];
foreach ($_POST as $k => $value) {
@ -232,48 +231,51 @@ class ModuleTemplates extends HTML
$dbResult_tnp = db_process_sql_update(
'tnetwork_profile',
[
'name' => $name,
'description' => $description,
'name' => $this->name,
'description' => $this->description,
],
['id_np' => $this->id_np]
);
$getProfilePens = db_get_all_rows_sql(sprintf('SELECT pen FROM tpen WHERE id_np = %s', $this->id_np));
$dbResult_pen = db_process_sql_update(
'tpen',
// The update gone fine!
if ($dbResult_tnp != false) {
// Clean the PENs associated with this id_np.
db_process_sql_delete('tnetwork_profile_pen', ['id_np' => $this->id_np]);
// Set again the new PENs associated.
foreach ($this->pen as $currentPen) {
$dbResult_pen = db_process_sql_insert(
'tnetwork_profile_pen',
[
'pen' => $pen,
'manufacturer' => '',
'description' => '',
'pen' => $currentPen,
'id_np' => $this->id_np,
],
['id_np' => $this->id_np]
]
);
}
}
break;
case 'Create':
$dbResult_tnp = db_process_sql_insert(
'tnetwork_profile',
[
'name' => $name,
'description' => $description,
'name' => $this->name,
'description' => $this->description,
]
);
// The insert gone fine!
if ($dbResult_tnp != false) {
foreach ($pensList as $currentPen) {
// Set the new id_np.
$this->id_np = $dbResult_tnp;
// Insert all of new PENs associated with this id_np.
foreach ($this->pen as $currentPen) {
hd($currentPen);
$dbResult_pen = db_process_sql_insert(
'tpen',
'tnetwork_profile_pen',
[
'pen' => $currentPen,
'manufacturer' => '',
'description' => '',
'id_np' => $this->id_np,
]
);
// If something is wrong, is better stop.
if ($dbResult_pen === false) {
break;
}
@ -296,6 +298,18 @@ class ModuleTemplates extends HTML
}
/**
* Get the match between this id_np and one pen in db
*
* @param integer $pen
* @return void
*/
private function penMatch($pen)
{
return db_get_num_rows('SELECT * FROM tnetwork_profile_pen WHERE pen = %d AND id_np = %d', $pen, $this->id_np);
}
/**
* Undocumented function
*
@ -303,7 +317,6 @@ class ModuleTemplates extends HTML
*/
public function addingModulesForm()
{
// Get the groups for select input
$result = db_get_all_rows_in_table('tnetwork_component_group', 'name');
if ($result === false) {
@ -326,9 +339,8 @@ class ModuleTemplates extends HTML
$groups_compound[$row['id_sg']] .= $row['name'];
}
# For erase
#$group_filter .= html_print_select($groups_compound, 'ncgroup', $ncgroup, 'javascript:this.form.submit();', __('Group').' - '.__('All'), -1, true, false, true, '" style="width:350px');
// For erase
// $group_filter .= html_print_select($groups_compound, 'ncgroup', $ncgroup, 'javascript:this.form.submit();', __('Group').' - '.__('All'), -1, true, false, true, '" style="width:350px');
// Get the components for show in a list for select
if ($this->ncGroup > 0) {
$sql = sprintf(
@ -533,10 +545,11 @@ class ModuleTemplates extends HTML
private function setNetworkProfile()
{
if ($this->id_np !== 0) {
$output = db_get_row('tnetwork_profile', 'id_np', $this->id_np);
$this->name = $output['name'];
$this->description = $output['description'];
$this->pen = $output['pen'];
$profileInfo = db_get_row('tnetwork_profile', 'id_np', $this->id_np);
$this->name = $profileInfo['name'];
$this->description = $profileInfo['description'];
$penInfo = db_get_all_rows_filter('tnetwork_profile_pen', ['id_np' => $this->id_np]);
$this->pen = $penInfo['pen'];
}
}