Random Image : Auto Select Sub-Categories
Posted: 15 May 2010, 00:55
Hi,
first of all, thx for your modules and plugins !!! They are great.
I'll begin this post by a thing i found into your components : when installing (at least the add image button plugin) some tools from you, i encountered an error which was solved like this :
Error :
occurs on line 51 or 52 depending version of phoca
Resolution :
replace
with :
which might be error coming because of a confusion between frontend and backend. In fact the original line do work on some sites and on some it does not ...
Back to the original subject of this post
I wanted to have a random image module, in which i haven't to go to configure each time i create a new phoca image sub-category.
So i've managed to modify your code to add a sub-category auto select feature.
You have just to select 1 or more categories into the list, and to enable a radio button => auto select sub-categories.
The random image will be taken from all sub-categories of the selected categories. So, there is no need to reconfigure the module if adding a sub-category into the images categories.
Here is the code, if someone want to try, or needs this thing.
in the "/modules/mod_photogallery_image/mod_phocagallery_image.xml" file add just after the list definition (line 61)
This adds a radio button to enable/disable auto sub-categories selection
in the "/modules/mod_photogallery_image/mod_phocagallery_image.php" file
we need first to get the new parameter :
put in line 94, at the end of the parameters lines.
and to finish, if the radio button is selected, we need to get all the childs of the categories which are selected in the options of the module.
Add these lines :
juste before the image selection in the SQL database (line 521 for me), juste before the line
The code is'nt very "SQL aware" but seems to work, and does what i wanted.
If someone is interested by this, i'll be happy to have shared that.
I also must say that into the french translation, there are javascript errors coming because of some ['] characters that are trying to be printed.
example : the PHOCAGALLERY_WARNING_AUTHORIZE_ALL parameter generates a javascript error in FR when clicking the User button in administration (ps i use the beta version 2.7.1)
Thx again for your work. (yes i know ... for a first post, its not a little one )
first of all, thx for your modules and plugins !!! They are great.
I'll begin this post by a thing i found into your components : when installing (at least the add image button plugin) some tools from you, i encountered an error which was solved like this :
Error :
Code: Select all
Fatal error: Class 'JSite' not found in xxxxxx/plugins/content/phocagallery.php
Resolution :
replace
Code: Select all
$menu = &JSite::getMenu();
Code: Select all
global $mainframe;
if ($mainframe->isSite()) $menu = &JSite::getMenu();
Back to the original subject of this post
I wanted to have a random image module, in which i haven't to go to configure each time i create a new phoca image sub-category.
So i've managed to modify your code to add a sub-category auto select feature.
You have just to select 1 or more categories into the list, and to enable a radio button => auto select sub-categories.
The random image will be taken from all sub-categories of the selected categories. So, there is no need to reconfigure the module if adding a sub-category into the images categories.
Here is the code, if someone want to try, or needs this thing.
in the "/modules/mod_photogallery_image/mod_phocagallery_image.xml" file add just after the list definition (line 61)
Code: Select all
<param name="get_subcategories" type="radio" default="1" label="Get Sub-categories images" description="Get Sub-categories images">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
in the "/modules/mod_photogallery_image/mod_phocagallery_image.php" file
we need first to get the new parameter :
Code: Select all
$get_subcategories = $params->get( 'get_subcategories',1);
and to finish, if the radio button is selected, we need to get all the childs of the categories which are selected in the options of the module.
Add these lines :
Code: Select all
// if we must look into subcategories
if ($get_subcategories == 1) {
$found_subs = 1 ; // init
$enplus = $implodeAllowedCategoriesArray ; // init
// while we do have categories to explore
while ($found_subs == 1) {
// select each selectionned categories
$categs = explode(',',$enplus) ;
$found_subs = 0 ;
$nouv= "" ; // we have found nothing for now
foreach ($categs as $categ) {
$query = 'SELECT cc.id as idcat FROM #__phocagallery_categories AS cc'
. ' where cc.parent_id = '.$categ ;
$db->setQuery($query);
$res = $db->loadObjectList(); //search for childs of the category
if ($res) { foreach ($res as $r) { $nouv .= ','.$r->idcat; } }
}
// remove possible duplicated categories
$implodeAllowedCategoriesArray=implode(',',array_unique(explode(",",$implodeAllowedCategoriesArray.$nouv)));
//if we have new childs then go find childs of them
if ( $nouv != "" ) {
$enplus = substr($nouv,1,strlen($nouv)-1) ; // remove the trailing ','
$found_subs = 1 ; // go again into while loop
}
}
}
Code: Select all
image='';
The code is'nt very "SQL aware" but seems to work, and does what i wanted.
If someone is interested by this, i'll be happy to have shared that.
I also must say that into the french translation, there are javascript errors coming because of some ['] characters that are trying to be printed.
example : the PHOCAGALLERY_WARNING_AUTHORIZE_ALL parameter generates a javascript error in FR when clicking the User button in administration (ps i use the beta version 2.7.1)
Thx again for your work. (yes i know ... for a first post, its not a little one )