Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
how to get total amount of ratings and (ez)comments for related pictures/blogs/profiles?
  • Posted: 26.01.2008, 18:31
     
    mdee24
    rank:
    Softmore Softmore
    registered:
     October 2007
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    67
    Hi,

    does anyone has an idea how to get/call total amount of Ratings and EZComments for needed modules? I mean, I would like to show something like "this picture (blog, profile...) has 19 ratings and 5 comments". It is possible?

    thanks for any help,
    Martin.
  • Posted: 27.01.2008, 01:00
     
    AmmoDump
    rank:
    Team Member Team Member
    registered:
     December 2003
    Status:
    offline
    last visit:
    04.12.08
    Posts:
    2992
    Where do you want to do this... can you give and example?

    --
    David Pahl
    Zikula Support Team
  • Posted: 27.01.2008, 01:45
     
    mdee24
    rank:
    Softmore Softmore
    registered:
     October 2007
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    67
    For example in block of UserPictures next to related picture ... or next to pnWebLog block's latest post.



    edited by: mdee24, Jan 26, 2008 - 09:07 PM
  • Posted: 27.01.2008, 04:30
     
    AmmoDump
    rank:
    Team Member Team Member
    registered:
     December 2003
    Status:
    offline
    last visit:
    04.12.08
    Posts:
    2992
    I don't have either of these installed at the moment. But look at the templates that have the features you desire, and grab the code, and rewrite your new template to include the code.

    --
    David Pahl
    Zikula Support Team
  • Posted: 29.01.2008, 00:14
     
    mdee24
    rank:
    Softmore Softmore
    registered:
     October 2007
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    67
    Thanks, but I don't have any template, which have this feature icon_frown ... I thought, this could be called "somehow" with pnmodfunc or pnmodapifunc...
  • Posted: 29.01.2008, 13:19
     
    jmvedrine
    rank:
    Professional Professional
    registered:
     January 2004
    Status:
    offline
    last visit:
    05.09.08
    Posts:
    633
    Hello,
    I don't know if you will be able to use them because I don't use the modules/blocks you are speaking of but here are 2 pnRender plugins that I have done for another module (books) when I did the pnRendered version.
    First one is a plugin to display the ratings for an item using exactly the same style (stars, ...) as the Ratings module.

    Code

    <?php
    /**
     *
     * Type: Function
     * Author: Jean-Michel Védrine (vedrine _AT_ vedrine _DOT_ net)
     *
     * Display the Ratings for an item
     *@param params['modname'] string module's name
     *@param params['objectid'] string item ID
     *@param params['style'] style
     *@return string processed smarty output
     */

    function smarty_function_rating($params, &$smarty)
    {
        extract($params);
        unset($params);
            if (!pnModAvailable('Ratings') || !pnModIsHooked('Ratings', $modname)) {
            return;
        }

        if (!isset($objectid)) {
            return;
        }

        if (!isset($style)) {
            $style = pnModGetVar('Ratings', 'defaultstyle');
        }

        // security check
        // check if the user is allowed to the any ratings for this module/style/objectid
        if (!pnSecAuthAction(0, 'Ratings::', "$modname:$style:$objectid", ACCESS_READ)) {
            return;
        }
       
        if (!pnModAPILoad('Ratings', 'user')) {
            return;
        }
        $rating = pnModAPIFunc('Ratings',
                               'user',
                               'get',
                               array('modname' => $modname,
                               'objectid' => $objectid));

        if (!isset($rating)) { 
            return;
        }

        // language
        $lang =  pnVarPrepForOS(pnUserGetLang());

        // theme directory
        $theme         = pnVarPrepForOS(pnUserGetTheme());
        $modname = 'Ratings';
        $osmodname     = pnVarPrepForOS($modname);
        $cWhereIsPerso = WHERE_IS_PERSO;
        if (!(empty($cWhereIsPerso))) {
            $themelangpath = $cWhereIsPerso . "themes/$theme/templates/modules/$osmodname/images/$lang";
            $themepath     = $cWhereIsPerso . "themes/$theme/templates/modules/$osmodname/images";
            $corethemepath = $cWhereIsPerso . "themes/$theme/images";
        } else {
            $themelangpath = "themes/$theme/templates/modules/$osmodname/images/$lang";
            $themepath     = "themes/$theme/templates/modules/$osmodname/images";
            $corethemepath = "themes/$theme/images";
        }
        // module directory
        $modinfo       = pnModGetInfo(pnModGetIDFromName($modname));
        $osmoddir      = pnVarPrepForOS($modinfo['directory']);
        if ($modinfo['type'] != 1) {
            $modlangpath   = "modules/$osmoddir/pnimages/$lang";
            $modpath       = "modules/$osmoddir/pnimages";
            $syslangpath   = "system/$osmoddir/pnimages/$lang";
            $syspath       = "system/$osmoddir/pnimages";
        } else {
            $modlangpath   = "modules/$osmoddir/images/$lang";
            $modpath       = "modules/$osmoddir/images";
            $syslangpath   = "system/$osmoddir/images/$lang";
            $syspath       = "system/$osmoddir/images";
        }
        $name1 = pnVarPrepForOS('star.gif');
        $name2 = pnVarPrepForOS('halfstar.gif');

        // search for the images
        $imgsrc1 = '';
        $imgsrc2 = '';
        foreach (array($themelangpath,
                       $themepath,
                       $corethemepath,
                       $modlangpath,
                       $modpath,
                       $syslangpath,
                       $syspath) as $path) {
            if (file_exists("$path/$name1") && is_readable("$path/$name1") && file_exists("$path/$name2") && is_readable("$path/$name2")) {
                $imgsrc1 = "$path/$name1";
                $imgsrc2 = "$path/$name2";
            break;
            }
        }
        if ($imgsrc1 == '') {
            $smarty->trigger_error("pnrender plugin rating: images not found");
            return;
        }


        switch($style) {
                case 'percentage':
                    $output = "$rating%";
                    break;
                case 'outoffive':
                    $rating = (int)(($rating+10)/20);
                    $output="$rating/5";
                    break;
                case 'outoffivestars':
                    $output = '';
                    $rating = (int)($rating/2);
                    $intrating = (int)($rating/10);
                    $fracrating = $rating - (10*$intrating);
                    for ($i=1;$i<=$intrating;$i++){
                        $output .= '<img src="' . $imgsrc1 . '" alt="" />';
                    }
                    if ($fracrating >=5) {
                        $output .= '<img src="' . $imgsrc2 . '" alt="" />';
                    }
                    break;
                case 'outoften':
                    $rating = (int)(($rating+5)/10);
                    $output="$rating/10";
                    break;
                case 'outoftenstars':
                    $output = '';
                    $intrating = (int)($rating/10);
                    $fracrating = $rating - (10*$intrating);
                    for ($i=1;$i<=$intrating;$i++){
                        $output .= '<img src="' . $imgsrc1 . '" alt="" />';
                    }
                    if ($fracrating >=5) {
                        $output .= '<img src="' . $imgsrc2 . '" alt="" />';
                    }
                    break;
        }
        if (isset($assign))
            $smarty->assign($assign, $output);
        else
            return $output;
    }
    ?>

    save in a function.rating.php file either in modules/your_module/pntemplates/plugins/ or in modules/pnRender/plugins
    usage
    Where you want the rating to appear, add in your template

    Where module_name is the name of the module the rated item belongs to and item_id is the rated item id
    And for the number of EZComments :

    Code

    <?php
    /**
     *
     * Type: Function
     * Author: Jean-Michel Védrine (vedrine _AT_ vedrine _DOT_ net)
     *
     * Display the number of EZComments for an item
     *@param params['modname'] string module's name
     *@param params['objectid'] string item ID
     *@return string processed smarty output
     */

    function smarty_function_ezcommentscount($params, &$smarty)
    {
        if (!pnModAvailable('EZComments')) {
            return;
        }

        extract($params);
        unset($params);

        if (!isset($objectid) || !isset($modname)) {
            return;
        }

        if (isset($status)) {
            $comments = pnModAPIFunc('EZComments',
                                     'user',
                                     'countitems',
                                      array('mod' => $modname,
                                            'objectid' => $objectid,
                                            'status' => $status))
        } else {
           $comments = pnModAPIFunc('EZComments',
                                     'user',
                                     'countitems',
                                      array('mod' => $modname,
                                            'objectid' => $objectid))
        }

        if (isset($assign))
            $smarty->assign($assign, $comments);
        else
            return $comments;
    }
    ?>

    of but here are 2 pnRender plugins that I have done for another module (books) when I did the pnRendered version.
    First one is a plugin to display the ratings for an item using exactly the same style (stars, ...) as the Ratings module.

    Code

    <?php
    /**
     *
     * Type: Function
     * Author: Jean-Michel Védrine (vedrine _AT_ vedrine _DOT_ net)
     *
     * Display the Ratings for an item
     *@param params['modname'] string module's name
     *@param params['objectid'] string item ID
     *@param params['style'] style
     *@return string processed smarty output
     */

    function smarty_function_rating($params, &$smarty)
    {
        extract($params);
        unset($params);
            if (!pnModAvailable('Ratings') || !pnModIsHooked('Ratings', $modname)) {
            return;
        }

        if (!isset($objectid)) {
            return;
        }

        if (!isset($style)) {
            $style = pnModGetVar('Ratings', 'defaultstyle');
        }

        // security check
        // check if the user is allowed to the any ratings for this module/style/objectid
        if (!pnSecAuthAction(0, 'Ratings::', "$modname:$style:$objectid", ACCESS_READ)) {
            return;
        }
       
        if (!pnModAPILoad('Ratings', 'user')) {
            return;
        }
        $rating = pnModAPIFunc('Ratings',
                               'user',
                               'get',
                               array('modname' => $modname,
                               'objectid' => $objectid));

        if (!isset($rating)) { 
            return;
        }

        // language
        $lang =  pnVarPrepForOS(pnUserGetLang());

        // theme directory
        $theme         = pnVarPrepForOS(pnUserGetTheme());
        $modname = 'Ratings';
        $osmodname     = pnVarPrepForOS($modname);
        $cWhereIsPerso = WHERE_IS_PERSO;
        if (!(empty($cWhereIsPerso))) {
            $themelangpath = $cWhereIsPerso . "themes/$theme/templates/modules/$osmodname/images/$lang";
            $themepath     = $cWhereIsPerso . "themes/$theme/templates/modules/$osmodname/images";
            $corethemepath = $cWhereIsPerso . "themes/$theme/images";
        } else {
            $themelangpath = "themes/$theme/templates/modules/$osmodname/images/$lang";
            $themepath     = "themes/$theme/templates/modules/$osmodname/images";
            $corethemepath = "themes/$theme/images";
        }
        // module directory
        $modinfo       = pnModGetInfo(pnModGetIDFromName($modname));
        $osmoddir      = pnVarPrepForOS($modinfo['directory']);
        if ($modinfo['type'] != 1) {
            $modlangpath   = "modules/$osmoddir/pnimages/$lang";
            $modpath       = "modules/$osmoddir/pnimages";
            $syslangpath   = "system/$osmoddir/pnimages/$lang";
            $syspath       = "system/$osmoddir/pnimages";
        } else {
            $modlangpath   = "modules/$osmoddir/images/$lang";
            $modpath       = "modules/$osmoddir/images";
            $syslangpath   = "system/$osmoddir/images/$lang";
            $syspath       = "system/$osmoddir/images";
        }
        $name1 = pnVarPrepForOS('star.gif');
        $name2 = pnVarPrepForOS('halfstar.gif');

        // search for the images
        $imgsrc1 = '';
        $imgsrc2 = '';
        foreach (array($themelangpath,
                       $themepath,
                       $corethemepath,
                       $modlangpath,
                       $modpath,
                       $syslangpath,
                       $syspath) as $path) {
            if (file_exists("$path/$name1") && is_readable("$path/$name1") && file_exists("$path/$name2") && is_readable("$path/$name2")) {
                $imgsrc1 = "$path/$name1";
                $imgsrc2 = "$path/$name2";
            break;
            }
        }
        if ($imgsrc1 == '') {
            $smarty->trigger_error("pnrender plugin rating: images not found");
            return;
        }


        switch($style) {
                case 'percentage':
                    $output = "$rating%";
                    break;
                case 'outoffive':
                    $rating = (int)(($rating+10)/20);
                    $output="$rating/5";
                    break;
                case 'outoffivestars':
                    $output = '';
                    $rating = (int)($rating/2);
                    $intrating = (int)($rating/10);
                    $fracrating = $rating - (10*$intrating);
                    for ($i=1;$i<=$intrating;$i++){
                        $output .= '<img src="' . $imgsrc1 . '" alt="" />';
                    }
                    if ($fracrating >=5) {
                        $output .= '<img src="' . $imgsrc2 . '" alt="" />';
                    }
                    break;
                case 'outoften':
                    $rating = (int)(($rating+5)/10);
                    $output="$rating/10";
                    break;
                case 'outoftenstars':
                    $output = '';
                    $intrating = (int)($rating/10);
                    $fracrating = $rating - (10*$intrating);
                    for ($i=1;$i<=$intrating;$i++){
                        $output .= '<img src="' . $imgsrc1 . '" alt="" />';
                    }
                    if ($fracrating >=5) {
                        $output .= '<img src="' . $imgsrc2 . '" alt="" />';
                    }
                    break;
        }
        if (isset($assign))
            $smarty->assign($assign, $output);
        else
            return $output;
    }
    ?>

    save in a function.ezcommentscount.php file either in modules/your_module/pntemplates/plugins/ or in modules/pnRender/plugins
    usage
    Where you want the number of comments to appear, add in your template

    Where module_name is the name of the module the commented item belongs to and item_id is the commented item id.
    Hope this help.
    Please note ezcommentscount plugin is a modified version of the one Jörn did for his Pagesetter module.




    edited by: jmvedrine, Jan 29, 2008 - 09:27 AM

    --
    Visit my live reef aquarium.

    My Amazon wish list.
  • Posted: 29.01.2008, 13:27
     
    jmvedrine
    rank:
    Professional Professional
    registered:
     January 2004
    Status:
    offline
    last visit:
    05.09.08
    Posts:
    633
    Well I don't seem to be able to post some code in this forum and my previous post appear empty but it is not ! if you quote it you will see my solution (I hope) to your problem

    --
    Visit my live reef aquarium.

    My Amazon wish list.
  • Posted: 29.01.2008, 14:33
     
    mdee24
    rank:
    Softmore Softmore
    registered:
     October 2007
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    67
    Hi jmvedrine,

    jmvedrine

    Well I don't seem to be able to post some code in this forum and my previous post appear empty but it is not ! if you quote it you will see my solution (I hope) to your problem

    It works, I'll try to play with your code and let know. Anyway thanks for your help.

    M.
  • Posted: 29.01.2008, 19:51
     
    mdee24
    rank:
    Softmore Softmore
    registered:
     October 2007
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    67
    @jmvedrine - so, first one for EZComments working pretty well icon_smile , but the second one for rating not working for me. It returns an error:Unsupported operand types in C:\web\www\system\Profile\pntemplates\plugins\function.rating.php on line 130 - and on the line 130, there is:

    Code

    $intrating = (int)($rating/10);
    . Do you have any idea? Thanks.
  • Posted: 30.01.2008, 02:48
     
    jmvedrine
    rank:
    Professional Professional
    registered:
     January 2004
    Status:
    offline
    last visit:
    05.09.08
    Posts:
    633
    This is quite stange because it seems to indicate $rating is not a number so $rating/10 can't be calculated.
    I never encoutered this problem.
    I will look at my code ...
    Is the item rated or not ? does it make a difference (is the error displayed on both cases ?)




    edited by: jmvedrine, Jan 29, 2008 - 10:49 PM

    --
    Visit my live reef aquarium.

    My Amazon wish list.
  • Posted: 30.01.2008, 03:01
     
    mdee24
    rank:
    Softmore Softmore
    registered:
     October 2007
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    67

    Quote

    Is the item rated or not ?
    Yes, it is

    Quote

    does it make a difference (is the error displayed on both cases ?
    When the item is rated then there's an error (above), when not, then there's no error (nothing).
  • Posted: 31.01.2008, 03:24
     
    videokid
    rank:
    Professional Professional
    registered:
     March 2003
    Status:
    offline
    last visit:
    03.12.08
    Posts:
    916
    I needed something similar for the number of ratings for a pub
    [pfew, that's long ago :-]

    In /modules/Ratings/pnuserapi.php, just before Mark West's getall I've inserted

    Code

    /**
     * Get a #number of ratings for a specific item
     * @author Igor VC
     * @param $args['modname'] name of the module this rating is for
     * @param $args['objectid'] ID of the item this rating is for
     * @param $args['ratingtype'] type of rating (optional)
     * @return int #ratings
     */

    function ratings_userapi_getnumber($args)
    {
        // Get arguments from argument array
        extract($args);

        // Argument check
        if ((!isset($modname)) ||
            (!isset($objectid))) {
            pnSessionSetVar('errormsg', _MODARGSERROR);
            return false;
        }

        if (!isset($ratingtype) || $ratingtype = 'default') {
            $ratingtype = pnModGetVar('ratings', 'defaultstyle');
        }

        // Security