Skip to content

Commit

Permalink
New functions in Project model to support keywords display
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjdann committed Aug 20, 2024
1 parent c7a69ca commit 201c7e5
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions application/models/Project_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,85 @@ function get_frozen_projects()
return $query->result();

}


public function get_projects_by_keywords_id($params)
{
// If calls to this function do not pass a project_type_description parameter,
// provide a sensible default

$keyword_id = $params['keywords_id'];
$offset = 0 + $params['offset'];
$limit = 0 + $params['limit'];

$sql = 'select p.id, p.title_prefix, p.title, COALESCE(p.date_catalog, "2001-01-01" ) as safe_release_date,
p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, l.two_letter_code, l.language, p.url_forum, p.project_type
FROM keywords k
JOIN project_keywords pk ON (k.id = pk.keyword_id)
JOIN projects p on (pk.project_id = p.id)
JOIN languages l ON (l.id = p.language_id) ';
$sql .= 'WHERE k.id = ? ';

// It is likely that either $params['project_type_description'] will not exist as a key at all,
// or that if it does exist, it will contain the values of 'either','solo' or 'group', matching values passed
// from Javascript embedded in the search page footer. Of these values, only 'solo' matches a value actually to be
// found in the projects.project_type field.

if ((!array_key_exists('project_type_description', $params)) || ($params['project_type_description'] == 'either'))
{
$sql .= 'AND p.project_type LIKE "%" ';
}
if ( array_key_exists('project_type_description', $params) && $params['project_type_description'] == 'group')
{
$sql .= 'AND p.project_type = "collaborative" ';
}
if ( array_key_exists('project_type_description', $params) && $params['project_type_description'] == 'solo')
{
$sql .= 'AND p.project_type = "solo" ';
}

if ($params['search_order'] == 'catalog_date')
{
$sql .= ' ORDER BY safe_release_date DESC ';
} else
{
$sql .= ' ORDER BY p.title ASC ';
}
$sql .= ' LIMIT ? , ? ';
$query = $this->db->query($sql, array($keyword_id, $offset, $limit));

return $query->result_array();

}


public function get_keywords_and_statistics_by_project($project_id)
{
$sql = '
SELECT keywords.id, keywords.value, keywords.count as keyword_count
FROM keywords
JOIN project_keywords
ON keywords.id = project_keywords.keyword_id
WHERE project_keywords.project_id = ?
ORDER BY keywords.count DESC' ;

$query = $this->db->query($sql, array($project_id));
if ($query->num_rows() > 0) return $query->result_array();
return '';
}

public function get_keywords_count_by_project($project_id)
{
$sql = '
SELECT COUNT(keywords.id) as keywords_number
FROM keywords
JOIN project_keywords
ON keywords.id = project_keywords.keyword_id
WHERE project_keywords.project_id = ?';

$query = $this->db->query($sql, array($project_id));
return $query->row();
}



Expand Down

0 comments on commit 201c7e5

Please sign in to comment.