Page 1 of 2

customize view_tab_content

PostPosted: Sat Oct 27, 2007 3:24 am
by kurisusan
Hi,
I'd like to change the details view of a record which has several 1-N relationships to other tables. The details view should include the list view of each related table. One way I can imagine is to supply a block__view_tab_content function in the tables delegate class and loop through the $record->getRelatedRecordObjects(name) arrays. However I'm wondering if I can't reuse a template (Dataface_List_View_summary.html). If that's possible how, would I do that?
Thanks for any hints, Christian

PostPosted: Sat Oct 27, 2007 12:09 pm
by shannah
Hi Christian,

You can define sections using the section__%sectionname%() delegate class method. This method should return an associative array with the following keys:

class : This should be either 'left' or 'main' depending on where the section is to be displayed.

label : The heading of the section
content : The HTML content to be displayed in the section.
order : The order of the section.
records : An array of Dataface_Record objects to be displayed

So suppose you had relationship named 'courses', you could create a section to display on the view page by:
Code: Select all
function section__courses(&$record){
    return array(
        'label'=> 'Courses',
        'class'=>'main',
        'records'=>$record->getRelatedRecordObjects('courses')
    );
}


or if you wanted to do your own custom HTML instead

Code: Select all
function section__courses(&$record){
    return array(
        'label'=>'Courses',
        'class'=>'main',
        'content'=> 'My Custom Content Here'
    );


You can see many examples of these custom sections in the fueleconomy database when you are looking at a given car's record. The craigsllist ad listings are created using a custom section like this.

-Steve

PostPosted: Sat Oct 27, 2007 11:19 pm
by kurisusan
Hi Steve,
thanks for the example. However, as I really want something very similar to the list view of a table embedded into the details view of another's table record, i.e. with clickable entries which will link to the corresponding details view, will I have to create the html output all by myself or is there something which I could reuse?
Christian

PostPosted: Sat Oct 27, 2007 11:33 pm
by shannah
There are quite a few options available, but most would require a little bit of experimentation with the various templates.

The simplest way to start would be to just produce your own HTML output. The Dataface_Record class has a getURL() method to return the URL to the details view for that record, which could be convenient.

You can get the table to look like the table in list view by using the 'listing' css class:

e.g.:
Code: Select all

 
     ....
   
   
      ...
   



Or you could go a step further and use the Dataface_RecordGrid class.

e.g.
Code: Select all
import('Dataface/RecordGrid.php');
$grid = new Dataface_RecordGrid($records);
echo $grid->toHTML();


You can also try to use the Dataface_ResultList class to get what you want, but you'll likely have to do some experimentation with it as I haven't used it outside of its intended context that I can remember.

-Steve

PostPosted: Sat Oct 27, 2007 11:37 pm
by shannah
The forum seems to strip some of the HTML out that I wanted.

The table tag in the example should have class="listing" as one of its attributes.

-Steve

PostPosted: Sat Oct 27, 2007 11:49 pm
by kurisusan
Great! This is what I was looking for. But I'm having problems with the following test:
Code: Select all
    function block__view_tab_content() {
       
      // Obtain reference to current Program record
      $app =& Dataface_Application::getInstance();
      $record =& $app->getRecord();
     
      import('Dataface/RecordGrid.php');
      $records = $record->getRelatedRecordObjects('samples');
      $grid = new Dataface_RecordGrid($records);
      echo $grid->toHTML();

    }

The page displays an error message:
Code: Select all
Warning: array_keys() [function.array-keys]: The first argument should be an array in /media/hda6/home/ck/arbeit/vis/web/dataface/Dataface/RecordGrid.php on line 95

Warning: Invalid argument supplied for foreach() in /media/hda6/home/ck/arbeit/vis/web/dataface/Dataface/RecordGrid.php on line 113

Warning: Invalid argument supplied for foreach() in /media/hda6/home/ck/arbeit/vis/web/dataface/Dataface/RecordGrid.php on line 113

Warning: Invalid argument supplied for foreach() in /media/hda6/home/ck/arbeit/vis/web/dataface/Dataface/RecordGrid.php on line 146

PostPosted: Sat Oct 27, 2007 11:56 pm
by shannah
Time to do some debugging... evidently it says that $records is not an array. So find out what it is.

PostPosted: Sun Oct 28, 2007 9:47 pm
by kurisusan
Ok, got the message. It should have been getRelatedRecords not getRelatedRecordObjects. I'm slowly beginning to understand how dataface works.

The closest to my needs (at least visually) I got by putting
Code: Select all
import('Dataface/RelatedList.php');
$rel = new Dataface_RelatedList($record, 'documents');
echo $rel->toHTML();

into the block__view_tab_content functions for every related table I have. However this approach breaks several things, e.g. the button actions, row sorting.
Clearly it wasn't meant to be used like that. Sorry to mess around with dataface, but my client doesn't want to have to click on the related tables' tabs, instead he wants every related table displayed on the details view, including all the possible actions on those tables.
I already started rendering the tables myself, but I don't know how to add buttons to update/remove/add items to the related tables. I guess I should read about 'actions', right?
Any pointers are highly appreciated.
Christian

PostPosted: Mon Oct 29, 2007 10:04 am
by shannah
For adding records, it may be easiest just to take advantage of Dataface's consistent URL conventions.

e.g.
Code: Select all
index.php?-action=new_related_record&-table=foo&fooid=10&-relationship=bar


will take you to the add new related record form for the 'bar' relationship on foo record with id=10.

-Steve

(Note, for the next release, the recordGrid class has been improved to offer javascript sorting).

PostPosted: Mon Oct 29, 2007 11:32 pm
by kurisusan
[quote="shannah"]For adding records, it may be easiest just to take advantage of Dataface's consistent URL conventions.

e.g.
Code: Select all
index.php?-action=new_related_record&-table=foo&fooid=10&-relationship=bar


will take you to the add new related record form for the 'bar' relationship on foo record with id=10.


That works very well, thank you. Is it right, that there's no need for a fooid when linking from the details view of a record? At least the standard 'add related' button link doesn't have that var.
After the new related record has been created, is there a way to directly go back to the parent's record detail view rather than to the related table's list view?

(Note, for the next release, the recordGrid class has been improved to offer javascript sorting).


Where's the development going on? I looked for RecordGrid.php in the cvs tree but that file hasn't been modified for a long time.

Christian

PostPosted: Mon Oct 29, 2007 11:46 pm
by shannah
I use a private subversion repository for all development. The CVS repository on sourceforge is old and out of date.

Source is released to the public only when a release is made.

Re: customize view_tab_content

PostPosted: Sat Jun 16, 2012 9:55 pm
by cookie720
I would like to utilize the left column for my foreign tables too but they are showing there by default. Is there a way to delete them and manually put my own up via the delegateclass php file?

Re: customize view_tab_content

PostPosted: Sat Jun 16, 2012 10:03 pm
by cookie720
Can someone please post their full function which displays related records in a tables' details tab?
I have tried some bits and pieces from the previous posts, and I am getting some results, but they are not exactly what I want.
I simply need to list basically the last related record from each related table, in my tables details view, in the same format.

I thought it would be nice and simple but I just cant seem to get anything to work. Xataface is a very diverse program and the learning curve is hard for me because I am a beginner in both PHP + MySQL too

Re: customize view_tab_content

PostPosted: Tue Jun 19, 2012 2:26 am
by cookie720
Sorry about the triple post, but anyone....?

Re: customize view_tab_content

PostPosted: Wed Jun 20, 2012 10:11 am
by shannah
cookie720 wrote:I would like to utilize the left column for my foreign tables too but they are showing there by default. Is there a way to delete them and manually put my own up via the delegateclass php file?


yes. Use the section:visible=0 directive in the relationships.ini file for the relationship.
http://xataface.com/wiki/relationships.ini_file

-Steve