klox7 VIP
Total posts: 914
08 Oct 2014 11:56

If I'm right you can display Cobalt fields from multiple types in one list template simply by adding <?php echo $item->fields_by_id[ID]->result; ?> to your list template.

So if I have Type1 with field ID 1 and Type2 with field ID 2 I can do this in my list template:

<?php echo $item->fields_by_id[ID1]->result; ?>
<?php echo $item->fields_by_id[ID2]->result; ?>

and it will display both fields in same template. Is this OK?

Last Modified: 16 Oct 2014


Konstantin
Total posts: 1,113
09 Oct 2014 05:21

Yes, but $item in one time has only one field fields_by_id[ID1] or fields_by_id[ID2], so you must check existing field end then display it.


klox7 VIP
Total posts: 914
09 Oct 2014 06:39

Konstantin Yes, but $item in one time has only one field fields_by_id[ID1] or fields_by_id[ID2], so you must check existing field end then display it.

Sorry I don't understand:). What do you mean check?


Konstantin
Total posts: 1,113
09 Oct 2014 10:41

Each $item may be different type and has different fields, you display fields one by one sometime will be exist fields_by_id[ID1], sometime fields_by_id[ID2]. Otherwise will be notise that field dont find.


Sergey
Total posts: 13,748
09 Oct 2014 10:42

This is depends. If you have the same field in both types. I mean the same label and type then you may use only

<?php echo $item->fields_by_key[key]->result; ?>

This will display field from both types.

But if those are different types, then yes, you have to call every field separately.

klox7 Sorry I don't understand:). What do you mean check?

Konstantin means you have to check if fields is not empty.

<?php if(!empty($item->fields_by_id[ID1])): ?>
    <?php echo $item->fields_by_id[ID1]->result; ?>
<? endif; ?>

klox7 VIP
Total posts: 914
10 Oct 2014 12:14

Thanks. I got it to work in section view but different types displays as different list items.

Is it possibe to do this:?

  • Type1
  • Type2
  • Section (for both types)

When in list view show list items as fields from Type1 + fields from Type2 and not as separate list items. list

As I said this works in section view but not for in comments list view under article.


Jeff VIP
Total posts: 745
10 Oct 2014 23:29

Sergey This is depends. If you have the same field in both types. I mean the same label and type then you may use only

<?php echo $item->fields_by_key[key]->result; ?>

+1

Just what I was looking for! I presume I can also use

<?php if(!empty($item->fields_by_key['key'])): ?>
    <?php echo $item->fields_by_key['key']->result; ?>
<? endif; ?>

klox7 VIP
Total posts: 914
11 Oct 2014 18:55
<?php
$key = $this->fields_keys_by_id[ID];
if(!empty($item->fields_by_key[$key])):
$field = $item->fields_by_key[$key];
echo $field->result;
?>

Jeff VIP
Total posts: 745
12 Oct 2014 00:59

@klox7

thank you for this, but I have used the next code which seems to work

<?php 
    if(isset($item->fields_by_key['key'])):     
        echo $item->fields_by_key['key']->result;
        unset ($item->fields_by_key['key']->result);
    endif; 
?>

I need the unset part to prevent rerendering because other fields are auto included in my template


Sergey
Total posts: 13,748
12 Oct 2014 03:08

I see. Yes i think it is possible. One is review and another is review replay.

In the first place I would create different section for review replys. And no link on frontend. Use never see ful article view of review reply and never see list of review replys.

Now in review you can find that article by SQL query.

$sql = "SELECT * FROM #__js_res_record WHERE parent_id = ".$item->id;
$db->setQuery($sql);
$record = $db->loadResult();

echo CobaltApi::renderField($record, 12, 'list');

where 12 is an ID of the field and list is the view. Show as in the list or as in the full view.


klox7 VIP
Total posts: 914
12 Oct 2014 18:40

Sergey In the first place I would create different section for review replys.

@Sergey do you have to use different section for your solution to work because of $type and $section in api.php (see bellow)?

$type = ItemsStore::getType($record->type_id);
$section = ItemsStore::getSection($record->section_id);

Since I use same section wouldn't something like this be more appropriate

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('field_value');
$query->from($db->quoteName('#__js_res_record_values'));
$query->where('field_id = 304');                    
$db->setQuery($query);
$review_reply = $db->loadObjectList();
foreach($review_reply as $reply) { 
    echo $reply->field_value;
};
?>

But this displays one result under every list item which is not OK.


Sergey
Total posts: 13,748
13 Oct 2014 02:07

You have to have differnt section, so that replays are not in the list of reviews.


klox7 VIP
Total posts: 914
13 Oct 2014 06:07

Sergey You have to have differnt section, so that replays are not in the list of reviews.

Aha OK, you were talking about list in section view. What about comments list under article?


Sergey
Total posts: 13,748
13 Oct 2014 08:22

I have already gave you code example. Or you mean in articles (1 level) list template?


klox7 VIP
Total posts: 914
14 Oct 2014 13:20

Yes, this is now working just fine except I can't get created date with $review_reply->created. It always displays one date for all items.

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = 'SELECT * FROM #__js_res_record WHERE published = 1 AND parent_id = '.$item->id;
$db->setQuery($query);
$review_reply = $db->loadResult();

if(isset($review_reply)): {
    echo "<h4>Review reply</h4><p>" .JText::sprintf('CONDATE', JHtml::_('date', $review_reply->created, $params->get('tmpl_core.item_time_format'))) . "</p>";
    echo @CobaltApi::renderField($review_reply, 304, 'list');  //304 is field ID
} 
endif;
?>

Sergey
Total posts: 13,748
15 Oct 2014 02:50

Use ctime instead of created.


klox7 VIP
Total posts: 914
15 Oct 2014 06:49

ctime and created in this case are the same. I was wondering if I need to add $review_reply->ctime in foreach because date's output is always the same?


Sergey
Total posts: 13,748
15 Oct 2014 12:04

Actualy there is no created property at all. created only used in template. It is prepared poerty. Not exists in DB. So you acualy always put NULL into date render that is why date is the same. Please change it to ctime.

This

 JHtml::_('date', $review_reply->created

To this

 JHtml::_('date', $review_reply->ctime

klox7 VIP
Total posts: 914
15 Oct 2014 12:12

klox7 ctime and created in this case are the same.

ctime still shows same date!


Sergey
Total posts: 13,748
15 Oct 2014 12:21

Then, it is the same date.


klox7 VIP
Total posts: 914
15 Oct 2014 13:50

No, only one record with this date in ctime column in db.

Is it maybe because this $review_reply = $db->loadResult(); is not loadObjectList. Can I display record values and parameters with something else than CobaltApi::renderField($review_reply, 304, 'list'); so I can include ctime here?

Replay Topic
Uploading
Click here to upload and insert file from you hard drive: (png, gif, jpg, jpeg, zip, txt, rar)
Powered by Cobalt