public function FeedsCommentProcessor::setTargetElement in Feeds Comment Processor 7
Same name and namespace in other branches
- 6 FeedsCommentProcessor.inc \FeedsCommentProcessor::setTargetElement()
File
- ./
FeedsCommentProcessor.inc, line 216 - Contains FeedsCommentProcessor.
Class
- FeedsCommentProcessor
- Creates comments from feed items.
Code
public function setTargetElement(FeedsSource $source, $target_comment, $target_element, $value) {
$value = is_array($value) ? reset($value) : $value;
switch ($target_element) {
case 'nid_by_guid':
$target_comment->nid = (int) db_select('feeds_item', 'f')
->fields('f', array(
'entity_id',
))
->condition('entity_type', 'node')
->condition('guid', $value)
->range(0, 1)
->execute()
->fetchField();
break;
case 'nid_by_title':
$target_comment->nid = (int) db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('title', $value)
->condition('type', substr($this
->bundle(), 13))
->range(0, 1)
->execute()
->fetchField();
break;
case 'pid_by_guid':
$target_comment->pid = (int) db_select('feeds_item', 'f')
->fields('f', array(
'entity_id',
))
->condition('entity_type', 'comment')
->condition('id', $this->id)
->condition('feed_nid', $source->feed_nid)
->condition('guid', $value)
->range(0, 1)
->execute()
->fetchField();
break;
case 'created':
case 'changed':
$target_comment->{$target_element} = feeds_to_unixtime($value, REQUEST_TIME);
break;
case 'user_name':
if ($account = user_load_by_name($value)) {
$target_comment->uid = $account->uid;
}
break;
case 'user_mail':
if ($account = user_load_by_mail($value)) {
$target_comment->uid = $account->uid;
}
break;
case 'cid':
case 'pid':
case 'nid':
case 'uid':
$target_comment->{$target_element} = (int) trim($value);
break;
case 'name':
case 'mail':
case 'hostname':
case 'thread':
$target_comment->{$target_element} = trim($value);
break;
default:
parent::setTargetElement($source, $target_comment, $target_element, $value);
break;
}
}