Multiple entity Icon

Hi,

I would like to upload 2 differents images for my group profile but I can not see how. Can somebody help me ?

I have already read : http://learn.elgg.org/en/stable/guides/file-system.html

My code is the following to save the images (in actions directory of the plugin)

$has_uploaded_icon = (!empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/'));

if ($has_uploaded_icon) {
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;
    $filehandler->setFilename("groups/$group->guid.jpg");
    $filehandler->open("write");
    $filehandler->write(get_uploaded_file('icon'));
    $filehandler->close();

    if ($filehandler->exists()) {
        // Non existent file throws exception
        $group->saveIconFromElggFile($filehandler);
    }
}

//BIG HEADER
//@see http://reference.elgg.org/filestore_8php.html#af281af99cbd2de352b8bcc0fd78b580b
$has_uploaded_icon = (!empty($_FILES['cover_photo']['type']) && substr_count($_FILES['cover_photo']['type'], 'image/'));

if ($has_uploaded_icon) {
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;
    $filehandler->setFilename("groups/$group->guid.jpg");
    $filehandler->open("write");
    $filehandler->write(get_uploaded_file('cover_photo'));
    $filehandler->close();

    if ($filehandler->exists()) {
        // Non existent file throws exception
        //@see $type http://reference.elgg.org/classElggEntity.html#a75c3ed83222ce4644b63b4d26e08bcfe
        $group->saveIconFromElggFile($filehandler, "cover_photo");
    }
}

And I retrieve an icon in the template like bellow. But I do not see how to get the "cover_photo" icon. Is it possible to have more than one icon in an entity ?

 

<div class="groups-profile-icon">
            <?php
                // we don't force icons to be square so don't set width/height
                echo elgg_view_entity_icon($group, 'large', array(
                    'href' => '',
                    'width' => '',
                    'height' => '',
                ));
            ?>
        </div>

 

Thanks

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking