1
bassyard
Pull random quotes from RM Myfolder
  • 2007/2/7 23:18

  • bassyard

  • Not too shy to talk

  • Posts: 157

  • Since: 2003/10/5


Hi there,

I'm using RM soft's MyFolder for my portofolio.
It has a build in field for a comment from the Client about the work.
These comments can be displayed in a block but it isn't random, it takes the last x comments.

Is there an easy way to get it to pull a random quote instead of the last ones?

I think this is the php code from the block:

function rmmf_bk_comments($options){
    
$db =& Database::getInstance();
    
$myts =& MyTextSanitizer::getInstance();
    
$result $db->query("SELECT * FROM ".$db->prefix("rmmf_works")." ORDER BY id_w DESC LIMIT 0,$options[0]");
    
$block = array();
    while (
$row $db->fetchArray($result)){
        
$rtn = array();
        
$rtn['id'] = $row['id_w'];
        
$rtn['titulo'] = $row['titulo'];
        
$rtn['texto'] = $myts->makeTareaData4Show($row['comentario']);
        
$rtn['cliente'] = $row['cliente'];
        
$block['works'][] = $rtn;
    }
    return 
$block;
}

function 
rmmf_bk_comments_edit($options){
    
$form _BK_RMMF_NUMCOMMS."<br /><input type='text' size='5' name='options[]' value='$options[0]' />";
    return 
$form;
}


And this is the block template:

<{foreach item=work from=$block.works}>
<
div style="font-size: 10px; text-align: right;">
    <
span style="font-style: italic;">"<{$work.texto}>"</span><br />
    <
a href="<{$xoops_url}>/modules/rmmf/view.php?id=<{$work.id}>"><{$work.cliente}></a>
</
div><br />
<{/foreach}>


I think it's an easy one if your good with php/mysql, which I'm not
. . . : : : | | | PressureLab.com | | | : : : . . .

2
zyspec
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 2:35

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


bassyard,

I think the following code will do what you want if you replace the functions in the block with these.

NOTE: Make a backup of your current file BEFORE you try this. I have not tried this code since I don't have the module loaded.

function rmmf_bk_comments($options){
    
$db =& Database::getInstance();
    
$myts =& MyTextSanitizer::getInstance();
    
$result $db->query("SELECT * FROM ".$db->prefix("rmmf_works")." ORDER BY id_w DESC");
    
$block = array();
    
$tmparray = array();
    while (
$row $db->fetchArray($result)){
        
$tmparray[] = $row;
    }
    
$limit = (count($tmparray) < $options[0]) ? count($tmparray) : $options[0] ;
    
$randarray array_rand($tmparray,$limit)
    for (
$i=0:$i<$limit:$i++) {
      
$rtn = array();
        
$rtn['id'] = $tmparray[$randarray[$i]]['id_w'];
        
$rtn['titulo'] = $tmparray[$randarray[$i]]['titulo'];
        
$rtn['texto'] = $myts->makeTareaData4Show($tmparray[$randarray[$i]]['comentario']);
        
$rtn['cliente'] = $tmparray[$randarray[$i]]['cliente'];
        
$block['works'][] = $rtn;
    }
    return 
$block;
}

function 
rmmf_bk_comments_edit($options){
    
$form _BK_RMMF_NUMCOMMS."<br /><input type='text' size='5' name='options[]' value='$options[0]' />";
    return 
$form;
}

3
bassyard
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 10:17

  • bassyard

  • Not too shy to talk

  • Posts: 157

  • Since: 2003/10/5


Thx Zyspec! But when I try it I get a blank screen

Any other thoughts?
. . . : : : | | | PressureLab.com | | | : : : . . .

4
zyspec
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 13:29

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


2 things...

1st... My DUMB mistake - should have read through the code before I sent it!

Change line 12 of the code I posted from:
for ($i=0:$i<$limit:$i++) {


to:
for ($i=0;$i<$limit;$i++) {


Note you're changing the ':' (colon) to a ';' (semicolon)

2nd... Turn on PHP debug in Admin=>Preferences and report back with any errors.

5
bassyard
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 15:20

  • bassyard

  • Not too shy to talk

  • Posts: 157

  • Since: 2003/10/5


I'm getting this error now:

Parse errorsyntax errorunexpected T_FOR in cms/modules/rmmf/blocks/rmmf_recent.php on line 85
All errors 
(0queries (14blocks (4extra (0timers (4)
Errors


That's this line:

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


Thx for your time! Really appreciated!!
. . . : : : | | | PressureLab.com | | | : : : . . .

6
zyspec
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 16:54

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Aaarrrgggghhhh - another DUMB mistake.

Please add a ';' to the end of line 84 - which should look like:

$randarray array_rand($tmparray,$limit)[b][color=FF0000];[/color][/b]

7
bassyard
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 19:19

  • bassyard

  • Not too shy to talk

  • Posts: 157

  • Since: 2003/10/5


heheh now the block shows but without any content
and the follow error appears:

NoticeUndefined indexin file /modules/rmmf/blocks/rmmf_recent.php line 87
Notice
Undefined indexin file /modules/rmmf/blocks/rmmf_recent.php line 88
Notice
Undefined indexcliente in file /modules/rmmf/blocks/rmmf_recent.php line 90


If you can't find the problem: don't worry, I'll get a seperate quote module and enter the quotes there too so they appear in a block...
. . . : : : | | | PressureLab.com | | | : : : . . .

8
zyspec
Re: Pull random quotes from RM Myfolder
  • 2007/2/8 21:11

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Hmmmm....

If I get time in the next couple of days I'll load the module on a test server and see if I can get it working.

In the mean time maybe one of the PHP gurus here can see the problem in the code - it's probably something obvious that I've overlooked but without loading it and debugging it I just don't see it off the top of my head. That's why they don't let the same people that code a module test it!

You did set the number of quotes to show in the block configuration, right?

9
bassyard
Re: Pull random quotes from RM Myfolder
  • 2007/2/9 7:48

  • bassyard

  • Not too shy to talk

  • Posts: 157

  • Since: 2003/10/5


Quote:

zyspec wrote:
You did set the number of quotes to show in the block configuration, right?


I forgot to check this, it was set to display 1 quote, but when I changed it to 2 quotes, they show without errors, and at random!!
When I changed it back to 1 quote, the quote dissappears again, and the errors are back...

I hope this helps with a sollution, if not: I thank you VERY much for your effort! I can use it with 2 qoutes meanwhile, so it's all good!!
. . . : : : | | | PressureLab.com | | | : : : . . .

10
zyspec
Re: Pull random quotes from RM Myfolder
  • 2007/2/11 22:56

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


bassyard,

I tried the code above (with the 2 sets of errors corrected) and the block displays random events correctly. I made one additional change in the code (although the original code worked fine) to remove sorting the customer comments in the SQL statement since they're randomized anyway and to only show Works with customer reviews in the block (eg. where customer review is not empty).

Please cut-and-paste the code below to replace your rmmf_bk_comments function and then let me know what happens.

function rmmf_bk_comments($options){
    
$db =& Database::getInstance();
    
$myts =& MyTextSanitizer::getInstance();
    
$result $db->query("SELECT * FROM ".$db->prefix("rmmf_works")." WHERE comentario != """);
    
$block = array();
    
$tmparray = array();
    while (
$row $db->fetchArray($result)){
        
$tmparray[] = $row;
    }
    
$limit = (count($tmparray) < $options[0]) ? count($tmparray) : $options[0] ;
    
$randarray array_rand($tmparray,$limit);
    for (
$i=0;$i<$limit;$i++) {
      
$rtn = array();
        
$rtn['id'] = $tmparray[$randarray[$i]]['id_w'];
        
$rtn['titulo'] = $tmparray[$randarray[$i]]['titulo'];
        
$rtn['texto'] = $myts->makeTareaData4Show($tmparray[$randarray[$i]]['comentario']);
        
$rtn['cliente'] = $tmparray[$randarray[$i]]['cliente'];
        
$block['works'][] = $rtn;
    }
    return 
$block;
}


Note: This modified code will display all Customer comments if the "Number of Comments" (set in block preferences) is larger than the number of Works that actually contain customer comments.

Login

Who's Online

181 user(s) are online (88 user(s) are browsing Support Forums)


Members: 0


Guests: 181


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits