CMS MADE SIMPLE FORGE

Quotes(MS)

 

[#11745] Implemented the "Number" parameter

avatar
Created By: TannSan (TannSan)
Date Submitted: Tue Feb 20 07:27:30 -0500 2018

Assigned To:
Version: 1.0.1
CMSMS Version: None
Severity: Trivial
Resolution: Accepted
State: Open
Summary:
Implemented the "Number" parameter
Detailed Description:
Hi, I noticed in the docs you show a Number parameter but it is not actually
implemented.  I added it for myself as it is a feature I needed.  Here's how to
do it:

Quotes.module.php
function SetParameters()
{
...
$this->CreateParameter('number', '1', 'Number of quotes to display');
$this->SetParameterType('number',CLEAN_INT);
}

action.default.php
if (isset($params["showall"]) && ($params["showall"] != '')) {
...
}
elseif (isset($params["number"]) && ($params["number"] != '')) {
   $total = (int)$params["number"];
   for ($i = 0; $i < $total; $i++)
      {
         // 5 is the maximum number of attempts to pull a random quote
         $rand_array = [];
         for ($rand_i = 0; $rand_i < 5; $rand_i++)
            {
               $quote = $this->SelectQuote($params);
               if (!in_array($quote["id"], $rand_array))
                  break;
            }
         $rand_array[] = $quote["id"];

         $this->IncreaseExposure($quote["id"]);
         foreach ($quote as $propname=>$value) {
            $this->smarty->assign("quote".$propname, $value);
         }
         echo $this->ProcessTemplateFromData($template);
      }
else{
...
}


History

Comments
avatar
Date: 2018-02-20 08:04
Posted By: TannSan (TannSan)

This is best used in conjunction with the pickby="random" option:

{Quotes number=3 pickedby="random"}

Which avoids having the same quote displayed multiple times. This entire depends
on how many quotes you have in the system, more the better.  Note that "random"
is the default pickedby value, I'm just mentioning it is the one that should be
used for the "number" option to really work best.
      
Updates

Updated: 2021-02-18 05:11
resolution_id: 5 => 6

Updated: 2018-02-20 08:16
description: Hi, I noticed in the docs you show a Number parameter but it is not actually implemented. I added it for myself as it is a feature I needed. Here's how to do it: Quotes.module.php function SetParameters() { ... $this->CreateParameter('number', '1 => Hi, I noticed in the docs you show a Number parameter but it is not actually implemented. I added it for myself as it is a feature I needed. Here's how to do it: Quotes.module.php function SetParameters() { ... $this->CreateParameter('number', '1

Updated: 2018-02-20 08:04
description: Hi, I noticed in the docs you show a Number parameter but it is not actually implemented. I added it for myself as it is a feature I needed. Here's how to do it: Quotes.module.php function SetParameters() { ... $this->CreateParameter('number', '1 => Hi, I noticed in the docs you show a Number parameter but it is not actually implemented. I added it for myself as it is a feature I needed. Here's how to do it: Quotes.module.php function SetParameters() { ... $this->CreateParameter('number', '1
resolution_id: => 5