Images in subcategories

Phoca Download - download manager
mentalhacker
Phoca Member
Phoca Member
Posts: 26
Joined: 14 Jun 2016, 14:28

Images in subcategories

Post by mentalhacker »

Hi,
The category images are displayed only in categories view, so in the case of multiple category levels, only the main categories can have images.
I'd like the category view to have the same or similar layout as the categories view has.
I was trying to modify the category template but that didn't work.

Code: Select all

echo '<div class="pd-subcategory">';
	echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias))
		.'">'. $valueSubCat->title.'</a>';
	echo '<small>('.$valueSubCat->numdoc.')</small>';
	echo '<div class="ph-img">';
	echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias)).'">'. '<img src="'.$this->t['cssimgpath'].$value->image.'" alt="'.htmlspecialchars(strip_tags($value->title)).'" />'.'</a>';
	echo '</div></div>' . "\n";
Could you please help? What is needed to display the images?
Thanks.

Tags:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Images in subcategories

Post by Jan »

Hi, do you get any error? Are all the needed variables loaded from the database?

Jan
If you find Phoca extensions useful, please support the project
mentalhacker
Phoca Member
Phoca Member
Posts: 26
Joined: 14 Jun 2016, 14:28

Re: Images in subcategories

Post by mentalhacker »

No, there is no error message. The template is ok, but the image filename is not loaded from the database.
The image container and the hyperlink are there:

Code: Select all

<div class="ph-img">
<a href="/letoeltes/pd-test/category/3-lelkipasztor"><img src="/images/phocadownload/" alt=""></a>
</div>
So the variables are missing, and the image is not rendered for some reason. Maybe it's not enough to modify the template because a necessary function is missing.
Any idea?
Thanks.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Images in subcategories

Post by Jan »

Hi, yes, then in model of the view the variables must be loaded (in the main item function or separately :idea: )

Jan
If you find Phoca extensions useful, please support the project
mentalhacker
Phoca Member
Phoca Member
Posts: 26
Joined: 14 Jun 2016, 14:28

Re: Images in subcategories

Post by mentalhacker »

Could you specify the task a little bit more accurately?
Do you mean this file?

components/com_phocadownload/models/category.php

If yes, what's next?
(Is it possible to copy the necessary code from models/categories.php?)
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Images in subcategories

Post by Jan »

Hi,
If yes, what's next?
we are speaking about programming, this means: coding -> testing -> going to next step -> coding -> testing -> going to next step, so I cannot list here all the steps to program some modifications as this is not possible to say it without coding/testing/next step :idea:

Could you specify the task a little bit more accurately?

Joomla! extensions are based on MVC - to see some variable in HTML, you first need to load it from database in the model and then you can format it in the View and its output, so for category view of Phoca Download it means:

view:
components/com_phocadownload/views/category/view.html.php -> asking model for the variable (in some current function or some new function)

model:
components/com_phocadownload/models/category.php ->returning the asked variable to view

view:
components/com_phocadownload/views/category/view.html.php -> managing this variable

view output:
components/com_phocadownload/views/category/tmpl/default_files.php

Unfortunately, I didn't do such customization yes, so the only clue advice for now is to see the categories view/model/output and modify the category view based on the categories view (to get the variable of the image, if it is not loaded in category view, to implement in in output on the place where you need to display it) :idea:

Jan
If you find Phoca extensions useful, please support the project
mentalhacker
Phoca Member
Phoca Member
Posts: 26
Joined: 14 Jun 2016, 14:28

Re: Images in subcategories

Post by mentalhacker »

Yes, these steps are quite obvious, thanks for mentioning and reminding. :D
But what I was really interested in is that in which files do I need to look around in order to modify templates and corresponding functions, because I only had some guesses but I was not sure.
And yes, I managed to solve the problem with your help: category/view.html.php and models/category.php were the two missing links. All the necessary codes were there in the files of categories view (main categories), so I just had to implement them in the files of subcategories.
Unfortunately, I made a mistake at first when modifying the category template through an oversight. I didn't realize that in subcategories $value is replaced by $valueSubCat, so the code was effectless.
The corrected code of the modified template that I shared in my first post is this:

Code: Select all

echo '<div class="pd-subcategory">';
echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias))
	 .'">'. $valueSubCat->title.'</a>';
echo '<small> ('.$valueSubCat->numdoc.')</small>';
echo '<div class="ph-img">';
echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias)).'">'. '<img src="'.$this->t['cssimgpath'].$valueSubCat->image.'" alt="'.htmlspecialchars(strip_tags($valueSubCat->title)).'" />'.'</a>';
echo '</div></div>' . "\n";
The images are displayed in subcategories now.
Thank you, Jan! :twisted:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Images in subcategories

Post by Jan »

Hi, great to hear it.

Jan
If you find Phoca extensions useful, please support the project
Post Reply