+
+ // Remember that we want the _activity_ notice here, not faves applied
+ // to the supplied Notice (as with byNotice)!
+ static public function fromStored(Notice $stored) {
+ $class = get_called_class();
+ $object = new $class;
+ $object->uri = $stored->uri;
+ if (!$object->find(true)) {
+ throw new NoResultException($object);
+ }
+ return $object;
+ }
+
+ static public function verbToTitle($verb) {
+ return ucfirst($verb);
+ }
+
+ static public function object_type()
+ {
+ return 'activity';
+ }
+
+ public function asActivityObject(Profile $scoped=null) {
+ $actobj = new ActivityObject();
+ $actobj->id = $this->getUri();
+ $actobj->type = ActivityUtils::resolveUri(ActivityObject::ACTIVITY);
+ $actobj->actor = $this->getActorObject();
+ $actobj->objects = array(clone($actobj->target));
+ $actobj->title = Stored_ActivityVerb::verbToTitle($this->verb);
+ //$actobj->verb = $this->verb;
+ //$actobj->target = $this->getTargetObject();
+ return $actobj;
+ }
+
+ static public function parseActivityObject(ActivityObject $actobj, Notice $stored) {
+ $actor = $stored->getProfile();
+ $object = new Fave();
+ $object->user_id = $actor->id;
+ $object->notice_id = $stored->id;
+ $object->object_uri = $stored->uri;
+ $object->created = $stored->created;
+ return $object;
+ }
+
+ static function saveActivityObject(ActivityObject $actobj, Notice $stored) {
+ $object = self::parseActivityObject($actobj, $stored);
+ $object->insert(); // exception throwing!
+ return $object;
+ }
+
+
+ public function getTarget() {
+ // throws exception on failure
+ return ActivityUtils::findLocalObject(array($this->uri), $this->type);
+ }
+
+ public function getTargetObject() {
+ return $this->getTarget()->asActivityObject();
+ }
+
+ protected $_stored = array();
+
+ public function getStored() {
+ if (!isset($this->_stored[$this->uri])) {
+ $stored = new Notice();
+ $stored->uri = $this->uri;
+ if (!$stored->find(true)) {
+ throw new NoResultException($stored);
+ }
+ $this->_stored[$this->uri] = $stored;
+ }
+ return $this->_stored[$this->uri];
+ }
+
+ public function getActor() {
+ $profile = new Profile();
+ $profile->id = $this->user_id;
+ if (!$profile->find(true)) {
+ throw new NoResultException($profile);
+ }
+ return $profile;
+ }
+
+ public function getActorObject() {
+ return $this->getActor()->asActivityObject();
+ }
+
+ public function getURI()
+ {
+ if (!empty($this->uri)) {
+ return $this->uri;
+ }
+
+ // We (should've in this case) created it ourselves, so we tag it ourselves
+ return self::newURI($this->getActor(), $this->getTarget(), $this->created);
+ }
+
+ static function newURI(Profile $actor, Managed_DataObject $target, $created=null)
+ {
+ if (is_null($created)) {
+ $created = common_sql_now();
+ }
+ return TagURI::mint(strtolower(get_called_class()).':%d:%s:%d:%s',
+ $actor->id,
+ ActivityUtils::resolveUri(self::object_type(), true),
+ $target->id,
+ common_date_iso8601($created));
+ }