Elgg\Database\PrivateSettingsTable::set PHP Method

set() public method

Sets a private setting for an entity.
public set ( integer $entity_guid, string $name, string $value ) : boolean
$entity_guid integer The entity GUID
$name string The name of the setting
$value string The value of the setting
return boolean
    public function set($entity_guid, $name, $value)
    {
        $this->cache->clear($entity_guid);
        _elgg_services()->boot->invalidateCache();
        if (!$this->entities->exists($entity_guid)) {
            return false;
        }
        $query = "\n\t\t\tINSERT into {$this->table}\n\t\t\t(entity_guid, name, value) VALUES\n\t\t\t(:entity_guid, :name, :value)\n\t\t\tON DUPLICATE KEY UPDATE value = :value\n\t\t";
        $params = [':entity_guid' => (int) $entity_guid, ':name' => (string) $name, ':value' => (string) $value];
        $result = $this->db->insertData($query, $params);
        return $result !== false;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function set($entity_guid, $name, $value)
 {
     $entity = get_entity((int) $entity_guid);
     if (!$entity) {
         return false;
     }
     if (!isset($value)) {
         return false;
     }
     $this->iterator++;
     $id = $this->iterator;
     $row = (object) ['id' => $id, 'entity_guid' => $entity->guid, 'name' => (string) $name, 'value' => (string) $value];
     $this->rows[$id] = $row;
     $this->addQuerySpecs($row);
     return parent::set($entity_guid, $name, $value);
 }