-
lbrun authoredef83712a
Class_Entity
Description
In PHP we have StdClass on which we can set and get any direct property
$o = new StdClass();
$o->title = 'my title';
echo $o->title; // -> my title
Class_Entity provides same functionality with getter and setter methods
$o = new Class_Entity();
$o->setTitle('my title');
echo $o->getTitle(); // -> my title
Implementation
Any call to set*() will be catched to populate an internal key => value array, it will return $this to chain calls. Any call to get*() will look for an existing key in internal array and will return its value or null if not found.
Keys of internal array are not transformed in any way
- setMyValue will produce a 'MyValue' key
- set_my_value will produce a '_my_value' key
- setmyvalue will produce a 'myvalue' key
You can define default values by setting
protected $_attribs = ['MyValue' => ''];
Then a getMyValue() call will return an empty string instead of null if not set.
Use cases
In tests
When you have an API relying on getter and setter methods you can provide a Class_Entity as a mock and easily verify that an attribute has been set or prepare it with attributes needed by tested code.
In general
When you are modeling an object and don't want to write all those standard getters and setters just extend Class_Entity.
ticket #22209
Search result
Reification of the array returned by Class_MoteurRecherche that contained queries for facets & record fetch. Now we have Class_MoteurRecherche_Result that depends on search engine & search criterias. Noticeable methods:
- recordsCollect($closure): for parsing all records. $closure must accept a record (Class_Notice).
- acceptCriteresVisitor($visitor): for parsing search criterias
Atom search feed generation
Add ZendAfi_Feed_SearchResult as a Class_MoteurRecherche_Result visitor that renders a search result as Atom feed.
ticket #24821
Notifications
In controllers, notifcations can be rendered as popup instead of static bars:
$this->getHelper('notify')->bePopup()
ZendAfi_Controller_Action_Helper_FlashMessenger notifications now stored as array and can accept parameters:
public function addNotification($message, $options = []) {
$params = ['message' => $message] + $options;
$this->addMessage([ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION => $params]);
}
and FlashMessengerNotification represent a notification. For example to get all popups notifications:
(new ZendAfi_Controller_Action_Helper_FlashMessenger())
->getNotifications()
->select(function($n) {return $n->isPopup();});
Users ILS subscription ('abonnement') related functions moved to new Class_User_ILSSubscription.
See Class_Users>>registerNotificationsOn for notifications usage.
ILS Web services
Add Class_WebService_SIGB_Reservation>>isWaitingToBePulled that returns true when holded document is available in library. Works for: Nanook, Koha, Microbib, Aloes, Carthame, Orphée, Pergame.
Reload module content with AJAX
On module ajax link, add tag attributes: 'data-reload-module = true'.
For example:
$this->view->tagAnchor($reload_link,
'',
['data-ajax-reload' => 'true',
'class' => 'reload-module',
'title' => $this->view->_('Recharger')]);
See public/opac/js/reload_module.js