/** * 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 PackageMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing Package object creation - defaults to CreateOrEdit * @return PackageMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objPackage = Package::Load($intId); // Package was found -- return it! if ($objPackage) { return new PackageMetaControl($objParentObject, $objPackage); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a Package 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 PackageMetaControl($objParentObject, new Package()); }
/** * Reload this Package from the database. * @return void */ public function Reload() { // Make sure we are actually Restored from the database if (!$this->__blnRestored) { throw new QCallerException('Cannot call Reload() on a new, unsaved Package object.'); } // Reload the Object $objReloaded = Package::Load($this->intId); // Update $this's local variables to match $this->PackageCategoryId = $objReloaded->PackageCategoryId; $this->strToken = $objReloaded->strToken; $this->strName = $objReloaded->strName; $this->strDescription = $objReloaded->strDescription; $this->dttLastPostDate = $objReloaded->dttLastPostDate; $this->LastPostedByPersonId = $objReloaded->LastPostedByPersonId; }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'Id': // Gets the value for intId (Read-Only PK) // @return integer return $this->intId; case 'TopicLinkTypeId': // Gets the value for intTopicLinkTypeId (Not Null) // @return integer return $this->intTopicLinkTypeId; case 'TopicCount': // Gets the value for intTopicCount // @return integer return $this->intTopicCount; case 'MessageCount': // Gets the value for intMessageCount // @return integer return $this->intMessageCount; case 'LastPostDate': // Gets the value for dttLastPostDate // @return QDateTime return $this->dttLastPostDate; case 'ForumId': // Gets the value for intForumId (Unique) // @return integer return $this->intForumId; case 'IssueId': // Gets the value for intIssueId (Unique) // @return integer return $this->intIssueId; case 'WikiItemId': // Gets the value for intWikiItemId (Unique) // @return integer return $this->intWikiItemId; case 'PackageId': // Gets the value for intPackageId (Unique) // @return integer return $this->intPackageId; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Forum': // Gets the value for the Forum object referenced by intForumId (Unique) // @return Forum try { if (!$this->objForum && !is_null($this->intForumId)) { $this->objForum = Forum::Load($this->intForumId); } return $this->objForum; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Issue': // Gets the value for the Issue object referenced by intIssueId (Unique) // @return Issue try { if (!$this->objIssue && !is_null($this->intIssueId)) { $this->objIssue = Issue::Load($this->intIssueId); } return $this->objIssue; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'WikiItem': // Gets the value for the WikiItem object referenced by intWikiItemId (Unique) // @return WikiItem try { if (!$this->objWikiItem && !is_null($this->intWikiItemId)) { $this->objWikiItem = WikiItem::Load($this->intWikiItemId); } return $this->objWikiItem; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Package': // Gets the value for the Package object referenced by intPackageId (Unique) // @return Package try { if (!$this->objPackage && !is_null($this->intPackageId)) { $this->objPackage = Package::Load($this->intPackageId); } return $this->objPackage; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '_Message': // Gets the value for the private _objMessage (Read-Only) // if set due to an expansion on the message.topic_link_id reverse relationship // @return Message return $this->_objMessage; case '_MessageArray': // Gets the value for the private _objMessageArray (Read-Only) // if set due to an ExpandAsArray on the message.topic_link_id reverse relationship // @return Message[] return (array) $this->_objMessageArray; case '_Topic': // Gets the value for the private _objTopic (Read-Only) // if set due to an expansion on the topic.topic_link_id reverse relationship // @return Topic return $this->_objTopic; case '_TopicArray': // Gets the value for the private _objTopicArray (Read-Only) // if set due to an ExpandAsArray on the topic.topic_link_id reverse relationship // @return Topic[] return (array) $this->_objTopicArray; case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'Id': // Gets the value for intId (Read-Only PK) // @return integer return $this->intId; case 'PackageId': // Gets the value for intPackageId (Not Null) // @return integer return $this->intPackageId; case 'PersonId': // Gets the value for intPersonId (Not Null) // @return integer return $this->intPersonId; case 'CurrentPackageVersionId': // Gets the value for intCurrentPackageVersionId // @return integer return $this->intCurrentPackageVersionId; case 'CurrentPostDate': // Gets the value for dttCurrentPostDate // @return QDateTime return $this->dttCurrentPostDate; case 'DownloadCount': // Gets the value for intDownloadCount // @return integer return $this->intDownloadCount; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Package': // Gets the value for the Package object referenced by intPackageId (Not Null) // @return Package try { if (!$this->objPackage && !is_null($this->intPackageId)) { $this->objPackage = Package::Load($this->intPackageId); } return $this->objPackage; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Person': // Gets the value for the Person object referenced by intPersonId (Not Null) // @return Person try { if (!$this->objPerson && !is_null($this->intPersonId)) { $this->objPerson = Person::Load($this->intPersonId); } return $this->objPerson; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'CurrentPackageVersion': // Gets the value for the PackageVersion object referenced by intCurrentPackageVersionId // @return PackageVersion try { if (!$this->objCurrentPackageVersion && !is_null($this->intCurrentPackageVersionId)) { $this->objCurrentPackageVersion = PackageVersion::Load($this->intCurrentPackageVersionId); } return $this->objCurrentPackageVersion; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '_PackageVersion': // Gets the value for the private _objPackageVersion (Read-Only) // if set due to an expansion on the package_version.package_contribution_id reverse relationship // @return PackageVersion return $this->_objPackageVersion; case '_PackageVersionArray': // Gets the value for the private _objPackageVersionArray (Read-Only) // if set due to an ExpandAsArray on the package_version.package_contribution_id reverse relationship // @return PackageVersion[] return (array) $this->_objPackageVersionArray; case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }
/** * @param string $strPackageName * @param string $strUsername * @param boolean $blnGzCompress * @return string */ public function DownloadPackage($strPackageName, $strUsername, $blnGzCompress) { $objPerson = Person::LoadByUsername($strUsername); $objPackage = Package::Load($this->GetPackageId($strPackageName)); if (!$objPerson) { return null; } if (!$objPackage) { return null; } $objPackageContribution = PackageContribution::LoadByPackageIdPersonId($objPackage->Id, $objPerson->Id); if (!$objPackageContribution) { return null; } if (!$objPackageContribution->CurrentPackageVersion) { return null; } $objPackageContribution->CurrentPackageVersion->DownloadCount++; $objPackageContribution->CurrentPackageVersion->Save(); $objPackageContribution->RefreshStats(); if ($blnGzCompress) { $strPath = $objPackageContribution->CurrentPackageVersion->GetFilePathCompressed(); } else { $strPath = $objPackageContribution->CurrentPackageVersion->GetFilePath(); } header('Content-Length: ' . filesize($strPath)); return file_get_contents($strPath); }