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
2015-01-31 13:12:30 +01:00

37 lines
880 B
PHP

<?php
class ModelTag extends Fiktiv_Model_Abstract
{
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
));
}
}
}