Archived
1
0
Fork 0

fixed a bunch of stuff

This commit is contained in:
Fredric N 2011-05-28 18:33:37 +02:00
parent 019a1e01dd
commit 2edc535102
19 changed files with 180 additions and 66 deletions

View file

@ -27,42 +27,53 @@ class ModelBlogPost extends Fiktiv_Model_Abstract
}
}
/**
* Find all posts with tag.
*
* @param string $tag
* @return mixed
*/
public function findByTag($tag)
{
// Is this right?
$tags = new ModelTag();
$row = $tags->fetchRow("name = 'Linux'");
$posts = $row->findManyToManyRowset('ModelBlogPost', 'ModelPostTag');
$row = $tags->fetchRow($this->quoteInto('name = ?', $tag));
if ($row) {
$posts = $row->findManyToManyRowset('ModelBlogPost', 'ModelPostTag');
return $posts;
return $posts;
}
return null;
}
public function findByDate($date, $format)
{
// This is a joke, FIXIT!
$date = new Fiktiv_Date($date,$format);
$where = $this->quoteInto('DATE_FORMAT(pubDate,"%Y %M") LIKE ?', $date->toString('Y MMMM'));
$date = new Fiktiv_Date($date, $format, Zend_Registry::get('Zend_Locale'));
$where = $this->quoteInto('DATE_FORMAT(pubDate,"%Y %m") LIKE ?', $date->toString('yyyy MM'));
return $this->fetchAll($where);
}
public function findByPermlink($permlink)
{
return $this->fetchRow($this->quoteInto('permlink', $permlink));
return $this->fetchRow($this->quoteInto('permlink = ?', $permlink));
}
public function createPost($data, $id = null)
{
$myTags = explode(',', $data['tags']);
unset($data['tags']);
$data['userId'] = Zend_Auth::getInstance()->getIdentity()->id;
$data['pubDate'] = Zend_Date::now()->getIso();
$data['isPublished'] = 1;
if (null == $id) {
$data['userId'] = Zend_Auth::getInstance()->getIdentity()->id;
$data['pubDate'] = Zend_Date::now()->getIso();
$data['isPublished'] = 1;
$data['permlink'] = $this->generatePermalink($data['title']);
}
if ($id) {
$row = $this->find($id)->current();
@ -79,9 +90,9 @@ class ModelBlogPost extends Fiktiv_Model_Abstract
}
protected function generatePermalink()
protected function generatePermalink($title)
{
$permalink = $this->_data['title'];
$permalink = date('Y-m').'-'.$title;
// All to lowercase
$permalink = strtolower($permalink);
@ -105,6 +116,6 @@ class ModelBlogPost extends Fiktiv_Model_Abstract
$permalink = str_replace($char,$value,$permalink);
}
$this->_data['permalink'] = $permalink;
return $permalink;
}
}