Speed performance: Use static to avoid querying the database.

pull/3023/head
Julio Montoya 6 years ago
parent b34f9b30e9
commit 69a397636b
  1. 30
      main/inc/lib/banner.lib.php
  2. 47
      main/inc/lib/plugin.lib.php
  3. 25
      plugin/studentfollowup/StudentFollowUpPlugin.php

@ -155,6 +155,12 @@ function get_tabs($courseId = null)
*/
function getCustomTabs()
{
static $customTabs = null;
if ($customTabs !== null) {
return $customTabs;
}
$urlId = api_get_current_access_url_id();
$tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql = "SELECT * FROM $tableSettingsCurrent
@ -385,22 +391,18 @@ function return_navigation_array()
$menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
}
///if (api_is_student()) {
if (true) {
$params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']];
$result = api_get_settings_params_simple($params);
$installed = AppPlugin::getInstance()->isInstalled('studentfollowup');
if ($installed) {
$plugin = StudentFollowUpPlugin::create();
if (!empty($result) && $result['selected_value'] === 'installed') {
// Students
$url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
$url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/my_students.php';
}
$navigation['follow_up']['url'] = $url;
$navigation['follow_up']['title'] = $plugin->get_lang('CareDetailView');
$navigation['follow_up']['key'] = 'homepage';
$navigation['follow_up']['icon'] = 'homepage.png';
// Students
$url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
$url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/my_students.php';
}
$navigation['follow_up']['url'] = $url;
$navigation['follow_up']['title'] = $plugin->get_lang('CareDetailView');
$navigation['follow_up']['key'] = 'homepage';
$navigation['follow_up']['icon'] = 'homepage.png';
}
// Administration

@ -31,6 +31,8 @@ class AppPlugin
public $installedPluginListName = [];
public $installedPluginListObject = [];
private static $instance;
/**
* Constructor.
@ -39,6 +41,18 @@ class AppPlugin
{
}
/**
* @return AppPlugin
*/
public static function getInstance()
{
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Read plugin from path.
*
@ -100,6 +114,18 @@ class AppPlugin
$this->installedPluginListObject = $pluginList;
}
/**
* @param string $plugin
*
* @return bool
*/
public function isInstalled($plugin)
{
$list = self::getInstalledPlugins(false);
return in_array($plugin, $list);
}
/**
* @param bool $fromDatabase
*
@ -140,10 +166,9 @@ class AppPlugin
*/
public function install($pluginName, $urlId = null)
{
$urlId = (int) $urlId;
if (empty($urlId)) {
$urlId = api_get_current_access_url_id();
} else {
$urlId = intval($urlId);
}
api_add_setting(
@ -175,10 +200,9 @@ class AppPlugin
*/
public function uninstall($pluginName, $urlId = null)
{
$urlId = (int) $urlId;
if (empty($urlId)) {
$urlId = api_get_current_access_url_id();
} else {
$urlId = intval($urlId);
}
// First call the custom uninstall to allow full access to global settings
@ -188,6 +212,7 @@ class AppPlugin
require $pluginPath;
}
// Second remove all remaining global settings
api_delete_settings_params(
['category = ? AND access_url = ? AND subkey = ? ' => ['Plugins', $urlId, $pluginName]]
@ -212,16 +237,6 @@ class AppPlugin
return $areas;
}
/**
* @param string $location
*
* @return bool
*/
public function is_valid_plugin_location($location)
{
return in_array($location, $this->plugin_list);
}
/**
* @param string $pluginName
*
@ -459,9 +474,9 @@ class AppPlugin
$plugin_info = $this->getPluginInfo($pluginName);
if (isset($plugin_info) && isset($plugin_info['templates'])) {
return $plugin_info['templates'];
} else {
return false;
}
return false;
}
/**

@ -92,14 +92,8 @@ class StudentFollowUpPlugin extends Plugin
*/
public static function getPermissions($studentId, $currentUserId)
{
$params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']];
$result = api_get_settings_params_simple($params);
$installed = false;
if (!empty($result) && $result['selected_value'] === 'installed') {
$installed = true;
}
if ($installed == false) {
$installed = AppPlugin::getInstance()->isInstalled('studentfollowup');
if ($installed === false) {
return [
'is_allow' => false,
'show_private' => false,
@ -187,8 +181,6 @@ class StudentFollowUpPlugin extends Plugin
switch ($status) {
case COURSEMANAGER:
/*$sessions = SessionManager::get_sessions_by_user($currentUserId);
$sessions = array_column($sessions, 'session_id');*/
$sessionsFull = SessionManager::getSessionsCoachedByUser($currentUserId);
$sessions = array_column($sessionsFull, 'id');
if (!empty($sessionId)) {
@ -229,19 +221,6 @@ class StudentFollowUpPlugin extends Plugin
$limit
);
/*$userList = [];
foreach ($sessions as $sessionId) {
foreach ($courses as $courseId) {
$courseInfo = ['real_id' => $courseId];
$userFromSessionList = SessionManager::getUsersByCourseSession(
$sessionId,
$courseInfo
);
$userList = array_merge($userList, $userFromSessionList);
}
$userList = array_unique($userList);
}*/
return [
'users' => $userList,
'sessions' => $sessionsFull,

Loading…
Cancel
Save