Jump to content



Toggle %s Welcome to JBZoo community !

English: Please, sign in for contact JBZoo techsupport. Accesses in your Email, which came after the purchase.

Russian: Для того чтобы обратиться в русскую техническую поддержку JBZoo — авторизуйтесь с помощью доступов, которые пришли к вам в письме после покупки. Внимание! Доступ туда имеют только тарифы со знаком «плюс». Подписки JBZoo без "+" форум расценивает как забаненные, поэтому для общения в публичном разделе используйте отдельный аккаунт (легко зайти через социальную сеть). Если форум вас не пускает, почистите куки браузера


Photo
- - - - -

How to derive the item image from the category


Best Answer Kess , 02 October 2014 - 05:57

Hello,

 

I think the easiest way is to make some small modifications to the jbimage element.

 

Here is one way to do it:

 

In the file

/media/zoo/applications/jbuniversal/elements/jbimage/jbimage.php

find the _getDefaultImage function and add these lines at the top:

$item = $this->getItem();
$mainCat = $item->getPrimaryCategory();
$mainCatImgPath = $mainCat->params->get('content.category_teaser_image', '');

and find this block of code:

if (strpos($imagePath, 'http') !== false) {
    $result = $imagePath;
} else if (JFile::exists($imagePath) || JFile::exists(JPATH_ROOT . '/' . $imagePath)) {
    return $this->app->jbimage->resize($imagePath, $width, $height);
} else {
    $result = $this->app->jbimage->placeholder($width, $height);
}

and add one more condition so it will look like this:

if (strpos($imagePath, 'http') !== false) {
    $result = $imagePath;
} else if (JFile::exists($imagePath) || JFile::exists(JPATH_ROOT . '/' . $imagePath)) {
    return $this->app->jbimage->resize($imagePath, $width, $height);
} else if (JFile::exists($mainCatImgPath) || JFile::exists(JPATH_ROOT . '/' . $mainCatImgPath)) {
    return $this->app->jbimage->resize($mainCatImgPath, $width, $height);
} else {
    $result = $this->app->jbimage->placeholder($width, $height);
}

That's seems to be enough.

 

Now go to the elements configuration of your item type and enable default image option for you image element while leaving its path blank. Now it will use the primary category image of your items.

Go to the full post


  • This topic is locked This topic is locked
2 replies to this topic

#1 dgwo

dgwo

Posted 29 September 2014 - 21:42

Hi,
 
I have created a blog application, with an image and text. The image has no default value. What I would like to achieve is that in case the image is not populated in the blog submission, the image must be derived from the category teaser image. So blogs in each category will get the same image, unless a specific image is selected for the blog.
 
In order to achieve this without modifying core files, I would like to use the jbevent item. In order to fetch the category teaser image url, I found some code in [TEMPLATE]/renderer/subcategory/_default.php that could be helpful:
 
$subcategory = $vars['object'];
$params = $subcategory->getParams('site');
 
[...]
 
    <?php if ($vars['params']->get('template.subcategory_teaser_image', 1) && $image['src']) : ?>
        <div class="subcategory-image align-<?php echo $imageAlign;?>">
            <a href="<?php echo $link;?>" title="<?php echo $subcategory->name; ?>"><img
               src="<?php echo $image['src']; ?>" <?php echo $image['width_height']; ?>
               alt="<?php echo $subcategory->name; ?>"
               title="<?php echo $subcategory->name; ?>"
            /></a>
        </div>
    <?php endif; ?> 
 
Unfortunately I cannot use the same way to get the category teaser image in the Event Handler, since the Event Handlers user static classes.
 
Do you have any hint how to proceed?

 

Oops, forgot to include some code:
 
$image = $this->app->jbimage->get('category_teaser_image', $params);

#2 Kess

Kess
  • JBZoo Partner
  • User rate: 12.2
  • posts: 406
  • topics: 40

Posted 02 October 2014 - 05:57   Best Answer

Hello,

 

I think the easiest way is to make some small modifications to the jbimage element.

 

Here is one way to do it:

 

In the file

/media/zoo/applications/jbuniversal/elements/jbimage/jbimage.php

find the _getDefaultImage function and add these lines at the top:

$item = $this->getItem();
$mainCat = $item->getPrimaryCategory();
$mainCatImgPath = $mainCat->params->get('content.category_teaser_image', '');

and find this block of code:

if (strpos($imagePath, 'http') !== false) {
    $result = $imagePath;
} else if (JFile::exists($imagePath) || JFile::exists(JPATH_ROOT . '/' . $imagePath)) {
    return $this->app->jbimage->resize($imagePath, $width, $height);
} else {
    $result = $this->app->jbimage->placeholder($width, $height);
}

and add one more condition so it will look like this:

if (strpos($imagePath, 'http') !== false) {
    $result = $imagePath;
} else if (JFile::exists($imagePath) || JFile::exists(JPATH_ROOT . '/' . $imagePath)) {
    return $this->app->jbimage->resize($imagePath, $width, $height);
} else if (JFile::exists($mainCatImgPath) || JFile::exists(JPATH_ROOT . '/' . $mainCatImgPath)) {
    return $this->app->jbimage->resize($mainCatImgPath, $width, $height);
} else {
    $result = $this->app->jbimage->placeholder($width, $height);
}

That's seems to be enough.

 

Now go to the elements configuration of your item type and enable default image option for you image element while leaving its path blank. Now it will use the primary category image of your items.


  • 0

#3 dgwo

dgwo
  • Topic Starter
  • Members
  • User rate: ~
  • posts: 4
  • topics: 3

Posted 08 October 2014 - 20:40

This solution works very good. Thanks!






Click to return to top of page in style!