/** * Loads Content Addon * We also validates that the content addon corresponds to the loaded content. * * @param string $className * @param int $pk */ public function loadContentAddon($className, $pk) { if (!\humhub\libs\Helpers::CheckClassType($className, ContentAddonActiveRecord::className())) { throw new \yii\base\Exception("Given className is not a content addon model!"); } $target = $className::findOne(['id' => $pk]); if ($target === null) { throw new HttpException(500, 'Could not find content addon record!'); } if ($target->object_model != get_class($this->parentContent) && $target->object_id != $this->parentContent->getPrimaryKey()) { throw new HttpException(500, 'Content addon not belongs to given content record!'); } $this->contentAddon = $target; }
/** * Loads Content Addon * We also validates that the content addon corresponds to the loaded content. * * @param string $className * @param int $pk */ public function loadContentAddon($className, $pk) { if (!Helpers::CheckClassType($className, 'HActiveRecordContentAddon')) { throw new CException("Given className is not a content addon model!"); } $model = call_user_func(array($className, 'model')); $target = $model->findByPk($pk); if ($target === null) { throw new CHttpException(500, 'Could not find content addon record!'); } if ($target->object_model != get_class($this->parentContent) && $target->object_id != $this->parentContent->getPrimaryKey()) { throw new CHttpException(500, 'Content addon not belongs to given content record!'); } $this->contentAddon = $target; }