Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Create new discussion on registration

2»

Comments

  • @MrVlad said:
    Do you think that this could be a good addition to the plugin database ?


    @Linc said:
    This is a brilliant plugin idea.

  • oops ... :D ! I'll work on it then !

  • @MrVlad said:
    ...I created some Globals to store the info and pass it from one function to the other...

    Using globals is considered bad practice as you are "polluting" the global name space. Use class variables to get around this:

    <?php if (!defined('APPLICATION')) exit();
    $PluginInfo['postonregister'] = array(
        'Name' => 'Post on register',
        'Description' => 'Create a new post each time a new user registers',
        'Version' => '0.1',
        'Author' => 'Vladvonvidden',
    );
    // Globals are BAD
    class postonregister extends Gdn_Plugin {
        private $game = "Aucun";
        private $quelJeu = "Aucun";
        private $comment = "Par Internet";
        private $plusSurVous = "je suis quelqu'un de distrait";
    
    
        public function entryController_RegisterValidation_handler($sender) {
            $this->game = $sender->Form->_FormValues['Aqueljeujouezvousgalement'];
            $this->quelJeu = $sender->Form->_FormValues['Pourqueljeupostulezvous'];
            $this->comment = $sender->Form->_FormValues['CommentavezvousetconnaissanceduConsortiumHorizon'];
            $this->plusSurVous = $sender->Form->_FormValues['Ditesnousenplussurvous'];
        }
    
        public function userModel_afterRegister_handler($sender, $Args) {
            // Get user ID from sender
            $userID = $sender->EventArguments['UserID'];
            // Retreive user object
            $user = $sender->GetID($userID);
            // Get UserName
            $name = (string)GetValue('Name', $user);
            // Get first visit date
            $date = Gdn_Format::ToDateTime();
            // Create new discussionModel
            $DiscussionModel = new DiscussionModel();
            // Feed it ! Feeeeeeeeed it !
            $SQL = Gdn::Database()->SQL();
            // Always initialize your variables to a known state
            $Discussion = array();
            // Where you wanna insert the discussion (which category)
            $Discussion['CategoryID'] = '9';
            // Discussion Format (BBcode)
            $Discussion['Format'] = 'BBCode';
            // Discussion title
            $Discussion['Name'] = '[' . $this->quelJeu . '] ' . $name . ' [En attente de validation]';
            // Discussion content
            $Discussion['Body'] = '[b]Pour quel jeu en particulier postulez-vous dans la Guilde ?[/b]
            '
            . $this->quelJeu .
            '
            [b]A quels autres jeux jouez-vous également ?[/b]
            '
            . $this->game .
            '
            [b]Comment avez-eu connaissance du Consortium Horizon ?[/b]
            '
            . $this->comment .
            '
            [b]Dites-en un peu plus sur vous :[/b]
            '
            . $this->plusSurVous .
            '
            En attente de validation par un modérateur';
            // Date of creation
            $Discussion['DateInserted'] = $date;
            // Date of last comment
            $Discussion['DateLastComment'] = $date;
            // The author
            $Discussion['InsertUserID'] = $userID ;
            // Insert in the right category
            $DiscussionID = $SQL->Insert('Discussion', $Discussion);
            // If everything is ok, refresh discussion count
            if ($DiscussionID) {
                $DiscussionModel->UpdateDiscussionCount($Discussion['CategoryID']);
            }
        }
    }
    

    Other than that it looks great! :)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.