Jump to content

Jyoti Rani

Clients
  • Posts

    76
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Jyoti Rani reacted to Adriano Faria in How to create hooks in invision new version?   
    Enable IN_DEV mode. It will appear.
  2. Thanks
    Jyoti Rani reacted to teraßyte in How to create hooks in invision new version?   
    Based on what you posted I now have a clearer idea of what you're doing, but I still see a few issues and optimizations that can be made:
    You can use a quick in_array() check for the group instead of multiple OR checks. Also, note that your code doesn't take into account secondary groups, if you want to check also those, you need to adjust the code. The $assign_point variable is not defined before the IF check, if the user is in a group outside of the listed IDs, PHP 8 will throw an error about an unknown variable. I see that you're basically loading the credit balance from a table, adding 250 to it, and then updating the same table back. The whole process can be simplified in a single query instead. The reset DB prefix code can be moved inside the IF check, if the user doesn't need a credit balance update, there's no point running it. Here's an updated code based on the points above:
    protected function processAfterCreate($comment, $values) { # Comment/uncomment either line below based on what you want #if ( \in_array( \IPS\Member::loggedIn()->member_group_id, array( 3, 4, 7, 8 ) ) ) # This line checks only the primary group if ( \IPS\Member::loggedIn()->inGroup( array( 3, 4, 7, 8 ) ) ) # This line checks also secondary groups { # Temporarily disable the DB prefix $previousPrefix = \IPS\Db::i()->prefix; \IPS\Db::i()->prefix = ''; # Update credit_balance column to add 250 credits to its current value \IPS\Db::i()->update('plug_mailing_master', "credit_balance=credit_balance+250", array('user_id=?', \IPS\Member::loggedIn()->member_id)); # Reset prefix \IPS\Db::i()->prefix = $previousPrefix; } return parent::processAfterCreate($comment, $values); } The code checks if the user has one of the specified groups, and adds 250 to their credit balance value based on their member ID. No need for anything else.
     
    P.S.: If you use the Code button in the editor the code you post will look better and formatted for the appropriate language. 😉
  3. Like
    Jyoti Rani reacted to teraßyte in How to create hooks in invision new version?   
    I'm having a really hard time understanding your code because it's all partial or missing context and variables.
    Anyway, you can temporarily disable the prefix in the database class if your tables don't have it. Or you can keep using manual query() calls, but there is no need to use mysqli_fetch_assoc.
     
    See the code below, I tried to update your processAfterCreate() function above with more consistent code:
    public function processAfterCreate($comment, $values) { # Remove prefix $previousPrefix = \IPS\Db::i()->prefix; \IPS\Db::i()->prefix = ''; # Vars $reward_mailing_points = 10; # Not sure where you're pulling this value from, so I set an arbitrary 10 here as example $cc = 0; # Get result - If this query always returns only 1 row, it can be changed to use ->first() $result = \IPS\Db::i()->select('*', 'xxxx', array( 'user_id=?', \IPS\Member::loggedIn()->member_id ) ); foreach( $result as $row ) { $cc += $reward_mailing_points + intval($row['cc']); } # Update database with new $cc value \IPS\Db::i()->update( 'xxx', array( 'credit_balance' => $cc ), array( 'user_id=?', \IPS\Member::loggedIn()->member_id ) ); # Reset prefix \IPS\Db::i()->prefix = $previousPrefix; return parent::processAfterCreate($comment, $values); }
  4. Thanks
    Jyoti Rani got a reaction from konon in How to create hooks in invision new version?   
    Hi
    In the invision version 3.6 i have 2 hooks. During the upgrade these has been lost. 
    Now in the version invision 4.7, How to implement the hooks?
    Any guide or link helps me a lot.
     
  5. Like
    Jyoti Rani got a reaction from Marc Stridgen in In setting up of developer mode i m facing below error   
    Thanks a lot TeraByte. Now the urls working.
×
×
  • Create New...