From 6d2c4b1b76708ea7423de10609d6d306a3385e67 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 3 Aug 2023 04:37:25 +0000 Subject: [PATCH] Switched from paper_name to paper_id --- application/controllers/Labels.php | 2 +- .../134_create_label_paper_types_table.php | 12 +++++----- application/models/Labels_model.php | 22 ++++++++++--------- application/views/labels/create.php | 6 ++--- application/views/labels/edit.php | 8 +++---- application/views/labels/editpaper.php | 2 +- application/views/labels/index.php | 8 +++---- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 15029d49..defd0db5 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -161,7 +161,7 @@ class Labels extends CI_Controller { try { if ($label) { - $ptype=$this->labels_model->getPaperType($label->paper_type); // fetch papersize out of paper-table + $ptype=$this->labels_model->getPaperType($label->paper_type_id); // fetch papersize out of paper-table // var_dump($ptype); $pdf = new PDF_Label(array( 'paper-size' => 'custom', // $label->paper_type, // The only Type left is "custom" because A4 and so on are also defined at paper_types diff --git a/application/migrations/134_create_label_paper_types_table.php b/application/migrations/134_create_label_paper_types_table.php index 70db4bad..5583a6f9 100644 --- a/application/migrations/134_create_label_paper_types_table.php +++ b/application/migrations/134_create_label_paper_types_table.php @@ -7,7 +7,7 @@ class Migration_create_label_paper_types_table extends CI_Migration { public function up() { if (!$this->db->table_exists('paper_types')) { $this->dbforge->add_field(array( - 'id' => array( + 'paper_id' => array( 'type' => 'INT', 'constraint' => 5, 'unsigned' => TRUE, @@ -53,15 +53,17 @@ class Migration_create_label_paper_types_table extends CI_Migration { ), )); - $this->dbforge->add_key('id', TRUE); + $this->dbforge->add_key('paper_id', TRUE); $this->dbforge->add_key('user_id', TRUE); $this->dbforge->create_table('paper_types'); + $this->db->query("ALTER TABLE label_types ADD COLUMN paper_type_id INT(5) NOT NULL;"); $this->db->query("CREATE UNIQUE INDEX idx_paper_types_user_id_paper_name ON paper_types (user_id, paper_name) ALGORITHM DEFAULT LOCK DEFAULT;"); - $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('1','-1','A4','mm','210.000','P','297.000');"); - $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('2','-1','A5','mm','148.000','P','210.000');"); - $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('3','-1','letter','mm','215.900','P','279.400');"); + $this->db->query("insert into paper_types (paper_id,user_id,paper_name,metric,width,orientation,height) values ('1','-1','A4','mm','210.000','P','297.000');"); + $this->db->query("insert into paper_types (paper_id,user_id,paper_name,metric,width,orientation,height) values ('2','-1','A5','mm','148.000','P','210.000');"); + $this->db->query("insert into paper_types (paper_id,user_id,paper_name,metric,width,orientation,height) values ('3','-1','letter','mm','215.900','P','279.400');"); $this->db->query("insert ignore paper_types (user_id,paper_name,metric,width,orientation,height) SELECT u.user_id, pt.paper_name, pt.metric, pt.width, pt.orientation,pt.height FROM paper_types pt inner join users u where pt.user_id = -1;"); + $this->db->query("update label_types l set l.paper_type_id=(select p.paper_id from paper_types p where upper(p.paper_name)=upper(l.paper_type) and p.user_id=l.user_id limit 1) where l.paper_type_id=0;"); } } diff --git a/application/models/Labels_model.php b/application/models/Labels_model.php index ac2c3e61..18854020 100644 --- a/application/models/Labels_model.php +++ b/application/models/Labels_model.php @@ -5,7 +5,7 @@ class Labels_model extends CI_Model { $data = array( 'user_id' => $this->session->userdata('user_id'), 'label_name' => xss_clean($this->input->post('label_name', true)), - 'paper_type' => xss_clean($this->input->post('paper_type', true)), + 'paper_type_id' => xss_clean($this->input->post('paper_type_id', true)), 'metric' => xss_clean($this->input->post('measurementType', true)), 'marginleft' => xss_clean($this->input->post('marginLeft', true)), 'margintop' => xss_clean($this->input->post('marginTop', true)), @@ -41,8 +41,9 @@ class Labels_model extends CI_Model { } function getLabel($id) { - $this->db->where('user_id', $this->session->userdata('user_id')); - $this->db->where('id', $id); + $this->db->join('paper_types', 'paper_types.paper_id = label_types.paper_type_id'); + $this->db->where('label_types.user_id', $this->session->userdata('user_id')); + $this->db->where('label_types.id', $id); $query = $this->db->get('label_types'); return $query->row(); @@ -52,7 +53,7 @@ class Labels_model extends CI_Model { $data = array( 'user_id' => $this->session->userdata('user_id'), 'label_name' => xss_clean($this->input->post('label_name', true)), - 'paper_type' => xss_clean($this->input->post('paper_type', true)), + 'paper_type_id' => xss_clean($this->input->post('paper_type_id', true)), 'metric' => xss_clean($this->input->post('measurementType', true)), 'marginleft' => xss_clean($this->input->post('marginLeft', true)), 'margintop' => xss_clean($this->input->post('marginTop', true)), @@ -82,7 +83,8 @@ class Labels_model extends CI_Model { } function fetchLabels($user_id) { - $this->db->where('user_id', $user_id); + $this->db->join('paper_types', 'paper_types.paper_id = label_types.paper_type_id'); + $this->db->where('label_types.user_id', $user_id); $query = $this->db->get('label_types'); return $query->result(); @@ -118,9 +120,9 @@ class Labels_model extends CI_Model { return $query->row(); } - function getPaperType($ptype) { + function getPaperType($ptype_id) { $this->db->where('user_id', $this->session->userdata('user_id')); - $this->db->where('paper_name',$ptype); + $this->db->where('paper_id',$ptype_id); $query = $this->db->get('paper_types'); return $query->row(); @@ -190,19 +192,19 @@ class Labels_model extends CI_Model { $cleanid = $this->security->xss_clean($id); $this->db->where('user_id', $this->session->userdata('user_id')); - $this->db->where('id', $cleanid); + $this->db->where('paper_id', $cleanid); $this->db->update('paper_types', $data); } function deletePaper($id) { $cleanid = xss_clean($id); - $this->db->delete('paper_types', array('id' => $cleanid, 'user_id' => $this->session->userdata('user_id'))); + $this->db->delete('paper_types', array('paper_id' => $cleanid, 'user_id' => $this->session->userdata('user_id'))); } function getPaper($id) { $this->db->where('user_id', $this->session->userdata('user_id')); - $this->db->where('id', $id); + $this->db->where('paper_id', $id); $query = $this->db->get('paper_types'); return $query->row(); diff --git a/application/views/labels/create.php b/application/views/labels/create.php index 9a074008..8b0fc017 100644 --- a/application/views/labels/create.php +++ b/application/views/labels/create.php @@ -25,12 +25,12 @@
- +
- paper_name . '>' . ucwords(strtolower(($paper->paper_name))) . ''; + echo ''; } ?> diff --git a/application/views/labels/edit.php b/application/views/labels/edit.php index ec509cdf..6483a63f 100644 --- a/application/views/labels/edit.php +++ b/application/views/labels/edit.php @@ -25,13 +25,13 @@
- +
- paper_name . '"'; - if ($label->paper_type == $paper->paper_name) echo ' selected'; + echo ''; } ?> diff --git a/application/views/labels/editpaper.php b/application/views/labels/editpaper.php index f7de1553..b6980a53 100644 --- a/application/views/labels/editpaper.php +++ b/application/views/labels/editpaper.php @@ -24,7 +24,7 @@ -
+

diff --git a/application/views/labels/index.php b/application/views/labels/index.php index 73375454..c2fc1782 100644 --- a/application/views/labels/index.php +++ b/application/views/labels/index.php @@ -46,14 +46,14 @@ - + paper_name; ?> metric; ?> width; ?> height; ?> last_modified; ?> - - + + label_name; ?> - paper_type; ?> + paper_name; ?> metric; ?> width; ?> height; ?>