Skip to content

[feature suggestion] deactivating of items in user panel #102

@trains58554

Description

@trains58554

Hi

I have made some changes to hDefines and item.php in the rood directory to add the functionality of letting the user deactivate their items. I though I would share this code with you and let you guys decide if you want to add it to the core.

This code I added to the hDefines.php file

/**
     * Gets url for deactivating an item
     *
     * @param int $id
     * @return string
     */
    function osc_item_deactivate_url($id = '') {
        if ($id == '') $id = osc_item_id();
        if ( osc_rewrite_enabled() ) {
            return osc_base_url() . 'item/deactivate/' . $id ;
        } else {
            return osc_base_url(true) . '?page=item&action=deactivate&id=' . $id  ;
        }
    }

item.php in root directory changes added at line 245

case 'deactivate':
                    $secret = Params::getParam('secret');
                    $id     = Params::getParam('id');
                    $item   = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId);
                    View::newInstance()->_exportVariableToView('item', $item[0]);
                    if ($item[0]['b_active']==1) {
                        // DEACTIVETE ITEM
                        $mItems = new ItemActions(false) ;
                        $success = $mItems->deactivate( $item[0]['pk_i_id']);

                        if( $success ){
                            osc_add_flash_ok_message( _m('The item has been deactivated') ) ;
                        }else{
                            osc_add_flash_error_message( _m('The item can\'t be deactivated') ) ;
                        }
                    }else{
                        osc_add_flash_error_message( _m('The item has already been deactivated') );
                    }

                    $this->redirectTo( osc_user_list_items_url( ) );
                break;

Lastly the change in theme user-items.php

<?php if(osc_item_is_active()) {?>
                                            <span>|</span>
                                            <a href="<?php echo osc_item_deactivate_url();?>" ><?php _e('Deactivate', 'modern'); ?></a>
                                            <?php } ?>

One more addition to make this work with permalinks
in generate_rules.php add the following code at line 53

$rewrite->addRule('^item/deactivate/([0-9]+)/?$', 'index.php?page=item&action=deactivate&id=$1');

Thanks

Jay

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions