Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author search by name #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions core/publications/class-db-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TP_Authors {
* In this case you should ignore the columns con_id and pub_id from return
*
* @param array $args {
* @type string author Author names (separated by comma)
* @type string author_id Author IDs (separated by comma)
* @type string pub_id Publication IDs (separated by comma)
* @type string user User IDs (separated by comma)
Expand All @@ -39,6 +40,7 @@ class TP_Authors {
*/
public static function get_authors ( $args = array() ) {
$defaults = array(
'author' => '',
'author_id' => '',
'pub_id' => '',
'user' => '',
Expand Down Expand Up @@ -74,7 +76,9 @@ public static function get_authors ( $args = array() ) {
$search = esc_sql(htmlspecialchars(stripslashes($atts['search'])));

$nwhere = array();
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['author_id'], "r.author_id", "OR", "=");
$nwhere[] = TP_DB_Helpers::compose_clause( array(
TP_DB_Helpers::generate_where_clause($atts['author'], "r.name", "OR", "="),
TP_DB_Helpers::generate_where_clause($atts['author_id'], "r.author_id", "OR", "=")), "OR", '' );
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['pub_id'], "r.pub_id", "OR", "=");
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['exclude'], "r.author_id", "AND", "!=");
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['user'], "u.user", "OR", "=");
Expand Down Expand Up @@ -239,4 +243,4 @@ public static function get_related_publications($author_id, $output_type = ARRAY

}

}
}
8 changes: 5 additions & 3 deletions core/publications/class-db-publications.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ public static function get_publications($args = array(), $count = false) {
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['tag'], "b.tag_id", "OR", "=");
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['tag_name'], "t.name", "OR", "=");
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['key'], "p.bibtex", "OR", "=");
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['author_id'], "r.author_id", "OR", "=");
$nwhere[] = TP_DB_Helpers::compose_clause( array(
TP_DB_Helpers::generate_where_clause($atts['author_id'], "r.author_id", "OR", "="),
TP_DB_Helpers::generate_where_clause($atts['author'], "p.author", "OR", "LIKE", '%')), "OR", '' );
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['import_id'], "p.import_id", "OR", "=");
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['editor'], "p.editor", "OR", "LIKE", '%');
$nwhere[] = TP_DB_Helpers::generate_where_clause($atts['author'], "p.author", "OR", "LIKE", '%');
$nwhere[] = ( $atts['author_id'] != '' && $atts['include_editor_as_author'] === false) ? " AND ( r.is_author = 1 ) " : null;
$nwhere[] = ( $search != '') ? $search : null;

Expand Down Expand Up @@ -218,9 +219,10 @@ public static function get_publications($args = array(), $count = false) {
// get_tp_message($sql,'red');
}
else {

$sql = "SELECT COUNT( pub_id ) AS `count` FROM ( $select_for_count $join $where $having) p ";
}

$sql = ( $count != true ) ? $wpdb->get_results($sql, $atts['output_type']): $wpdb->get_var($sql);
return $sql;
}
Expand Down
31 changes: 28 additions & 3 deletions core/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@ public static function generate_filter ($key, $filter_parameter, $sql_parameter,
// Use the visible filter o the SQL parameter
$author_id = ($filter_parameter['show_in_author_filter'] !== '') ? $filter_parameter['show_in_author_filter'] : $filter_parameter['author_preselect'];

$author_ids = '';
$author_names = '';
$authors = explode(",", $author_id);
foreach ( $authors as $author ) {
if ( ctype_digit($author) ) {
$author_ids .= $author . ',';
} else {
$author_names .= $author . ',';
}
}

$row = TP_Authors::get_authors( array( 'user' => $sql_parameter['user'],
'author_id' => $author_id,
'author' => $author_names,
'author_id' => $author_ids,
'output_type' => ARRAY_A,
'group_by' => true ) );
$defaults['url_slug'] = 'auth';
Expand Down Expand Up @@ -1069,7 +1081,7 @@ function tp_links_shortcode ($atts) {
* @type string user the WordPress IDs or login names of on or more users (separated by commas)
* @type string tag tag IDs (separated by comma)
* @type string type the publication types you want to show (separated by comma)
* @type string author author IDs (separated by comma)
* @type string author author IDs or names (separated by comma). If the entry is numeric then it is interpreted as an ID, otherwise as an author name.
* @type string year one or more years (separated by comma)
* @type string exclude one or more IDs of publications you don't want to show (separated by comma)
* @type string include one or more IDs of publications you want to show (separated by comma)
Expand Down Expand Up @@ -1398,6 +1410,18 @@ function tp_publist_shortcode ($args) {
$sql_parameter['order'] = "year DESC, type ASC, date DESC";
}

// Separate authors names from authors IDs
$author_ids = '';
$author_names = '';
$authors = explode(",", $sql_parameter['author']);
foreach ( $authors as $author ) {
if ( ctype_digit($author) ) {
$author_ids .= $author . ',';
} else {
$author_names .= $author . ',';
}
}

// Parameters for returning publications
$args = array(
'tag' => $sql_parameter['tag'],
Expand All @@ -1407,7 +1431,8 @@ function tp_publist_shortcode ($args) {
'type' => $sql_parameter['type'],
'user' => $sql_parameter['user'],
'search' => $filter_parameter['search'],
'author_id' => $sql_parameter['author'],
'author' => $author_names,
'author_id' => $author_ids,
'order' => $sql_parameter['order'],
'exclude' => $sql_parameter['exclude'],
'exclude_tags' => $sql_parameter['exclude_tags'],
Expand Down