diff --git a/application/config/routes.php b/application/config/routes.php index b9f322e7..17f50510 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -80,6 +80,10 @@ $route['validator/(:num)'] = 'private/validator/index/$1'; $route['validator/adjust_file_volume/(:num)'] = 'private/validator/adjust_file_volume/$1'; +$route['admin/author_manager/(:num)'] = 'admin/author_manager/index/id/$1'; +$route['admin/author_manager/(project)/(:num)'] = 'admin/author_manager/index/$1/$2'; +$route['admin/author_manager/(all|unconfirmed)'] = 'admin/author_manager/index/$1'; + $route['volunteers'] = 'private/volunteers/index'; $route['volunteers/(:any)'] = 'private/volunteers/index/$1'; diff --git a/application/controllers/admin/Author_manager.php b/application/controllers/admin/Author_manager.php index 7a96973d..351ca736 100644 --- a/application/controllers/admin/Author_manager.php +++ b/application/controllers/admin/Author_manager.php @@ -16,17 +16,49 @@ public function __construct() $this->template->add_js('js/libs/jquery.jeditable.js'); } - public function index() + public function index($route = 'unconfirmed', $id = 0) { - ini_set('memory_limit', '-1'); //we need to see about chunking this - $this->data['menu_header'] = $this->load->view('private/common/menu_header', $this->data, TRUE); $this->data['author_blurb_modal'] = $this->load->view('admin/author_manager/author_blurb_modal', $this->data, TRUE); $this->data['author_projects_modal'] = $this->load->view('admin/author_manager/author_projects_modal', $this->data, TRUE); $this->data['author_pseudonyms_modal'] = $this->load->view('admin/author_manager/author_pseudonyms_modal', $this->data, TRUE); $this->data['author_new_modal'] = $this->load->view('admin/author_manager/author_new_modal', $this->data, TRUE); - $this->data['authors'] = $this->author_model->order_by('id', 'asc')->get_many_by(array('linked_to' => '0')); //limit(100)-> + if ($route == 'unconfirmed') + { + // Default: view unconfirmed authors + $this->data['authors'] = $this->author_model->order_by('id', 'asc')->get_many_by(array('linked_to' => '0', 'confirmed' => '0')); + } + elseif ($route == 'id') + { + // Individual: view author by ID + $this->data['authors'] = array($this->author_model->get($id)); + } + elseif ($route == 'all') + { + // Old way: view all non-duplicate authors (very slow!) + ini_set('memory_limit', '-1'); // Still a hack + $this->data['authors'] = $this->author_model->order_by('id', 'asc')->get_many_by(array('linked_to' => '0')); + } + elseif ($route == 'project') + { + // Authors and translators by project ID + $this->data['authors'] = array(); + $results_to_cast = array(); + $this->load->model('project_model'); + + $project_authors = $this->project_model->get_authors_by_project($id, 'author', include_sections: true); + if ($project_authors) $results_to_cast = array_merge($results_to_cast, $project_authors); + + $project_translators = $this->project_model->get_authors_by_project($id, 'translator'); + if ($project_translators) $results_to_cast = array_merge($results_to_cast, $project_translators); + + // Hack: get_authors_by_project returns an array of *arrays*. + // We need to cast them as objects, to match types with the db->get*() results + foreach ($results_to_cast as $person) { + $this->data['authors'][] = (object) $person; + } + } $this->insertMethodCSS(); $this->insertMethodJS(); @@ -142,7 +174,7 @@ public function delete_pseudonym() $message = 'Deleted'; } - $this->ajax_output(array('message' => $message), TRUE, FALSE); + $this->ajax_output(array('message' => $message), (bool)$fields['id'], FALSE); } public function add_new_author() @@ -159,7 +191,7 @@ public function add_new_author() $message = 'Added'; } - $this->ajax_output(array('message' => $message), TRUE, FALSE); + $this->ajax_output(array('message' => $message), (bool)$insert_id, FALSE); } //// ********* TESTING ************///// diff --git a/application/controllers/catalog/Author.php b/application/controllers/catalog/Author.php index 1204bb4c..12ba7eed 100644 --- a/application/controllers/catalog/Author.php +++ b/application/controllers/catalog/Author.php @@ -17,6 +17,7 @@ public function index($author_id) $this->load->model('author_model'); $this->data['author'] = $this->author_model->get($author_id); + $this->data['edit_link'] = $this->_get_edit_link($author_id); $this->data['search_category'] = 'author'; @@ -143,4 +144,30 @@ function _get_all_author($author_id, $offset = 0, $limit = 1000000, $search_orde return $projects; } + + function _get_edit_link($author_id) + { + $link = ''; + $auth_checker = new Librivox_auth(); + + if (empty($author_id)) + { + return $link; + } + + $user_id = $auth_checker->get_user_id(); + if ($user_id < 1) { + return $link; + } + + //check permissions + $allowed_groups = array(PERMISSIONS_ADMIN, PERMISSIONS_MCS); + if ($auth_checker->has_permission($allowed_groups, $user_id)) + { + $link = base_url() . 'admin/author_manager/' . $author_id ; + return $link; + } + + return $link; + } } diff --git a/application/controllers/private/Projects.php b/application/controllers/private/Projects.php index e0f5c8c3..6ea2ade3 100644 --- a/application/controllers/private/Projects.php +++ b/application/controllers/private/Projects.php @@ -30,10 +30,12 @@ public function index($user_projects = false) $this->data['project_statuses'] = $this->config->item('project_statuses'); $this->data['view_validator'] = false; + $this->data['view_author_manager'] = false; $allowed_groups = array(PERMISSIONS_ADMIN, PERMISSIONS_MCS); if ($this->librivox_auth->has_permission($allowed_groups, $this->data['user_id'])) { $this->data['view_validator'] = true; + $this->data['view_author_manager'] = true; } if (!empty($this->data['projects'])) diff --git a/application/models/Project_model.php b/application/models/Project_model.php index 99ea6d56..d6940624 100644 --- a/application/models/Project_model.php +++ b/application/models/Project_model.php @@ -482,7 +482,7 @@ public function search($where) } - public function get_authors_by_project($project_id, $type= 'author') + public function get_authors_by_project($project_id, $type= 'author', $include_sections = false) { $sql = ' SELECT a.* @@ -490,8 +490,20 @@ public function get_authors_by_project($project_id, $type= 'author') JOIN authors a ON (pa.author_id = a.id) WHERE pa.project_id = ? AND pa.type = ? '; + $bind = array($project_id, $type); - $query = $this->db->query($sql, array($project_id, $type)); + if ($include_sections and $this->get($project_id)->is_compilation) { + $sql .= ' + UNION + SELECT a.* + FROM sections s + JOIN authors a ON (s.author_id = a.id) + WHERE s.project_id = ?'; + + $bind[] = $project_id; + } + + $query = $this->db->query($sql, $bind); if ($query->num_rows() > 0) return $query->result_array(); diff --git a/application/views/admin/author_manager/index.php b/application/views/admin/author_manager/index.php index 257a5faf..87572940 100644 --- a/application/views/admin/author_manager/index.php +++ b/application/views/admin/author_manager/index.php @@ -8,6 +8,11 @@ white-space: nowrap; overflow: hidden; } +/* Tweak dataTables "Show X entries" control, so that it lines up with other buttons */ +.dataTables_length { + float: none; + display: inline; +} @@ -16,13 +21,14 @@
= $author->blurb ?>
External Links
+Links
author_url)) { echo '' . format_author($author, FMT_AUTH_WIKI) . '
'; } - + if (!empty($edit_link)) + { + echo ''; + } ?>