Automatically create Category

Phoca Gallery plugins - plugins for Phoca Gallery extension
azjoe
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 14 Jul 2012, 01:01

Automatically create Category

Post by azjoe »

Is there a plugin which creates a default gallery main category for each new user registration ? I much prefer (and recently switched to) Phoca Gallery, but I really miss the "joomautocat" plugin which I used when I had Joomgallery. Manually creating a main category of "username Pictures" for each new registrant is a big pain (I allow users to create sub-categories only).
dzaviech
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 25 Jul 2012, 19:37
Contact:

Re: Automatically create Category

Post by dzaviech »

Hi,

I'm interested by this functionnality too. Because if all the users name their main category for example "My pictures" it's not practical.

--
http://xldev.fr
Last edited by dzaviech on 26 Jul 2012, 17:02, edited 1 time in total.
dzaviech
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 25 Jul 2012, 19:37
Contact:

Re: Automatically create Category

Post by dzaviech »

Hi again,

I wrote some code to automatically create category with the username of the user.
This create the category if the user go on the page "Add pictures" and if he hasn't yet main category.

I think this have to be improved, because I'm using SQL request in the view.html.php file.

Edit the file: YourSite/components/com_phocagallery/views/user/view.html.php

And add this code:

Code: Select all

if($ownerMainCategory == null){
	$db =& JFactory::getDBO();

	// User parameters
	$query = 'SELECT count(*) FROM `#__phocagallery_user`';
	$db->setQuery($query);
	$ordering = $db->loadResult();
	
	$newUser = null;
	$newUser->userid = $user->id;
	$newUser->published = 1;
	$newUser->approved = 1;
	$newUser->ordering = $ordering;
	
	//Create User in DB
	$fields = array(
					'userid',
					'published',
					'approved',
					'ordering');
	$values = array(
					(int)$newUser->userid,
					(int)$newUser->published,
					(int)$newUser->approved,
					(int)$newUser->ordering);

	$query = 'INSERT INTO `#__phocagallery_user` ('.implode(',',$fields).') VALUES ('.implode(',',$values).')';
	$db->setQuery($query);
	$db->query();
	
	// Category parameters
	$query = 'SELECT count(*) FROM `#__phocagallery_categories`';
	$db->setQuery($query);
	$ordering = $db->loadResult();
	
	$new = null;
	$new->owner_id = $user->id;
	$new->title = $user->username;
	$new->alias = str_replace(" ", "-", strToLower($user->username));
	$new->image_position = 'left';
	$new->date = date('Y-m-d H:i:s', time());
	$new->published = 1;
	$new->approved = 1;
	$new->ordering = $ordering + 1;
	$new->access = 1;
	$new->userfolder = $new->alias;
	$new->language = '*';
	$new->accessuserid = '-1';
	$new->uploaduserid = $user->id;
	$new->deleteuserid = $user->id;
	
	//Create Category in DB
	$fields = array(
					'owner_id',
					'title',
					'alias',
					'image_position',
					'date',
					'published',
					'approved',
					'ordering',
					'access',
					'userfolder',
					'language',
					'accessuserid',
					'uploaduserid',
					'deleteuserid');
	$values = array(
					(int)$new->owner_id,
					$db->quote($new->title),
					$db->quote($new->alias),
					$db->quote($new->image_position),
					$db->quote($new->date),
					(int)$new->published,
					(int)$new->approved,
					(int)$new->ordering,
					(int)$new->access,
					$db->quote($new->userfolder),
					$db->quote($new->language),
					$db->quote($new->accessuserid),
					$db->quote($new->uploaduserid),
					$db->quote($new->deleteuserid));

	$query = 'INSERT INTO `#__phocagallery_categories` ('.implode(',',$fields).') VALUES ('.implode(',',$values).')';
	$db->setQuery($query);
	$result = $db->query();
	
	//create the folder in the good place
	mkdir('images/phocagallery/'.$new->userfolder, 0755, true);
	
	//Reload owner main category
	$ownerMainCategory = $model->getOwnerMainCategory($user->id);
}
Just after the lines: (~l-134)

Code: Select all

$model = $this->getModel('user');
$ownerMainCategory	= $model->getOwnerMainCategory($user->id);

Don't forget to replace '#_' by your database prefix.

Then you can add this property in your css file to hide the "Main category" menu:
#phocagallery-pane .category { display: none;}

--
http://xldev.fr
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48386
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Automatically create Category

Post by Jan »

Hi, thank you for this guide.

Jan
If you find Phoca extensions useful, please support the project
piersol
Phoca Member
Phoca Member
Posts: 10
Joined: 30 Jan 2009, 17:35

Re: Automatically create Category

Post by piersol »

I did as is outlined above, but im seeing no change. Is there a common mistake made or any way to troubleshoot this?

I allow only one main category for each member and want it to be username or name with them only adding subcategories to their own main. But it seemed a hassle to ask each one to make a self titled category and allow for possible confusions.
Post Reply