How to create a quote encased variable from another variable.

Author Message

steve walker

Monday 04 October 2004 5:32:07 am

Hi there,

This is a new thread coming out of:

http://www.ez.no/community/forum/developer/dynamic_fetch_using_simple_form

I'm trying to encase a variable in quotes for fetch purposes... the eind result I' m after is:

let x=example
let encased_x='$x'
so that the value of $encased_x is 'example'

Paul B had given me some pointers but I wasnt able to get this working - does anyone have a past example or some ideas on this one?

Many thanks, Steve.

http://www.oneworldmarket.co.uk

Paul Forsyth

Monday 04 October 2004 5:51:52 am

Try:

{let x=example
     encased_x=concat('',$x)}

paul

steve walker

Monday 04 October 2004 7:05:28 am

Paul,

Thanks for the reponse.

I tried the code, but it doesnt make any change - my variable stays the same. The full code I have is:

{let carat=ezhttp( 'search_carat', 'get' )}
{let clarity=ezhttp( 'search_clarity', 'get' )}

{let carat_in='('|concat($carat,')') 
let ecarat_in=concat('',$carat_in)

let clarity_in='('|concat($clarity,')')
let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','$carat_in'), 
array('stone_product/clarity','in','$clarity_in'))))
}
ecarat is {$ecarat_in} and clarity is {$clarity_in}

The line "{let carat_in='('|concat($carat,')')" encases the variable in brackets - perhaps I could introduce the quote here at the same time, but attempts so far have failed...

Of all the characters, the quote mark seems the most difficult to get in there.

Regards, Steve.

http://www.oneworldmarket.co.uk

Paul Forsyth

Monday 04 October 2004 7:52:07 am

Steve,

Could you show before and after text of what you want to achieve?

Paul

Paul Borgermans

Monday 04 October 2004 10:31:12 am

OK, The quotes are a bit difficult to generate. You will need additional concat("'") to make sure the strings are quoted inside the "array" (actually a string which build a SQL array like thing).

I upgraded kernel/classes/ezcontentobjecttreenode.php to version 3.4.2 (actually, the most recent in stable, but it works in 3.4.2).

Extra with this update: two more filter operators: between and not_between for integer/float ranges.

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Tuesday 05 October 2004 6:59:32 am

Paul B,

Are you sure this fetch will work with alpahnumeric characters? I've been tryin get this to work just with static info.... even if I use your example:

let exactresults=fetch(content,tree,hash(parent_node_id, 59, 
attribute_filter,  
array(and,array('stone_product/carat','in','paul%'), 
array('stone_product/clarity','in',$clarity_in))))
}

I still get:

Query error: You have an error in your SQL syntax.  
Check the manual that corresponds to your MySQL server version for the right syntax 
to use near 'paul% AND a1.sort_key_string IN  (2) ) AND 

If I change the line to:

array(and,array('stone_product/carat','in','(2)'), 

It works, but putting alphanumerics in as:

'(a)' or '('a')'

Gives sql or 'too many character' errors.

Could you let me know what I'm missing here?

Thanks, Steve.

http://www.oneworldmarket.co.uk

Paul Borgermans

Tuesday 05 October 2004 7:54:13 am

Hi Steve

I overlooked the fact that filtervalue strings are escaped in kernel/classes/ezcontentobjecttreenode.php

I corrected this in pubsvn and uploaded the corrected file in the contributions.

A working example in a production site here is as follows, and note the complicated concat to create the string:

{let myinstring=concat("('",'WP1.1',"','",'WP6.1',"')")
      test_fetch=fetch(content,tree,hash(parent_node_id,2,attribute_filter,array(OR,array('task/acronym','in',$myinstring))))}

My inistring: {$myinstring}
<ul>
{section loop=$test_fetch var=test}
<li>{$test.name}</li>
{/section}
</ul>
{/let}

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

steve walker

Tuesday 05 October 2004 9:38:15 am

Paul,

Finally got this working :)))) - the code I have to wrap the variable in the quotes etc is:

{let carat_in=concat("('",$carat,"')") 

Thanks for the help.

Steve.

http://www.oneworldmarket.co.uk

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:05:24
Script start
Timing: Jan 18 2025 19:05:24
Module start 'layout'
Timing: Jan 18 2025 19:05:24
Module start 'content'
Timing: Jan 18 2025 19:05:25
Module end 'content'
Timing: Jan 18 2025 19:05:25
Script end

Main resources:

Total runtime0.6852 sec
Peak memory usage4,096.0000 KB
Database Queries74

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0116 588.1719152.6563
Module start 'layout' 0.01160.0090 740.828139.5078
Module start 'content' 0.02060.6627 780.3359636.6484
Module end 'content' 0.68330.0019 1,416.984420.0938
Script end 0.6851  1,437.0781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.5669160.0002
Check MTime0.00140.2108160.0001
Mysql Total
Database connection0.00250.365610.0025
Mysqli_queries0.595286.8646740.0080
Looping result0.00090.1349720.0000
Template Total0.635992.820.3180
Template load0.00230.329120.0011
Template processing0.633792.480520.3168
Template load and register function0.00020.033410.0002
states
state_id_array0.00430.628910.0043
state_identifier_array0.00100.147620.0005
Override
Cache load0.00200.2920620.0000
Sytem overhead
Fetch class attribute can translate value0.00080.116430.0003
Fetch class attribute name0.00150.213090.0002
XML
Image XML parsing0.00100.151630.0003
class_abstraction
Instantiating content class attribute0.00000.0029100.0000
General
dbfile0.00640.9346170.0004
String conversion0.00000.001940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs