iMattPro / topicpreview

Topic Preview mouse-over preview effect for phpBB3
https://www.phpbb.com/customise/db/extension/topicpreview/
GNU General Public License v2.0
22 stars 14 forks source link

Add event vse.topicpreview.display_topic_preview #9

Closed PayBas closed 10 years ago

PayBas commented 10 years ago

Will make it easier to modify the avatars. The alternative would be to modify all the same events as TP, but this is way easier of course.

iMattPro commented 10 years ago

What is it you are wanting to modify about avatars? If it's 'cuz you don't like the default no avatars, maybe I can just make that an option.

PayBas commented 10 years ago

My code:

public function display_topic_preview($row, $block, $tp_avatars) {
    if($this->config['load_cpf_viewtopic'] && $tp_avatars) {
        $grab_ids = array();

        if(empty($row['first_poster_avatar'])) {
            $grab_ids[] = $row['topic_poster'];
        }
        if($row['topic_poster'] !== $row['topic_last_poster_id'] && empty($row['last_poster_avatar'])) {
            $grab_ids[] = $row['topic_last_poster_id'];
        }

        if(!empty($grab_ids)) {
            $cp = $this->profilefields_manager->grab_profile_fields_data($grab_ids);

            if(empty($row['first_poster_avatar']) && isset($cp[$row['topic_poster']])) {
                $profile_fields = $this->profilefields_manager->generate_profile_fields_template_data($cp[$row['topic_poster']]);
                $block['TOPIC_PREVIEW_FIRST_AVATAR'] = isset($profile_fields['row']['PROFILE_PBAVATAR']) ? $profile_fields['row']['PROFILE_PBAVATAR'] : '';
            }

            if(empty($row['last_poster_avatar']) && isset($cp[$row['topic_last_poster_id']])) {
                if($row['topic_poster'] == $row['topic_last_poster_id']) {
                    $block['TOPIC_PREVIEW_LAST_AVATAR'] = $block['TOPIC_PREVIEW_FIRST_AVATAR'];
                } else {
                    $profile_fields = $this->profilefields_manager->generate_profile_fields_template_data($cp[$row['topic_last_poster_id']]);
                    $block['TOPIC_PREVIEW_LAST_AVATAR'] = isset($profile_fields['row']['PROFILE_PBAVATAR']) ? $profile_fields['row']['PROFILE_PBAVATAR'] : '';
                }
            }
        }
    }
    return $block;
}
PayBas commented 10 years ago

If you need me to change anything in the PR, just let me know. But I hope we can merge this.

Having this event in place will allow us to do more fun things in the future as well.

iMattPro commented 10 years ago

Forgot about this. Can you rebase it to the latest version of this branch please.

PayBas commented 10 years ago

Done

iMattPro commented 10 years ago

I will merge this as soon as the unit testing framework gets fixed/updated... may be a few days.

iMattPro commented 10 years ago

Think you can fix the test which are failing now? Should be just as simple as adding the mock dispatcher to the setup of the topic_preview instance in tests/topic_preview_base

PayBas commented 10 years ago

The dispatcher depends on the phpbb container by calling $dispatcher = new \phpbb\event\dispatcher(new phpbb_mock_container_builder());, but since I'm not well versed in the test platform yet, this is a bit tricky at the moment.