Esempio n. 1
0
 public static function insertPackageTags(Package $pkg, TagSet $tags, $con = null)
 {
     $bind = array(':package_id' => $pkg->getId());
     if ($tags->count()) {
         $bulk = array();
         foreach ($tags as $tag) {
             $bulk[] = "(:package_id,{$tag->getId()})";
         }
         $sql = 'INSERT INTO package_tag (package_id,tag_id) VALUES ' . implode(',', $bulk);
         mfwDBIBase::query($sql, $bind, $con);
     }
 }
Esempio n. 2
0
/**
 * Searches tags by node name based on the first chartacters
 *
 * @param string $q the query term(s)
 * @param string $scope (optional, either 'all' or 'my' - default: 'my')
 * @return TagSet or Error
 */
function getTagsByFirstCharacters($q, $scope)
{
    global $CFG, $USER, $HUB_SQL;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $params = array();
    // Don't want speech marks added in MySQL version
    $next = new stdClass();
    $params[0] = $next->value = $q;
    $sql = $HUB_SQL->APILIB_TAGS_BY_FIRST_CHARACTER_SELECT_PART1;
    if ($scope == 'my') {
        $params[1] = $currentuser;
        $sql .= $HUB_SQL->AND;
        $sql .= $HUB_SQL->FILTER_USER;
    }
    $sql = $HUB_SQL->APILIB_TAGS_BY_FIRST_CHARACTER_SELECT_PART2;
    $ts = new TagSet();
    return $ts->load($sql, $params);
}