protected function beforeRender()
 {
     parent::beforeRender();
     $currentVersion = $this->addonVersions->getCurrent($this->addon->versions);
     if ($this->getUser()->isLoggedIn()) {
         $row = $this->addonVotes->findOneBy(array('userId' => $this->getUser()->getId(), 'addonId' => $this->addon->id));
         $myVote = $row ? $row->vote : NULL;
     } else {
         $myVote = NULL;
     }
     $this['subMenu']->setAddon($this->addon);
     $this->template->addon = $this->addon;
     $this->template->version = $currentVersion;
     $this->template->composer = $currentVersion->composerJson;
     $this->template->myVote = $myVote;
 }
Beispiel #2
0
 /**
  * Creates Addon entity from Nette\Database row.
  *
  * @todo   Consider lazy loading for versions and tags.
  *
  * @param \Nette\Database\Table\ActiveRow
  * @param AddonVotes
  * @return Addon
  */
 public static function fromActiveRow(ActiveRow $row, AddonVotes $addonVotes = NULL)
 {
     $addon = new static();
     $addon->id = (int) $row->id;
     $addon->name = $row->name;
     $addon->composerVendor = $row->composerVendor;
     $addon->composerName = $row->composerName;
     $addon->userId = (int) $row->user->id;
     $addon->shortDescription = $row->shortDescription;
     $addon->description = $row->description;
     $addon->descriptionFormat = $row->descriptionFormat;
     $addon->defaultLicense = $row->defaultLicense;
     $addon->repository = $row->repository;
     $addon->repositoryHosting = $row->repositoryHosting;
     $addon->demo = $row->demo;
     $addon->updatedAt = $row->updatedAt ? DateTime::from($row->updatedAt) : NULL;
     $addon->deletedAt = $row->deletedAt;
     $addon->deletedBy = $row->ref('deletedBy');
     $addon->type = $row->type;
     $addon->stars = $row->stars;
     foreach ($row->related('versions') as $versionRow) {
         $version = AddonVersion::fromActiveRow($versionRow);
         $version->addon = $addon;
         $addon->versions[$version->version] = $version;
     }
     foreach ($row->related('tags') as $tagRow) {
         $addon->tags[$tagRow->tag->id] = Tag::fromActiveRow($tagRow->tag);
     }
     foreach ($row->related('addons_resources') as $resourceRow) {
         $addon->resources[$resourceRow->type] = $resourceRow->resource;
     }
     if ($addonVotes) {
         $addon->votes = $addonVotes->calculatePopularity($row);
     }
     return $addon;
 }