Nuclear General

Content Relational Records Field

31 posts in this topic

%7Boption%7D



File Name: Content Relational Records Field

File Submitter: Nuclear General

File Submitted: 28 Jul 2012

File Category: Content Management



This Hook and field source will add a single IP.Content field type that is an advanced usage database relational field.
The selected field to use will be used for input only, the value of this field is always an ARRAY of 'record' data, you should NEVER select to show this field in listing or display and manually show the data you wish to show in the templates, as such, there is no field preview available.
You should never use this as a title or body field. You should never use this field's topic posting options.
If the selected field input type is a drop-down, the value will be a single-dimensional array of 'record' data from the selected 'record' with all other field types parsed, the field data there-of, the category(if any) data, and the data of the database pulled.
If the selected field input type is not a drop-down, the value will be a multi-dimensional array of 'records' data from the selected 'records' with all other field types parsed, the field data there-of, the category(if any) data for each record, and the data of the database pulled.
Available field input types are drop-down, multi-select, type-ahead, and check-box.
Check-box is designed In a Show/hide set of h3 tags and div's, will be the database name if no categories are present in the selected relational database in one header, will be grouped by the category name of the records to pull if categories are used in the selected relational database.
All Check-box div's default to not-expanded(hidden) to keep the form clean, and open with a click on the header.
With a drop-down in use, display template code could look like this:

<if test="$data['record']['myfieldkey']">

<a href="{$data['record']['myfieldkey']['record_link']}">{$data['record']['myfieldkey']['record_title']}</a>

</if>


With a multi-select, type-ahead, or check-box in use, display template code could look like this:

<if test="is_array($data['record']['myfieldkey']) && count($data['record']['myfieldkey'])">

<foreach loop="$data['record']['myfieldkey'] as $id => $recordData">

<a href="{$recordData['record_link']}">{$recordData['record_title']}</a>

</foreach>

</if>


record_title is the field that was selected for input's value.
Known issues/bugs.

  • The attachments field type is directly incompatible with this field due to string functions being performed in the source code.



here to download this file

Share this post


Link to post
Share on other sites

I'm not sure to use it correctly

I have this error :


Fatal error: Uncaught exception 'Exception' with message 'ccsTags-3 is not an object' in /home/www/141d2093c0e41809bf75f6f93edc4124/web/test-forum-32/admin/sources/base/ipsRegistry.php:1079 Stack trace: #0 /home/www/141d2093c0e41809bf75f6f93edc4124/web/test-forum-32/admin/applications_addon/ips/ccs/sources/databases/fields/relational_data.php(503): ipsRegistry::getClass('ccsTags-3') #1 /home/www/141d2093c0e41809bf75f6f93edc4124/web/test-forum-32/admin/applications_addon/ips/ccs/sources/databases/fields.php(419): fields_relational_data->getFieldValue(Array, Array, '0') #2 /home/www/141d2093c0e41809bf75f6f93edc4124/web/test-forum-32/admin/applications_addon/ips/ccs/extensions/content/feed_blocks/databases.php(1115): ccs_database_fields->getFieldValue(Array, Array, '0') #3 /home/www/141d2093c0e41809bf75f6f93edc4124/web/test-forum-32/admin/applications_addon/ips/ccs/extensions/content/feed_blocks/databases.php(848): feed_databases->_getRecords(Array, Array, Array, false) #4 /home/www/141d2093c0e41809bf75f6f93edc4124/web/test- in /home/www/141d2093c0e41809bf75f6f93edc4124/web/test-forum-32/admin/sources/base/ipsRegistry.php on line 1079

Share this post


Link to post
Share on other sites

yes, good. There is no error now.

But, I can't display field from the other database


I create a new field in db A
The field typ is "Database Records"
I choose db B (database & field) with Dropdown (type of field)

(in my db B, I have 2 fields : Title & Content)

In the template "Display" of my db A, if I read your "Read Me" file, I must use this :


<if test="$data['record']['myfieldkey']">

<a href='{$data['record']['myfieldkey']['record_link']}'>{$data['record']['myfieldkey']['record_title']}</a>

</if>



But I'm not sure what I need to change.

Share this post


Link to post
Share on other sites

what is the key of the field you entered? Will happily spit some example code and guide you where to put it.... is fairly basic templating as the data is all handed to you, no advanced/extra code needed for a lack of data.

Share this post


Link to post
Share on other sites

In my db A, the field (database records) is "test" (key = "test")

in my db B, there is 2 fields :

- Field "Title" (key = title)
- Field "Content" (key = content)

Display fields from db B in my db A

Share this post


Link to post
Share on other sites

>_< Why.... do.... people do that? title, content, url, these are generic keys you should not use in field keys.... is like using record_link.... content stock would go insane with that one..
anywhom.


<if test="$data['record']['test']">

<a href='{$data['record']['test']['record_link']}'>{$data['record']['test']['record_title']}</a>

<br />

<if test="is_array($data['record']['test']['_category'])">

<a href='{$data['record']['test']['_category']['category_link']}'>{$data['record']['test']['_category']['category_name']}</a>

</if>

<if test="is_array($data['record']['test']['tags'])">

	 {$data['record']['test']['tags']['formatted']['parsedWithoutComma']}

</if>

<br />

{$data['record']['test']['content']}

</if>

Share this post


Link to post
Share on other sites

>_< Why.... do.... people do that? title, content, url, these are generic keys you should not use in field keys.... is like using record_link.... content stock would go insane with that one..


anywhom.





I know :lol:
It's just for test on my test board.... :sweat:


I try an other test on other database, because nothing happened with your code.

Share this post


Link to post
Share on other sites

hrmm... just retested drop-down locally.... :unsure:
This showed me data fine, my local test field key is 'some_field' without quotes(I know, so original, shoot me):


<if test="$data['record']['some_field']">

<a href='{$data['record']['some_field']['record_link']}'>{$data['record']['some_field']['record_title']}</a>

-

<if test="is_array($data['record']['some_field']['_category'])">

<a href='{$data['record']['some_field']['_category']['category_link']}'>{$data['record']['some_field']['_category']['category_name']}</a>

</if>

<if test="is_array($data['record']['some_field']['tags'])">

		 {$data['record']['some_field']['tags']['formatted']['parsedWithoutComma']}

</if>

<br />

<if test="is_array($data['record']['some_field']['_fields'])">

<foreach loop="$data['record']['some_field']['_fields'] as $field">

<if test="'field_'.$field['field_id']!=$data['record']['some_field']['_database']['database_field_title']">

<div style='width:100%;'>

<strong style='width: 20%; display: inline-block; font-weight: bold; text-align: right; vertical-align: top; margin-right: 10px;'>{$field['field_name']}:</strong>

{$data['record']['some_field']['field_' . $field['field_id'] . '_value']}

</div>

</if>

</foreach>

</if>

</if>


similar code, just a little more jaz piled on for helpful what do I have :smile:
Showing records from another db fine locally.... previously had a bit of multi-usage(not drop-down :smile: ) code present working fine as well.

Share this post


Link to post
Share on other sites


<if test="$data['record']['test']">

<a href='{$data['record']['test']['record_link']}'>{$data['record']['test']['record_title']}</a>

<br />

<if test="is_array($data['record']['test']['_category'])">

<a href='{$data['record']['test']['_category']['category_link']}'>{$data['record']['test']['_category']['category_name']}</a>

</if>

<if test="is_array($data['record']['test']['tags'])">

	 {$data['record']['test']['tags']['formatted']['parsedWithoutComma']}

</if>

<br />

{$data['record']['test']['content']}

</if>




I think I begin to understand lol

And can you give me exemple if I choose type-ahead ?

Share this post


Link to post
Share on other sites

mmhh... With dropdown :

I try to put this


<if test="$data['record']['salles_concerts']">

{$data['record']['salles_concerts']['record_title']}

</if>

it works on my test board.... but on my live board, I have this error :


Warning: stristr() expects parameter 1 to be string, array given in /home/www/141d2093c0e41809bf75f6f93edc4124/web/forums/admin/applications_addon/ips/ccs/sources/databases.php on line 3209



See : http://www.depeche-mode.be/tournees.html/_/totu09-10/esch-sur-alzette-r1014

Share this post


Link to post
Share on other sites

working on it... seems i need to hook into that method and unset the fields of this type.... great, that does not work.
Added a note of warning to the download description, cause no matter how much changing I do by hook or in the field source attachments freak out.

Share this post


Link to post
Share on other sites

If I understand this correctly, this will allow me to pull a whole row of data from a database?

For example if in DB A I have team (which is a relationship to DB B team field), In DB A, I can display any field from DB B where the relationship occurs?

If so, this is perfect and should have already been included in IP Content. If that's not what it does, forgive me and please give me a little example if you don't mind.

BTW, you are a IP Content god. smile.png

Share this post


Link to post
Share on other sites

correct.

I must note however, not for lack of trying to sidestep it, it makes the attachments field type if used on one of these interlinked databases scream violently, as noted in file description.

SECTalk.com likes this

Share this post


Link to post
Share on other sites

correct.

I must note however, not for lack of trying to sidestep it, it makes the attachments field type if used on one of these interlinked databases scream violently, as noted in file description.

Not a big deal, I suppose using a text field with a URL for an image in it will work fine?

Share this post


Link to post
Share on other sites

Very nice work Marcher,

How feasible would it be to add 3 features:

Cross Link records like in the normal database relationship?

order by field including last updated date?

Max results to return?

I think I can see how the last two things could be added by modfiying your query in the getFieldValue function and adding the fields to save in the field_extra field, but I can't figure out how the stock database relationship knows to show cross linked records so I'm not sure what would be involved to get yours to do it.

Share this post


Link to post
Share on other sites

Very nice work Marcher,

How feasible would it be to add 3 features:

Cross Link records like in the normal database relationship?

order by field including last updated date?

Max results to return?

I think I can see how the last two things could be added by modfiying your query in the getFieldValue function and adding the fields to save in the field_extra field, but I can't figure out how the stock database relationship knows to show cross linked records so I'm not sure what would be involved to get yours to do it.

I get to pull hijinkery in the hook to show the option and mod the field to save it, already looking at exactly that for this and fields pack relationals.

order by field, as a note, is practically useless without direction as well smile.png , at norms, it follows the linked database config, but this seems much more flexible being configurable at the field level anyway.

Darksbane0 likes this

Share this post


Link to post
Share on other sites

I dug. Going to have to be happy with 2 and 3, easy bits which i code now.

1, is currently not possible. I could code something for it into a display template, but to put it simply, that data cannot be fed to the view template properly.... that cross-linking is relatively hard-coded in for solely the relational field type.

Share this post


Link to post
Share on other sites

I dug. Going to have to be happy with 2 and 3, easy bits which i code now.

1, is currently not possible. I could code something for it into a display template, but to put it simply, that data cannot be fed to the view template properly.... that cross-linking is relatively hard-coded in for solely the relational field type.

Thats cool Marcher, thanks for looking into it.

Share this post


Link to post
Share on other sites

Just wanted to follow up on an issue I had when getting back into using this field type again hopefully share some lessons that might help someone else coming at it either from the start, or after a long hiatus like I had. :smile:

First thing: It's mentioned in the readme, but I missed a part of the significance in making sure that the field configured to use the Relational Records Field type is configured to NOT show up in either the "Show field in listing template" or "Show field in display template". I knew that the field value was an array and thus shouldn't be displayed directly, but somehow I forgot that that holds just as true for the Display template as it does for the listing template. :: facepalm ::

Also, to help someone else that may need more than one example to grok the proper usage I'm going to include a code snippet from a DB system we're building. It has TWO areas of interest:

1. It does contain the code to properly display the Relational Records Field, specifically it's for a DB where the Relational Records Field is being used for a field with the key "ingredient". Look for the code below to see the relevant section:

<if test="is_array($data['record']['ingredient']) && count($data['record']['ingredient'])">

2. It also contains a brilliant tweak (if I do say so myself) that Marcher helped me implement that uses the "Topic format" setting to allow you to control layout/style/css and formatting etc on a field by field basis. Look for the code below to see the relevant section:

<if test="$field['field_topic_format']">

Anyway, hope that helps someone else. :smile:

Here's the relevant chunk of the DB display template:

<div class="ipsBox">
    <div class="ipsBox_container ipsPad ipsType_textblock">
        {$data['record'][$data['database']['database_field_content'] . '_value' ]}
        {parse template="repButtons" group="global_other" params="$data['record'], array_merge( array( 'primaryId' => $data['record']['primary_id_field'], 'domLikeStripId' => 'like_post_' . $data['record']['primary_id_field'], 'domCountId' => 'rep_post_' . $data['record']['primary_id_field'], 'app' => 'ccs', 'type' => 'record_id_' . $data['database']['database_id'], 'likeFormatted' => $data['record']['like']['formatted'] ), $data['record'] )"}
        <br />
        
        <foreach loop="$data['fields'] as $field">
            <if test="$field['field_type'] == 'attachments' AND $data['record']['field_' . $field['field_id'] . '_value']">
                <div id='attach_wrap' class='rounded clearfix'>
                    <h4>{$field['field_name']}</h4>
                    <br />
                    {$data['record']['field_' . $field['field_id'] . '_value']}
                    <br /><br />
                </div>
            </if>
        </foreach>
        
        <table class='ipb_table'>
            <if test="count($data['fields'])">
                <foreach loop="$data['fields'] as $field">
                    <if test="'field_'.$field['field_id'] != $data['database']['database_field_title'] and 'field_'.$field['field_id'] != $data['database']['databse_field_content'] and $field['field_type'] != 'attachments'">


<if test="$field['field_topic_format']">
{parse expression="str_replace( array('{value}', '{key}'), array($data['record']['field_' . $field['field_id'] . '_value'], $field['field_name']), $field['field_topic_format'])"}
<else />

                        <tr>
                           <td style='width: 20%; font-weight: bold; text-align: right; vertical-align: top;'>{$field['field_name']}:</td>
                            <td>{$data['record']['field_' . $field['field_id'] . '_value']}</td>
                        </tr>
</if>
</if>
                    </if>
                </foreach>
<if test="is_array($data['record']['ingredient']) && count($data['record']['ingredient'])">
       <tr>
                           <td style='width: 20%; font-weight: bold; text-align: right; vertical-align: top;'>{$this->caches['ccs_fields'][$data['database']['database_id']][26]['field_name']}:</td>
                            <td>
<foreach loop="$data['record']['ingredient'] as $id => $recordData">
<a href='{$recordData['record_link']}'>{$recordData['record_title']}</a>
</foreach>
</td>
                        </tr>
</if>
            <else />
                <tr>
                    <td style='text-align: center;'><em>{$this->lang->words['record_not_found']}</em></td>
                </tr>
            </if>
        </table>
    </div>
</div>

James (of James and Susan)

Share this post


Link to post
Share on other sites

Wanted to follow up on this a bit. One of the BIG differences between this and the stock IP.C relational field is the fact that you can pull other data from the linked to record onto the current record. The IP.C stock relational only shows the record title as a link.

In contract:

This field allows you to include any other fields from the record you are linking to. So, for instance, if you have an image associated with each record in an "ingredients" IP.C DB, you can tweak the display template for the primary DB (Recipes in this case) so that the recipe shows not just a list of ingredients linked to the relevant ingredient DB record, but also a picture of the ingredient and any tips about working with that particular ingredient etc, all on the Recipe record itself! :smile:

Pretty dang cool.

Here's an example of how that could be implemented (this one shows just an image in addition to the title) in the display template used above:

<if test="is_array($data['record']['ingredient']) && count($data['record']['ingredient'])">
       <tr>
                           <td style='width: 20%; font-weight: bold; text-align: right; vertical-align: top;'>{$this->caches['ccs_fields'][$data['database']['database_id']][26]['field_name']}:</td>
                            <td>
<foreach loop="$data['record']['ingredient'] as $id => $recordData">
<img src="{$recordData['photo_ingredient']}" height="100" width="100" />
<a href='{$recordData['record_link']}'>{$recordData['record_title']}</a>
</foreach>
</td>

James

Share this post


Link to post
Share on other sites

So there is no way to combine cross-referencing and pulling all data from the linked record?

So if I have like a music album database which links to artists I can either:

  • use this hook to show the artist’s picture and bio on the music album record view
  • use the stock IPS relation field, show only a link to the artist, but have the music album automatically listed on the artist’s page.

But I cannot have both, can I?

Share this post


Link to post
Share on other sites

Can anyone help me with what I am doing wrong with the following code....

<if test="is_array($data['record']['country_linked_db']) && count($data['record']['country_linked_db'])">
<br /><br />
<a href="/country/c/{parse expression="$data['record']['country_linked_db']['field_15'] = strtolower($data['record']['country_linked_db']['field_15'])"}/">Visit the main {$data['record']['country_linked_db']['field_15']} section...</a> 

{$data['record']['country_linked_db']['field_15']}

<ol class='ipsList_inline ffsubforums' id='pages'>
<foreach loop="$data['record']['country_linked_db'] as $id => $recordData">


<li><a href="{$recordData['record_link']}"rel='bookmark' title='{$recordData['field_17']}'>{$recordData['field_17']} in {$recordData[field_15]}</a>
</li>
</foreach>
</ol>
</if>

The loop works fine.

However I can't seem to be able to pull in field_15 before the loop.

I only need the content of that field to show once above the loop.

Any clues?

Many thanks.

Share this post


Link to post
Share on other sites

I am not sure what you are tryring to achieve. That variable holds an array with different records, each with different values for the individual fields.

Is that field_15 identical for all linked records and you want to grab just any of them, e.g. the one in the first record?

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.