Add lender history

A place to discuss and receive support for the Library DB application.

Postby apenticy » Wed Aug 22, 2007 7:55 am

First of all, great application!

I want to add a history tab in de books view, the same as the bidding history in the auction application.
The only problem is that I don't know how to do this.

A different question (however, related) is how to give USER permission to edit the borrow and due date only (and if possible send the owner of the book, mostly myself, an e-mail). I already made an owner_id which works perfect.
apenticy
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Aug 22, 2007 9:27 am

2 Parts:
1. History
2. Permissions

For the history part there is an easy way that will *sort of* do what you need. And there is a more involved way that requires some custom coding. The easy way is to enable dataface's built-in history feature:
http://framework.weblite.ca/documentation/how-to/history-howto
This will track all changes including changes to the borrower of the book.

The hard way would involve creating a separate table called "borrowers" (or something like it) to track who borrows the books, etc.. and make a custom action to insert a new record when someone wants to borrow a book.


Your permissions will depend on the way you implement the borrowing feature. If you keep the borrower info in the books table then you will need to adjust the getPermissions() method in the tables/books/books.php file to allow all logged in users to edit the book. Then add %fieldname%__permissions() methods for each of the individual fields to deny edit access to all users except the admin and owner.

See the following tutorials for info on Dataface permissions:
http://framework.weblite.ca/documentation/tutorial/getting_started/permissions
http://framework.weblite.ca/documentation/manual/delegate_classes/delegate_class_permissions
http://framework.weblite.ca/documentation/tutorial/submission_forms/permissions

A cleaner way to do this is to just create a custom action (say "checkout") to handle the checking out of a book, so that the user just has to click a button to check out the book.
See the following tutorials for info on actions:
http://framework.weblite.ca/documentation/tutorial/getting_started/dataface_actions
http://framework.weblite.ca/documentation/tutorial/getting_started/dataface_actions_2

The more pure solution is to separate the borrowers out into another table and the create a custom action to allow users to check out the books... and probably create a relationship from the books to the borrowers table so you can see the borrowers history. But as always, there are 800 ways to skin this cat.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby apenticy » Wed Aug 22, 2007 4:37 pm

Thanks!
However, when I add the following in books/books.php it disables access (and even for admin) even when the function is empty:

function book_taal__permissions(&$record){

$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
if ( !$user ) return Dataface_PermissionsTool::READ_ONLY();
$role = $user->val('role');
switch ($role){
case 'ADMIN':
return Dataface_PermissionsTool::ALL();
default:
return Dataface_PermissionsTool::READ_ONLY();
}


}

What am i doing wrong?
apenticy
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Aug 23, 2007 10:57 am

The function looks right.
An empty function certainly would disable access because that would imply that no permissions are granted. permissions methods must always return something.

As to why it isn't working... sometimes it helps to throw in a few echo statements to see where the flow of control is going - and what is happening.

e.g. Find out which case is being handled by doing:


function book_taal__permissions(&$record){

$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
if ( !$user ){
echo "User not logged in";
return Dataface_PermissionsTool::READ_ONLY();
}
$role = $user->val('role');
switch ($role){
case 'ADMIN':
echo "Admin user";
return Dataface_PermissionsTool::ALL();
default:
echo "Other user";
return Dataface_PermissionsTool::READ_ONLY();
}


Also.. just confirming that you have a field named 'book_taal' in your books table?

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby dclijste » Sat Sep 01, 2007 3:26 pm

I did it diffrent. I combined the bidding engine from auction with libriandb. With some modification it is now possible to borrow a book the same way you could bid on a product in auction. By doing this you don't have permission problems and it's much cleaner and easier for external users.
dclijste
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sun Sep 02, 2007 3:00 pm

Sounds like a truly creative solution.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Library DB Discussion

Who is online

Users browsing this forum: No registered users and 9 guests

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