Data Entry with Xataface |
Written by Nikos Vaggalis | |||||||
Monday, 29 February 2016 | |||||||
Page 3 of 3
Model to Operating SystemAs a final example we will examine another m:n relationship, that We see that it was automatically assigned the id 44: __sql__ = "SELECT ModelOS.*,concat(OSName,' ',OSVersion) as
OSName from OS,ModelOS,Model
where ModelOS.OS_OSid=OS.OSid and
ModelOS.Model_ModelId=Model.ModelId"
;So OS OSId does not display a number but instead display Windows Phone 8.10 [OS_OSid] widget:type = select vocabulary = OSs [Model_ModelId] widget:type = select vocabulary = Models [ModelOSInstalled] widget:type=select vocabulary = ModelOSInstalled order=4 [ModelOSUpgraded] widget:type=select vocabulary = ModelOSUpgraded order=5 [ModelOSSupported] widget:type=select vocabulary = ModelOSSupported order=6
relationships.ini [OSs]
OS.OSid="$OS_OSId" [Models] Model.ModelId="$Model_ModelId"
valuelists.ini [OSs]
__sql__ = "SELECT OSid,Concat(OSName,OSVersion) from OS" [Models] __sql__ = "SELECT ModelId,ModelName from Model" [ModelOSSupported] Y=Y [ModelOSInstalled] Y=Y [ModelOSUpgraded] Y=Y
[modelos]
transient=1 relationship=modelos widget:type=grid widget:columns="OS_OSid, ModelOSInstalled,
ModelOSUpgraded,
ModelOSSupported"
[modelos]
__sql__ = "SELECT * FROM ModelOS WHERE Model_ModelId='$ModelId'"
More advanced functionalityThat's the basic idea but additionally Xataface offers more advanced functionality and customizations through its API. You can for example use triggers and Delegate classes to update tables that require special treatment not covered by the defaults.For example the following code is fired before and after saving a Model's record: <?php
class tables_Model { function afterSave(Dataface_Record $record){ if ( $record->valueChanged('FrequencyId') ){ if ($record->val('FrequencyId')) { $modelid=$record->val('ModelId'); $frequencyid=$record->val('FrequencyId'); df_q( "INSERT INTO ModelFrequency (Model_ModelId,Frequency_FrequencyId) VALUES ($modelid,$frequencyid)"); df_clear_views(); df_clear_cache(); } } } function beforeSave(Dataface_Record $record){ if ( $record->valueChanged('FrequencyId') ){ df_q("delete ModelFrequency.* from ModelFrequency,Frequency where Model_ModelId='".$record->val('ModelId')."' and ModelFrequency.Frequency_FrequencyId= Frequency.FrequencyId and Frequency.G_GId=2"); } } } ?>
A table may have only one delegate class, thus there can be only one .php file per table directory, i.e Model/Model.php (Note that to avoid SQL injections you have to always validate input and escape strings that you include in your SQL queries.)
Other examples of what you can do:
and much more through the exposed API SummarySumming up, Xataface is a feature rich framework that can be further extended and customized, easing the tedious but crucial task of data entry. Give it a try and make a gift to your data entry personnel;they'll love it!
More InformationRelated ArticlesA Generic SQL Performance Test Harness Full Text Database Indexing with dtSearch Linq to ADO - using the TableAdapter
To be informed about new articles on I Programmer, sign up for our weekly newsletter,subscribe to the RSS feed and follow us on, Twitter, Facebook, Google+ or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
|||||||
Last Updated ( Monday, 29 February 2016 ) |