Elgg  Version 3.0
ElggSite.php
Go to the documentation of this file.
1 <?php
23 class ElggSite extends \ElggEntity {
24 
28  protected function initializeAttributes() {
30 
31  $this->attributes['guid'] = null;
32  $this->attributes['type'] = 'site';
33  $this->attributes['subtype'] = 'site';
34 
35  $this->attributes['owner_guid'] = 0;
36  $this->attributes['container_guid'] = 0;
37 
38  $this->attributes['access_id'] = ACCESS_PUBLIC;
39  $this->attributes['time_updated'] = null;
40  $this->attributes['last_action'] = null;
41  $this->attributes['enabled'] = "yes";
42  }
43 
47  public function getType() {
48  return 'site';
49  }
50 
54  public function save() {
55  $db = $this->getDatabase();
56  $qb = \Elgg\Database\Select::fromTable('entities', 'e');
57  $qb->select('e.*')
58  ->where($qb->compare('e.type', '=', 'site', ELGG_VALUE_STRING));
59 
60  $row = $db->getDataRow($qb);
61 
62  if (!empty($row)) {
63  if ($row->guid == $this->attributes['guid']) {
64  // can save active site
65  return parent::save();
66  }
67 
68  _elgg_services()->logger->error('More than 1 site entity cannot be created.');
69  return false;
70  }
71 
72  return parent::save(); // TODO: Change the autogenerated stub
73  }
74 
85  public function delete($recursive = true) {
86  if ($this->guid == 1) {
87  throw new \SecurityException('You cannot delete the current site');
88  }
89 
90  return parent::delete($recursive);
91  }
92 
104  public function disable($reason = "", $recursive = true) {
105  if ($this->guid == 1) {
106  throw new \SecurityException('You cannot disable the current site');
107  }
108 
109  return parent::disable($reason, $recursive);
110  }
111 
115  public function __set($name, $value) {
116  if ($name === 'url') {
117  _elgg_services()->logger->warning("ElggSite::url cannot be set");
118  return;
119  }
120  parent::__set($name, $value);
121  }
122 
126  public function __get($name) {
127  if ($name === 'url') {
128  return $this->getURL();
129  }
130  return parent::__get($name);
131  }
132 
138  public function getURL() {
139  return _elgg_config()->wwwroot;
140  }
141 
145  public function isCacheable() {
146  return false;
147  }
148 
152  protected function prepareObject(\Elgg\Export\Entity $object) {
153  $object = parent::prepareObject($object);
154  $object->name = $this->getDisplayName();
155  $object->description = $this->description;
156  unset($object->read_access);
157  return $object;
158  }
159 
166  public function getDomain() {
167  $breakdown = parse_url($this->url);
168  return $breakdown['host'];
169  }
170 
179  public function getEmailAddress() {
181  if (empty($email)) {
182  // If all else fails, use the domain of the site.
183  $token = _elgg_services()->crypto->getRandomString(24);
184  $email = "noreply-{$token}@{$this->getDomain()}";
185  }
186 
187  return $email;
188  }
189 
195  public function canComment($user_guid = 0, $default = null) {
196  return false;
197  }
198 }
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:50
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
__set($name, $value)
{}
Definition: ElggSite.php:115
__get($name)
{}
Definition: ElggSite.php:126
getType()
{}
Definition: ElggSite.php:47
save()
{}
Definition: ElggSite.php:54
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:442
getEmailAddress()
Get the email address for the site.
Definition: ElggSite.php:179
$email
Definition: register.php:18
$user_guid
Validate a user.
Definition: validate.php:6
disable($reason="", $recursive=true)
Disable the site.
Definition: ElggSite.php:104
Configuration exception.
canComment($user_guid=0, $default=null)
Definition: ElggSite.php:195
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:36
prepareObject(\Elgg\Export\Entity $object)
{}
Definition: ElggSite.php:152
$default
Definition: checkbox.php:35
$token
getURL()
Returns the URL for this site.
Definition: ElggSite.php:138
isCacheable()
{}
Definition: ElggSite.php:145
_elgg_config()
Get the Elgg config service.
$value
Definition: debugging.php:7
$CONFIG url
The full URL where Elgg is installed.
Definition: config.php:38
const ELGG_VALUE_STRING
Definition: constants.php:139
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
const ACCESS_PUBLIC
Definition: constants.php:14
if(elgg_view_exists("plugins/{$plugin_id}/settings")) $description
Definition: full.php:179
getDomain()
Get the domain for this site.
Definition: ElggSite.php:166
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:307
initializeAttributes()
{}
Definition: ElggSite.php:28