parent
							
								
									5cb082885a
								
							
						
					
					
						commit
						05ae9e78b1
					
				@ -0,0 +1,4 @@ | 
				
			|||||||
 | 
					Resubscription | 
				
			||||||
 | 
					============== | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Limit session resubscriptions | 
				
			||||||
@ -0,0 +1,9 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Config the plugin | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require_once api_get_path(SYS_PATH) . 'main/inc/global.inc.php'; | 
				
			||||||
@ -0,0 +1,8 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Config the plugin | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					require_once __DIR__ . '/config.php'; | 
				
			||||||
@ -0,0 +1,10 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Initialization install | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					require_once __DIR__ . '/config.php'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Resubscription::create()->install(); | 
				
			||||||
@ -0,0 +1,13 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Strings to english L10n | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					$strings['plugin_title'] = 'Resubscription'; | 
				
			||||||
 | 
					$strings['plugin_comment'] = 'This plugin limits session resubscription.'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$strings['resubscription_limit'] = 'Resubscription limit'; | 
				
			||||||
 | 
					$strings['resubscription_limit_help'] = 'This limits how often a user can be resubscribed'; | 
				
			||||||
 | 
					$strings['CanResubscribeFromX'] = 'Subscription available from %s'; | 
				
			||||||
@ -0,0 +1,13 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Strings to spanish L10n | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					$strings['plugin_title'] = 'Reinscripción'; | 
				
			||||||
 | 
					$strings['plugin_comment'] = 'Este plugin limita las reinscripiones a sesiones.'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$strings['resubscription_limit'] = 'Límite de reinscripción'; | 
				
			||||||
 | 
					$strings['resubscription_limit_help'] = 'Esto limita cada cuánto puede reinscribirse un usuario'; | 
				
			||||||
 | 
					$strings['CanResubscribeFromX'] = 'Inscripción posible a partir del %s'; | 
				
			||||||
@ -0,0 +1,10 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Get the plugin info | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					require_once __DIR__.'/config.php'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$plugin_info = Resubscription::create()->get_info(); | 
				
			||||||
@ -0,0 +1,2 @@ | 
				
			|||||||
 | 
					<h1>Resubscription</h1> | 
				
			||||||
 | 
					<p>Limit session resubscriptions</p> | 
				
			||||||
@ -0,0 +1,98 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Hook to limit session resubscriptions | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					class HookResubscription extends HookObserver implements HookResubscribeObserverInterface | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Class constructor | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public function __construct() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        parent::__construct( | 
				
			||||||
 | 
					            'plugin/resubscription/src/Resubscription.php', 'resubscription' | 
				
			||||||
 | 
					        ); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Limit session resubscription when a Chamilo user is resubscribed to a session | 
				
			||||||
 | 
					     * @param HookCreateUserEventInterface $hook The hook | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public function hookResubscribe(HookResubscribeEventInterface $hook) | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        $data = $hook->getEventData(); | 
				
			||||||
 | 
					        if ($data['type'] === HOOK_EVENT_TYPE_PRE) { | 
				
			||||||
 | 
					            $resubscriptionLimit = Resubscription::create()->get('resubscription_limit'); | 
				
			||||||
 | 
					            $limitDate = gmdate('Y-m-d', strtotime(gmdate('Y-m-d')." -$resubscriptionLimit year")); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $join = " INNER JOIN ".Database::get_main_table(TABLE_MAIN_SESSION)."ON id = id_session"; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // User sessions and courses | 
				
			||||||
 | 
					            $userSessions = Database::select( | 
				
			||||||
 | 
					                'id_session, date_end', | 
				
			||||||
 | 
					                Database::get_main_table(TABLE_MAIN_SESSION_USER).$join, | 
				
			||||||
 | 
					                array( | 
				
			||||||
 | 
					                    'where' => array( | 
				
			||||||
 | 
					                        'id_user = ? AND date_end >= ?' => array( | 
				
			||||||
 | 
					                            api_get_user_id(), | 
				
			||||||
 | 
					                            $limitDate | 
				
			||||||
 | 
					                        ) | 
				
			||||||
 | 
					                    ), | 
				
			||||||
 | 
					                    'order' => 'date_end DESC' | 
				
			||||||
 | 
					                ) | 
				
			||||||
 | 
					            ); | 
				
			||||||
 | 
					            $userSessionCourses = array(); | 
				
			||||||
 | 
					            foreach ($userSessions as $userSession) { | 
				
			||||||
 | 
					                $userSessionCourseResult = Database::select( | 
				
			||||||
 | 
					                    'course_code', | 
				
			||||||
 | 
					                    Database::get_main_table(TABLE_MAIN_SESSION_COURSE), | 
				
			||||||
 | 
					                    array( | 
				
			||||||
 | 
					                        'where' => array( | 
				
			||||||
 | 
					                            'id_session = ?' => array( | 
				
			||||||
 | 
					                                $userSession['id_session'] | 
				
			||||||
 | 
					                            ) | 
				
			||||||
 | 
					                        ) | 
				
			||||||
 | 
					                    ) | 
				
			||||||
 | 
					                ); | 
				
			||||||
 | 
					                foreach ($userSessionCourseResult as $userSessionCourse) { | 
				
			||||||
 | 
					                    if (!isset($userSessionCourses[$userSessionCourse['course_code']])) { | 
				
			||||||
 | 
					                        $userSessionCourses[$userSessionCourse['course_code']] = $userSession['date_end']; | 
				
			||||||
 | 
					                    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Current session and courses | 
				
			||||||
 | 
					            $currentSessionCourseResult = Database::select( | 
				
			||||||
 | 
					                'course_code', | 
				
			||||||
 | 
					                Database::get_main_table(TABLE_MAIN_SESSION_COURSE), | 
				
			||||||
 | 
					                array( | 
				
			||||||
 | 
					                    'where' => array( | 
				
			||||||
 | 
					                        'id_session = ?' => array( | 
				
			||||||
 | 
					                            $data['session_id'] | 
				
			||||||
 | 
					                        ) | 
				
			||||||
 | 
					                    ) | 
				
			||||||
 | 
					                ) | 
				
			||||||
 | 
					            ); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Check if current course code matches with one of the users | 
				
			||||||
 | 
					            foreach ($currentSessionCourseResult as $currentSessionCourse) { | 
				
			||||||
 | 
					                if (isset($userSessionCourses[$currentSessionCourse['course_code']])) { | 
				
			||||||
 | 
					                    $endDate = $userSessionCourses[$currentSessionCourse['course_code']]; | 
				
			||||||
 | 
					                    $resubscriptionDate = gmdate('Y-m-d', strtotime($endDate." +$resubscriptionLimit year")); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    $icon = Display::return_icon('students.gif', get_lang('Student')); | 
				
			||||||
 | 
					                    $canResubscribeFrom = sprintf(get_plugin_lang('CanResubscribeFromX', 'resubscription'), $resubscriptionDate); | 
				
			||||||
 | 
					                    $data['result'] = Display::label($icon . ' ' . $canResubscribeFrom, "info"); | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,72 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Limit session resubscriptions | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					class Resubscription extends Plugin implements HookPluginInterface | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Class constructor | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    protected function __construct() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        $parameters = array( | 
				
			||||||
 | 
					            'resubscription_limit' => 'text' | 
				
			||||||
 | 
					        ); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        parent::__construct('0.1', 'Imanol Losada Oriol', $parameters); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Instance the plugin | 
				
			||||||
 | 
					     * @staticvar null $result | 
				
			||||||
 | 
					     * @return Resubscription | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    static function create() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        static $result = null; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $result ? $result : $result = new self(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Install the plugin | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public function install() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        $this->installHook(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Uninstall the plugin | 
				
			||||||
 | 
					     * @return void | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public function uninstall() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        $this->uninstallHook(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Install the Resubscription hook | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public function installHook() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        $hook = HookResubscription::create(); | 
				
			||||||
 | 
					        HookResubscribe::create()->attach($hook); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * Uninstall the Resubscription hook | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    public function uninstallHook() | 
				
			||||||
 | 
					    { | 
				
			||||||
 | 
					        $hook = HookResubscription::create(); | 
				
			||||||
 | 
					        HookResubscribe::create()->detach($hook); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,10 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Initialization uninstall | 
				
			||||||
 | 
					 * @author Imanol Losada Oriol <imanol.losada@beeznest.com> | 
				
			||||||
 | 
					 * @package chamilo.plugin.resubscription | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					require_once __DIR__ . '/config.php'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Resubscription::create()->uninstall(); | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue