Returns a random ID from a particular model

@param string $sModel    The model to use
@param string $sProvider The model's provider
@param array  $aData     Any data to pass to the model

@return int|null
518116
protected function randomId($sModel, $sProvider, $aData = [])
    {
        $oModel   = Factory::model($sModel, $sProvider);
        $aResults = $oModel->getAll(0, 1, $aData + ['sort' => [['id', 'random']]]);
        $oRow     = reset($aResults);

        return $oRow ? $oRow->id : null;
    }
98769
public static function generateToken($sMask = null, $aChars = [], $aDigits = [])
    {
        $sMask   = empty($sMask) ? 'AAAA-AAAA-AAAA-AAAA-AAAA-AAAA' : $sMask;
        $aChars  = empty($aChars) ? str_split('abcdefghijklmnopqrstuvwxyz') : $aChars;
        $aDigits = empty($aDigits) ? str_split('0123456789') : $aDigits;

        $aMask    = str_split(strtoupper($sMask));
        $aOut     = [];
        $iMaskLen = count($aMask);

        for ($i = 0; $i < $iMaskLen; $i++) {

            if ($aMask[$i] === 'A') {

                if (mt_rand(0, 1)) {
                    $aOut[] = random_element($aChars);
                } else {
                    $aOut[] = random_element($aDigits);
                }

            } else {
                if ($aMask[$i] === 'C') {

                    $aOut[] = random_element($aChars);

                } else {
                    if ($aMask[$i] === 'D') {

                        $aOut[] = random_element($aDigits);

                    } else {

                        $aOut[] = $aMask[$i];
                    }
                }
            }
        }

        return implode($aOut);
    }
148084
public function getAssertionId()
    {
        if (!$this->validateNumAssertions()) {
            throw new InvalidArgumentException("SAML Response must contain 1 Assertion.");
        }
        $assertionNodes = $this->_queryAssertion("");
        $id = null;
        if ($assertionNodes->length == 1 && $assertionNodes->item(0)->hasAttribute('ID')) {
            $id = $assertionNodes->item(0)->getAttribute('ID');
        }
        return $id;
    }
1114248
protected function setDataSlug(array &$aData, bool $bIsCreate = true, int $iIgnoreId = null): Base
    {
        if ($this->isAutoSetSlugs() &&
            empty($aData[$this->tableSlugColumn]) &&
            ($bIsCreate || !static::AUTO_SET_SLUG_IMMUTABLE)
        ) {

            if (empty($this->tableSlugColumn)) {
                throw new ModelException(static::class . '::create() Slug column variable not set', 1);
            }

            if (empty($this->tableLabelColumn)) {
                throw new ModelException(static::class . '::create() Label column variable not set', 1);
            }

            if (empty($aData[$this->tableLabelColumn])) {
                throw new ModelException(
                    static::class . '::create() "' . $this->tableLabelColumn .
                    '" is required when automatically generating slugs.',
                    1
                );
            }

            $aData[$this->tableSlugColumn] = $this->generateSlug(
                $aData[$this->tableLabelColumn],
                $iIgnoreId
            );
        }

        return $this;
    }
382500
public function getModuleUrl($sModule, $sFile = '')
    {
        $c = $this->getConfig();
        $shopUrl = null;
        if ($this->isAdmin()) {
            if ($c->isSsl()) {
                // From admin and with SSL we try to use sAdminSSLURL config directive
                $shopUrl = $c->getConfigParam('sAdminSSLURL');
                if ($shopUrl) {
                    // but we don't need the admin directory
                    $adminDir = '/'.$c->getConfigParam('sAdminDir');
                    $shopUrl = substr($shopUrl, 0, -strlen($adminDir));
                } else {
                    // if no sAdminSSLURL directive were defined we use sSSLShopURL config directive instead
                    $shopUrl = $c->getConfigParam('sSSLShopURL');
                }
            }
            // From admin and with no config usefull directive, we use the sShopURL directive
            if (!$shopUrl) {
                $shopUrl = $c->getConfigParam('sShopURL');
            }
        }
        // We are either in front, or in admin with no $sShopURL defined
        if (!$shopUrl) {
            $shopUrl = $c->getCurrentShopUrl();
        }
        $shopUrl = rtrim($shopUrl, '/');

        $sUrl = str_replace(
            rtrim($c->getConfigParam('sShopDir'), '/'),
            $shopUrl,
            $this->getModulePath($sModule, $sFile)
        );

        return $sUrl;
    }
759547
public function getRandom()
    {
        return empty($this->entities) ? null : $this->entities[array_rand($this->entities)];
    }
538166
public function getModel($sModel)
    {
        $namespacedClass = $this['database.models_namespace'] . '\\' . $sModel;

        if (!isset(static::$models[$sModel])) {
            static::$models[$sModel] = new $namespacedClass($this);
        }

        return static::$models[$sModel];
    }
214745
public function createId( $nCenter, $nNode, $sSource = null, & $arrData = null )
	{
		if ( ! $this->isValidCenterId( $nCenter ) )
		{
			return null;
		}
		if ( ! $this->isValidNodeId( $nNode ) )
		{
			return null;
		}

		//	...
		$nRet		= 0;
		$nTime		= $this->getEscapedTime();
		$nCenter	= intval( $nCenter );
		$nNode		= intval( $nNode );

		if ( is_string( $sSource ) && strlen( $sSource ) > 0 )
		{
			//	use crc32 hash value instead of rand
			$nRand	= crc32( $sSource );
		}
		else
		{
			//	0 ~ 4095
			$nRand	= rand( 0, 0xFFF );
		}

		//	...
		$nCenterV	= ( ( $nCenter << 17 ) & 0x00000000003E0000 );
		$nNodeV		= ( ( $nNode   << 12 ) & 0x000000000001F000 );
		$nTimeV		= ( ( $nTime   << 22 ) & 0x7FFFFFFFFFC00000 );
		$nRandV		= ( ( $nRand   << 0  ) & 0x0000000000000FFF );

		$nRet		= ( $nCenterV + $nNodeV + $nTimeV + $nRandV );

		//	...
		if ( ! is_null( $arrData ) )
		{
			$arrData =
			[
				'center'	=> $nCenter,
				'node'		=> $nNode,
				'time'		=> $nTime,
				'rand'		=> $nRandV,
			];
		}

		return intval( $nRet );
	}
392268
public function evtAddFile(ServiceManager $sm, array $params)
    {
        /** @var ZF3GotServices $gs */
        $gs         = $sm->get('graphic.object.templating.services');
        $ret        = [];
        /** @var ODDragNDrop $objet */
        $sessionObj = self::validateSession();
        /** @var ODDragNDrop $objet */
        $objet      = self::buildObject($params['id'], $sessionObj);

        $maxCountFile   = $objet->getMaxFileCount();
        $loadedFiles    = $objet->getLoadedFiles();

        if ($maxCountFile === 0 || sizeof($loadedFiles) < $maxCountFile) {
            $tempFolder = $objet->getTempFolder();
            $pathPublic = $_SERVER['DOCUMENT_ROOT'];
            /** si tempFolder vide, voir de créer un répertoire uploadFile dans public */
            if (empty($tempFolder)) {
                if (!file_exists($pathPublic.'/uploadedFiles')) {
                    $returnCall  = shell_exec('cd '.$pathPublic.' 2>&1');

                    $returnCall .= shell_exec('mkdir public/uploadedFiles 2>&1');
                    $returnCall .= shell_exec('chmod 777 public/uploadedFiles/ 2>&1');
                    if (!empty($returnCall)) { throw new Exception($returnCall); }
                }
                $tempFolder  = $pathPublic.'/uploadedFiles';
            }

            /**
             * traitement d'ajout d'un fichier
             */
            $fileName   = $params['name'];
            $fileExt    = pathinfo($fileName, PATHINFO_EXTENSION);
            $mimeType   = $this->getMimeString($fileExt);
            $imgSrc     = $params['file'];
            $imgFile    = base64_decode($imgSrc);
            $dest       = $tempFolder.'/'.$fileName;
            if ( $objet->addLoadedFile($params['name'], $dest) !== false ) {
                $file       = fopen($dest, 'wb');
                fwrite($file, $imgFile);
                fclose($file);

                $objet->setTempFolder($tempFolder);
                $objet->saveProperties();

                $mode   = 'addFile';
                $html   = ['name'=> $params['name'], 'mime'=> $mimeType];
                $ret[]  = $objet::formatRetour($objet->getId(), $objet->getId(), $mode, $html);
            } else {
                $alertMsg = 'alert("Nom de fichier '.$$params['name'].' existe dèjà, veuillez changer");';
                $ret[]  = $objet::formatRetour($objet->getId(), $objet->getId(), 'exec', $alertMsg);
            }
        } else if ($maxCountFile != 0) {
            $alertMsg = 'alert("Maximum de '.$maxCountFile.' fichier(s) atteint");';
            $ret[]  = $objet::formatRetour($objet->getId(), $objet->getId(), 'exec', $alertMsg);
        }

        return $ret;
    }
75846
public function getUserId() {

		if (!$this->authSource->isAuthenticated()) {
			return NULL;
		}

		$attributes = $this->authSource->getAttributes();
		if (!array_key_exists($this->usernameAttribute, $attributes)) {
			throw new SimpleSAML_Error_Exception('Missing username attribute ' .
				var_export($this->usernameAttribute, TRUE) . ' in the attributes of the user.');
		}

		$values = array_values($attributes[$this->usernameAttribute]);
		if (empty($values)) {
			throw new SimpleSAML_Error_Exception('Username attribute was empty.');
		}
		if (count($values) > 1) {
			throw new SimpleSAML_Error_Exception('More than one attribute value in username.');
		}

		$userId = $values[0];
		return $userId;
	}
166548
static function createMId( $nCenter = 0, $nNode = 0, $sSource = null, & $arrData = null )
	{
		return CDId::getInstance()->createId( $nCenter, $nNode, $sSource, $arrData );
	}
924594
public function GetRemoveFromBasketLink($sMessageHandler = null)
    {
        if (is_null($sMessageHandler)) {
            $sMessageHandler = MTShopBasketCore::MSG_CONSUMER_NAME;
        }
        $oShopConfig = $this->getShopService()->getActiveShop();

        return $this->getActivePageService()->getLinkToActivePageRelative(array(
            'module_fnc' => array(
                $oShopConfig->GetBasketModuleSpotName() => 'RemoveVoucher',
            ),
            MTShopBasketCore::URL_REQUEST_PARAMETER => array(
                MTShopBasketCore::URL_MESSAGE_CONSUMER_NAME => $sMessageHandler,
                MTShopBasketCore::URL_VOUCHER_BASKET_KEY => $this->sBasketVoucherKey,
            ),
        ));
    }
667626
public function getBySlug($sSlug, array $aData = [])
    {
        if (!$this->tableSlugColumn) {
            throw new ModelException(static::class . '::getBySlug() Column variable not set.', 1);
        }

        return $this->getByColumn($this->tableSlugColumn, $sSlug, $aData);
    }
377546
public function get($identifier, $params = [])
    {
        if (!isset($this->dependencies[$identifier])) {
            throw new \Exception("Dependency identified by '$identifier' does not exist", 500);
        }

        return $this->dependencies[$identifier]->get($params);
    }
537980
public function stream_write($aData): int
    {
        if ($this->normaliseForWin) {
            $data = preg_replace('/(?<!\r)\n/', "\r\n", $aData);
        } else {
            $data = $aData;
        }

        if ($this->write) {
            $left = substr($this->string, 0, $this->position);
            $right = substr($this->string, $this->position + strlen($data));
            $this->string = $left . $data . $right;
            $this->position += strlen($data);

            return strlen($data);
        }

        return 0;
    }
888365
public function findByIdentifier($identifier, $pageTsPids = array())
    {
        $backendLayouts = $this->findAll($pageTsPids);
        if (isset($backendLayouts[$identifier])) {
            return $backendLayouts[$identifier];
        } else {
            return null;
        }
    }
1333038
function randomAccessor(caller) {
        if (nrAccesses > nrAllowed || !contains(allowed, caller)) {
            throw new Error('Can\'t access random identifier.');
        }

        nrAccesses += 1;

        return random;
    }