php class Works_model extends Model var part_table works_part function

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
class Works_model extends Model
{
var $part_table = 'works_part';
function __construct()
{
parent::Model();
}
function add_part($data)
{
$this->db->insert($this->part_table, $data);
return $this->db->insert_id();
}
function get_parts()
{
$this->db->order_by("sort", "ASC");
$this->db->where('id_module', 3);
$query = $this->db->get('navigation');
return $query->result();
}
function get_projects($id_part)
{
//$this->db->sele
$result = array();
$this->db->from("works_part2projects p2p");
$this->db->from("works_projects p");
$this->db->where("p.id = p2p.id_project");
$this->db->where("p2p.id_part", $id_part);
$query = $this->db->get();
foreach ($query->result() as $val)
{
$project = $val;
$project->parts = $this->get_project_parts($val->id);
$result[] = $project;
}
return $result;
}
function get_project_parts($id_project)
{
$this->db->select("n.name");
$this->db->select("n.id");
$this->db->from('navigation n');
$this->db->from('works_part2projects p');
$this->db->where("p.id_part = n.id");
$this->db->where("p.id_project", $id_project);
$query = $this->db->get();
return $query->result();
}
function get_project_by_path($path)
{
$this->db->where('path', $path);
$query = $this->db->get('works_projects');
//return $query->row();
$result = $query->row();
$result->previews = $this->get_preview($result->id);
return $result;
}
function get_preview($id_project)
{
$this->db->where('id_project', $id_project);
$query = $this->db->get('works_preview');
return $query->result();
}
function get_part($id_part)
{
$this->db->where("id", $id_part);
$query = $this->db->get($this->part_table);
return $query->row();
}
function delete_part($id_part)
{
$part = $this->get_part($id_part);
if ( ! $part ) return ;
$this->db->where("id", $id_part);
$this->db->delete($this->part_table);
return $part->id_navigation;
}
function save_part($id_part, $data)
{
$this->db->where('id', $id_part);
$this->db->update($this->part_table, $data);
}
function add_project($data)
{
$parts = $data['part'];
unset($data['part']);
$this->db->insert('works_projects', $data);
$id_project = $this->db->insert_id();
$this->_insert_part2projects($parts, $id_project);
return $id_project;
}
function save_project($id_project, $data)
{
$parts = $data['part'];
unset($data['part']);
$this->db->where('id', $id_project);
$this->db->update('works_projects', $data);
$this->_insert_part2projects($parts, $id_project);
}
function _add_preview($data)
{
$this->db->insert('works_preview', $data);
}
function _insert_part2projects($parts, $id_project)
{
$this->db->where('id_project', $id_project);
$this->db->delete('works_part2projects');
foreach ($parts as $part)
{
$this->db->insert('works_part2projects', array('id_part' => $part, 'id_project' => $id_project));
}
}
function delete_preview($id_preview)
{
$this->db->where('id', $id_preview);
$query = $this->db->get('works_preview');
$result = $query->row();
if ( ! $result ) return false;
if (file_exists($this->config->item('works_upload_path').$result->name))
{
unlink($this->config->item('works_upload_path').$result->name);
}
if (file_exists($this->config->item('works_upload_path').'s_'.$result->name))
{
unlink($this->config->item('works_upload_path').'s_'.$result->name);
}
$this->db->where('id', $id_preview);
$this->db->delete('works_preview');
return true;
}
}