示例#1
0
 /**
  * Creates an activity
  *
  * @throws \yii\base\Exception
  */
 public function create()
 {
     $model = new Activity();
     $model->class = $this->className();
     if ($this->moduleId == "") {
         throw new \yii\base\InvalidConfigException("No moduleId given!");
     }
     $model->module = $this->moduleId;
     // Set content container and visibility
     if ($this->source instanceof ContentActiveRecord || $this->source instanceof ContentAddonActiveRecord) {
         $model->content->container = $this->source->content->container;
         $model->content->visibility = $this->source->content->visibility;
     } elseif ($this->source instanceof ContentContainerActiveRecord) {
         $model->content->visibility = $this->visibility;
         $model->content->container = $this->source;
     } else {
         throw new \yii\base\InvalidConfigException("Invalid source object type!");
     }
     $model->object_model = $this->source->className();
     $model->object_id = $this->source->getPrimaryKey();
     // Set user
     if ($this->originator !== null) {
         $model->content->user_id = $this->originator->id;
     } elseif ($this->source instanceof ContentActiveRecord) {
         $model->content->user_id = $this->source->content->user_id;
     } elseif ($this->source instanceof ContentAddonActiveRecord) {
         $model->content->user_id = $this->source->created_by;
     }
     if (!$model->validate() || !$model->save()) {
         throw new \yii\base\Exception("Could not save activity!" . $model->getErrors());
     }
 }
示例#2
0
 /**
  * Creates an activity
  *
  * @throws \yii\base\Exception
  */
 public function create()
 {
     if ($this->moduleId == "") {
         throw new \yii\base\InvalidConfigException("No moduleId given!");
     }
     if (!$this->source instanceof \yii\db\ActiveRecord) {
         throw new \yii\base\InvalidConfigException("Invalid source object given!");
     }
     $model = new Activity();
     $model->class = $this->className();
     $model->module = $this->moduleId;
     $model->content->visibility = $this->visibility;
     $model->object_model = $this->source->className();
     $model->object_id = $this->source->getPrimaryKey();
     // Automatically determine content container
     if ($this->container == null) {
         if ($this->source instanceof ContentActiveRecord || $this->source instanceof ContentAddonActiveRecord) {
             $this->container = $this->source->content->container;
             // Take visibility from Content/Addon
             $model->content->visibility = $this->source->content->visibility;
         } elseif ($this->source instanceof ContentContainerActiveRecord) {
             $this->container = $this->source;
         } else {
             throw new \yii\base\InvalidConfigException("Could not determine content container for activity!");
         }
     }
     $model->content->container = $this->container;
     // Automatically determine originator - if not set
     if ($this->originator !== null) {
         $model->content->user_id = $this->originator->id;
     } elseif ($this->source instanceof ContentActiveRecord) {
         $model->content->user_id = $this->source->content->user_id;
     } elseif ($this->source instanceof ContentAddonActiveRecord) {
         $model->content->user_id = $this->source->created_by;
     } else {
         throw new \yii\base\InvalidConfigException("Could not determine originator for activity!");
     }
     if (!$model->validate() || !$model->save()) {
         throw new \yii\base\Exception("Could not save activity!" . $model->getErrors());
     }
 }
示例#3
0
 private function saveModelInstance()
 {
     $model = new Activity();
     $model->class = $this->className();
     $model->module = $this->moduleId;
     $model->object_model = $this->source->className();
     $model->object_id = $this->source->getPrimaryKey();
     $model->content->container = $this->container;
     $model->content->visibility = $this->getContentVisibility();
     $model->content->created_by = $this->getOriginatorId();
     if ($model->content->created_by == null) {
         throw new \yii\base\InvalidConfigException("Could not determine originator for activity!");
     }
     if (!$model->validate() || !$model->save()) {
         throw new \yii\base\Exception("Could not save activity!" . $model->getErrors());
     }
 }