Ejemplo n.º 1
0
/**
 * Get the number of matching entries for the view $view
 * @param $view is the name of the view. By default view rule is empty.
 * @param $page is the page in the view
 * @return Array of associative arrays for each entry.
 */
function get_entries_count($view = '', $page = 1)
{
    global $dbh, $config;
    $rule = get_view_rule($view);
    $r = rule2sql($rule, 'COUNT(*) AS nb', $config->entries_per_page, ($page - 1) * $config->entries_per_page);
    $query = $dbh->prepare($r[0]);
    $query->execute($r[1]);
    $fetched = $query->fetch(PDO::FETCH_ASSOC);
    return $fetched['nb'];
}
Ejemplo n.º 2
0
/**
 * Remove tag $tag from all entries of view $view
 */
function remove_tag_to_all($view = '', $tag)
{
    global $dbh;
    $dbh->beginTransaction();
    $rule = get_view_rule($view);
    $r = rule2sql($rule, 'id');
    $query = $dbh->prepare($r[0]);
    $query->execute($r[1]);
    $fetched_entries = $query->fetchall(PDO::FETCH_ASSOC);
    $q = $dbh->prepare('DELETE FROM tags_entries WHERE tag_id=(SELECT id FROM tags WHERE name=:tag_name) AND entry_id=:id');
    $q->bindParam(':id', $id, PDO::PARAM_INT);
    $q->bindParam(':tag_name', $tag);
    foreach ($fetched_entries as $entry) {
        $id = intval($entry['id']);
        $q->execute();
    }
    $dbh->commit();
}