<?xml version="1.0"?>
<record><wiki id="wiki?page_id=126">
	<page_name>getChildren</page_name>
	<page_id>126</page_id>
	<page_title>getChildren Delegate Class Method</page_title>
	<content>Return to [[Delegate class methods]]

[[toc]]

The getChildren() method can be implemented in a table&apos;s delegate class to specify the logical &quot;child&quot; records of a given record which can be used when creating hierarchical applications.  This method will effectively override the output of the Dataface_Record::getChildren() method for records of this table.

===Signature===

&lt;code&gt;
function getChildren( Dataface_Record $record) : Dataface_Record[]
&lt;/code&gt;

===Parameters===

# &apos;&apos;&apos;$record&apos;&apos;&apos; - The Dataface_Record that is the subject of the query 

===Returns===

This method should return an array of Dataface_Record objects that are considered to be children of the subject record.

===Examples===

&lt;code&gt;
function getChildren($record){
    return df_get_records(&apos;webpages&apos;, 
        array(
            &apos;parent_id&apos;=&gt;&apos;=&apos;.$record-&gt;val(&apos;webpage_id&apos;)
        )
    );
}
&lt;/code&gt;


==See Also==

* &apos;&apos;&apos;[[getParent]]&apos;&apos;&apos; - A Delegate class method to return the logical parent of a given record.</content>
	<keywords>getChildren Delegate class method</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=127">
	<page_name>meta:class</page_name>
	<page_id>127</page_id>
	<page_title>meta:class relationships.ini file directive</page_title>
	<content>Return to [[relationships.ini file]]

[[toc]]

The &apos;&apos;meta:class&apos;&apos; directive allows you to ascribe special meaning to a relationship which Xataface can use in various parts of your application to provide enhanced capabilities.

For example you can specify a relationship as a &quot;parent&quot; relationship, thereby using the relationship to obtain the &quot;parent&quot; of records of this table.  This can be used to help build breadcrumbs.

You can also specify a relationship as a &quot;children&quot; relationship which would treat records in the relationship as children of the current record.  This can be used in conjunction with the [[list:type]]=treetable directive of the [[relationships.ini file]] to build a tree table that navigates all child records and subtrees.

The Dataface_Record class contains some methods for retrieving the parent and children of records and these methods will take into account any settings you make here.

===Allowed Values===

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| parent
| Designates the relationship as a &apos;parent&apos; relationship, meaning that the first record in this relationship will be treated as the parent of the current record.  This setting can be overridden by the [[getParent]] method of the table delegate class if implemented.
| 0.8
|-
| children
| Designates the relationship as a &apos;children&apos; relationship meaning that records of the the relationship will be treated as a children.  This setting can be overridden by the [[getChildren]] method of the table delegate class if implemented.
| 0.8
|}


==See Also==

# &apos;&apos;&apos;[[list:type]]&apos;&apos;&apos; - [[relationships.ini file]] directive to use a treetable for the related record list of a relationship.
# &apos;&apos;&apos;[[getChildren]]&apos;&apos;&apos; - Delegate class method to explicitly define the Dataface_Record objects that are to be considered as child records of the current record.
# &apos;&apos;&apos;[[getParent]]&apos;&apos;&apos; - Delegate class method to explicitly define the Dataface_Record object that is to be considered as the parent record of the current record.
</content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=128">
	<page_name>list:type</page_name>
	<page_id>128</page_id>
	<page_title>list:type relationships.ini file directive</page_title>
	<content>Return to [[relationships.ini file]]

[[toc]]

The list:type directive allows you to override the default list that is used to display related records.  As of Xataface 1.3 there is only one possible value that will have any effect on this directive: &quot;treetable&quot;.  

Setting
&lt;code&gt;
list:type=treetable
&lt;/code&gt;
will cause the related records to be displayed as an expandable/collapsible tree table as shown here:
&lt;nowiki&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Screen%20shot%202011-04-29%20at%2011.49.33%20AM.png?max_width=640&quot;/&gt;&lt;/nowiki&gt;

===Prerequisites===

The TreeTable component needs to be able to figure out the logical children of each record in order to know what to show when a row is expanded.  You can use either the [[meta:class]] directive of the [[relationships.ini]] file to specify a relationship as a &quot;children&quot; relationship, or you can implement the [[getChildren]] method of the table delegate class to manually define a record&apos;s child elements.

==See Also==

* [[getChildren]]
* [[meta:class]]
* [[getParent]]</content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=133">
	<page_name>fieldname__default</page_name>
	<page_id>133</page_id>
	<page_title>fieldname__default Delegate Class Method</page_title>
	<content>Return to [[Delegate class methods]]

[[toc]]

===Synopsis===

Xataface allows you to pre-populate any particular field in a table by adding a fieldname__default method to the table&apos;s delegate class of the form:
&lt;code&gt;
function fieldname__default(){
    return value;
}&lt;/code&gt;

Returns the default value for the field fieldname. New record forms will be prepopulated with this value.

===Examples===

&lt;code&gt;
function minimum_bid__default(){
    return 100;
}&lt;/code&gt;

&lt;code&gt;
function mydatecol__default(){
    return date(&apos;Y-m-d&apos;);
}&lt;/code&gt;

&lt;code&gt;
function owner_id__default(){
    $auth =&amp; Dataface_AuthenticationTool::getInstance();
    $user =&amp; $auth-&gt;getLoggedInUser();
    if ( isset($user) ) return $user-&gt;val(&apos;userid&apos;);
    return null;
}&lt;/code&gt;

===See Also===

* [http://xataface.com/forum/viewtopic.php?t=5028 Pre-entered Data] (forum thread) - setting defaults field values on general fields using the fieldname__default delegate class function
* [http://xataface.com/forum/viewtopic.php?t=4004 How to initialize a Date field to today&apos;s date?] (forum thread) - alternate methods to use specifically with a date/time field
* [http://xataface.com/forum/viewtopic.php?t=3988 Setting default select setting from users table] (forum thread) - solution to populate the current user</content>
	<keywords>default, initialize, populate, pre-populate, delegate class default</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=181">
	<page_name>after_action_activate</page_name>
	<page_id>181</page_id>
	<page_title>after_action_activate Delegate Class Method</page_title>
	<content>Return to [[Application Delegate Class]]

[[toc]]


The &apos;&apos;&apos;after_action_activate&apos;&apos;&apos; hook is a method that can be defined in the [[Application Delegate Class]] which is called after an account has been activated via the registration process.  The full registration process goes as follows:

# User fills in registration form.
# An email is sent to the user with a link to activate their account.
# User clicks on activation link.
# User is taken back to the application and activation occurs, which consists of creating a new record in the &apos;&apos;&apos;users&apos;&apos;&apos; table.
# The &apos;&apos;after_action_activate&apos;&apos; trigger is called.

===Since===

This hook has been available since Xataface Version 1.2

===Example===

&lt;code&gt;
/**
 * A trigger to send the user a confirmation email after their account has been activated.
 * @params array $params Associative array of passed parameters.  Contains a single key &apos;record&apos;
 * with the Dataface_Record object of the users table with the user that was activated.
 */
function after_action_activate(array $params){
    $user = $params[&apos;record&apos;];
    
    mail($user-&gt;val(&apos;email&apos;), &apos;Your account is activated&apos;, &apos;Your account has been activated... etc..&apos;);
}
&lt;/code&gt;

===See Also===

* [[Application Delegate Class]]
* [[registration_form]] - More information user registration forms.
* [[beforeRegister]] - Trigger called before the user registration form is saved.
* [[afterRegister]] - Trigger called after registration form is saved.
* [[validateRegistrationForm]] - Validates the input into the registration form.
* [[sendRegistrationActivationEmail]] - Overrides the sending of the registration activation email.
* [[getRegistrationActivationEmailInfo]] - Overrides the activation email info.  Returns an associative array of the email details (e.g. subject, to, headers, etc...
* [[getRegistrationActivationEmailSubject]] - Returns the subject of the activation email.
* [[getRegistrationActivationEmailMessage]] - Returns the message body for the activation email.
* [[getRegistrationActivationEmailParameters]] - Returns the parameters for the actication email.
* [[getRegistrationActivationEmailHeaders]] - Returns the headers for the activation email.
</content>
	<keywords>Registration, activation, register, activate, users</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=141">
	<page_name>field__fieldname</page_name>
	<page_id>141</page_id>
	<page_title>Defining Calculated Fields</page_title>
	<content>Return to [[Delegate class methods]]

Xataface allows you to define calculated fields using the delegate class.  These fields won&apos;t be visible in the UI by default, but they will be accessible to some modules (e.g. the HTML Reports Module) and they are always accessible to you via the API.

E.g.  If you define a calculated field named &apos;&apos;year&apos;&apos;, you would be able to access this value using the regular Dataface_Record syntax:

&lt;code&gt;
$record-&gt;val(&apos;year&apos;);
&lt;/code&gt;

You could also define any number of filter methods and permissions on this field just as you can on regular fields.

e.g. &lt;code&gt;
function year__permissions($record){
    // Return special permissions on the year field.
}
&lt;/code&gt;

or &lt;code&gt;
function year__display($record){
    // Override how the year is displayed in the UI.
    return $record-&gt;val(&apos;year&apos;).&apos; A.D.&apos;;
}
&lt;/code&gt;

==How to Define a Calculated Field==

In the delegate class you simply create a method with the following naming convention:
&lt;code&gt;
function field__fieldname(Dataface_Record $record);
&lt;/code&gt;

where the return value is the value that the given record should have for the field &apos;&apos;filedname&apos;&apos;.

E.g.

&lt;code&gt;
function field__year($record){
    $time = trtotime($record-&gt;strval(&apos;date&apos;));
    if ( $time ){
        return date(&apos;Y&apos;, $time));
    } else {
        return &apos;&apos;;
    }
}
&lt;/code&gt;</content>
	<keywords>calculated fields, field__fieldname</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=140">
	<page_name>init</page_name>
	<page_id>140</page_id>
	<page_title>init() Delegate Class Method</page_title>
	<content>== Synopsis ==

This method is called once, just after the table is loaded for the first time. It allows you to specify initialization details, such as [[setSecurityFilters|security filters]].

Note that it takes a single parameter: a Dataface_Table object of the table that is being initialized. 

== Example ==
&lt;code&gt;
function init(&amp;$table){

   ....
}
&lt;/code&gt;</content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=158">
	<page_name>Grafted_fields</page_name>
	<page_id>158</page_id>
	<page_title>Grafted fields</page_title>
	<content>==Grafted Fields==

===Introduction===
When there are numerous tables, it is difficult for the user to see get an information that will help one to enter the right data in the right field. So instead of navigating in the relative tables and lose some time, it is more convenient to add a grafted field from that relative table in the table. To be able to sort a column by the content displayed when this content is extracted form a relative table, a grafted field is necessary because the real content is just an id, not the most convenient to sort in human-readable way.
===Procedure===
Two ways to add a grafted filed
* The first one is to add a __sql__ statement at the beginning of fields.ini, including the grafted field through a join.
&lt;code&gt;__sql__ = &quot;select p.*, d.total from programmation p left join dev d on p.id_programmation=d.id_programmation&quot; &lt;/code&gt;
* The second one is to create the function __sql__ in the delegate class
&lt;code&gt;function __sql__(){
return &quot;select p.*, d.total from programmation p left join dev d on p.id_programmation=d.id_programmation&quot;;
}
&lt;/code&gt;
===Sorting order based on relationship===
The solution is to hide the field with the id and to add the grafted field with the name in the fields.ini
&lt;code&gt;[name_programmation]
order=10

[id_programmation]
visibility:list=hidden
&lt;/code&gt;

===Debugging===
A couple of things to check for:
*1. If you have set blanket default permissions for your fields using the __field__permissions() method you could be disallowing access to the field.
*2. If you have set default field visibility in the fields.ini file via the [__global__] section....
*3. Check to make sure that your __sql__ directive is at the beginning of the file and that it is __sql__ and not _sql_
*4. Try to enter an obviously invalid SQL query for the __sql__ directive to see if you get an error (to confirm that it is picking up the __sql__ directive at all).
</content>
	<keywords>grafted fields, grafted, sorting columns, sort, relative records, relative tables</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=178">
	<page_name>Clean_the_html_for_the_export</page_name>
	<page_id>178</page_id>
	<page_title>Clean the HTML to export data</page_title>
	<content>==Clean HTML tags and entities to export your data==
#Override the display() of the field to strip the tags... but this would affect all parts of the application where the HTML fields are displayed.
#Create a grafted field, then override its display to show the stripped contents of the HTML area field.

e.g. in the fields.ini:

&lt;code&gt; 
    __sql__ = &quot;select t.*, null as stripped_field from mytable t&quot;
    [original_field]
       widget:type=htmlarea
       visibility:csv=hidden

    [stripped_field]
        visibility:csv = visible
        visibility:list=hidden
        visibility:browse=hidden
        visibility:find=hidden

&lt;/code&gt; 


Then in the delegate class:


&lt;code&gt; 
    function stripped_field__display($record){
        return html_entity_decode(strip_tags($record-&gt;val(&apos;original_field&apos;)), ENT_QUOTES, &apos;UTF-8&apos;);
    }
&lt;/code&gt; </content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=179">
	<page_name>Cached_permissions</page_name>
	<page_id>179</page_id>
	<page_title>Cached Permissions</page_title>
	<content>==Cached Permissions==

===Introduction===
When you insert a SQL query in your getPermissions function, this will slow down the app dramatically because this function is called by each query. To resolve this problem, it is better to use cached permissions in your /conf/ApplicationDelegate.php or table/table.php.

===Procedure===
Here is an example :
&lt;code&gt;
class tables_mytable {

    private $cachedPerms = null;
    private function _getCachedPerms($param1, $param2, ..., $paramN){
        if ( !isset($this-&gt;cachedPerms) ) {
            $this-&gt;cachedPerms = array();
            // do some stuff
            $res = mysql_query(&quot;select * from foo where bar=1 and param2=&apos;&quot;.addslashes($param2).&quot;&apos;&quot;);
            while ( $row = mysql_fetch_assoc($res) )  $this-&gt;cachedPerms[$row[&apos;fooid&apos;]] = $row;
        }
        return $this-&gt;cachedPerms;
    }

    function getPermissions($record){
        // do some stuff
        $perms = $this-&gt;getCachedPerms($param1, $param2, ..., $paramN);
        return $perms;
    }
}&lt;/code&gt;
Here, getPermissions() will run a db query on its first request, but subsequent requests will just load the cached value.</content>
	<keywords>permissions, cache, quick, query</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=177">
	<page_name>test_page_34</page_name>
	<page_id>177</page_id>
	<page_title>Hello World</page_title>
	<content>Hello world</content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=180">
	<page_name>viewable_editable_fields</page_name>
	<page_id>180</page_id>
	<page_title>How to make a field editable for some users and only viewable for some other users</page_title>
	<content>If we want only some users to edit a field and some other users only to view that field, then we need to define a &apos;&apos;&apos;fieldX__permissions()&apos;&apos;&apos; method for that field which gives desired permissions for specific users.

One solution is as below.

==permissions.ini==
&lt;code&gt;
[Field Viewer]
view=1
edit=0
new=0

[Field Editor extends Field Viewer]
new=1
edit=1
&lt;/code&gt;

==TableX.php (Delegate class of TableX)==
&lt;code&gt;
function fieldX__permissions(&amp;$record) {
	$user=&amp;Dataface_AuthenticationTool::getInstance()-&gt;getLoggedInUser();
	
	if($user) {
		if($user-&gt;val(&apos;usernameField&apos;)==&quot;UserX&quot;)
			$role=&apos;Field Viewer&apos;;
		else if($user-&gt;val(&apos;usernameField&apos;)==&quot;UserY&quot;)
			$role=&apos;Field Editor&apos;;				

			return Dataface_PermissionsTool::getRolePermissions($role);
	}
		
	return Dataface_PermissionsTool::NO_ACCESS();
}
&lt;/code&gt;</content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=182">
	<page_name>column:legend</page_name>
	<page_id>182</page_id>
	<page_title></page_title>
	<content></content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=183">
	<page_name>advmultiselect</page_name>
	<page_id>183</page_id>
	<page_title></page_title>
	<content></content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=184">
	<page_name>loginFailed</page_name>
	<page_id>184</page_id>
	<page_title>loginFailed() Application Delegate Trigger</page_title>
	<content>[[toc]]

The loginFailed() method of the Application Delegate class is executed after a failed login attempt.

&apos;&apos;&apos;Available since 2.0.1&apos;&apos;&apos;

==Example==

&lt;code&gt;
function loginFailed($username, $userIp, $time){
    error_log(&quot;Failed login for username: $username at IP $userIp at time $time&quot;);
}
&lt;/code&gt;
</content>
	<keywords>login permissions failed password</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki></record>