本文整理汇总了PHP中Tags::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::fetch方法的具体用法?PHP Tags::fetch怎么用?PHP Tags::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tags
的用法示例。
在下文中一共展示了Tags::fetch方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSuggestions
/**
* getSuggestions
*
* This method returns an array of strings matching the user's query for
* display in the autocomplete box.
*
* @param string $query The user query
*
* @return array The suggestions for the provided query
* @access public
*/
public function getSuggestions($query)
{
$tagList = array();
$tag = new Tags();
$query = $tag->escape($query);
$tag->whereadd("lower(\"tag\") LIKE lower('{$query}%')");
$tag->whereadd('"id" IN (SELECT DISTINCT "tag_id" FROM "resource_tags")');
$tag->find();
if ($tag->N) {
while ($tag->fetch()) {
$tagList[] = $tag->tag;
}
}
return $tagList;
}
示例2: getTags
/**
* Get tags associated with the current resource.
*
* @param int $limit Max. number of tags to return (0 = no limit)
*
* @return array
* @access public
*/
public function getTags($limit = 0)
{
$tagList = array();
$query = 'SELECT MIN("tags"."id"), "tags"."tag", COUNT(*) as cnt ' . 'FROM "tags", "resource_tags" ' . 'WHERE "tags"."id" = "resource_tags"."tag_id" ' . 'AND "tags"."id" IN (SELECT "resource_tags"."tag_id" ' . 'FROM "resource", "resource_tags" ' . 'WHERE "resource"."id" = "resource_tags"."resource_id" ' . 'AND "resource"."record_id" = ' . "'" . $this->escape($this->record_id) . "' " . 'AND "resource"."source" = ' . "'" . $this->escape($this->source) . "' " . ')' . 'GROUP BY "tags"."tag" ORDER BY cnt DESC, "tags"."tag"';
$tag = new Tags();
$tag->query($query);
if ($tag->N) {
while ($tag->fetch()) {
$tagList[] = clone $tag;
// Return prematurely if we hit the tag limit:
if ($limit > 0 && count($tagList) >= $limit) {
return $tagList;
}
}
}
return $tagList;
}
示例3: getTags
/**
* Get a list of all tags generated by the user in favorites lists. Note that
* the returned list WILL NOT include tags attached to records that are not
* saved in favorites lists.
*
* @param int $resourceId Filter for tags tied to a specific resource (null
* for no filter).
* @param int $listId Filter for tags tied to a specific list (null for no
* filter).
*
* @return array
* @access public
*/
public function getTags($resourceId = null, $listId = null)
{
$tagList = array();
$sql = 'SELECT MIN("tags"."id"), "tags"."tag", ' . 'COUNT("resource_tags"."id") AS cnt ' . 'FROM "tags", "resource_tags", "user_resource", "resource" ' . 'WHERE "tags"."id" = "resource_tags"."tag_id" ' . 'AND "user_resource"."user_id" = ' . "'" . $this->escape($this->id) . "' " . 'AND "user_resource"."resource_id" = "resource"."id" ' . 'AND "resource_tags"."user_id" = ' . "'" . $this->escape($this->id) . "' " . 'AND "resource"."id" = "resource_tags"."resource_id" ' . 'AND "user_resource"."list_id" = "resource_tags"."list_id" ';
if (!is_null($resourceId)) {
$sql .= 'AND "resource"."record_id" = ' . "'" . $this->escape($resourceId) . "' ";
}
if (!is_null($listId)) {
$sql .= 'AND "resource_tags"."list_id" = ' . "'" . $this->escape($listId) . "' ";
}
$sql .= 'GROUP BY "tags"."tag" ORDER BY "tag"';
$tag = new Tags();
$tag->query($sql);
if ($tag->N) {
while ($tag->fetch()) {
$tagList[] = clone $tag;
}
}
return $tagList;
}
示例4: getTagsForList
/**
* Get tags associated with the current resource that the current user added.
*
* @access public
* @param int $limit Max. number of tags to return (0 = no limit)
* @return array
*/
function getTagsForList($listId, $limit = 10)
{
//Get a reference to the scope we are in.
global $library;
global $user;
$tagList = array();
$query = "SELECT tags.id as id, tags.tag " . "FROM tags inner join resource_tags on tags.id = resource_tags.tag_id " . "WHERE resource_id = '{$this->id}' and list_id = '{$listId}'" . "ORDER BY tags.tag LIMIT 0, {$limit}";
$tag = new Tags();
$tag->query($query);
if ($tag->N) {
//Load all bad words.
require_once ROOT_DIR . '/Drivers/marmot_inc/BadWord.php';
$badWords = new BadWord();
$badWordsList = $badWords->getBadWordExpressions();
while ($tag->fetch()) {
//Determine if the current user added the tag
$userAddedThis = false;
if ($user) {
$rTag = new Resource_tags();
$rTag->tag_id = $tag->id;
$rTag->user_id = $user->id;
$rTag->find();
if ($rTag->N > 0) {
$userAddedThis = true;
}
}
$tag->userAddedThis = $userAddedThis;
//Filter the tags prior to display to censor bad words
$okToAdd = true;
if (!$userAddedThis) {
//The user will always see their own tags no matter how filthy.
foreach ($badWordsList as $badWord) {
if (preg_match($badWord, trim($tag->tag))) {
$okToAdd = false;
break;
}
}
}
if ($okToAdd) {
$tagList[] = clone $tag;
// Return prematurely if we hit the tag limit:
if ($limit > 0 && count($tagList) >= $limit) {
return $tagList;
}
}
}
}
return $tagList;
}
示例5: _getTagCloud
/**
* Build an array of tag cloud information.
*
* @return array
* @access private
*/
private function _getTagCloud()
{
//global $interface;
global $configArray;
$tags = new Tags();
// Specify different font sizes in descending order here
$fontSizes = array(5, 4, 3, 2, 1);
$nFonts = count($fontSizes);
// no of different tags to display
$RecLimit = 50;
// Query to retrieve tags and their counts
$query = 'SELECT "tags"."tag", COUNT("tag") as cnt ' . 'FROM "tags", "resource_tags" ' . 'WHERE "tags"."id" = "resource_tags"."tag_id" ' . 'GROUP BY "tags"."tag" ORDER BY cnt DESC, "tag" ' . "LIMIT {$RecLimit}";
$tags->query($query);
$actualRecs = $tags->N;
// Create data array as
// key = tag_name and value = tag_count
//from the results returned by query
$data = array();
if ($actualRecs) {
while ($tags->fetch()) {
$data["{$tags->tag}"] = $tags->cnt;
}
} else {
return;
}
$temp = $data;
// sort array in alphabetical
// order of its keys
uksort($data, "strnatcasecmp");
// Create arry which contains only
// count of all tags
$onlyCnt = array();
foreach ($temp as $item) {
$onlyCnt[] = $item;
}
// create array which will contain only
// uniqe tag counts
$DistinctValues = array($onlyCnt[0]);
for ($i = 1; $i < count($onlyCnt); $i++) {
if ($onlyCnt[$i] != $onlyCnt[$i - 1]) {
$DistinctValues[] = $onlyCnt[$i];
}
}
$cntDistinct = count($DistinctValues);
// set step which will
// decide when to change font size
$step = 1;
$mod = 0;
if ($cntDistinct > $nFonts) {
$step = (int) ($cntDistinct / $nFonts);
$mod = $cntDistinct % $nFonts;
}
$distinctToFont = array();
$fontIndex = 0;
$stepCnt = 0;
for ($i = 0; $i < $cntDistinct; $i++) {
$distinctToFont["{$DistinctValues[$i]}"] = $fontSizes[$fontIndex];
$stepCnt++;
if ($mod && $nFonts - ($fontIndex + 1) == $mod) {
$step++;
$fontIndex++;
$stepCnt = 0;
}
if ($stepCnt == $step) {
$fontIndex++;
$stepCnt = 0;
}
}
foreach ($data as $key => $value) {
$data[$key] = array("font" => $distinctToFont["{$value}"], "count" => $value);
}
return $data;
}
示例6: getTagList
/**
* Get a list of tags based on current GET parameters.
*
* @access private
* @param string $extra_where Where clause to add to lookup query;
* it is caller's responsibility to
* make sure this is safe!!
* @return array Tag details.
*/
private function getTagList($extra_where = '')
{
$tagList = array();
$tag = new Tags();
$sql = "SELECT tags.tag, COUNT(resource_tags.id) as cnt " . "FROM tags, resource_tags " . "WHERE tags.id = resource_tags.tag_id{$extra_where} GROUP BY tags.tag";
switch ($_GET['findby']) {
case 'alphabetical':
$sql .= " ORDER BY tags.tag, cnt DESC";
break;
case 'popularity':
$sql .= " ORDER BY cnt DESC, tags.tag";
break;
case 'recent':
$sql .= " ORDER BY resource_tags.posted DESC, cnt DESC, tags.tag";
break;
}
// Limit the size of our results based on the ini browse limit setting
$browseLimit = isset($configArray['Browse']['result_limit']) ? $configArray['Browse']['result_limit'] : 100;
$sql .= " LIMIT " . $browseLimit;
$tag->query($sql);
if ($tag->N) {
while ($tag->fetch()) {
$tagList[] = clone $tag;
}
}
return $tagList;
}
示例7: _getTagList
/**
* Get a list of tags based on current GET parameters.
*
* @param string $extra_where Where clause to add to lookup query; it is the
* caller's responsibility to make sure this is safe!!
*
* @return array Tag details.
* @access private
*/
private function _getTagList($extra_where = '')
{
$tagList = array();
$tag = new Tags();
$sql = 'SELECT "tags"."tag", COUNT("resource_tags"."id") AS cnt ' . 'FROM "tags", "resource_tags" ' . 'WHERE "tags"."id" = "resource_tags"."tag_id"' . $extra_where . ' GROUP BY "tags"."tag"';
switch ($_GET['findby']) {
case 'alphabetical':
$sql .= ' ORDER BY "tags"."tag", cnt DESC';
break;
case 'popularity':
$sql .= ' ORDER BY cnt DESC, "tags"."tag"';
break;
case 'recent':
$sql .= ' ORDER BY max("resource_tags"."posted") DESC, cnt DESC, ' . '"tags"."tag"';
break;
}
// Limit the size of our results based on the ini browse limit setting
$browseLimit = isset($configArray['Browse']['result_limit']) ? $configArray['Browse']['result_limit'] : 100;
$sql .= " LIMIT " . $browseLimit;
$tag->query($sql);
if ($tag->N) {
while ($tag->fetch()) {
$tagList[] = clone $tag;
}
}
return $tagList;
}
示例8: getTags
function getTags($resourceId = null, $listId = null)
{
require_once 'Resource_tags.php';
require_once 'Tags.php';
$tagList = array();
$sql = "SELECT tags.id, tags.tag, COUNT(resource_tags.id) AS cnt " . "FROM tags INNER JOIN resource_tags on tags.id = resource_tags.tag_id " . "INNER JOIN resource on resource_tags.resource_id = resource.id WHERE " . "resource_tags.user_id = '{$this->id}' ";
if (!is_null($resourceId)) {
$sql .= "AND resource.record_id = '{$resourceId}' ";
}
if (!is_null($listId)) {
$sql .= "AND resource_tags.list_id = '{$listId}' ";
}
$sql .= "GROUP BY tags.tag ORDER BY cnt DESC, tags.tag ASC";
$tag = new Tags();
$tag->query($sql);
if ($tag->N) {
while ($tag->fetch()) {
$tagList[] = clone $tag;
}
}
return $tagList;
}