/** * @return Author */ public function getAuthor() { if (!$this->hasData('author')) { $this->setData('author', $this->authorFactory->create()->load($this->getAuthorId())); } return $this->getData('author'); }
public function testJoinWithAliasAndRelationId() { $author = AuthorFactory::create('John'); ok($author->id); $author->addresses[] = array('address' => 'Address I'); $author->addresses[] = array('address' => 'Address II'); $authors = new AuthorCollection(); ok($authors); $authors->join(new \AuthorBooks\Model\Address(), 'LEFT', 'a', 'addresses'); $authors->fetch(); $sql = $authors->toSQL(); ok($sql, $sql); $size = $authors->size(); is(2, $size); foreach ($authors as $a) { ok($a->a_address); ok($a->a_id); } }
/** * @param string $pathInfo * @return bool|DataObject */ public function match($pathInfo) { $identifier = trim($pathInfo, '/'); $parts = explode('/', $identifier); if (count($parts) >= 1) { $parts[count($parts) - 1] = $this->trimSuffix($parts[count($parts) - 1]); } if ($parts[0] != $this->config->getBaseRoute()) { return false; } if (count($parts) > 1) { unset($parts[0]); $parts = array_values($parts); $urlKey = implode('/', $parts); $urlKey = urldecode($urlKey); $urlKey = $this->trimSuffix($urlKey); } else { $urlKey = ''; } if ($urlKey == '') { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'index', 'params' => []]); } if ($parts[0] == 'search') { return new DataObject(['module_name' => 'blog', 'controller_name' => 'search', 'action_name' => 'result', 'params' => []]); } if ($parts[0] == 'tag' && isset($parts[1])) { $tag = $this->tagFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem(); if ($tag->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'tag', 'action_name' => 'view', 'params' => ['id' => $tag->getId()]]); } else { return false; } } if ($parts[0] == 'author' && isset($parts[1])) { $author = $this->authorFactory->create()->getCollection()->addFieldToFilter('user_id', $parts[1])->getFirstItem(); if ($author->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'author', 'action_name' => 'view', 'params' => ['id' => $author->getId()]]); } else { return false; } } if ($parts[0] == 'rss' && isset($parts[1])) { $category = $this->categoryFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem(); if ($category->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => ['id' => $category->getId()]]); } else { return false; } } elseif ($parts[0] == 'rss') { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => []]); } $post = $this->postFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem(); if ($post->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'post', 'action_name' => 'view', 'params' => ['id' => $post->getId()]]); } $category = $this->categoryFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem(); if ($category->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'view', 'params' => ['id' => $category->getId()]]); } return false; }