PHP File Manager
Editing File: Teams.php
<?php class Teams extends CI_Model { function get($team_id = null) { $sql = "SELECT team.* " . "FROM team " . "WHERE team.deleted IS NULL "; if ($team_id) { $sql .= sprintf('AND team_id = %s ', $this->db->escape($team_id)); } $sql .= "ORDER BY team.name ASC "; $query = $this->db->query($sql); $result = $query->result(); if ($team_id && $result) { return reset($result); } return $result; } function save($data) { $this->load->library('upload', array ( 'upload_path' => 'assets/uploads/teams', 'allowed_types' => 'jpeg|jpg|png|gif', 'file_ext_tolower' => true, 'overwrite' => true )); $save_data = array( 'name' => $data['name'], 'deleted' => (isset($data['deleted']) && $data['deleted'] ? date('Y-m-d H:i:s') : null), ); if ($this->upload->do_upload('image')) { $upload_data = $this->upload->data(); if ($upload_data['image_width'] > 200 || $upload_data['image_height'] > 200) { $this->load->library('image_lib', array ( 'source_image' => $upload_data['full_path'], 'create_thumb' => false, 'new_image' => $upload_data['full_path'], 'width' => 200, 'height' => 200, 'maintain_ratio' => true, 'quality' => 75 )); $this->image_lib->resize(); } $save_data['image'] = $upload_data['file_name']; } $team_id = null; if (isset($data['team_id'])) { $team_id = $data['team_id']; $this->db->query($this->db->update_string('team', $save_data, "team_id = {$this->db->escape($team_id)}")); } else { $this->db->query($this->db->insert_string('team', $save_data)); $team_id = $this->db->insert_id(); } return $team_id; } function delete($team_id) { $this->db->where('team_id', $team_id); $this->db->set('deleted', date('Y-m-d H:i:s')); $this->db->update('team'); } function getImageLocation() { return 'assets/uploads/teams/'; } function getImagePath($team) { if (!$team) { return; } return $this->getImageLocation() . $team->image; } function getDropdownData(array $teams) { $ret = array('' => ' --- '); foreach ($teams as $team) { $ret[$team->team_id] = $team->name; } return $ret; } }
Cancel