function update_slugs() { $this->trace .= 'update_slugs()<br/>'; $result = array(); $this->db->select('l.id, l.name, l.country_id')->from('labels l'); $query = $this->db->get(); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; foreach ($query->result() as $row) { if ($row->name) { $new_slug = create_unique_slug($row->name . '-' . $row->country_id, 'labels'); $this->db->where('id', $row->id); $this->db->update('labels', array('slug' => $new_slug)); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $result[$row->id] = $new_slug; } } return $result; }
function fix_slugs() { $this->trace .= 'fix_slugs<br/>'; $result = ''; $artist_list = array(); $this->db->select('id, title, artist, year_released')->from('releases'); $query = $this->db->get(); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $artist_list = $query->result_array(); foreach ($artist_list as $item) { $slug = create_unique_slug($item['artist'] . '-' . $item['title'] . '-' . $item['year_released'], 'artists'); $result .= 'update releases set slug = ' . $this->db->escape($slug) . ' where id = ' . $this->db->escape($item['id']) . ";\n"; } return $result; }
function update($user_input, $reset_slug = FALSE) { $this->trace .= 'update<br/>'; $result = array('status' => 'ok'); $this->db->trans_start(); $article_id = 0; // basic info $data = array('title' => $user_input['title'], 'category_id' => $user_input['category_id'], 'intro' => $user_input['intro'], 'body' => $user_input['body'], 'status' => $user_input['status'], 'issue_no' => $user_input['issue_no'], 'user_id' => $user_input['user_id'], 'front_page' => $user_input['front_page'], 'updated_on' => date('Y-m-d H:i:s')); if ($user_input['published_on']) { $data['published_on'] = $user_input['published_on']; } if (array_key_exists('image_file', $user_input) && $user_input['image_file']) { $data['image_file'] = $user_input['image_file']; } if ($user_input['article_id'] == 0) { $this->trace .= 'new article, insert' . "<br/>\n"; $slug_src = $user_input['title']; if (count($user_input['author'])) { foreach ($user_input['author'] as $user => $item) { $slug_src .= '-' . $user; } } $data['slug'] = create_unique_slug($slug_src, 'articles'); $result['slug'] = $data['slug']; $this->db->insert('articles', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $article_id = $this->db->insert_id(); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'new id is: ' . $article_id . "<br/>\n"; $result['id'] = $article_id; } else { if ($reset_slug) { $slug_src = $user_input['title']; if (count($user_input['author'])) { foreach ($user_input['author'] as $user => $item) { $slug_src .= '-' . $user; } } $data['slug'] = create_unique_slug($slug_src, 'articles'); $result['slug'] = $data['slug']; } else { $result['slug'] = $user_input['slug']; } $article_id = $user_input['article_id']; $result['id'] = $article_id; $this->db->where('id', $user_input['article_id']); $this->db->update('articles', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; // echo $this->trace; exit; } // credits if (count($user_input['author'])) { foreach ($user_input['author'] as $user => $item) { if ($item['action'] == 'insert') { $data = array('article_id' => $article_id, 'user_id' => $user, 'role_id' => $item['role']); $this->db->insert('article_user_role', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'add new author ' . "<br/>\n"; } elseif ($item['action'] == 'delete') { $this->db->where('article_id', $article_id)->where('user_id', $user)->where('role_id', $item['role']); $this->db->delete('article_user_role'); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'delete author ' . "<br/>\n"; } } } else { $this->trace .= 'no changes in author list ' . "<br/>\n"; } if (count($user_input['photographer'])) { foreach ($user_input['photographer'] as $user => $item) { if ($item['action'] == 'insert') { $data = array('article_id' => $article_id, 'user_id' => $user, 'role_id' => $item['role']); $this->db->insert('article_user_role', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'add new photographer ' . "<br/>\n"; } elseif ($item['action'] == 'delete') { $this->db->where('article_id', $article_id)->where('user_id', $user)->where('role_id', $item['role']); $this->db->delete('article_user_role'); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'delete photographer ' . "<br/>\n"; } } } else { $this->trace .= 'no changes in photographer list ' . "<br/>\n"; } // artists if (count($user_input['artist'])) { foreach ($user_input['artist'] as $id => $action) { if ($action == 'insert') { $data = array('article_id' => $article_id, 'artist_id' => $id); $this->db->insert('article_artist', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'add new artist ' . "<br/>\n"; } elseif ($action == 'delete') { $this->db->where('article_id', $article_id)->where('artist_id', $id); $this->db->delete('article_artist'); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'delete artist ' . "<br/>\n"; } } } else { $this->trace .= 'no changes in artist list ' . "<br/>\n"; } // topics if (count($user_input['topic'])) { foreach ($user_input['topic'] as $id => $action) { if ($action == 'insert') { $data = array('article_id' => $article_id, 'topic_id' => $id); $this->db->insert('article_topic', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'add new topic ' . "<br/>\n"; } elseif ($action == 'delete') { $this->db->where('article_id', $article_id)->where('topic_id', $id); $this->db->delete('article_topic'); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'delete topic ' . "<br/>\n"; } } } else { $this->trace .= 'no changes in topics list ' . "<br/>\n"; } // links if (count($user_input['links'])) { $this->db->where('article_id', $article_id); $this->db->delete('article_links'); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'delete links ' . "<br/>\n"; foreach ($user_input['links'] as $url) { $data = array('article_id' => $article_id, 'link' => $url); $this->db->insert('article_links', $data); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $this->trace .= 'add new link ' . "<br/>\n"; } } else { $this->trace .= 'no changes in links list ' . "<br/>\n"; } // releases if ($user_input['release_id']) { // need to make array? $data = array('article_id' => $article_id, 'release_id' => $user_input['release_id']); $this->db->insert('article_release', $data); } else { $this->trace .= 'no release id ' . "<br/>\n"; } $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { // generate an error... or use the log_message() function to log your error $result['status'] = 'error'; } return $result; }
public function edit($artist_slug = '') { // authorize if ($this->input->post('slug')) { $artist_slug = $this->input->post('slug'); } //check for id? // init $action = 'update'; $this->page_data['show_ads'] = FALSE; $upload_config = array('upload_path' => './assets/img/artists/', 'allowed_types' => 'jpg|png', 'max_size' => '500', 'max_width' => '1024', 'max_height' => '768'); $this->load->library('upload', $upload_config); // handle incoming post if ($this->input->post('artist-submit')) { $ok = TRUE; $update_params = array('slug' => $artist_slug); if ($this->input->post('display-name')) { $update_params['display'] = $this->input->post('display-name'); } else { $ok = FALSE; } if ($this->input->post('sort-name')) { $update_params['name'] = $this->input->post('sort-name'); } else { $ok = FALSE; } if ($this->input->post('country')) { $update_params['country_id'] = $this->input->post('country'); } else { $ok = FALSE; } if ($artist_slug == '') { $artist_slug = create_unique_slug($update_params['name'] . '-' . $update_params['country_id'], 'artists'); $update_params['slug'] = $artist_slug; } if ($this->input->post('artist-url')) { $update_params['url'] = $this->input->post('artist-url'); } else { $update_params['url'] = ''; //$ok = FALSE; } if ($this->input->post('country')) { $update_params['country_id'] = $this->input->post('country'); } else { $ok = FALSE; } /* if ( ! $this->upload->do_upload('filebrowse')) { echo $this->upload->display_errors('<p>', '</p>'); exit; } else { $data = $this->upload->data(); }*/ if ($this->input->post('artist-image')) { $update_params['image_file'] = $this->input->post('artist-image'); } else { $ok = FALSE; } if ($this->input->post('info')) { $update_params['info'] = $this->input->post('info'); } else { $update_params['info'] = ''; } if ($this->input->post('artist-id')) { $artist_id = $this->input->post('artist-id'); } if ($ok) { $update_result = $this->Artist_model->update_info($artist_id, $update_params); if ($update_result['status'] == 'ok') { // clear cached list $this->cache->model('Artist_model', 'get_select_list', array(0, 0), -1); redirect('artists/display/' . $artist_slug); } } } // process $artist_info = $this->Artist_model->get_info($artist_slug); $this->page_data['country_list'] = $this->Masterdata_model->get_country_list(TRUE); $this->page_data['artist_info'] = $artist_info; $this->page_data['action'] = $action; // display $this->page_data['trace'] .= $this->Artist_model->trace; $this->page_data['trace'] .= print_r($this->page_data['artist_info'], TRUE) . '<br/>'; $this->page_data['show_columns'] = 2; $this->template->title($this->page_data['site_name'], $this->page_data['page_name'], $artist_info['display'])->build('artists/edit_form', $this->page_data); }
function fix_slugs() { $this->trace .= 'fix_slugs<br/>'; $result = ''; $artist_list = array(); $this->db->select('id, name, country_id, slug')->from('artists'); $query = $this->db->get(); $this->trace .= 'sql: ' . $this->db->last_query() . "<br/>\n"; $artist_list = $query->result_array(); foreach ($artist_list as $item) { if ($item['country_id'] == '???') { $slug = create_unique_slug($item['name'], 'artists'); } else { $slug = create_unique_slug($item['name'] . '-' . $item['country_id'], 'artists'); } $result .= 'update artists set slug = ' . $this->db->escape($slug) . ' where id = ' . $this->db->escape($item['id']) . ";\n"; } return $result; }