Пример #1
0
/**
 * Delete market post and pictures
 *
 * @param Market $post
 * @return array
 */
function market_delete_post($post = NULL)
{
    if (!$post) {
        return false;
    }
    // Get owning user
    $owner = get_entity($post->getOwner());
    $owner_guid = $owner->guid;
    // Delete the images
    $prefix = "market/" . $guid;
    $small = $prefix . "small.jpg";
    $medium = $prefix . "medium.jpg";
    $large = $prefix . "large.jpg";
    $master = $prefix . "master.jpg";
    $original = $prefix . ".jpg";
    if ($small) {
        $delfile = new ElggFile();
        $delfile->owner_guid = $owner_guid;
        $delfile->setFilename($small);
        $delfile->delete();
    }
    if ($medium) {
        $delfile = new ElggFile();
        $delfile->owner_guid = $owner_guid;
        $delfile->setFilename($medium);
        $delfile->delete();
    }
    if ($large) {
        $delfile = new ElggFile();
        $delfile->owner_guid = $owner_guid;
        $delfile->setFilename($large);
        $delfile->delete();
    }
    if ($master) {
        $delfile = new ElggFile();
        $delfile->owner_guid = $owner_guid;
        $delfile->setFilename($master);
        $delfile->delete();
    }
    if ($original) {
        $delfile = new ElggFile();
        $delfile->owner_guid = $owner_guid;
        $delfile->setFilename($original);
        $delfile->delete();
    }
    // Delete the market post
    $rowsaffected = $post->delete();
    if ($rowsaffected > 0) {
        // Success
        return true;
    } else {
        // Error
        return false;
    }
}