示例#1
0
 /**
  * Given a Wiki object for this WikiItem, this will post it as a new version.
  * 
  * The passed in WikiObject will be saved to the database 
  * @param string $strName the name of this WikiItem
  * @param object $objWikiObject the linked Wiki object (e.g. WikiPage or WikiImage) that is not yet saved or assigned
  * @param string $strSaveMethod the name of the Save method to call on the WikiObject
  * @param array $arrSaveParameters an array of parameters to pass in to the Save method on the WikiObject
  * @param Person $objPerson the Person who posted it
  * @param QDateTime $dttPostDate the optional datetime of the post (will use NOW if none passed)
  * @return WikiVersion
  */
 public function CreateNewVersion($strName, $objWikiObject, $strSaveMethod, $arrSaveParameters, Person $objPerson, QDateTime $dttPostDate = null)
 {
     // Ensure the WikiObject is not yet saved or assigned
     if ($objWikiObject->WikiVersionId) {
         throw new QCallerException('WikiObject is already saved or has already been assigned to a version');
     }
     // Ensure the WikiObject is the right type
     if (WikiItemType::$ClassNameArray[$this->intWikiItemTypeId] != get_class($objWikiObject)) {
         throw new QCallerException('WikiObject class does not match this wiki item type');
     }
     // Create and Save the WikiVersion
     $objWikiVersion = new WikiVersion();
     $objWikiVersion->WikiItem = $this;
     $objWikiVersion->VersionNumber = $this->CountWikiVersions() + 1;
     $objWikiVersion->Name = trim($strName);
     $objWikiVersion->PostedByPerson = $objPerson;
     $objWikiVersion->PostDate = $dttPostDate ? $dttPostDate : QDateTime::Now();
     $objWikiVersion->Save();
     // Assign the WikiObject
     $objWikiObject->WikiVersion = $objWikiVersion;
     // Save the WikiObject using the MethodName and MethodParameters passed in
     if (is_null($arrSaveParameters)) {
         $arrSaveParameters = array();
     }
     call_user_func_array(array($objWikiObject, $strSaveMethod), $arrSaveParameters);
     // Update my metadata
     $this->SetCurrentVersion($objWikiVersion);
     // Return
     return $objWikiVersion;
 }