HOW TO: Create a predefined Poll with a php function??

Hi,

I recently posted a similar topic, but Ive made some progress so I have updated this to the appropriate category.

 

So, I have a new module (LiveStream) that I would like to use the existing Poll module to automatically create a new poll.

I need to accomplished two things:

1) Create a new poll when the "Add room" form is submitted.

   - I have a simple "if" statement that will only run if the LiveStream modules Add form is successfully submitted. If the form successfully submits the statement will run a custom function from the BxPollModule.php file ("autocreatepoll"). *This custom function is the same as the original createpoll function that is found in that file at line 2062, but Im working on modifications to create the predefine question and answers. The function is explained in # 2...

 

2) Give the newly created poll a predefined question and answers.

   - I created a custom function call autocreatepoll, which is based on the original createpoll function of the BxPollModule.php file.

   For the modifications, I want to create a predefined question and answers for the new poll whenever the form is successfully submitted. This is what I have so far...

function autocreatePoll($sPollQuestion, $sPollAnswers, $iCommentGroupValue, $iVoteGroupValue, $sCategory, $iViewGroupValue)
                {
                   
                    // Predefined function arguments
                   
                    $sPollQuestion = 'How would you rate this?';
                    $sPollAnswers = array (1, 2, 3, 4, 5); // For standard rating from 1 to 5
                    $iCommentGroupValue = 3;
                    $iVoteGroupValue = 3;
                    $sCategory = 'Videos';
                    $iViewGroupValue = 3;
                   
                   

                    // Everything below is unchanged
                   
                    // check membership;
                    if(!$this -> isPollCreateAlowed($this -> aPollSettings['member_id'], true) ) {
                        return;
                    }
               
                    // ** init some needed variables ;
                    $aPoolInfo = array();
               
                    if ( !$sPollQuestion or !$sPollAnswers ) {
                        $this -> sActionAnswer  = MsgBox(POLL_EMPTY_FIELDS);
                    }
                   
                    else {
                        $aPoolInfo = array
                        (
                            'owner_id'      => $this -> aPollSettings['member_id'],
                            'question'      => $sPollQuestion,
                            'answers'       => $sPollAnswers,
                            'results'       => $sPollResults,
                            'tags'          => $sTags,
                            'allow_comment' => $iCommentGroupValue,
                            'allow_vote'    => $iVoteGroupValue,
                            'category'      => $sCategory,
                            'allow_view'    => $iViewGroupValue
                        );
               
                        $iResponse = $this -> _oDb -> createPoll($aPoolInfo, $this -> aPollSettings['admin_mode']);
                        $iLastPoll = $this -> _oDb -> lastId();
               
                        // define the action number ;
                        switch($iResponse) {
                            case '0':
                                $this -> sActionAnswer  = MsgBox(POLL_NOT_ALLOW);
                                break;   
               
                            case '1' :
                                $this -> sActionAnswer  = MsgBox(POLL_CREATED);
                                // create system event
                                $oZ = new BxDolAlerts('bx_poll', 'add', $iLastPoll);
                                $oZ->alert();
               
                                $oTag = new BxDolTags();
                                $oTag -> reparseObjTags('bx_poll', $iLastPoll);
               
                                $oCateg = new BxDolCategories();
                                $oCateg->reparseObjTags('bx_poll', $iLastPoll);
                                break;
               
                            case '2' :
                                $this -> sActionAnswer  = MsgBox(POLL_MAX_REACHED);
                                break;
                        }
                    }   
                }

 

 

Can someone more experienced with Dolphin modules please help me. Thanks a lot

Quote · 26 Jul 2012

And what is your question or problem?

http://www.boonex.com/market/posts/paansystems - your resource for Dolphin Pro
Quote · 27 Jul 2012

My question is how do I create a predefined poll from another module? A poll that is created when a particular form from the other module is submitted. The function within the BxPollModule.php is createPoll().

 

My initial post gives more deatils to my inquiry. Thank you

Quote · 27 Jul 2012

why not just calling the createpool function in your script?

 

$aMyModule = array(
    'path' => 'boonex/poll',
    'class_prefix' => 'BxPoll'
);
bx_import('Module', $aMyModule);

$oPool = new BxPollModule();
$oPool->createPoll(
    $sPollQuestion,
    $sPollAnsers,
    $sPollResults,
    $sTags,
    $iCommentGroupValue,
    $iVoteGroupValue,
    $sCategory,
    $iViewGroupValue
);

 

you just have to define the parameters before ...

 

PS: quick&dirty ... not tested

http://www.boonex.com/market/posts/paansystems - your resource for Dolphin Pro
Quote · 7 Aug 2012
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.