Advertisement:

Author Topic: (SOLVED)How to make new items inactive by default,until the admin activates them  (Read 1222 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
I want items "inactive" as default for all new items.
After this the admin will verify them and activate them from admin.
In which file should I modify this?

I gues the admin option to validate items means that users must validate their ads from email validation link. Or it isn't like that?

For example in ItemAction.php there is:

Code: [Select]
            if( $is_add ) {   // ADD
                if($this->is_admin) {
                    $active = 'ACTIVE';
                } else {
                    if(osc_moderate_items()>0) { // HAS TO VALIDATE
                        if(!osc_is_web_user_logged_in()) { // NO USER IS LOGGED, VALIDATE
                            $active = 'INACTIVE';
                        } else { // USER IS LOGGED
                            if(osc_logged_user_item_validation()) { //USER IS LOGGED, BUT NO NEED TO VALIDATE
                                $active = 'ACTIVE';
                            } else { // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS
                                $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
                                if($user['i_items']<osc_moderate_items()) {
                                    $active = 'INACTIVE';
                                } else {
                                    $active = 'ACTIVE';
                                }
                            }
                        }
                    } else if(osc_moderate_items()==0 ){
                        if(osc_is_web_user_logged_in() && osc_logged_user_item_validation() ) {
                            $active = 'ACTIVE';
                        } else {
                            $active = 'INACTIVE';
                        }
                    } else {
                        $active = 'ACTIVE';
                    }
                }
                $aItem['active']        = $active;
            } else {          // EDIT
                $aItem['secret']    = Params::getParam('secret');
                $aItem['idItem']    = Params::getParam('id');
            }

EDIT

From what I can understand from oc-admin/themes/modern/items/settings.php

The osc_moderate_items() refers to user validation not admin validation.

So maybe the solution would be to change the value of $enabled to 0 in ItemActions.php?:

Code: [Select]
       /**
         * @return boolean
         */
        public function add()
        {
            $aItem       = $this->data;
            $aItem = osc_apply_filter('item_add_prepare_data', $aItem);
            $is_spam     = 0;
            $enabled     = 1;

EDIT

If I do that the add apears as BLOCKED in admin area and the admin can unblock it after. But this means that if the admin ads a new item from admin, he must unblock it after that.

Can I use
Code: [Select]
if($this->is_admin) {in public function add() ?

EDIT:

it seems I can

Code: [Select]
if($this->is_admin) $enabled     = 1;
            else $enabled     = 0;

EDIT

I modified also the messages.po and messages.mo files with poedit to reflect the new functionality:

Code: [Select]
#: oc-includes/osclass/controller/item.php:165
msgid "Your listing has been published"
msgstr "Your listing is awaiting moderation"


Please mention your observations for the implications of this modification. Thank you.
« Last Edit: July 17, 2017, 12:03:52 am by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Now the following question arizes. How to send mail confirmation to user after it's ad is enabled(unblocked)?

As I disabled the comments, the "email_comment_validated" could be used for this.

Edit: I posted this new question here:

https://forums.osclass.org/development/how-to-notify-the-user-via-mail-model-when-it's-ad-is-unblocked/
« Last Edit: July 16, 2017, 09:27:52 am by marius-ciclistu »

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
There are a few things,

1.- Again, modifying core files (while possible) is not encouraged, it could be done with a plugin, in fact, there's a free plugin that does exactly that : More edit https://market.osclass.org/plugins/ad-management/more-edit_23 (it's a bit old)
2.- There are two different attributes for a listing active/inactive & enabled/disabled, both have a 0/1 value and are similar but the different is quite big. Users can change the state from inactive to active, but can not from disabled to enabled, only admins could do both. (I see you got this ok, but just want to remember it)

3.- Use brackets, really, use them
Instead of this :
Code: [Select]
if($this->is_admin) $enabled     = 1;
            else $enabled     = 0;

write this

Code: [Select]
if($this->is_admin) {
    $enabled     = 1;
} else {
    $enabled     = 0;
}

4.- Don't modify .po nor .mo files directly, let poedit parse the sources and get new strings. I know, in this case, this is the only option since the code has a text different than the one it should, but it's a bad idea to modify .po / .mo files

Take a look at more edit plugin to see how it could be done without modifying core files

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Thank you for your reply.
1. Regarding the plugin, I followed the road of not using plugins and this enables me to learn more php than if I would use them, and to learn more info about osclass.
2. Thank you, I realized that after I tested my modifications.
3. I didn't use {} because there is only one action and then the ; ends the if/else condition. Your obs. is usefull for later edits, it eliminates the risk of forgeting to put them if there will be more than one action in that if /else condition.
4. I used poedit to modify them in my language.

Conclusion: I love osclass, but I can't believe how many times I say: "Now I'm done with it, it's fine" and the next day a new idea comes in my mind :)))))

Maybe some of the free plugins should be incorporated into the initial instalation as it is in opencart for example. In that way osclass would be more closer to "out of the box" opensource (I know, I know...the money part is essential, but if they are free anyway...?).

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
I found a bug to my solution.
It increases the stats in admin for number of items/user even if the item is blocked($enabled=0)

Solution:
itemActions.php

Replace

Code: [Select]
                    // if is_spam not increase stats
                    if($is_spam == 0) {
                        $this->_increaseStats($aAux);
                    }
                    $success = 2;

with
                   
Code: [Select]
// if is_spam not increase stats
                    if($is_spam == 0 && $enabled == 1) {
                        $this->_increaseStats($aAux);
                    }
                    $success = 2;