Please note that Form2Content is no longer being developed. All files from the latest version can be found on Github.

Form2Content Forum

Questions and answers for Form2Content, a Joomla CCK.
  1. Sebastian Fischbach
  2. F2C Search settings
  3. Tuesday, 17 March 2020
  4.  Subscribe via email
Hello everyone,

simple question: in F2C search, the dropdown to filter by Joomla Author shows all registered users instead of only those who have actually authored an article. This causes avoidable searches with no results. I know I can manually exclude authors in the settings but this is not an option here (it's cumbersome and users might wrongly remain excluded when they author an article at a later point). Is there a way to change this behaviour?

Thanks and best regards
Sebastian
Responses (4)
Accepted Answer Pending Moderation
Hi Sebastian,

Good question, one I can't answer but I'll ask Julien.

Regards,
Patrick
Please read the F2C documentation before asking questions! Thank you if you've done so ;)
  1. more than a month ago
  2. F2C Search settings
  3. # 1
Accepted Answer Pending Moderation
Hey guys,

any news regarding my question or are you all stuck in homeoffice? ;)

Best wishes, stay healthy
Sebastian
  1. more than a month ago
  2. F2C Search settings
  3. # 2
Accepted Answer Pending Moderation
Hi Sebastian,

Yes, that's actually true: I'm stuck in my home-office. I can't go anywhere on the moment.....

Anyway, here's a little hack, that only shows you the authors that have authored F2C Articles:

In the file /components/com_form2contentsearch/lib/Form2ContentSearch/Fields/FieldAuthor.php there's this function:


private function getAuthorList()
{
$db = Factory::getDBO();
$query = $db->getQuery(true);

if($this->searchFieldSettings->get('aut_display_name', 0))
{
$query->select('id as value, username as text');
$query->order('username ASC');
}
else
{
$query->select('id as value, name as text');
$query->order('name ASC');
}

$query->from('#__users');

switch((int)$this->searchFieldSettings->get('aut_filter'))
{
case 0:
// show all authors
break;
case 1:
// exclude selected authors
$query->where('id NOT IN ('. implode(',', $this->searchFieldSettings->get('aut_ids')) .')');
break;
case 2:
// only show selected authors
$query->where('id IN ('. implode(',', $this->searchFieldSettings->get('aut_ids')) .')');
break;
}

$db->setQuery($query);

return $db->loadRowList();
}


And here's the function with the hack:


private function getAuthorList()
{
$db = Factory::getDBO();
$query = $db->getQuery(true);

if($this->searchFieldSettings->get('aut_display_name', 0))
{
$query->select('distinct u.id as value, u.username as text');
$query->order('u.username ASC');
}
else
{
$query->select('distinct u.id as value, u.name as text');
$query->order('u.name ASC');
}

$query->from('#__users u');
$query->innerJoin('#__f2c_form f ON u.id = f.created_by');

switch((int)$this->searchFieldSettings->get('aut_filter'))
{
case 0:
// show all authors
break;
case 1:
// exclude selected authors
$query->where('u.id NOT IN ('. implode(',', $this->searchFieldSettings->get('aut_ids')) .')');
break;
case 2:
// only show selected authors
$query->where('u.id IN ('. implode(',', $this->searchFieldSettings->get('aut_ids')) .')');
break;
}

$db->setQuery($query);

return $db->loadRowList();
}


Hope this helps!

Best,
Julien
  1. more than a month ago
  2. F2C Search settings
  3. # 3
Accepted Answer Pending Moderation
Hey Julien,

that's great help, thank you very much! It works as expected after I fixed a little typo in line 4 of your code: Instead of
$db 	= Factory::getDBO();

it should be (I guess)
$db 	= JFactory::getDBO();


Is this change going to be in the next release of F2C Search or do I have to keep track of it on my own?
Again: Thank you very much! :)

Best wishes,
Sebastian
  1. more than a month ago
  2. F2C Search settings
  3. # 4
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.