/** * Renders an activity object. * * @param ComActivitiesActivityObjectInterface $object The activity object. * @param KObjectConfig $config The configuration object. * @return string The rendered object. */ protected function _renderObject(ComActivitiesActivityObjectInterface $object, KObjectConfig $config) { $config->append(array('html' => true, 'escaped_urls' => true, 'fqr' => false, 'links' => true)); if ($output = $object->getDisplayName()) { if ($config->html) { $output = $object->getDisplayName(); $attribs = $object->getAttributes() ? $this->buildAttributes($object->getAttributes()) : ''; if ($config->links && ($url = $object->getUrl())) { // Make sure we have a fully qualified route. if ($config->fqr && !$url->getHost()) { $url->setUrl($this->getTemplate()->url()->toString(KHttpUrl::AUTHORITY)); } $url = $url->toString(KHttpUrl::FULL, $config->escaped_urls); $output = "<a {$attribs} href=\"{$url}\">{$output}</a>"; } else { $output = "<span {$attribs}>{$output}</span>"; } } } else { $output = ''; } return $output; }
/** * Activity object data getter. * * @param ComActivitiesActivityObjectInterface $object The activity object. * @return array The object data. */ protected function _getObjectData(ComActivitiesActivityObjectInterface $object) { $data = $object->toArray(); // Make sure we get fully qualified URLs. if ($url = $object->getUrl()) { $data['url'] = $this->_getUrl($url); } $attachments = array(); // Handle attachments recursively. foreach ($object->getAttachments() as $attachment) { $attachments[] = $this->_getObjectData($attachment); } $data['attachments'] = $attachments; // Convert date objects to date time strings. foreach (array('published', 'updated') as $property) { $method = 'get' . ucfirst($property); if ($date = $object->{$method}()) { $data[$property] = $date->format('M d Y H:i:s'); } } foreach ($object as $key => $value) { if ($value instanceof ComActivitiesActivityObjectInterface) { $data[$key] = $this->_getObjectData($value); } if ($value instanceof ComActivitiesActivityMedialinkInterface) { $data[$key] = $this->_getMedialinkData($value); } } return $this->_cleanupData($data); }