Ejemplo n.º 1
0
 /**
  * Before Save Addons
  *
  * @return type
  */
 public function afterSave()
 {
     parent::afterSave();
     if ($this->isNewRecord) {
         $activity = Activity::CreateForContent($this);
         $activity->type = "PostCreated";
         $activity->module = "post";
         $activity->save();
         $activity->fire();
     }
     // Handle mentioned users
     UserMentioning::parse($this, $this->message);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Parses a given text for mentioned users and creates an mentioning for them.
  * 
  * @param HActiveRecordContent|HActiveRecordContentAddon $record
  * @param string $text
  */
 public static function parse($record, $text)
 {
     if ($record instanceof HActiveRecordContent || $record instanceof HActiveRecordContentAddon) {
         preg_replace_callback('@\\@\\-u([\\w\\-]*?)($|\\s|\\.)@', function ($hit) use(&$record) {
             $user = User::model()->findByAttributes(array('guid' => $hit[1]));
             if ($user !== null) {
                 // Check the user was already mentioned (e.g. edit)
                 $mention = UserMentioning::model()->findByAttributes(array('object_model' => get_class($record), 'object_id' => $record->getPrimaryKey(), 'user_id' => $user->id));
                 if ($mention === null) {
                     $mention = new UserMentioning();
                     $mention->object_model = get_class($record);
                     $mention->object_id = $record->getPrimaryKey();
                     $mention->user_id = $user->id;
                     $mention->save();
                     $mention->setUnderlyingObject($record);
                 }
             }
         }, $text);
     } else {
         throw new Exception("Mentioning can only used in HActiveRecordContent or HActiveRecordContentAddon objects!");
     }
 }
Ejemplo n.º 3
0
 /**
  * After Saving of comments, fire an activity
  *
  * @return type
  */
 protected function afterSave()
 {
     // flush the cache
     $this->flushCache();
     $activity = Activity::CreateForContent($this);
     $activity->type = "CommentCreated";
     $activity->module = "comment";
     $activity->save();
     $activity->fire();
     // Handle mentioned users
     // Execute before NewCommentNotification to avoid double notification when mentioned.
     UserMentioning::parse($this, $this->message);
     if ($this->isNewRecord) {
         // Send Notifications
         NewCommentNotification::fire($this);
     }
     return parent::afterSave();
 }