Elgg  Version 3.0
AdminNotices.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database;
4 
16 class AdminNotices {
17 
33  public function add($id, $message) {
34  if (!$id || !$message) {
35  return false;
36  }
37 
39  return false;
40  }
41 
42  // need to handle when no one is logged in
43  $old_ia = _elgg_services()->session->setIgnoreAccess(true);
44 
45  $admin_notice = new \ElggObject();
46  $admin_notice->subtype = 'admin_notice';
47  // admins can see ACCESS_PRIVATE but no one else can.
48  $admin_notice->access_id = ACCESS_PRIVATE;
49  $admin_notice->admin_notice_id = $id;
50  $admin_notice->description = $message;
51 
52  $result = $admin_notice->save();
53 
54  _elgg_services()->session->setIgnoreAccess($old_ia);
55 
56  if (!$result) {
57  return false;
58  }
59 
60  return $admin_notice;
61  }
62 
70  public function delete($id = '') {
71  $result = true;
72 
73  $notices = $this->find([
74  'metadata_name' => 'admin_notice_id',
75  'metadata_value' => $id,
76  'limit' => false,
77  'batch' => true,
78  'batch_inc_offset' => false,
79  ]);
80 
81  $ia = _elgg_services()->session->setIgnoreAccess(true);
82 
83  // in case a bad plugin adds many, let it remove them all at once.
84  foreach ($notices as $notice) {
85  $result = ($result && $notice->delete());
86  }
87 
88  _elgg_services()->session->setIgnoreAccess($ia);
89 
90  return $result;
91  }
92 
100  public function find(array $options = []) {
101  $options = array_merge($options, [
102  'type' => 'object',
103  'subtype' => 'admin_notice',
104  ]);
105 
106  return Entities::find($options);
107  }
108 
117  public function exists($id) {
118  $old_ia = _elgg_services()->session->setIgnoreAccess(true);
120  'type' => 'object',
121  'subtype' => 'admin_notice',
122  'metadata_name_value_pair' => ['name' => 'admin_notice_id', 'value' => $id],
123  'count' => true,
124  ]);
125  _elgg_services()->session->setIgnoreAccess($old_ia);
126 
127  return ($notice) ? true : false;
128  }
129 }
elgg_admin_notice_exists($id)
Check if an admin notice is currently active.
Definition: admin.php:95
exists($id)
Check if an admin notice is currently active.
if($count > 5) $notices
static find(array $options=[])
Build and execute a new query from an array of legacy options.
Definition: Repository.php:85
$options
Elgg admin footer.
Definition: footer.php:6
$id
River item delete action.
Definition: delete.php:6
const ACCESS_PRIVATE
Definition: constants.php:12
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
add($id, $message)
Write a persistent message to the admin view.
find(array $options=[])
Get admin notices.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
WARNING: API IN FLUX.