need a better way to wirte this..

Posted on 2009-02-18
Last Modified: 2013-11-10
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 ($|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 (($|lower eq $fld_41|lower))) or


(($selector eq '10010') and (($|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 ($|lower eq $fld_39|lower)) or


(($selector eq '01010') and (($|lower eq $fld_39|lower) and ($|lower eq $fld_41|lower))) or

(($selector eq '00001') and (($|lower eq $fld_43|lower))) or

(($selector eq '11001') and (($|lower eq $fld_39|lower) and ($|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($}<strong>Salon name</strong>:{$}<br/>{/if}

                            {if isset($}<strong>email</strong>:{$}<br/>{/if}

                            {if isset($userprops.state)}<strong>State</strong>:{$userprops.state}<br/>{/if}

                            {if isset($}<strong>City</strong>:{$}<br/>{/if}

                            {if isset($}<strong>Zip</strong>:{$}<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

Question by:jeremyBass26
    LVL 49

    Expert Comment

    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.

    LVL 4

    Author Comment

    >>>>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...
    LVL 49

    Accepted Solution

    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:

    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

    LVL 4

    Author Comment

    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.

    LVL 4

    Author Comment

    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...

    LVL 4

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now