Real Tennis - EE as relational database
Posted: 08 November 2005 10:36 AM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

This site started out as a fairly straightforward news based site with a list of clubs and players.  Then we added tournaments, linked to player performance and to clubs and clubs have multiple links to players and it all got very complicated.  If anyone is interested in the code behind it, I am happy to share.

http://www.irtpa.com

Profile
 
 
Posted: 08 November 2005 11:41 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  148
Joined  11-17-2002

Hi Phoebe, nice site !

I’m interested indeed to know how you used EE to structure your data : table (data container) structure, relations btw tables, and your approach to querying those tables.

Thanks in advance for sharing.

Profile
 
 
Posted: 08 November 2005 02:42 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

Basically, I create a new weblog for each new “table”, so one for players, clubs and tournaments, then wrote a plugin for each (but could have been all in one plugin) to pull the data out. 

Lots of functions like this one, to list specific data in particular order:

function current_world_rankings()
{
global $DB, $TMPL;

$limit = $TMPL->fetch_param('limit');
$return_data='';

$sql = "SELECT  field_id_21 as world_ranking,
         title as player,
         url_title as player_link,
         field_id_23*1 as world_championship_points ,
         if(field_id_25='UK','',concat('(',upper(left(field_id_25,3)),')')) as nationality
      FROM exp_weblog_data,exp_weblog_titles
      WHERE exp_weblog_data.weblog_id=4 AND
         exp_weblog_data.entry_id=exp_weblog_titles.entry_id AND
         field_id_21>0
       ORDER BY (field_id_21*1)
      "
;
         
if (
$limit>0)
    
$sql.='LIMIT '.$limit;
    


$query = $DB->query($sql);

unset(
$sql);

if (
$query->num_rows == 0)
{
return false;
}


$tagdata
= $TMPL->tagdata;
  
$rows=$query->result;
       
   foreach (
$rows as $row) {
       $t
=$tagdata;
      foreach (
$row as $key=>$value) {
   $t
=str_replace(
'{'.$key.'}',
$value,
$t
);
       
} //foreach
       
$return_data.=$t;
} //while

  
return $return_data;
  
}  //current_world_rankings

then a template that includes this:

{exp:players:current_world_rankings limit="8" }
              
<tr bgcolor="#F0F0F0">
                <
td align="center">{world_ranking}</td>
                <
td align="center"><a href="{path="realtennis/player_details/{player_link}"}">{player}
                     {nationality}
</a></td>
                <
td align="center">{world_championship_points}</td>
              </
tr>
              
{/exp:players:current_world_rankings}

I fudged the relationship bit by putting a list of the data that doesn’t change much (the clubs) into a custom field for the players, then coverted the club name to a url where I needed it.  This has not worked very well and I should really have done a custom entry template and written a plugin to deliver an up-to-date drop-down.  If I did it again I think I would store both the name and the entry_id of the related entry in the child entry.

Also used a general weblog for content.  Wanted the users to be able to control entries but not have access to templates.  So some entries are whole pages, other entries are used for odd bits, like last updated date, like this:

World Rankings last updated: {exp:weblog:entries weblog="realtennis" category="39" limit="1"}{summary}{/exp:weblog:entries}

Does that make sense?

Phoebe.

Profile
 
 
Posted: 08 November 2005 04:54 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  148
Joined  11-17-2002

It makes a lot of sense indeed, as I can relate to using MsAccess DB and some php/MySQL experience.

I get the general idea : very interesting.

Some questions though :

- any reason to use abstract names for the data fields (ie : field_id_23, field_id_25, etc) instead of some real names like “country” or “world_ranking” ?

- is ” field_id_21*1 ” a field name or some expression ?

I also would like to know how you enter the data into the different tables (=weblogs/data containers) :

- do you use a standalone entry form or the CP ?
- how do you handle the relationship encoding ?

This has not worked very well and I should really have done a custom entry template and written a plugin to deliver an up-to-date drop-down.  If I did it again I think I would store both the name and the entry_id of the related entry in the child entry.

that’s how I thought to approach the data encoding too (I have to use EE as a RDBMS too) :
a standalone entry form with dropdowns for the related data ids.

PS : Thanks for making a clear code layout.

Profile
 
 
Posted: 09 November 2005 10:12 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

- any reason to use abstract names for the data fields (ie : field_id_23, field_id_25, etc) instead of some real names like “country” or “world_ranking” ?

These are the names used in the table exp_weblog_data.  The real names are held in exp_weblog_fields but not the data. 

- is “ field_id_21*1 “ a field name or some expression ?

just multiplying by 1 because I want to be able to sort with confidence, otherwise it would sort as if the numbers were strings with potential mistakes such as sorting ” 123” when what you wanted was “123” without the space.

I also would like to know how you enter the data into the different tables (=weblogs/data containers) :

- do you use a standalone entry form or the CP ?
- how do you handle the relationship encoding ?

I used the CP because there was no time left in the project to do stand-alone forms.  Bear in mind that EE holds data very inefficiently if you create a different set of custom fields for each weblog.  It is not after all an RDMS.  The data is all held in exp_weblog_data and an extra field is added on the end for each new field you create, we are up to exp_weblog_55 I think!  For the module for ladders/draws which I am in process of writing for this site, I have created a separate table because I don’t need to access the information directly using templates.  However I then have to write input forms to be used by the CP, a whole new skill! 

Hope this helps.

Phoebe.

Profile
 
 
Posted: 10 November 2005 09:00 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  02-27-2003

Hi Phoebe

Nice site. I live in Hobart, Tasmania which has the oldest real tennis court in the southern hemisphere. Might send you some photos.

In Safari on a Mac your pop-out menus pop-under the main pic and cannot be read or accessed. Not sure why.

 Signature 

Allan Moult | Leatherwood Online | Chile Pepper High

Profile
 
 
Posted: 11 November 2005 02:48 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

Allan,

Thanks for your feedback and we will checkout the safari problem.

Phoebe.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65075 Total Logged-in Users: 19
Total Topics: 82207 Total Anonymous Users: 18
Total Replies: 441819 Total Guests: 180
Total Posts: 524026    
Members ( View Memberlist )
Newest Members:  TomsBmackskithbtggAdminempoleongwishPasha MahardikarmarkdurandomcatClutch Bearings