customize view_tab_content

Archived from the Xataface Users forum.

kurisusan — Sat Oct 27, 2007 3:24 am

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


shannah — Sat Oct 27, 2007 12:09 pm

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


kurisusan — Sat Oct 27, 2007 11:19 pm

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


shannah — Sat Oct 27, 2007 11:33 pm

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


shannah — Sat Oct 27, 2007 11:37 pm

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


kurisusan — Sat Oct 27, 2007 11:49 pm

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`


shannah — Sat Oct 27, 2007 11:56 pm

Time to do some debugging… evidently it says that $records is not an array. So find out what it is.


kurisusan — Sun Oct 28, 2007 9:47 pm

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


shannah — Mon Oct 29, 2007 10:04 am

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).


kurisusan — Mon Oct 29, 2007 11:32 pm

[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.


shannah — Mon Oct 29, 2007 11:46 pm

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.


cookie720 — Sat Jun 16, 2012 9:55 pm

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?


cookie720 — Sat Jun 16, 2012 10:03 pm

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


cookie720 — Tue Jun 19, 2012 2:26 am

Sorry about the triple post, but anyone….?


shannah — Wed Jun 20, 2012 10:11 am

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


shannah — Mon Oct 29, 2007 11:46 pm

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.


cookie720 — Sat Jun 16, 2012 9:55 pm

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?


cookie720 — Sat Jun 16, 2012 10:03 pm

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


cookie720 — Tue Jun 19, 2012 2:26 am

Sorry about the triple post, but anyone….?


shannah — Wed Jun 20, 2012 10:11 am

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


shannah — Wed Jun 20, 2012 10:15 am

cookie720 wrote: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

Here is a function that builds a related section for a details view. I call this function from appropriate section_xxx() methods of the delegate class.

Code: Select all
function buildRelatedSection(Dataface_Record $record, $relationship){        import('Dataface/RelatedList.php');        $relatedList = new Dataface_RelatedList($record, $relationship);       $relatedList->noLinks = true;       $relatedList->hideActions = true;       $content = $relatedList->toHtml();                        $rel = $record->table()->getRelationship($relationship);                        return array(           'class'=>'main',           'content'=>$content,           'label'=>$rel->getLabel(),           'order'=>10        );         }

Creating a section for the “ingredients” relationship:

Code: Select all
function section__ingredients($record){        return $this->buildRelatedSection($record, 'Ingredientes');     }

-Steve


cookie720 — Thu Jun 21, 2012 5:57 am

Interesting, that creates a section that looks just like the list view of a table. It even has the add related record button…which didnt work for me.
That might come in handy!
However, what I wanted is a section that looks like the default tables display of fields. The view/display that comes up when you click on the display tab of a table