Jump to content

Recommended Posts

  • 1 month later...

a little more detail....

 

here is my situation in detail...

i retrieve a "value" from database...and call a function named $this->value('some id again from database'); the "value" here is the name of the function i wish to call....i manually entered those function names into the db and if a condition is satisfied tht function gets called..... an example of value could be _getProcessedPlyr or _getReadPlyr or _getWritePlyr.......is it possible or not? as the value changes the function called should be different.... if anyone has some better suggestion to implement this please feel free to comment....

 

well, my db has class functions names cos i need to use those corresponding functions, only if certain condition is met....again this condition is stored ion the db too....condition means like if it is a do this function and if b do this other function.... hope you got a clearer picture now...so i would like to process this in a beter way.....

Link to comment
https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1069287
Share on other sites

  • 3 weeks later...

:facewall:Please I badly need help!!!

:facewall:

 

Let's make this simpler as to why I should avoid switch/case statement.

 

Switch/case is used as such...

 

a list of fatas(i.e. player stats and external stats like weather) and a list of players are selected by user.

now we have to calculate for each player his grade or say percentage based on the fatas selected

Fatas are stored in db, with their id's and selected fatas are stored in a table with foreign keys.

Now, the switch is used based on the fata id.

so i give a code sample here which would help you people to help me out.

Inside analyze function i do the switching for each fata.

switch ($f['Fata']['id']) {
//Rushing - Yds - Total (2009)
                    case 14:
                        $results[$p['Plyr']['id']][$f['Fata']['id']] = $this->_getFataRushYdTot($p['Plyr']['id']);
                        if ($results[$p['Plyr']['id']][$f['Fata']['id']] == '') {
                            $results[$p['Plyr']['id']][$f['Fata']['id']] = 'Info Not Available';
                        } else {
                            $results[$p['Plyr']['id']][$f['Fata']['id']] = $results[$p['Plyr']['id']][$f['Fata']['id']].' yds';
                        }
                        break;
}

//calculate fata          
    function _getFataRushYdTot($id=null) {
        if ($id) {
            //get the user's team
            $this->Plyr->recursive = 0;
            $p = $this->Plyr->findById($id);
            
            // get XML file
            $parsed_xml = $this->_parseXml(WWW_ROOT.'xml_data/NFLRushingLeadersXML-RUSHERS.xml');

            //get the info from XML
            $data = '';
            foreach ($parsed_xml['Message']['Listing'] as $p_xml) {
                if (strncasecmp($p_xml['name'], $p['Plyr']['first_name'].' '.$p['Plyr']['last_name'].', '.$p['SportTm']['location_abbrev'], strlen($p_xml['name'])) == 0) {
                    $data = $p_xml['yards'];
                    break;
                }
            }
            
            return ($data);
        }
    }

 

 

so, here is my problem now. i want to remove these switch/case cos currently i have just 100 fatas, but i plan to include about a 1000 fatas. u don't expect me to write a function and also a case for each fata added. anybody wid suggestions???

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1078613
Share on other sites

//calculate fata          
    function _getFataInj($id=null) {
        if ($id) {
            //get the user's team
            $this->Plyr->recursive = 0;
            $p = $this->Plyr->findById($id);
            
            // get XML file
            $parsed_xml = $this->_parseXml(WWW_ROOT.'xml_data/Injuries_Detail_XML.xml');

            // XML Path
                // Sports-content-set... Sports-content... Statistic... Team... []... 
                    // Team-metadata... Name... 
                        // team --> "first" or "last"
                    // Player... []... 
                        // Player-metadata...
                            // Plyr -> Name... full
                            // Injury (body part) --> Injury-phase... injury-type
                            // Injury (type) --> Injury-phase... phase-type 
                            // Injury (details) --> Injury-phase... xts:tsn-phase-type
            $data = '';
            foreach ($parsed_xml['Sports-content-set']['Sports-content']['Statistic']['Team'] as $key => $tm) {
//                if ($key != 0) {
                    if ($tm['Team-metadata']['Name']['last'] == $p['SportTm']['mascot_name']) {
                        foreach ($tm['Player'] as $p_xml) {
                            if ($p_xml['Player-metadata']['Name']['full'] == ($p['Plyr']['first_name'].' '.$p['Plyr']['last_name'])) {
                                $data = $p_xml['Player-metadata']['Injury-phase']['phase-type'].' ('.$p_xml['Player-metadata']['Injury-phase']['injury-type'].') - '.$p_xml['Player-metadata']['Injury-phase']['xts:tsn-phase-type'];
                                break;
                            }
                        }
                        break;
                    }
//                }
            }

            //return injury status
            return($data);
        }
    }

Link to comment
https://forums.phpfreaks.com/topic/200264-cakephp-switching/#findComment-1078625
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.