Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

need a better way to wirte this..

I have this php smarty out put template that is fro a form post... it works fine... but it's really awkward and not want I thought would be the end result should be...

So I'm wanting to know if a php foo master would know a better way to write this out... it's a search based off a module for CMSMS called FEU... in a short way I faked it here but I'd think there has to be a better way.  

One flaw I see is that I have to have the search input be the same as the entry, which has not room for error on the user's part, like saam should pick up sam?  It's not a great start but as I said it works mostly.

Here is the test for the code below


Really I need a better idea then what I worked out.  I want to learn a better way.  Thank you for the help.  

<h2>Search Completed</h2>
{if isset($fld_36) && ($fld_36 neq 'No Default')}<strong>Stylist/Salon by State </strong>: {$fld_36}<br />
{assign var=State value=1}{else}{assign var=State value=0}
{if isset($fld_39) && ($fld_39 neq '[unspecified]')}<strong>city</strong>: {$fld_39}<br />
{assign var=city value=1}{else}{assign var=city value=0}
{if isset($fld_40) && ($fld_40 neq '[unspecified]')}<strong>Hair Stylist Name</strong>: {$fld_40}<br />
{assign var=Name value=1}{else}{assign var=Name value=0}
{if isset($fld_41) && ($fld_41 neq '[unspecified]')}<strong>Hair Salon name</strong>: {$fld_41}<br />
{assign var=Salon value=1}{else}{assign var=Salon value=0}
{if isset($fld_43) && ($fld_43 neq '[unspecified]')}<strong>zip</strong>: {$fld_43}<br />
{assign var=zip value=1}{else}{assign var=zip value=0}
{assign var=selector value=$State$city$Name$Salon$zip}
<h3>Matching Members:</h3>
{assign var=noMATCH value='<h4>No Matches!!!!</h4>'}
{assign var=ISone value=false}
{assign var=blankMATCH value='<a href="javascript: history.go(-1)"><h4>Sorry the search form was blank</h4></a><br/><br/>'}   
{assign var=ISblank value=false}
        {foreach from=$mymembers item=entry}
{if $selector eq '00000'}
{assign var=ISblank value=true}
		(($selector eq '10000') and ($userprops.state|lower eq $fld_36|lower)) or
(($selector eq '11000') and (($userprops.state|lower eq $fld_36|lower) and ($userprops.city|lower eq $fld_39|lower))) or
((($selector eq '00010')|($selector eq '11011')|($selector eq '01011')|($selector eq '00011')|($selector eq '10011')|($selector eq '11010')) and (($userprops.company|lower eq $fld_41|lower))) or
(($selector eq '10010') and (($userprops.company|lower eq $fld_41|lower) && ($userprops.state|lower eq $fld_36|lower))) or
((($selector eq '00100')|($selector eq '11101')|($selector eq '01101')|($selector eq '00101')|($selector eq '10101')|($selector eq '10100')|($selector eq '11100')) and ( $entry.username|lower eq $fld_40|lower)) or
(($selector eq '01000') and ($userprops.city|lower eq $fld_39|lower)) or
(($selector eq '01010') and (($userprops.city|lower eq $fld_39|lower) and ($userprops.company|lower eq $fld_41|lower))) or
(($selector eq '00001') and (($userprops.zip|lower eq $fld_43|lower))) or
(($selector eq '11001') and (($userprops.city|lower eq $fld_39|lower) and ($userprops.zip|lower eq $fld_43|lower) and ($userprops.state|lower eq $fld_36|lower)))}
                	{assign var=WINNER value=true}
                    {assign var=ISone value=true}
        {if $WINNER eq true}
            <span style="float:left; width:250px;">{$entry.username}<br/><br/></span>
                        <span style="background-color:#990000;float:left; ">
                            {if isset($userprops.company)}<strong>Salon name</strong>:{$userprops.company}<br/>{/if}
                            {if isset($userprops.email)}<strong>email</strong>:{$userprops.email}<br/>{/if}
                            {if isset($userprops.state)}<strong>State</strong>:{$userprops.state}<br/>{/if}
                            {if isset($userprops.city)}<strong>City</strong>:{$userprops.city}<br/>{/if}
                            {if isset($userprops.zip)}<strong>Zip</strong>:{$userprops.zip}<br/>{/if}
                            {get_feu_properties username=$entry.username property="avatar" method="assign"}
                            {if isset($avatar)}avatar:{$avatar}<br/>{/if}
                        </span><br style="clear:left;"/><hr/><br/>
                        {assign var=WINNER value=false}
        {if $ISone eq false}
        {if $ISblank eq true}
<a href="javascript: history.go(-1)"><h4>New Search??</h4></a><br/><br/>

Open in new window

  • 4
  • 2
1 Solution
Personally I feel that you have way to much logic in your template. Not sure how much influence you have on the php, but I can imagine that you put the determiniation of whether or not a member is a winner inside you control layer, and not in your view layer.

Then you would use {if $entry.winner eq 'true'} rather than the whole bunch of selector eq somethings.

jeremyBass26Author Commented:
>>>>Personally I feel that you have way to much logic in your template.
Oh I agree with that... that's way I am here on this... but

>>>Not sure how much influence you have on the php, but I can imagine that you put the determiniation of whether or not a member is a winner inside you control layer, and not in your view layer.

it has to be all in there... sigh... it's a matter of upgrading, I could put a php file in but then on upgrade there is a chance of that being lost.  My orders were to not have anything but what I can do in that template...

I would like to be able to just say something like if the str has this than output via regex may-be?... but haven't found the right solution yet... looked at the haystack needle way, but that didn't work right .. but I can't seem to find a smarty based search either.  I guess if I could just get rid of all that logic for something a little more flexible I'd be happy...

thanks for the help...
You could try and write a smarty plugin function. In that way you don't work directly in the Smarty layer, but also not directly in the application layer, other than assigning your plugin to smarty.

Following the tutorial found here: http://codepoets.co.uk/smarty_php_quickstart_howto_tutorial

There are some easy steps:

Assuming that we want a smarty function {printwinner $entry}

1. Create a file function.printwinner.php in a directory of your choosing
2. Have that function hold a function smarty_function_printwinner($params, &$smarty) { .. your logic, returning html... }
3. Make smarty aware of your new plugin: $smarty->plugins_dir[] = "/where/to/find/plugins/";
4. Update your smarty template to using the new {printwinner $entry} function.

For the time being you could insert the {printwinner $entry} without removing your current code, to make sure it outputs exactly the same html. If that is tested properly, you can comment out your original code.

Hope this helps,

Kind regards

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

jeremyBass26Author Commented:
hmm... I'm going to have to think on this... I'm not suppose to add files, just to the db which is where the template lives.  That is way I was thinking there may be a better way to handle the search other then the that funky logic I wrote out.

Just a side note the $WINNER is just to trigger the no match result and nothing more.  I could be handling that better to I'd think.. anyways I'll get back... thank you for the help.

jeremyBass26Author Commented:
Ok, after much thought, I don't think that will help other then clean up the area, If I understood it right, what I want to do is take that logic out, meaning search in a better way that picks up Sam and Samantha... I can pull it out now, but that only cleans an area no one else but me sees, so it's not high on the work me list.  Hope that made sense there.. thank you Roonaan for the help...

jeremyBass26Author Commented:
I'll be doing this is I can.. thank you for the help...

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now