Ejemplo n.º 1
0
 /**
  * Posts a new version of this package for a given person.
  * @param Person $objPerson
  * @param string $strQpmXml
  * @param QDateTime $dttPostDate optional, uses Now() if not specified
  * @return PackageContribution
  */
 public function PostContributionVersion(Person $objPerson, $strQpmXml, QDateTime $dttPostDate = null)
 {
     // Get PackageContribution
     $objContribution = PackageContribution::LoadByPackageIdPersonId($this->intId, $objPerson->Id);
     // Parse the QPM XML
     try {
         $objQpmXml = new SimpleXMLElement($strQpmXml);
     } catch (Exception $objExc) {
         throw new Exception('Invalid QPM Schema');
     }
     // Compress the XML
     $strQpmXmlCompressed = gzencode($strQpmXml, 9);
     // Validate the XML
     $strQpmVersion = (string) $objQpmXml['version'];
     if ($strQpmVersion != '1.0') {
         throw new Exception('Invalid QPM Schema Version: ' . $strQpmVersion);
     }
     // Pull out the rest of the data and validate it all
     $strPackageName = (string) $objQpmXml->package['name'];
     $strPackageUsername = (string) $objQpmXml->package['user'];
     $intVersionNumber = (string) $objQpmXml->package['version'];
     $strQcodoVersionNumber = (string) $objQpmXml->package['qcodoVersion'];
     $strNotes = (string) $objQpmXml->package->notes;
     $intNewFileCount = count($objQpmXml->package->newFiles->children());
     $intChangedFileCount = count($objQpmXml->package->changedFiles->children());
     if ($strPackageName != $this->Token) {
         throw new Exception('Invalid QPM Package Name: ' . $strPackageName);
     }
     if ($strPackageUsername != $objPerson->Username) {
         throw new Exception('Invalid QPM Package User: '******'Invalid QPM Package Version: ' . $intVersionNumber);
         }
     } else {
         if ($intVersionNumber != 1) {
             throw new Exception('Invalid QPM Package Version: ' . $intVersionNumber);
         }
     }
     preg_match('/[0-9]+\\.[0-9]+\\.[0-9]+/', $strQcodoVersionNumber, $arrMatches);
     if ($arrMatches[0] != $strQcodoVersionNumber) {
         throw new Exception('Invalid Qcodo Version Number in QpmXml: ' . $strQcodoVersionNumber);
     }
     // Create PackageContribution (if none exists)
     if (!$objContribution) {
         $objContribution = new PackageContribution();
         $objContribution->Package = $this;
         $objContribution->Person = $objPerson;
         $objContribution->Save();
     }
     $objVersion = new PackageVersion();
     $objVersion->PackageContribution = $objContribution;
     $objVersion->Notes = $strNotes;
     $objVersion->QcodoVersion = $strQcodoVersionNumber;
     $objVersion->NewFileCount = $intNewFileCount;
     $objVersion->ChangedFileCount = $intChangedFileCount;
     $objVersion->PostDate = $dttPostDate ? $dttPostDate : QDateTime::Now();
     $objVersion->DownloadCount = 0;
     $objVersion->VersionNumber = $intVersionNumber;
     $objVersion->Save();
     $objContribution->CurrentPackageVersion = $objVersion;
     $objContribution->CurrentPostDate = $objVersion->PostDate;
     $objContribution->RefreshStats();
     $this->LastPostDate = $objVersion->PostDate;
     $this->LastPostedByPerson = $objPerson;
     $this->Save();
     $objVersion->SaveFile($strQpmXml, $strQpmXmlCompressed);
     $this->PackageCategory->RefreshStats();
     return $objContribution;
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, PackageVersion::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objPackage) {
         $objObject->objPackage = Package::GetSoapObjectFromObject($objObject->objPackage, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intPackageId = null;
         }
     }
     if ($objObject->objPerson) {
         $objObject->objPerson = Person::GetSoapObjectFromObject($objObject->objPerson, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intPersonId = null;
         }
     }
     if ($objObject->objCurrentPackageVersion) {
         $objObject->objCurrentPackageVersion = PackageVersion::GetSoapObjectFromObject($objObject->objCurrentPackageVersion, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intCurrentPackageVersionId = null;
         }
     }
     if ($objObject->dttCurrentPostDate) {
         $objObject->dttCurrentPostDate = $objObject->dttCurrentPostDate->__toString(QDateTime::FormatSoap);
     }
     return $objObject;
 }
 /**
  * Default / simple DataBinder for this Meta DataGrid.  This can easily be overridden
  * by calling SetDataBinder() on this DataGrid with another DataBinder of your choice.
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  */
 public function MetaDataBinder()
 {
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = PackageVersion::CountAll();
     }
     // Setup the $objClauses Array
     $objClauses = array();
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from PackageVersion, given the clauses above
     $this->DataSource = PackageVersion::LoadAll($objClauses);
 }
 /**
  * Static Helper Method to Create using PK arguments
  * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
  * edit, or if we are also allowed to create a new one, etc.
  * 
  * @param mixed $objParentObject QForm or QPanel which will be using this PackageVersionMetaControl
  * @param integer $intId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing PackageVersion object creation - defaults to CreateOrEdit
  * @return PackageVersionMetaControl
  */
 public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intId)) {
         $objPackageVersion = PackageVersion::Load($intId);
         // PackageVersion was found -- return it!
         if ($objPackageVersion) {
             return new PackageVersionMetaControl($objParentObject, $objPackageVersion);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a PackageVersion object with PK arguments: ' . $intId);
             }
         }
         // If EditOnly is specified, throw an exception
     } else {
         if ($intCreateType == QMetaControlCreateType::EditOnly) {
             throw new QCallerException('No PK arguments specified');
         }
     }
     // If we are here, then we need to create a new record
     return new PackageVersionMetaControl($objParentObject, new PackageVersion());
 }
 /**
  * Refresh this MetaControl with Data from the local PackageContribution object.
  * @param boolean $blnReload reload PackageContribution from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objPackageContribution->Reload();
     }
     if ($this->lblId) {
         if ($this->blnEditMode) {
             $this->lblId->Text = $this->objPackageContribution->Id;
         }
     }
     if ($this->lstPackage) {
         $this->lstPackage->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstPackage->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objPackageArray = Package::LoadAll();
         if ($objPackageArray) {
             foreach ($objPackageArray as $objPackage) {
                 $objListItem = new QListItem($objPackage->__toString(), $objPackage->Id);
                 if ($this->objPackageContribution->Package && $this->objPackageContribution->Package->Id == $objPackage->Id) {
                     $objListItem->Selected = true;
                 }
                 $this->lstPackage->AddItem($objListItem);
             }
         }
     }
     if ($this->lblPackageId) {
         $this->lblPackageId->Text = $this->objPackageContribution->Package ? $this->objPackageContribution->Package->__toString() : null;
     }
     if ($this->lstPerson) {
         $this->lstPerson->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstPerson->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objPersonArray = Person::LoadAll();
         if ($objPersonArray) {
             foreach ($objPersonArray as $objPerson) {
                 $objListItem = new QListItem($objPerson->__toString(), $objPerson->Id);
                 if ($this->objPackageContribution->Person && $this->objPackageContribution->Person->Id == $objPerson->Id) {
                     $objListItem->Selected = true;
                 }
                 $this->lstPerson->AddItem($objListItem);
             }
         }
     }
     if ($this->lblPersonId) {
         $this->lblPersonId->Text = $this->objPackageContribution->Person ? $this->objPackageContribution->Person->__toString() : null;
     }
     if ($this->lstCurrentPackageVersion) {
         $this->lstCurrentPackageVersion->RemoveAllItems();
         $this->lstCurrentPackageVersion->AddItem(QApplication::Translate('- Select One -'), null);
         $objCurrentPackageVersionArray = PackageVersion::LoadAll();
         if ($objCurrentPackageVersionArray) {
             foreach ($objCurrentPackageVersionArray as $objCurrentPackageVersion) {
                 $objListItem = new QListItem($objCurrentPackageVersion->__toString(), $objCurrentPackageVersion->Id);
                 if ($this->objPackageContribution->CurrentPackageVersion && $this->objPackageContribution->CurrentPackageVersion->Id == $objCurrentPackageVersion->Id) {
                     $objListItem->Selected = true;
                 }
                 $this->lstCurrentPackageVersion->AddItem($objListItem);
             }
         }
     }
     if ($this->lblCurrentPackageVersionId) {
         $this->lblCurrentPackageVersionId->Text = $this->objPackageContribution->CurrentPackageVersion ? $this->objPackageContribution->CurrentPackageVersion->__toString() : null;
     }
     if ($this->calCurrentPostDate) {
         $this->calCurrentPostDate->DateTime = $this->objPackageContribution->CurrentPostDate;
     }
     if ($this->lblCurrentPostDate) {
         $this->lblCurrentPostDate->Text = sprintf($this->objPackageContribution->CurrentPostDate) ? $this->objPackageContribution->__toString($this->strCurrentPostDateDateTimeFormat) : null;
     }
     if ($this->txtDownloadCount) {
         $this->txtDownloadCount->Text = $this->objPackageContribution->DownloadCount;
     }
     if ($this->lblDownloadCount) {
         $this->lblDownloadCount->Text = $this->objPackageContribution->DownloadCount;
     }
 }
 /**
  * Main utility method to aid with data binding.  It is used by the default BindAllRows() databinder but
  * could and should be used by any custom databind methods that would be used for instances of this
  * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. 
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  *
  * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself
  * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query		 
  * @return void
  */
 public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null)
 {
     // Setup input parameters to default values if none passed in
     if (!$objCondition) {
         $objCondition = QQ::All();
     }
     $objClauses = $objOptionalClauses ? $objOptionalClauses : array();
     // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = PackageVersion::QueryCount($objCondition, $objClauses);
     }
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from PackageVersion, given the clauses above
     $this->DataSource = PackageVersion::QueryArray($objCondition, $objClauses);
 }