Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/application/models/ModelTag.php
2011-05-28 18:33:37 +02:00

38 lines
920 B
PHP

<?php
class ModelTag extends Fiktiv_Model_Abstract
{
protected $_schema = 'fiktivkod';
protected $_name = 'Tag';
protected $_dependentTables = array('ModelPostTag');
public function tagsToPost($tags, $postId)
{
$postsTags = new ModelPostTag();
$postsTags->delete($this->quoteInto('postId = ?', $postId));
foreach ($tags as $key => $tag) {
$tags[$key] = trim($tag);
if (empty($tags[$key]))
continue;
$tag = $this->fetchRow($this->quoteInto('name = ?', $tags[$key]));
if (!$tag) {
$tagId = $this->insert(array('name' => $tags[$key]));
} else {
$tagId = $tag->id;
}
$postsTags->insert(array(
'postId' => $postId,
'tagId' => $tagId
));
}
}
}