for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\View\Cell;
use Cake\Core\Configure;
use Cake\View\Cell;
class NotificationCell extends Cell
{
/**
* Display the notifications.
*
* @return \Cake\Network\Response
*/
public function notifications()
$this->loadModel('Notifications');
$notifications = $this->Notifications
Notifications
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
->find()
->where([
'user_id' => $this->request->session()->read('Auth.User.id')
])
->order([
'is_read' => 'ASC',
'created' => 'DESC'
->limit(Configure::read('User.max_notifications'))
->find('map', [
'session' => $this->request->session()
->toArray();
$statistics = [
'read' => 0,
'unread' => 0
];
//A map function to count the read/unread notifications
$map = function ($v) {
if ($v->is_read == 0) {
return 'unread';
} else {
return 'read';
}
};
$statistics = array_merge(
$statistics,
array_count_values(
array_map(
$map,
$notifications
)
);
$hasNewNotifs = ($statistics['unread'] >= 1) ? true : false;
$this->set(compact('notifications', 'statistics', 'hasNewNotifs'));
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: