Skip to content

Conversation

@trabisdementia
Copy link
Contributor

  • Added @var for better code inspection
  • Fixed Recent Faq Block option for displaying categories with no content
  • Removed unnecessary duplicated queries

I know this is an RC so feel free to ignore this changes.
Thank you for the nice module!

- Fixed Recent Faq Block option for displaying categories with no content
- Removed unnecessary duplicated queries
@zyspec
Copy link
Collaborator

zyspec commented May 19, 2017

Thanks Trabis!

I'll look these over. I do have a couple of questions though...

  1. Isn't the syntax for @var suppose to be something like /* @var XoopsObject $object */ instead of /* @var $object XoopsObject */ for code inspection?
  2. Is there a reason you didn't use the Criteria class in the getCategoriesIdsWithContent() method? It appears the code in the new method does the same thing, just moves it to the XoopsfaqContents class - which is a good thing. I think there's a couple of additional lines of code that can now be removed in the blocks/xoopsfaq_category.php file too. Looks to me like we should be able to use something like:
/**
 * Returns category ids of categories that have content
 */
public function getCategoriesIdsWithContent()
{
    $ret      = array();
    $fields   = array('contents_cid');
    $criteria = new Criteria('contents_active', XoopsfaqConstants::ACTIVE);
    $criteria->setGroupBy('contents_cid');
    $results = $this->getAll($criteria, $fields, false);
    if (false === $results) {
        return $ret;
    }
    foreach ($results as $result) {
        $ret[$result['contents_cid']] = $result['contents_cid'];
    }

    return $ret;
}

Thoughts?

@trabisdementia
Copy link
Contributor Author

trabisdementia commented May 19, 2017 via email

@mambax7
Copy link
Contributor

mambax7 commented May 19, 2017

Trabis, when you click on the variable $xfCatHandler in

$xfCatHandler = $xfHelper->getHandler('category');

with Alt+Enter, you'll get:
/** @var TYPE_NAME $xfCatHandler */

which then becomes:
/** @var XoopsfaqCategoryHandler $xfCatHandler */

Since this is already built-in in PhpStorm, for consistency I would suggest to follow that style

@trabisdementia
Copy link
Contributor Author

Thank you Mamba, did not know about that. I have rearranged the docs now :)

@zyspec
Copy link
Collaborator

zyspec commented May 19, 2017

Thanks guys...

@trabisdementia ,

The SQL problem is good to know - I'm pretty sure that is, or will be, a problem in several other modules. What if I just add 'content_id' to the $fields() array in the call to the getAll() method so SQL expects it to return the column? That should make SQL happy and it's one less thing to remember to change when we transition this to using the XOOPS 2.6 dB access methods. Thoughts?

@trabisdementia
Copy link
Contributor Author

trabisdementia commented May 19, 2017

@zyspec,
Adding content_id to the list of fields will not change anything, as I said, if you do not pass the content_id, the getAll method will append it anyway. The problem arises only when you need to use "group by". You can only "group by" the fields that you have selected. In this case, you would have to use group by 'content_id', 'content_pid'. Since I did not want to group by the content_id, I had to create a method that does not inject it in the list of selected fields.
Example:
select * from table group by col1 == bad
select col1 from table group by col1 == good
select col1, col2 from table group by col1 == bad (and this is what happens when using getAll
select col1, col2 from table group by col1, col2 == good

@zyspec
Copy link
Collaborator

zyspec commented May 19, 2017

Ok, now I get it - sorry. I had to re-read your post from earlier. The problem is also explained in the 12.19.3 MySQL Handling of GROUP BY Documentation. Looks like the only way around this would be to get rid of setGroupBy() and return everything. Cycling through the foreach() loop is then equivalent to performing an array_unique() on the results since it'll just overload the $ret key each time the 'contents_cid' is duplicated. Something like:

/**
 * Returns category ids of categories that have content
 */
public function getCategoriesIdsWithContent()
{
    $ret      = array();
    $fields   = array('contents_cid');
    $criteria = new Criteria('contents_active', XoopsfaqConstants::ACTIVE);
    $results = $this->getAll($criteria, $fields, false);
    if (false === $results) {
        return $ret;
    }
    foreach ($results as $result) {
        $ret[$result['contents_cid']] = $result['contents_cid'];
    }
    return $ret;
}

I like your solution for this better until we get to Doctrine, etc. in XOOPS 2.6. Returning all of the 'contents' from a dB call doesn't seem like a great idea (especially if there's a lot of FAQs in the dB).

@zyspec zyspec merged commit 68ef381 into XoopsModules25x:master May 20, 2017
mambax7 added a commit that referenced this pull request May 26, 2023
[ImgBot] Optimize images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants