Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
44 changes: 38 additions & 6 deletions application/controllers/admin/Author_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand All @@ -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 ************/////
Expand Down
27 changes: 27 additions & 0 deletions application/controllers/catalog/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions application/controllers/private/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down
16 changes: 14 additions & 2 deletions application/models/Project_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,28 @@ 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.*
FROM project_authors pa
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();

Expand Down
25 changes: 14 additions & 11 deletions application/views/admin/author_manager/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

</style>

Expand All @@ -16,13 +21,14 @@

<h4>Author Manager</h4>

<div data-filter="status_filter" id="status_filter" style="margin-bottom: 20px;">
<span style="vertical-align:middle;" >Show only unconfirmed authors: </span>
<input style="margin-left:10px;vertical-align:middle;" class="status_group" name="status_group[]" type="radio" id="active_status" value="1" checked>
<span style="margin-left:10px;vertical-align:middle;" >Show all authors: </span>
<input style="margin-left:10px;vertical-align:middle;" class="status_group" name="status_group[]" type="radio" id="all_status" value="all" >
<div id="response_message_authormanager" class="alert" style="display:none;"></div>

<input style="margin-left:20px;vertical-align:middle;" class="btn" name="new_author_modal_btn" type="button" id="new_author_modal_btn" value="New Author" >
<div class="controls center" style="float:left;">
<a style="display:inline;margin-right:10px;" class="btn" role="button" href="/admin/author_manager/unconfirmed">Load unconfirmed</a>
<a style="display:inline;margin-right:10px;" class="btn" role="button" href="/admin/author_manager/all">Load all</a>
<input style="display:inline;margin-right:10px;" class="btn" name="new_author_modal_btn" type="button" role="button" id="new_author_modal_btn" value="Add author" >
<label style="display:inline;margin-right:5px;" for="author_search">Load author by name:</label>
<input style="width:200px;display:inline;margin-right:10px;vertical-align:top;" type="text" id="search_author" class="autocomplete" data-search_field="full_name" data-search_area="author" data-search_func="autocomplete_author">
</div>


Expand All @@ -31,7 +37,7 @@
<tr> <th>Status</th> <th>Id</th> <th>First name</th> <th>Last name</th> <th>Pseudonyms</th>
<th>Url</th> <th>Blurb</th> <th>DOB</th> <th>DOD</th>
<th class="data_filter" data-filter="status_filter">Confirm</th>
<th>Link to</th> <th>Wiki</th> <th>Image URL</th></tr>
<th>Link to</th> <th>Wiki</th></tr>
</thead>

<tbody>
Expand Down Expand Up @@ -96,10 +102,7 @@

?>


<td><a href="<?= $url?>" target = "_blank"><i class="icon-edit"></i></a></td>

<td id="image_url-<?= $author->id ?>" class="edit" ><?= $author->image_url;?></td>
<td><a href="<?= $url?>" target = "_blank"><i class="icon-edit"></i></a></td>
</tr>

<?php endforeach; ?>
Expand Down
7 changes: 5 additions & 2 deletions application/views/catalog/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
<p class="description"><?= $author->blurb ?></p>

<div class="page-header-half">
<p><span>External Links</span></p>
<p><span>Links</span></p>
<?php
if (!empty($author->author_url))
{
echo '<p>' . format_author($author, FMT_AUTH_WIKI) . '</p>';
}

if (!empty($edit_link))
{
echo '<p><a href="' . $edit_link . '">Edit this page</a></p>';
}
?>
</div>

Expand Down
7 changes: 6 additions & 1 deletion application/views/private/projects/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
<?php endif;?>

<td id="title-<?= $project->id ?>" ><?= $project->title ?></td>
<td id="author-<?= $project->id ?>" ><?= $project->author ?></td>
<td id="author-<?= $project->id ?>" >
<?php if ($view_author_manager):?>
<a href="<?= base_url().'admin/author_manager/project/'.$project->id ?>"><i class="icon-search meta_data"></i></a>
<?php endif;?>
<?= $project->author ?>
</td>
<td id="status-<?= $project->id ?>" ><?= $project_statuses[$project->status] ?></td>
<td id="url_forum-<?= $project->id ?>" ><a href="<?= $project->url_forum ?>">link</a></td>
<td id="url_librivox-<?= $project->id ?>" ><a href="<?= $project->url_librivox ?>">link</a></td>
Expand Down
78 changes: 37 additions & 41 deletions public_html/js/admin/author_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ $(document).ready(function() {

bind_edit();

var table_size = $('#authors_table').find('tr').length;

$.extend( $.fn.dataTable.defaults, {
"bFilter": true,
"bFilter": table_size > 10 + 1, // Header row counts!
"bPaginate" : true,
"bInfo" : true,
"sPaginationType": "full_numbers",
Expand All @@ -39,29 +41,6 @@ $(document).ready(function() {
var oTable = $('#authors_table').dataTable();

oTable.fnSort([[1, 'asc']]);


//default -only unconfirmed
// need to make this check which radio button is checked
var checked_radio = $('input[class=status_group]:checked').val();
apply_filter(checked_radio);

$('.status_group').live('click', function(){
apply_filter( $(this).val());
}) ;

function apply_filter(filter_value)
{
if (filter_value == '1')
{
oTable.fnFilter( 0, 0 );
}
else
{
oTable.fnFilter('', 0);
//oTable.fnFilter( '' );
}
}

function bind_edit()
{
Expand Down Expand Up @@ -126,11 +105,6 @@ $(document).ready(function() {
var row_id = oTable.fnGetPosition(row);

update_author_status(value, row_id);

//the one from above was static
var sub_checked_radio = $('input[class=status_group]:checked').val();
apply_filter(sub_checked_radio);

},
});

Expand All @@ -148,11 +122,12 @@ $(document).ready(function() {
type: 'post',
data: $('#add_new_author_form').serialize(),
complete: function(r){
//var response_obj = jQuery.parseJSON(r.responseText);

alert('You will need to refresh the page in order to see your newly added author. This can be slow, so we let you do it manually when you are ready.')
$('#author_new_modal').modal('hide');

json_set_message(
'response_message_authormanager', r.responseText,
'Author added! Click "Load unconfirmed" or load the author by name to view.<br>Message from server: ',
'The author may not have been added. Click "Load unconfirmed" or search by name to verify.<br>Message from server: '
);
},
});
});
Expand Down Expand Up @@ -274,11 +249,9 @@ $(document).ready(function() {
url: CI_ROOT + 'admin/author_manager/update_add_pseudonym',
type: 'post',
data: {'id' : id, 'author_id' : author_id, 'first_name': first_name, 'last_name': last_name },
complete: function(r){
var response_obj = jQuery.parseJSON(r.responseText);

complete: function(r){
$('#author_pseudonyms_modal').modal('hide');
alert(response_obj.data.message);
json_set_message('response_message_authormanager', r.responseText);
},
});

Expand All @@ -294,10 +267,8 @@ $(document).ready(function() {
type: 'post',
data: {'id' : id },
complete: function(r){
var response_obj = jQuery.parseJSON(r.responseText);

$('#author_pseudonyms_modal').modal('hide');
alert(response_obj.data.message);
json_set_message('response_message_authormanager', r.responseText);
},
});

Expand Down Expand Up @@ -336,4 +307,29 @@ $(document).ready(function() {

});

});
});


// Autocomplete the "Load author by name" search

function autocomplete_assign_vars(item)
{
var name_field;
if (item.username == undefined) {
name_field = author_string(item);
} else {
name_field = item.username;
}

return {
label: name_field,
value: name_field,
source_id: item.id,
source_name: name_field,
}
}

function autocomplete_assign_elements(search_area, ui)
{
window.location.href = CI_ROOT + 'admin/author_manager/' + ui.item.source_id
}
Loading