RedBeanPHP\QueryWriter\AQueryWriter::queryTagged PHP Method

queryTagged() public method

See also: QueryWriter::queryTagged
public queryTagged ( $type, $tagList, $all = FALSE, $addSql = '', $bindings = [] )
    public function queryTagged($type, $tagList, $all = FALSE, $addSql = '', $bindings = array())
    {
        $assocType = $this->getAssocTable(array($type, 'tag'));
        $assocTable = $this->esc($assocType);
        $assocField = $type . '_id';
        $table = $this->esc($type);
        $slots = implode(',', array_fill(0, count($tagList), '?'));
        $score = $all ? count($tagList) : 1;
        $sql = "\n\t\t\tSELECT {$table}.*, count({$table}.id) FROM {$table}\n\t\t\tINNER JOIN {$assocTable} ON {$assocField} = {$table}.id\n\t\t\tINNER JOIN tag ON {$assocTable}.tag_id = tag.id\n\t\t\tWHERE tag.title IN ({$slots})\n\t\t\tGROUP BY {$table}.id\n\t\t\tHAVING count({$table}.id) >= ?\n\t\t\t{$addSql}\n\t\t";
        $bindings = array_merge($tagList, array($score), $bindings);
        $rows = $this->adapter->get($sql, $bindings);
        return $rows;
    }