How do I get instance of the current record in block func?

A place for users and developers of the Xataface to discuss and receive support.

How do I get instance of the current record in block func?

Postby kevinwen » Wed Dec 30, 2009 5:28 pm

In Dataface/templates/Dataface_Form_Section_Template.html at line 69 is as following:
{define_slot name="`$element.field.name`_delete_link"}<a class="delete-file-link" href="#" title="Delete this file" onclick="Xataface.deleteFile ...

What it does is to provide a link to delete the file uploaded. Now I want to make this link disappear when a condition is satisfied, like the logged_in user permission and/or some criteria in the current record are met, like status == 'approved'. I created a function in the table's delegate class like function block__source_attachment_1_delete_link(). I can do it for the permission with the following code just like the getPermission():

$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
//If the user is null then nobody is logged in... no access. This will force a login prompt.
if (!isset($user)) return Dataface_PermissionsTool::NO_ACCESS();
$role = $user->val('user_role');
if ($role == "ADMIN") return Dataface_PermissionsTool::getRolePermissions($role);
if ($role == "GUEST") return Dataface_PermissionsTool::getRolePermissions("READ ONLY");

However, There is no way to get the current record so I can check if certain criteria in the current record are met. Does somebody know how to do it? What parameter does this function take? Can I just pass a &$record as arguement to this function?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: How do I get instance of the current record in block func?

Postby shannah » Wed Dec 30, 2009 5:45 pm

To get the current record
Code: Select all
$record =& Dataface_Application::getInstance()->getRecord();
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How do I get instance of the current record in block func?

Postby kevinwen » Thu Dec 31, 2009 1:01 pm

Thank you so much for your quick response :D . There are some questions down to the road:

I know I can use $record->_tablename to get the name of the table for the record, but is there any function (like getTable()) to retrieve the table name instead of direct access to the class member? Also, if this slot is related to a field in the table, is there any way I can get the field name as well? Now I have to hard-code the table name and field name in the block function (source_attachment_1 is the field name in a table and the block function below is used to override the output for the slot in Dataface_Form_Section_Template.html mentioned above):

function block__source_attachment_1_delete_link(){
$record =& Dataface_Application::getInstance()->getRecord();
$status_id = $record->val('status_id');
if (!in_array($status_id, array(6))){
echo '<a class="delete-file-link" href="#" title="Delete this file" onclick="Xataface.deleteFile(\'' . $record->getURL() . '\', \'source_attachment_1\', \'change_memos-source_attachment_1-preview\');return false;"><img src="' . DATAFACE_URL . '/images/delete.gif" alt="Delete"/></a>';
} else {
echo '';
}
}
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 17 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved