本文整理汇总了PHP中Resource::addTag方法的典型用法代码示例。如果您正苦于以下问题:PHP Resource::addTag方法的具体用法?PHP Resource::addTag怎么用?PHP Resource::addTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resource
的用法示例。
在下文中一共展示了Resource::addTag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* The autocomplete callback function for the Linkit Entity plugin.
*
* @return
* An associative array whose values are an
* associative array containing:
* - title: A string to use as the search result label.
* - description: (optional) A string with additional information about the
* result item.
* - path: The URL to the item.
* - group: (optional) A string with the group name for the result item.
* Best practice is to use the plugin name as group name.
* - addClass: (optional) A string with classes to add to the result row.
*/
function autocomplete_callback()
{
$matches = array();
// Get the EntityFieldQuery instance.
$this->getQueryInstance();
// Add the search condition to the query object.
$this->query->propertyCondition($this->entity_field_label, '%' . db_like($this->search_string) . '%', 'LIKE')->addTag('linkit_entity_autocomplete')->addTag('linkit_' . $this->plugin['entity_type'] . '_autocomplete');
// Add access tag for the query.
// There is also a runtime access check that uses entity_access().
$this->query->addTag($this->plugin['entity_type'] . '_access');
// Bundle check.
if (isset($this->entity_key_bundle) && isset($this->conf['bundles'])) {
if ($bundles = array_filter($this->conf['bundles'])) {
$this->query->propertyCondition($this->entity_key_bundle, $bundles, 'IN');
}
}
// Execute the query.
$result = $this->query->execute();
if (!isset($result[$this->plugin['entity_type']])) {
return array();
}
$ids = array_keys($result[$this->plugin['entity_type']]);
// Load all the entities with all the ids we got.
$entities = entity_load($this->plugin['entity_type'], $ids);
foreach ($entities as $entity) {
// Check the access againt the definded entity access callback.
if (entity_access('view', $this->plugin['entity_type'], $entity) === FALSE) {
continue;
}
$matches[] = array('title' => $this->buildLabel($entity), 'description' => $this->buildDescription($entity), 'path' => $this->buildPath($entity), 'group' => $this->buildGroup($entity), 'addClass' => $this->buildRowClass($entity));
}
return $matches;
}
示例2: save
function save($source = 'eContent')
{
global $user;
// Fail if we don't know what record we're working with:
if (!isset($_GET['id'])) {
return false;
}
// Create a resource entry for the current ID if necessary (or find the
// existing one):
$resource = new Resource();
$resource->record_id = $_GET['id'];
$resource->source = $source;
if (!$resource->find(true)) {
$resource->insert();
}
// Parse apart the tags and save them in association with the resource:
preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words);
foreach ($words[0] as $tag) {
$tag = trim(strtolower(str_replace('"', '', $tag)));
$resource->addTag($tag, $user);
}
// Done -- report success:
return true;
}
示例3: SaveTag
function SaveTag()
{
$user = UserAccount::isLoggedIn();
if ($user === false) {
return json_encode(array('result' => 'Unauthorized'));
}
// Create a resource entry for the current ID if necessary (or find the
// existing one):
$resource = new Resource();
$resource->record_id = $_GET['id'];
$resource->source = $_REQUEST['source'];
if (!$resource->find(true)) {
$resource->insert();
}
// Parse apart the tags and save them in association with the resource:
preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words);
foreach ($words[0] as $tag) {
$tag = trim(strtolower(str_replace('"', '', $tag)));
$resource->addTag($tag, $user);
}
return json_encode(array('result' => 'Done'));
}
示例4: save
/**
* Save the tag information based on GET parameters.
*
* @param object $user User that is adding the tag.
*
* @return bool True on success, false on failure.
* @access public
*/
public static function save($user)
{
// Fail if we don't know what record we're working with:
if (!isset($_GET['id'])) {
return false;
}
$db = ConnectionManager::connectToIndex();
if (!($record = $db->getRecord($_GET['id']))) {
return false;
}
// Create a resource entry for the current ID if necessary (or find the
// existing one):
$resource = new Resource();
$resource->record_id = $_GET['id'];
if (!$resource->find(true)) {
$resource->insert();
}
// Parse apart the tags and save them in association with the resource:
preg_match_all('/"[^"]*"|[^ ]+/', $_REQUEST['tag'], $words);
foreach ($words[0] as $tag) {
$tag = str_replace('"', '', $tag);
$resource->addTag($tag, $user);
}
// Done -- report success:
return true;
}