Keyword

Limit # of posted items per user

  • Markus R
  • Markus R's Avatar Topic Author
  • Offline
  • New Member
More
12 years 10 months ago - 12 years 10 months ago #58672 by Markus R
Limit # of posted items per user was created by Markus R
Hi,

I was wondering if there is a way to limit how many items a person can make, I would like to limit this to 1 per registered user.

Trying to make some kind of a directory with the Idea that a user X can register, submit 1 item (place) with custom fields to be formatted nicely, and of course he could edit it afterwards.

And then user B who has more rights can see every item placed on specific category, but only to see them, not to modify or anything.

If anyone has any pointers if and how I could accomplish this with K2 I would appreciate it very much.

And I was wondering about the item submission form too, is it possible to make tabless form that those fields that I need, would be listed nicely and on preformatted order?

- Markus R

So this is not doable?? any confirmation for this would be helpful

Please Log in or Create an account to join the conversation.

  • jorge mejia gallegos
  • jorge mejia gallegos's Avatar
  • Offline
  • Junior Member
More
12 years 10 months ago #58673 by jorge mejia gallegos
Replied by jorge mejia gallegos on topic Re: Limit # of posted items per user
Im trying to do the same thing, if i come up with something will let you know

Please Log in or Create an account to join the conversation.

  • Markus R
  • Markus R's Avatar Topic Author
  • Offline
  • New Member
More
12 years 10 months ago #58674 by Markus R
Replied by Markus R on topic Re: Limit # of posted items per user
Well I came up with some workaround (but not very effective)

You have to modify your custom layouts so that there is no "add item" buttons around anymore, and then you can try to automate user create function so that it creates a not published dummy item that the user can edit from his profile view and then publish.

Still working on the tabless forms and trying to figure out how to make user profiles private, so that no other user can see them if they get the url somewhere or anything.

- Markus R

Please Log in or Create an account to join the conversation.

  • jorge mejia gallegos
  • jorge mejia gallegos's Avatar
  • Offline
  • Junior Member
More
12 years 10 months ago #58675 by jorge mejia gallegos
Replied by jorge mejia gallegos on topic Re: Limit # of posted items per user
I put together this code to find out the K2 user group a signed user belongs to and the number of items that belong to that user, that way i can create some conditionals in the user.php to either show or hide the add item link depending on the user group and number of published items.
<?php
// get user ID
$user = &JFactory::getUser();
$userId = $user->get('id');
// get Items
$db =& JFactory::getDBO();
$query = "
  SELECT ".$db->nameQuote('title')."
    FROM ".$db->nameQuote('jos_k2_items')."
    WHERE ".$db->nameQuote('created_by')." = ".$db->quote($userId)." AND  ".$db->nameQuote('trash')." = ".$db->quote("0").";
  ";
$db->setQuery($query);
$result = $db->loadResultArray();
$number = count($result);
// get user Group
$query = "
  SELECT ".$db->nameQuote('group')."
    FROM ".$db->nameQuote(jos_K2_users)."
    WHERE ".$db->nameQuote('userID')." = ".$db->quote($userId).";
  ";
$db->setQuery($query);
$userGroup = $db->loadResult();

//print the results
print "User Group:".$userGroup."<br/>".
   "User ID:".$userId."<br/>".
   "Number of items:".$number."<br/>";

?>

For doing the user page private i guess maybe in the user.php you could do something like:
//get user id
$user = &JFactory::getUser();
//compare if its the same as user page id
if ( $this->user->id==$user->get('id'))
//show the user page;
else
//do something else;

this way you can compare if the logged in user id and the user page id are the same.

Please Log in or Create an account to join the conversation.

More
12 years 4 months ago #58676 by Nicholas Loggie
Replied by Nicholas Loggie on topic Re: Limit # of posted items per user
Hi

Just came cross this little snippet.

Don't forget to change jos_ to your own prefix if your are using J!2.5

It is great use if you want to add some extra user fields just for specific user groups.....

Gracias amigo

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum