@author Leo Fajardo (@leorw)
@since  2.0.0

@param array       $new_user_id_license_ids_map
@param number      $module_id
@param number|null $user_id
428753
private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
            $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
            if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
                $all_modules_user_id_license_ids_map = array();
            }

            if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
                $all_modules_user_id_license_ids_map[ $module_id ] = array();
            }

            if ( FS_User::is_valid_id( $user_id ) ) {
                $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
            } else {
                $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
            }

            self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
        }
1130385
function _update_site_license( $new_license ) {
            $this->_logger->entrance();

            $this->_license = $new_license;

            if ( ! is_object( $new_license ) ) {
                $this->_site->license_id = null;
                $this->_sync_site_subscription( null );

                return $this->_license;
            }

            $this->_site->license_id = $this->_license->id;

            if ( ! is_array( $this->_licenses ) ) {
                $this->_licenses = array();
            }

            $is_license_found = false;
            for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
                if ( $new_license->id == $this->_licenses[ $i ]->id ) {
                    $this->_licenses[ $i ] = $new_license;

                    $is_license_found = true;
                    break;
                }
            }

            // If new license just append.
            if ( ! $is_license_found ) {
                $this->_licenses[] = $new_license;
            }

            $this->_sync_site_subscription( $new_license );

            return $this->_license;
        }
301020
private function _userId($userId)
    {
        if (!$userId) {
            $currentUser = Craft::$app->getUser()->getIdentity();
            if ($currentUser) {
                $userId = $currentUser->id;
            }
        }
        return (int)($userId);
    }
80980
public function canInstall($module_id)
    {
        if ($this->module->isInstalled($module_id)) {
            throw new UnexpectedValueException($this->translation->text('Module already installed'));
        }

        if ($this->module->isLocked($module_id)) {
            throw new UnexpectedValueException($this->translation->text('Module is locked in code'));
        }

        if ($this->module->isInstaller($module_id)) {
            $error = $this->translation->text('Modules with "installer" type cannot be installed/enabled when system is already set up');
            throw new UnexpectedValueException($error);
        }

        $this->module->getInstance($module_id); // Test module class
        return $this->checkRequirements($module_id);
    }
1215024
public function activateModule($moduleId, $shopId, $output)
    {
        /** @var ModuleInstaller $moduleInstaller */
        $moduleInstaller = Registry::get(ModuleInstaller::class);

        if ($shopId) {
            $oConfig = ShopConfig::get($shopId);
            $moduleInstaller->setConfig($oConfig);
        }

        $moduleList = oxNew(ModuleList::class);
        $moduleList->getModulesFromDir(Registry::getConfig()->getModulesDir());
        $modules = $moduleList->getList();

        /** @var Module $module */
        $module = $modules[$moduleId];
        if ($module == null) {
            $output->writeLn("$moduleId not found. choose from:");
            $output->writeLn(join("\n", array_keys($modules)));

            exit(1);
        }

        if ($module->isActive()) {
            $output->writeLn("$moduleId already active");
        } else {
            $moduleInstaller->activate($module);
        }
    }
1219355
public static function set_user_id($user_id) {
	if (self::is_active() == false) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('inactive session');
	}
	
	$_SESSION['_session_user_id'] = $user_id;
}
1275416
public function setClientUser($client_id, $user_id)
    {
        if ($this->getClientUser($client_id, $user_id)) {
            return true;
        } else {
            $created_at = date('Y-m-d H:i:s');
            $sql        = 'INSERT INTO %s (client_id, user_id, created_at) VALUES (:client_id, :user_id, :created_at)';
            $sql        = sprintf($sql, $this->config['client_user_table']);

            $params = array_map('trim', compact('client_id', 'user_id', 'created_at'));

            return $this->db->prepare($sql)->execute($params);
        }
    }
566811
private function store_id_slug_type_path_map( $module_id, $slug ) {
            $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );

            $store_option = false;

            if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
                $id_slug_type_path_map[ $module_id ] = array(
                    'slug' => $slug
                );

                $store_option = true;
            }

            if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
                 /**
                  * This verification is for cases when suddenly the same module
                  * is installed but with a different folder name.
                  *
                  * @author Vova Feldman (@svovaf)
                  * @since  1.2.3
                  */
                 ! file_exists( $this->get_absolute_path(
                     $id_slug_type_path_map[ $module_id ]['path'],
                     $id_slug_type_path_map[ $module_id ]['type']
                 ) )
            ) {
                $caller_main_file_and_type = $this->get_caller_main_file_and_type();

                $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
                $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;

                $store_option = true;
            }

            if ( $store_option ) {
                self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
            }
        }
898959
public static function update($userId, $id, $params = null, $options = null)
    {
        return self::_userBasedUpdate($userId, $id, $params, $options);
    }
114769
public function is_course_complete($user_id) {
        $params = array(
            'userid'    => $user_id,
            'course'  => $this->course_id
        );

        $ccompletion = new completion_completion($params);
        return $ccompletion->is_complete();
    }
651193
function _add_license_activation() {
            if ( ! $this->is_user_admin() ) {
                // Only admins can activate a license.
                return;
            }

            if ( ! $this->has_paid_plan() ) {
                // Module doesn't have any paid plans.
                return;
            }

            if ( ! $this->is_premium() ) {
                // Only add license activation logic to the premium version.
                return;
            }

            // Add license activation link and AJAX request handler.
            if ( self::is_plugins_page() ) {
                /**
                 * @since 1.2.0 Add license action link only on plugins page.
                 */
                $this->_add_license_action_link();
            }

            // Add license activation AJAX callback.
            $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );

            // Add resend license AJAX callback.
            $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
        }
735171
private static function get_all_licenses( $module_id = null ) {
            $licenses = self::get_account_option( 'all_licenses' );

            if ( ! is_array( $licenses ) ) {
                $licenses = array();
            }

            if ( is_null( $module_id ) ) {
                return $licenses;
            }

            $licenses = isset( $licenses[ $module_id ] ) ?
                $licenses[ $module_id ] :
                array();

            return $licenses;
        }
757579
function _sync_licenses( $site_license_id = false, $blog_id = null ) {
            $this->_logger->entrance();

            $is_network_admin = fs_is_network_admin();

            if ( $is_network_admin && is_null( $blog_id ) ) {
                $all_licenses = self::get_all_licenses( $this->_module_id );
            } else {
                $all_licenses = $this->get_user_licenses( $this->_user->id );
            }

            $foreign_licenses = array(
                'ids'          => array(),
                'license_keys' => array()
            );

            $all_licenses_map = array();
            foreach ( $all_licenses as $license ) {
                $all_licenses_map[ $license->id ] = true;
                if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
                    continue;
                }

                $foreign_licenses['ids'][]          = $license->id;
                $foreign_licenses['license_keys'][] = $license->secret_key;
            }

            if ( empty( $foreign_licenses['ids'] ) ) {
                $foreign_licenses = array();
            }

            $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );

            if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
                $licenses_map = array();
                foreach ( $licenses as $license ) {
                    $licenses_map[ $license->id ] = true;
                }

//                $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
//                foreach ( $license_ids_to_keep as $license_id ) {
//                    if ( isset( $licenses_map[ $license_id ] ) ) {
//                        continue;
//                    }
//
//                    $missing_license = self::_get_license_by_id( $license_id, false );
//                    if ( is_object( $missing_license ) ) {
//                        $licenses[]                           = $missing_license;
//                        $licenses_map[ $missing_license->id ] = true;
//                    }
//                }

                $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );

                foreach ( $user_license_ids as $key => $license_id ) {
                    if ( ! isset( $licenses_map[ $license_id ] ) ) {
                        // Remove access to licenses that no longer exist.
                        unset( $user_license_ids[ $key ] );
                    }
                }

                if ( ! empty( $user_license_ids ) ) {
                    foreach ( $licenses_map as $license_id => $value ) {
                        if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
                            // Associate new licenses with the user who triggered the license syncing.
                            $user_license_ids[] = $license_id;
                        }
                    }

                    $user_license_ids = array_unique( $user_license_ids );
                } else {
                    $user_license_ids = array_keys( $licenses_map );
                }

                if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
                    $user_licenses = array();
                    foreach ( $licenses as $license ) {
                        if ( ! in_array( $license->id, $user_license_ids ) ) {
                            continue;
                        }

                        $user_licenses[] = $license;
                    }

                    $this->_licenses = $user_licenses;
                } else {
                    $this->_licenses = $licenses;
                }

                $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );

                $this->_store_licenses( true, $this->_module_id, $licenses );
            }

            // Update current license.
            if ( is_object( $this->_license ) ) {
                $this->_license = $this->_get_license_by_id( $this->_license->id );
            }

            return $this->_licenses;
        }
849410
public function installModule($plugin_id)
	{
		$moduleVendorPath = Yii::getPathOfAlias('application.vendor.ommu');
		$module = OmmuPlugins::model()->findByPk($plugin_id);

		if($module != null) {
			$moduleName = $module->folder;
			if($model->parent_id != 0)
				$moduleName = $module->parent->folder;
			
			if($model->install == 1) {
				$config = $this->getModuleConfig($moduleName);
				if($config) {
					$tableName = $config['db_table_name'];
					$fileName  = trim($config['db_sql_filename']);
					$sqlFile = $moduleVendorPath.'/'.$moduleName.'/data/'.$fileName;
	
					if($tableName && !empty($tableName) && $fileName != '' && file_exists($sqlFile)) {
						$tables  = Yii::app()->db->createCommand('SHOW FULL TABLES WHERE table_type = "BASE TABLE"')->queryColumn();
	
						if(!in_array($tableName[0], $tables)) {
							$sql = file_get_contents($sqlFile);
							Yii::app()->db->createCommand($sql)->execute();
						}
					}
				}

			} else
				$this->deleteModuleDatabase($moduleName);

		} else
			return false;
	}
638724
function _get_license_by_id( $id, $sync_licenses = true ) {
            $this->_logger->entrance();

            if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
                return false;
            }

            /**
             * When running from the network level admin and opted-in from the network,
             * check if the license exists in the network user licenses collection.
             *
             * @author Vova Feldman (@svovaf)
             * @since  2.0.0
             */
            if ( fs_is_network_admin() &&
                 $this->is_network_registered() &&
                 ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
            ) {
                $licenses = $this->get_user_licenses( $this->_storage->network_user_id );

                foreach ( $licenses as $license ) {
                    if ( $id == $license->id ) {
                        return $license;
                    }
                }
            }

            if ( ! $this->has_any_license() && $sync_licenses ) {
                $this->_sync_licenses( $id );
            }

            if ( is_array( $this->_licenses ) ) {
                foreach ( $this->_licenses as $license ) {
                    if ( $id == $license->id ) {
                        return $license;
                    }
                }
            }

            return false;
        }
746944
function _get_subscription( $license_id ) {
            if ( ! isset( $this->_storage->subscriptions ) ||
                 empty( $this->_storage->subscriptions )
            ) {
                return null;
            }

            foreach ( $this->_storage->subscriptions as $subscription ) {
                if ( $subscription->license_id == $license_id ) {
                    return $subscription;
                }
            }

            return null;
        }
718220
public function disable($module_id)
    {
        try {
            $result = $this->canDisable($module_id);
        } catch (Exception $ex) {
            $result = $ex->getMessage();
        }

        $this->hook->attach("module.disable.before|$module_id", $result, $this);

        if ($result !== true) {
            return $result;
        }

        if ($this->module->isInstalled($module_id)) {
            $this->module->update($module_id, array('status' => false));
        } else {
            $this->module->add(array('status' => false, 'module_id' => $module_id));
        }

        $this->setOverrideConfig();

        $this->hook->attach("module.disable.after|$module_id", $result, $this);
        return $result;
    }