Angel Fernando Quiroz Campos e5d5fd2265 Minor - Flint fixes - refs BT#15821 5 ani în urmă
..
interfaces e5d5fd2265 Minor - Flint fixes - refs BT#15821 5 ani în urmă
HookAdminBlock.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookConditionalLogin.php f503aa75a7 Add hooks for conditional login - refs BT#15813 5 ani în urmă
HookCreateCourse.php 6a21f38c32 Allow add hooks when creating course - refs BT#14552 6 ani în urmă
HookCreateUser.php b0d43b5e69 Minor - fix phpdoc - refs BT#15813 5 ani în urmă
HookEvent.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookManagement.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookMyStudentsLpTracking.php 4741443dd3 Add hook system for My Student's LP tracking table - refs BT#15821 5 ani în urmă
HookMyStudentsQuizTracking.php 91ab2f7353 Add hook system for My Student's Quizzes tracking table - refs BT#15821 5 ani în urmă
HookNotificationContent.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookNotificationTitle.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookObserver.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookResubscribe.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookSkype.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
HookUpdateUser.php b739373a9e Set user as event data in update user hook - refs BT#14666 6 ani în urmă
HookWSRegistration.php ecdc2037e2 Applied fixes from FlintCI 6 ani în urmă
README.md 0a8495e3b5 Remove gid unset, use api_get_group_id, api_get_course_id 9 ani în urmă

README.md

Hook Management plugin for Chamilo LMS

Enable hooks in Chamilo to allow plugins and core to extend current features and watch for certain events.

The Hooks structure is based on the Observer pattern

The base structure is composed of 3 Interfaces

  • HookEvent: will call the hook methods in Chamilo code
  • HookObserver: will be executed when a Hook event is called
  • HookManagement: manages hooks, creation, instantiation, persistence and connection to the database

From version 1.10.x, the following Hooks (or more) exist:

Number Directory EventClass ObserverInterface Reference
1 /main/inc/lib/usermanager.lib.php HookCreateUser HookCreateUserObserverInterface UserManager::createUser()
2 /main/inc/lib/usermanager.lib.php HookUpdateUser HookUpdateUserObserverInterface UserManager::updateUser()
3 /main/admin/index.php HookAdminBlock HookAdminBlockObserverInterface ADMIN BLOCK

What do I need to use Hooks?

You need to create a class extending the HookObserver class and implement any (or many) Hook Observer Interfaces, e.g. HookCreateUserObserverInterface. An observer can implement many Hook Observer Interfaces. This was developed to allow plugins to have a unique Hook Observer class. Don't forget to add your Hook Observer class to the autoload file (vendor/composer/autoload_classmap.php).

How to add MyHookObserver to my plugin?

When installing your plugin (or other functions) you should call the attach method from a specific Hook Observer class, e.g. HookCreateUser class

$myHookObserver = MyHookObserver::create();
HookCreateUser::create()->attach($myHookObserver);

How to detach MyHookObserver from inside my plugin?

To detach the HookObserver, it should be detached from a specific Hook Event class

$myHookObserver = MyHookObserver::create();
HookCreateUser::create()->detach($myHookObserver);

How to add HookEvents to the Chamilo code (add the possibility to be hooked)?

To expand Hooks in Chamilo you should:

  1. Identify an event that could be customized through a plugin
  2. Create an interface for the Hook Event and the Hook Observer. The names should be like the Hooks interfaces already created, with The Pattern: HookXyzEventInterface and HookXyzObserverInterface. e.g. Hook event: HookUpdateUserEventInterface, Hook observer: HookUpdateUserObserverInterface
  3. Add at least one notify method to Hook Event Interface and update method to Hook Observer Interface
  4. Create a class extending the HookEvent class and implementing your Hook Event Interface
  5. Complete the notify method calling the Hook Observer update
  6. Add your Interfaces and Class to the autoload file (vendor/composer/autoload_classmap.php)
  7. Test your hook. If your Observer requires data, you can use the data property from Hook Event