return the users wishlist. if no wishlist exists, the method will return
null - unless the option bCreateIfNotExists is set, then we will
create a new on.

@param bool $bCreateIfNotExists

@return TdbPkgShopWishlist
330598
public function &GetWishlist($bCreateIfNotExists = false)
    {
        $oWishlist = &$this->GetFromInternalCache('oUserWishlist');
        if (is_null($oWishlist)) {
            $oWishlists = $this->GetFieldPkgShopWishlistList();
            if ($oWishlists->Length() > 0) {
                $oWishlist = $oWishlists->Current();
            }
            if (is_null($oWishlist) && $bCreateIfNotExists) {
                $oWishlist = TdbPkgShopWishlist::GetNewInstance();
                /** @var $oWishlist TdbPkgShopWishlist */
                if (!$oWishlist->LoadFromField('data_extranet_user_id', $this->id)) {
                    $aBaseData = array('data_extranet_user_id' => $this->id, 'is_public' => '0');
                    $oWishlist->LoadFromRow($aBaseData);
                    $oWishlist->Save();
                }
            }
            $this->SetInternalCache('oUserWishlist', $oWishlist);
        }

        return $oWishlist;
    }
677907
public function getWishList()
    {
        if ($this->_oWishList === null) {
            $this->_oWishList = false;

            // passing wishlist information
            if ($oUser = $this->getWishUser()) {
                $oWishlistBasket = $oUser->getBasket('wishlist');
                $this->_oWishList = $oWishlistBasket->getArticles();

                if (!$oWishlistBasket->isVisible()) {
                    $this->_oWishList = false;
                }
            }
        }

        return $this->_oWishList;
    }
151774
public static function getMySets($user = false)
    {
        $app = Facade::getFacadeApplication();

        if ($user === false) {
            $user = $app->make(User::class);
        }

        /** @var $database \Concrete\Core\Database\Connection\Connection */
        $database = $app->make('database')->connection();
        $fileSets = array();

        $queryBuilder = $database->createQueryBuilder();
        $results = $queryBuilder->select('*')->from('FileSets')->where(
            $queryBuilder->expr()->eq('fsType', self::TYPE_PUBLIC)
            )->orWhere(
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->in('fsType',[self::TYPE_PRIVATE, self::TYPE_STARRED, self::TYPE_PUBLIC]),
                    $queryBuilder->expr()->eq('uID', $user->getUserID())
                )
            )->orderBy('fsName', 'ASC')->execute();


        while ($row = $results->fetch()) {
            $fileSet = new static();
            $fileSet = array_to_object($fileSet, $row);
            $fileSets[] = $fileSet;
        }

        return $fileSets;
    }
221207
public static function create_users($users) {
        global $CFG, $DB;
        require_once($CFG->dirroot."/lib/weblib.php");
        require_once($CFG->dirroot."/user/lib.php");
        require_once($CFG->dirroot."/user/editlib.php");
        require_once($CFG->dirroot."/user/profile/lib.php"); // Required for customfields related function.

        // Ensure the current user is allowed to run this function.
        $context = context_system::instance();
        self::validate_context($context);
        require_capability('moodle/user:create', $context);

        // Do basic automatic PARAM checks on incoming data, using params description.
        // If any problems are found then exceptions are thrown with helpful error messages.
        $params = self::validate_parameters(self::create_users_parameters(), array('users' => $users));

        $availableauths  = core_component::get_plugin_list('auth');
        unset($availableauths['mnet']);       // These would need mnethostid too.
        unset($availableauths['webservice']); // We do not want new webservice users for now.

        $availablethemes = core_component::get_plugin_list('theme');
        $availablelangs  = get_string_manager()->get_list_of_translations();

        $transaction = $DB->start_delegated_transaction();

        $userids = array();
        foreach ($params['users'] as $user) {
            // Make sure that the username, firstname and lastname are not blank.
            foreach (array('username', 'firstname', 'lastname') as $fieldname) {
                if (trim($user[$fieldname]) === '') {
                    throw new invalid_parameter_exception('The field '.$fieldname.' cannot be blank');
                }
            }

            // Make sure that the username doesn't already exist.
            if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
                throw new invalid_parameter_exception('Username already exists: '.$user['username']);
            }

            // Make sure auth is valid.
            if (empty($availableauths[$user['auth']])) {
                throw new invalid_parameter_exception('Invalid authentication type: '.$user['auth']);
            }

            // Make sure lang is valid.
            if (empty($availablelangs[$user['lang']])) {
                throw new invalid_parameter_exception('Invalid language code: '.$user['lang']);
            }

            // Make sure lang is valid.
            if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) { // Theme is VALUE_OPTIONAL,
                                                                                     // so no default value
                                                                                     // We need to test if the client sent it
                                                                                     // => !empty($user['theme']).
                throw new invalid_parameter_exception('Invalid theme: '.$user['theme']);
            }

            // Make sure we have a password or have to create one.
            $authplugin = get_auth_plugin($user['auth']);
            if ($authplugin->is_internal() && empty($user['password']) && empty($user['createpassword'])) {
                throw new invalid_parameter_exception('Invalid password: you must provide a password, or set createpassword.');
            }

            $user['confirmed'] = true;
            $user['mnethostid'] = $CFG->mnet_localhost_id;

            // Start of user info validation.
            // Make sure we validate current user info as handled by current GUI. See user/editadvanced_form.php func validation().
            if (!validate_email($user['email'])) {
                throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
            } else if (empty($CFG->allowaccountssameemail)) {
                // Make a case-insensitive query for the given email address.
                $select = $DB->sql_equal('email', ':email', false) . ' AND mnethostid = :mnethostid';
                $params = array(
                    'email' => $user['email'],
                    'mnethostid' => $user['mnethostid']
                );
                // If there are other user(s) that already have the same email, throw an error.
                if ($DB->record_exists_select('user', $select, $params)) {
                    throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
                }
            }
            // End of user info validation.

            $createpassword = !empty($user['createpassword']);
            unset($user['createpassword']);
            $updatepassword = false;
            if ($authplugin->is_internal()) {
                if ($createpassword) {
                    $user['password'] = '';
                } else {
                    $updatepassword = true;
                }
            } else {
                $user['password'] = AUTH_PASSWORD_NOT_CACHED;
            }

            // Create the user data now!
            $user['id'] = user_create_user($user, $updatepassword, false);

            $userobject = (object)$user;

            // Set user interests.
            if (!empty($user['interests'])) {
                $trimmedinterests = array_map('trim', explode(',', $user['interests']));
                $interests = array_filter($trimmedinterests, function($value) {
                    return !empty($value);
                });
                useredit_update_interests($userobject, $interests);
            }

            // Custom fields.
            if (!empty($user['customfields'])) {
                foreach ($user['customfields'] as $customfield) {
                    // Profile_save_data() saves profile file it's expecting a user with the correct id,
                    // and custom field to be named profile_field_"shortname".
                    $user["profile_field_".$customfield['type']] = $customfield['value'];
                }
                profile_save_data((object) $user);
            }

            if ($createpassword) {
                setnew_password_and_mail($userobject);
                unset_user_preference('create_password', $userobject);
                set_user_preference('auth_forcepasswordchange', 1, $userobject);
            }

            // Trigger event.
            \core\event\user_created::create_from_userid($user['id'])->trigger();

            // Preferences.
            if (!empty($user['preferences'])) {
                $userpref = (object)$user;
                foreach ($user['preferences'] as $preference) {
                    $userpref->{'preference_'.$preference['type']} = $preference['value'];
                }
                useredit_update_user_preference($userpref);
            }

            $userids[] = array('id' => $user['id'], 'username' => $user['username']);
        }

        $transaction->allow_commit();

        return $userids;
    }
539212
public function getIContacts($force = false)
     {
         if ($this->nb_icontact_list->isEmpty() || $force) {
             $this->nb_icontact_list->clear();
             $this->nb_icontact_list->merge(CNabuIContact::getAlliContacts($this));
         }

         return $this->nb_icontact_list->getItems();
     }
1076846
public function getAttributeValueObject($ak, $createIfNotExists = false)
    {
        if (!is_object($ak)) {
            $ak = UserKey::getByHandle($ak);
        }
        if (is_object($ak)) {
            $value = $this->getObjectAttributeCategory()->getAttributeValue($ak, $this->entity);
        } else {
            $value = null;
        }

        if ($value === null && $createIfNotExists) {
            $value = new UserValue();
            $value->setUser($this->entity);
            $value->setAttributeKey($ak);
        }

        return $value;
    }
1137438
protected function getRequest($recreate = false)
    {
        if (!$recreate && $this->_request) {
            return $this->_request;
        }
        return $this->_request = HttpRequest::createFromGlobals($this->environment);
    }
666360
public function getCommerces($force = false)
    {
        if ($this->nb_commerce_list->isEmpty() || $force) {
            $this->nb_commerce_list->clear();
            $this->nb_commerce_list->merge(CNabuCommerce::getAllCommerces($this));
        }

        return $this->nb_commerce_list->getItems();
    }
1000805
static function &creatorList( $checkRoles = false )
    {
        $allowedCreators = false;

        $currentUser = eZUser::currentUser();
        $accessResult = $currentUser->hasAccessTo( 'package', 'create' );
        $limitationList = array();
        $canCreate = false;
        if ( $accessResult['accessWord'] == 'no' )
        {
            $creators = array();
            return $creators;
        }

        if ( $accessResult['accessWord'] == 'limited' )
        {
            $limitationList = $accessResult['policies'];
            foreach( $limitationList as $limitationArray ) // TODO : fix this
            {
                foreach ( $limitationArray as $key => $limitation )
                {
                    if ( $key == 'CreatorType' )
                    {
                        if ( !is_array( $allowedCreators ) )
                            $allowedCreators = array();
                        $list = $limitation;
                        $allowedCreators = array_merge( $allowedCreators, $list );
                    }
                }
            }
        }

        $creators =& $GLOBALS['eZPackageCreatorList'];
        if ( !isset( $creators ) )
        {
            $creators = array();
            $ini = eZINI::instance( 'package.ini' );
            $list = $ini->variable( 'CreationSettings', 'HandlerList' );
            foreach ( $list as $name )
            {
                if ( is_array( $allowedCreators ) and
                     !in_array( $name, $allowedCreators ) )
                     continue;
                $handler = eZPackageCreationHandler::instance( $name );
                $creators[] = $handler;
            }
        }
        return $creators;
    }
218479
public static function GetIndexes ($forced_obtain = false, $options = []) {
		$options += $options + static::GetDefaultOptions();
		return DBI::GetIndexes($options, static::GetName(), $forced_obtain);
	}
516168
protected function getVoucherList(TdbShopOrder $oOrder, $bSponsored = false, IMapperCacheTriggerRestricted $oCacheTriggerManager, $bCachingEnabled)
    {
        $aVoucherList = array();

        // get vouchers
        $oVoucherUseList = &$oOrder->GetFieldShopVoucherUseList();
        $oVoucherUseList->GoToStart();
        if (0 < $oVoucherUseList->Length()) {
            while ($oVoucherUse = &$oVoucherUseList->Next()) {
                if ($bCachingEnabled) {
                    $oCacheTriggerManager->addTrigger($oVoucherUse->table, $oVoucherUse->id);
                }
                $oVoucher = $oVoucherUse->GetFieldShopVoucher();
                if (null !== $oVoucher) {
                    if ($bCachingEnabled) {
                        $oCacheTriggerManager->addTrigger($oVoucher->table, $oVoucher->id);
                    }
                    if (false === $oVoucher->IsSponsored() && false === $bSponsored) {
                        $aVoucher = $this->getDataFromVoucher($oVoucherUse, $oVoucher, $oCacheTriggerManager, $bCachingEnabled);
                        $aVoucherList[] = $aVoucher;
                    } elseif (true === $oVoucher->IsSponsored() && true === $bSponsored) {
                        $aVoucher = $this->getDataFromVoucher($oVoucherUse, $oVoucher, $oCacheTriggerManager, $bCachingEnabled);
                        $aVoucherList[] = $aVoucher;
                    }
                } else {
                    $aVoucher = $this->getDataFromVoucher($oVoucherUse, null, $oCacheTriggerManager);
                    $aVoucherList[] = $aVoucher;
                }
            }
            $oVoucherUseList->GoToStart();
        }

        return $aVoucherList;
    }
234016
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();

        if (!is_a($context, \context_module::class)) {
            return;
        }

        $params = [
            'modname' => 'wiki',
            'contextlevel' => CONTEXT_MODULE,
            'contextid' => $context->id,
        ];

        $sql = "
          SELECT s.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);

        $sql = "
          SELECT p.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            JOIN {wiki_pages} p ON p.subwikiid = s.id
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);

        $sql = "
          SELECT v.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            JOIN {wiki_pages} p ON p.subwikiid = s.id
            JOIN {wiki_versions} v ON v.pageid = p.id
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);

        $sql = "
          SELECT l.userid
            FROM {modules} m
            JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
            JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
            JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
            JOIN {wiki_pages} p ON p.subwikiid = s.id
            JOIN {wiki_locks} l ON l.pageid = p.id
            WHERE ctx.id = :contextid";

        $userlist->add_from_sql('userid', $sql, $params);
        \core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $context->id);
    }
909196
public static function &GetLastCreatedOrder($bResetValue = false)
    {
        $oOrder = null;
        if (array_key_exists(self::SESSION_KEY_LAST_CREATED_ORDER_ID, $_SESSION)) {
            $oOrder = TdbShopOrder::GetNewInstance();
            /** @var $oOrder TdbShopOrder */
            if ($oOrder->Load($_SESSION[self::SESSION_KEY_LAST_CREATED_ORDER_ID])) {
                // now we want to make sure that the current user is the owner of that order. this is
                // the case if: the user is logged in and the user id in the order matches, or the user is
                // not logged in and the order has no user id
                $oUser = TdbDataExtranetUser::GetInstance();
                $isOwner = ($oUser->IsLoggedIn() && $oOrder->fieldDataExtranetUserId == $oUser->id);
                $isOwner = ($isOwner || (!$oUser->IsLoggedIn() && $oOrder->fieldDataExtranetUserId < 1));
                if (!$isOwner) {
                    $oOrder = null;
                }
            } else {
                $oOrder = null;
            }
            if ($bResetValue) {
                unset($_SESSION[self::SESSION_KEY_LAST_CREATED_ORDER_ID]);
            }
        }

        return $oOrder;
    }
1256383
public function getWishList(int $userId)
    {
        $response = $this->handler->handle('GET', false, 'wishlist/' . $userId);

        return $this->make($response, true);
    }
477408
public static function get_users_in_context(userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();

        if (!$context instanceof \context_user) {
            return;
        }

        $userid = $context->instanceid;

        $hasdata = false;
        $hasdata = $hasdata || $DB->record_exists_select('external_tokens', 'userid = ? OR creatorid = ?', [$userid, $userid]);
        $hasdata = $hasdata || $DB->record_exists('external_services_users', ['userid' => $userid]);

        if ($hasdata) {
            $userlist->add_user($userid);
        }
    }
1238313
protected function getProductsWishlist()
    {
        $list = $this->getWishlist();

        if (empty($list)) {
            return array();
        }

        $ids = array();

        foreach ((array) $list as $result) {
            $ids[] = $result['product_id'];
        }

        $conditions = array('product_id' => $ids);

        $options = array(
            'buttons' => array(
                'cart_add', 'wishlist_remove', 'compare_add')
        );

        return $this->getProducts($conditions, $options);
    }
433889
public function getUser($force = false)
    {
        if ($this->nb_user === null || $force) {
            $this->nb_user = null;
            if ($this instanceof CNabuDataObject &&
                $this->contains(NABU_USER_FIELD_ID) &&
                $this->isValueNumeric(NABU_USER_FIELD_ID)
            ) {
                $nb_user = new CNabuUser($this->getValue(NABU_USER_FIELD_ID));
                if ($nb_user->isFetched()) {
                    $this->nb_user = $nb_user;
                }
            }
        }

        return $this->nb_user;
    }