Overwrite ElggGroup Function

I just want to overwrite an ElggGroup function (the 'leave()' function).  Right now, it works (user can't leave) if I have the user join and leave in the same file, but if I wait until the user joins (say through the groups page), and then they try to leave, it still lets them leave!  I want them to be forced to stay in the group unless MY plugin specifies 'force_leave = true.'  Thank you in advance!

 

Here is the file I have included in my start.php file:

 


// Achievement class

class Achievement extends ElggGroup {

        function __contruct($guid = null) {
                parent::__construct($guid);
        }

        function leave($user, $force_stay = false) {
                if ($force) {
                        parent::leave($user);
                } else {
                        return false;
                        display_message('You cannot leave an achievement.');
                }
        }
}





  • typo ?

            function leave($user, $force_stay = false) {
                    if ($force) {

    and swap lines..

  • HAHAHA.... Well it sure does help to have a second pair of eyes sometimes!  I fixed that and still have the same problem. :(

  • <?php
    class            Achievement
            extends    ElggGroup
    {
        ////////////////////////////////////////
        function __contruct($guid = null)
        {
            parent::__construct($guid);
        }//function __contruct($guid = null)
        ////////////////////////////////////////
        function leave($user, $force_stay = false)
        {
            if ($force_stay)
            {
                display_message('You Cannot Leave an Achievement.');
                return false;
            }
            else
            {
                display_message('OK You Left an Achievement.');
                parent::leave($user);// Where does this logic go to ???
            }//if ($force_stay)
        }//function leave($user, $force_stay = false)
        ////////////////////////////////////////
    }
    ?>

  • Ok, so I must have been out of it when I wrote this... geez. Anyways, it still doesn't work.  I have put a die('crap'); statement at the beginning of the function and it doesn't get called...  So, my leave function must not even be called, right? 

    As for this:

    parent::leave($user);// Where does this logic go to ???

    This calls the original leave(ElggUser) function defined in the Elgg core system.  Since $force_stay is false, the user is allowed to leave the group. 

     

    I just noticed that the name of $force_stay should be $can_leave.  I want to have the original leave() function work fine, so $achv->leave($user) works like before, but if you do $achv->leave($user, true), the user cannot leave the group.  Here is exactly what I have in that file now:

     

    <?php

    // Achievement class

    class Achievement extends ElggGroup {

            function __contruct($guid = null) {
                    parent::__construct($guid);
            }

            function leave($user, $can_leave = false) {

                    die('crap');

                    if ($can_leave) {
                            echo 'The user is leaving the group';
                            parent::leave($user);
                    } else {
                            echo 'The user is forced to stay in the group';
                            return false;
                            //display_message('You cannot leave an achievement.');
                    }
                    die('end');
            }
    }


  • Do I need to declare Achievement as a new enitity type as well in my start.php?