I figured it out. It was a careless mistake of not setting the $img->owner_guid to the $group->owner_guid. I had it set to $group->guid on accident.
I am still curious as to why $img->delete() returns 'false' even when it does successfully delete the icons for that group though (I have it in my owner php script so that I can call it by using jQuery).
<?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?
It saves it as metadata. Have you had a look at the data model discussion in the docs? Especially the part about metadata.
Don't forget to call $entity->save() after to persist the data in the db.
Thanks Brett! I completely missed that second page apparently! Sorry for the nub question.
Np. The interface for this is a bit confusing because it requires knowledge of the data model.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.