Thursday, July 31, 2008

Xataface: Setting a logo for a xataface record

When you go into the details view of a record, in addition to the all the different values in the database about the record, you can also specify a logo for that record and this logo will appear in the top left corner of the record.

You should first refer to this document on how to actually store images/file in xataface.

I used method two because I always find it much easier to manage when the files exist physically and not just as bytes in the database. So let's assume that the picture field in the database is what is storing the file name in the database, and you have a directory called picture in your delegate class.

The next step is to go into your delegate class that represents this record and include this function:




function friend_picture__htmlValue(&$record){
return '<img src="'.$record->display('picture').'"></img>';
}



What this does is define a custom field called friend_picture which will basically return the image. By using $record->display() we are returning the whole address of the picture. Xataface is smart enough to figure out how to return the address.

This is opposed to using $record->val('picture') which would return the raw value of the field in the database which would just be the filename.

And then final step is to go into the fields.ini file of this delegate class and include this:


[friend_picture]
logo = 1


This causes xataface to recognize this was a logo field for the record and then display the picture in the top left hand corner of the detail view of the record.

And volia!

Some things to note is that trying to include the logo = 1 as attribute for the field that holds the filename that's seem to work. For example, say in the fields.ini file you have:


[picture]
logo = 1


This would place this field to the top left hand corner, but it would just say "View Field Content In New Window ()" in the top left hand corner. You have to make a custom field.

Also, you can specify exactly records of which table should display logos by including this line of code in the ApplicationDelegate class' getPreferences() function:


//this is needed to determine which table records will have a logo on them
if ( !in_array($query['-table'], array('companies', 'dealers','news', 'strategies', 'offerings') ) ){
$prefs['hide_record_view_logo'] = 1;
}


What this basically did was check whether the current table viewing this record was either companies, dealer, etc. And if it wasn't, it would turn the hide_record_view_logo preference. So a modified line of code could be like this:


if ( !in_array($query['-table'], array('companies', 'dealers','news', 'strategies, 'offerings') ) ){
$prefs['hide_record_view_logo'] = 1;
}

Monday, July 14, 2008

Installing Zope/Plone

This took me nearly 2 hours to figure out how to deal not because it was hard, but because I had no idea how Zope/Plone worked and there was honestly no documentation on it. But basically you can go to the plone.org website and download the windows installer.

This installer will then install Zope, the application server, python and plone all at once. Plone actually becomes a Zope "product" The key thing is that Zope acts as your web server to host files, but it's more advanced than just a web server because it can serve client application calls (which is why it is a called an application server.

In any case, the installer will automatically create an instance of a zope for you and should be able to start this in the windows services menu. The instance will be in the folder Data of the directory where you installed everything. Once you have this instance started, you can access the zope management interface by going to http://localhost:8080/manage. This provides a backend to the zope application server.

To go to the plone installation go to http://localhost:8080/plone.

That's it!

Tuesday, July 8, 2008

Using smarty tags in a template

This is a tutorial to show how to specify some variables in a php class and then use them in the smarty template. Here is the situation: There is a below_header.html file needs to have a drop down menu which lists a bunch of offering_types as a classification of offerings.

The Dataface_Main_Template.html contains this code:


{block name="before_below_header"}
{define_slot name="below_header"}{/define_slot}
{block name="after_below_header"}


Notice the below_header slot. Since we want this slot to be replaced on every page of Dataface, we will use the function block__below_header() in the ApplicationDelegate.php file to replace this slot.

So the next step is to retrieve the variables that we will use to display in our below_header slot.

ApplicationDelegate.php


function block__below_header(){

//only broker dealers and broker customers should be able to see offerings
if (isBrokerDealer() or isBrokerCustomer()){
$offering_types = df_get_valuelist("offerings", "offering_types");
}

//any users can see the strategy types
$strategy_types = df_get_valuelist("strategies", "strategy_types");

$context = array('offering_types' => $offering_types, 'strategy_types' => $strategy_types);
df_display($context, 'below_header.html');
}


The if statements are just some fancy permission features where we only want like the offering_types to show up for broker dealers and customers. But the important lines are:


$offering_types = df_get_valuelist("offerings", "offering_types");

$strategy_types = df_get_valuelist("strategies", "strategy_types");

$context = array('offering_types' => $offering_types, 'strategy_types' => $strategy_types);
df_display($context, 'below_header.html');


Here we are using the df_get_valuelist() function in the dataface_public_api.php file which takes two parameters (tablename, valuelistname). And the valuelists are found in the valuelist.ini of the delegate classes:

valuelist.ini of offering/strategy tables
[strategy_types]
Managed Stocks = "Managed Stocks"
Managed Funds = "Managed Funds"
Managed ETFs = "Managed ETFs"
Managed Blend = "Managed Blend"
Managed Annuity = "Managed Annuity"
Currency = "Currency"
Derivatives = "Derivatives"
Commodities = "Commodities"
Unknown = "Unknown"

Nothing special here. Just a list of the strategy types. I didn't show the offering_types which is in the valuelists.ini of the offering table. But it's the same thing.

And so after we have retrieve the valuelist as variables, we place them into this context variable which we then send in as a parameter to the df_display function. The second parameter below_header.html is the file to display which will use the variables from the context variable.

below_header.html
The important code:


<select name="Offerings" onchange="window.location=this.options[this.selectedIndex].value">
{foreach from=$offering_types key=okey item=otype}
<option value="{$ENV.DATAFACE_SITE_HREF}?-table=offerings&offering_type={$otype}">{$okey}</option>
{/foreach}
</select>


The smarty tag foreach from is retrieving the offering_types variable which is an array (remember from the ApplicationDelegate.php file) and so we are getting the key and value (as item) and using them as the option value and as the labels.

One interesting thing is the onchange javascript event which automatically changes the page to the value of the option.

That's it!