/** * Copies a poll from one object id to another. */ public function copy() { $sourceObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.poll', $this->parameters['sourceObjectType']); $targetObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.poll', $this->parameters['targetObjectType']); // // step 1) get data // // get poll $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_poll\n\t\t\tWHERE\tobjectTypeID = ?\n\t\t\t\tAND objectID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($sourceObjectType->objectTypeID, $this->parameters['sourceObjectID'])); $row = $statement->fetchArray(); if ($row === false) { return array('pollID' => null); } // get options $pollOptionList = new PollOptionList(); $pollOptionList->getConditionBuilder()->add("poll_option.pollID = ?", array($row['pollID'])); $pollOptionList->readObjects(); // // step 2) copy // // cretae poll $pollData = $row; $pollData['objectTypeID'] = $targetObjectType->objectTypeID; $pollData['objectID'] = $this->parameters['targetObjectID']; unset($pollData['pollID']); $newPoll = PollEditor::create($pollData); // create options $newOptionIDs = array(); foreach ($pollOptionList as $pollOption) { $newOption = PollOptionEditor::create(array('pollID' => $newPoll->pollID, 'optionValue' => $pollOption->optionValue, 'votes' => $pollOption->votes, 'showOrder' => $pollOption->showOrder)); $newOptionIDs[$pollOption->optionID] = $newOption->optionID; } // copy votes WCF::getDB()->beginTransaction(); foreach ($newOptionIDs as $oldOptionID => $newOptionID) { $sql = "INSERT INTO\twcf" . WCF_N . "_poll_option_vote\n\t\t\t\t\t\t(pollID, optionID, userID)\n\t\t\t\tSELECT\t\t" . $newPoll->pollID . ", " . $newOptionID . ", userID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_poll_option_vote\n\t\t\t\tWHERE\t\toptionID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($oldOptionID)); } WCF::getDB()->commitTransaction(); return array('pollID' => $newPoll->pollID); }
/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { $poll = PollEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID))); ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $poll->pollID); return $poll->pollID; }