- One way to do this is to grab the current query:
The --msg query string variable allows you to display a confirmation message. We put an exit after the header function to make sure nothing else in the script runs. - The above way works, but it leaves the primary id of the record you just added in the url. Probably not the best thing to do, another way to do it is just use the header function and manually enter the query parameters:
header('Location: '.DATAFACE_SITE_HREF.'?-table=tablename&-action=new
I used the DATAFACE_SITE_HREF constant variable here which provides the path your application. You NEVER want to hardcode your application path since portable. You can put this function like in your after_action_new() trigger so that after you add a record, it allow you to add another record right away.
Thursday, August 14, 2008
Redirecting to a page
Say after an action in Xataface (eg. finished adding a new record), by default it goes to the edit action for that record you just added. But say you want it to go to the new action to add another another. There are a few ways to do this:
Saturday, August 2, 2008
Displaying Xataface record values
Taking a look at the Xataface Record API presents you with several techniques to display the values of the record. At the lowest level, there is a function called val and can be called like this (assuming $rec is a Xataface record)
What this does is it displays the raw value of field. As in exactly what is stored in the database.
But what happens if the value is say a foreign key to another table say like a number of a company. We don't really want to display just the number, but rather the company name of the id. If a valuelist has been setup for this company_id in a valuelist.ini file, then you can easily display the field you really want by simply using the "display" function.
So say for example, in your application delegate's valuelists.ini file you have this:
So you are basically telling Xataface to use the company_name as a replacement for the company_id. Since this is the application's delegate, this valuelist is accessible by any table and can be overwritten the own table's valuelist. In any case, if in your other table you just call:
Xataface will be smart enough to use the company_name in replacement for the company_id. This display function is also useful for database field types datetime, time, or date. If you were simply use the "val" function it would return the date as an array with keys "year", "month", "seconds", etc. And you would be left with having to piece together the information yourself. But by using the display() function you can quickly circumvent this problem.
$rec->val('fieldname')
What this does is it displays the raw value of field. As in exactly what is stored in the database.
But what happens if the value is say a foreign key to another table say like a number of a company. We don't really want to display just the number, but rather the company name of the id. If a valuelist has been setup for this company_id in a valuelist.ini file, then you can easily display the field you really want by simply using the "display" function.
So say for example, in your application delegate's valuelists.ini file you have this:
[companies]
__sql__="select company_id,company_name from companies order by company_name"
So you are basically telling Xataface to use the company_name as a replacement for the company_id. Since this is the application's delegate, this valuelist is accessible by any table and can be overwritten the own table's valuelist. In any case, if in your other table you just call:
$rec->display('company_id')
Xataface will be smart enough to use the company_name in replacement for the company_id. This display function is also useful for database field types datetime, time, or date. If you were simply use the "val" function it would return the date as an array with keys "year", "month", "seconds", etc. And you would be left with having to piece together the information yourself. But by using the display() function you can quickly circumvent this problem.
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:
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:
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:
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:
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:
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!
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:
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
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:
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:
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!
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!
Thursday, June 26, 2008
Displaying actions in a html select object
Here is an interesting example of how to use actions in an html select from object.
In our actions.ini file (delegate or conf.ini) we have a set of actions each with the category attribute set to bd_company_filters. Like this:
In our delegate class, we can access these actions like this:
The first line retrieves the Dataface_ActionTool object which we then use to return an array of actions underneath the category bd_company_filters. Each action in the array of actions will contain the attributes specified in the actions.ini and can be accessed by simply using the normal array key like this:
Here we are accessing the url attribute of each action under this category.
So putting it all together, we can do something like this (NOTE: this code is in the block__before_result_list() function):
Here we are creating a html select object and then we are placing the different actions as options for the select valuelist. The labels of the actions act as the labels in the select list, and the urls are used as the values of the options.
A little simple javascript is used to change the window.location to the value of the selected item in the list on change.
In our actions.ini file (delegate or conf.ini) we have a set of actions each with the category attribute set to bd_company_filters. Like this:
[show_only_approved_news]
;; Show only companies that have been approved by this broker dealer
url="{$this->url('approval_status=2')}"
condition="$query['-table'] == 'news' and isBrokerDealer()"
label="Approved News"
category=bd_news_filters
In our delegate class, we can access these actions like this:
$at =& Dataface_ActionTool::getInstance();
$actions = $at->getActions(array('category'=>'bd_company_filters'));
The first line retrieves the Dataface_ActionTool object which we then use to return an array of actions underneath the category bd_company_filters. Each action in the array of actions will contain the attributes specified in the actions.ini and can be accessed by simply using the normal array key like this:
foreach ($actions as $action){
echo action['url']
}
Here we are accessing the url attribute of each action under this category.
So putting it all together, we can do something like this (NOTE: this code is in the block__before_result_list() function):
$at =& Dataface_ActionTool::getInstance();
$actions = $at->getActions(array('category'=>'bd_company_filters'));
echo '<select onchange="window.location=this.options[this.selectedIndex].value" class="company_filters">';
echo '<option value="#">Filter Resources in this Category</option>';
foreach ($actions as $action){
echo '<option value="'.$action['url'].'">'.$action['label'].'</option>';
}
echo '</select>';
Here we are creating a html select object and then we are placing the different actions as options for the select valuelist. The labels of the actions act as the labels in the select list, and the urls are used as the values of the options.
A little simple javascript is used to change the window.location to the value of the selected item in the list on change.
Saturday, June 7, 2008
Using the df_display() function
You can use the function df_display() to actually include html files (or I think any other file) in your templates folder that can then be displayed in your delegate class functions. For example,
Here we have included the offeringApprovalForm.html file into block at the top or the page. You can then like use javascript to get elements from the form if you need it.
Additionally, the 1st parameter for the df_display() function actually takes an array of variables that can be used in the template as a smarty tag. For example, if we had an array and sent it into the df_display() function
Then the left_menu.html file can access the approved variable using a smarty tag like this {$approved}. This will display 3 in the location you specified.
function block__before_header(){
df_display(array(), 'offeringApprovalForm.html');
}
Here we have included the offeringApprovalForm.html file into block at the top or the page. You can then like use javascript to get elements from the form if you need it.
Additionally, the 1st parameter for the df_display() function actually takes an array of variables that can be used in the template as a smarty tag. For example, if we had an array and sent it into the df_display() function
$context = array();
$context['approved'] = 3;
df_display($context, 'left_menu.html');
Then the left_menu.html file can access the approved variable using a smarty tag like this {$approved}. This will display 3 in the location you specified.
Subscribe to:
Posts (Atom)