本文整理汇总了PHP中X2Model::getModelOfTypeWithId方法的典型用法代码示例。如果您正苦于以下问题:PHP X2Model::getModelOfTypeWithId方法的具体用法?PHP X2Model::getModelOfTypeWithId怎么用?PHP X2Model::getModelOfTypeWithId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X2Model
的用法示例。
在下文中一共展示了X2Model::getModelOfTypeWithId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModelFromTypeAndId
private function getModelFromTypeAndId($modelName, $modelId)
{
$model = X2Model::getModelOfTypeWithId($modelName, $modelId);
if (!$model) {
throw new CHttpException(400, Yii::t('app', 'Invalid record type or record id'));
}
return $model;
}
示例2: validateParams
/**
* Helper method for action<workflow action> actions to validate get parameters and to
* retrieve the associated model.
* @param int $workflowId the id of the workflow
* @param int $stageNumber the number of the stage
* @param int $modelId the id of the associated model
* @param string $type the association type of the associated model
* @return object model with specified id and associationType
*/
private function validateParams($workflowId, $stageNumber, $modelId, $type, $recordName = null)
{
if (!is_numeric($workflowId) || !is_numeric($stageNumber) || !is_numeric($modelId) && $recordName === null) {
throw new CHttpException(400, 'Bad Request');
}
if (!is_numeric($modelId)) {
$model = X2Model::getModelOfTypeWithName($type, $recordName);
} else {
$model = X2Model::getModelOfTypeWithId($type, $modelId, true);
}
if ($model === null) {
throw new CHttpException(400, 'Bad Request');
}
return $model;
}
示例3: actionShowWidgetContents
/**
* Called to retieve widget contents
* Expected POST data:
* widgetClass - the name of the widget class
* Echoes:
* 'failure' if the request action fails, an HTML string containing the widget contents
* otherwise
*/
public function actionShowWidgetContents()
{
if (!isset($_POST['widgetClass']) || !isset($_POST['widgetType'])) {
echo 'failure';
return;
}
if (isset($_POST['widgetType']) && SortableWidget::getParentType($_POST['widgetType']) === 'recordView' && (!isset($_POST['modelId']) || !isset($_POST['modelType']))) {
echo 'failure';
return;
}
$profile = self::getModelFromPost();
$widgetKey = $_POST['widgetClass'];
$widgetType = $_POST['widgetType'];
list($widgetClass, $widgetUID) = SortableWidget::parseWidgetLayoutKey($widgetKey);
if ($profile && class_exists($widgetClass)) {
if ($widgetClass::setJSONProperty($profile, 'hidden', 0, $widgetType, $widgetUID)) {
if (SortableWidget::getParentType($widgetType) === 'recordView') {
$model = X2Model::getModelOfTypeWithId($_POST['modelType'], $_POST['modelId']);
if ($model !== null && $model instanceof X2Model) {
echo $widgetClass::getWidgetContents($this, $profile, $widgetType, $widgetUID, array('model' => $model));
}
} else {
echo $widgetClass::getWidgetContents($this, $profile, $widgetType, $widgetUID);
}
return;
}
}
echo 'failure';
return;
}
示例4: getModelFromTypeAndId
protected function getModelFromTypeAndId($modelName, $modelId, $x2ModelOnly = true)
{
$model = X2Model::getModelOfTypeWithId($modelName, $modelId);
if (!$model || $x2ModelOnly && !$model instanceof X2Model) {
throw new CHttpException(400, Yii::t('app', 'Invalid record type or record id'));
}
return $model;
}
示例5: testGetStageMemberDataProvider
/**
* Tests a method in WorkflowController which belongs in the Workflow model class
*/
public function testGetStageMemberDataProvider()
{
$workflow = $this->workflows('workflow2');
$workflowStatus = Workflow::getWorkflowStatus($workflow->id);
$this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 1);
$this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
// make record invisible
$action = Actions::model()->findByAttributes(array('workflowId' => $workflow->id, 'complete' => 'No', 'stageNumber' => 8));
$record = X2Model::getModelOfTypeWithId($action->associationType, $action->associationId);
$record->visibility = 0;
$record->assignedTo = 'admin';
$this->assertSaves($record);
$counts = $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
$this->assertEquals(1, $counts[3]);
TestingAuxLib::suLogin('testuser');
$counts = $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
$this->assertEquals(0, $counts[3]);
$record->assignedTo = 'testuser';
$this->assertSaves($record);
$counts = $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
$this->assertEquals(1, $counts[3]);
}
示例6: actionUpload
//.........这里部分代码省略.........
$name = str_replace(' ', '_', $name);
$check = Media::model()->findAllByAttributes(array('fileName' => $name));
// rename file if there name conflicts by suffixing "(n)"
if (count($check) != 0) {
$count = 1;
$newName = $name;
$arr = explode('.', $name);
$name = $arr[0];
while (count($check) != 0) {
$newName = $name . '(' . $count . ').' . $temp->getExtensionName();
$check = Media::model()->findAllByAttributes(array('fileName' => $newName));
$count++;
}
$name = $newName;
}
$username = Yii::app()->user->name;
// copy file to user's media uploads directory
if (FileUtil::ccopy($tempName, "uploads/protected/media/{$username}/{$name}")) {
if (isset($_POST['associationId'])) {
$model->associationId = $_POST['associationId'];
}
if (isset($_POST['associationType'])) {
$model->associationType = $_POST['associationType'];
}
if (isset($_POST['private'])) {
$model->private = true;
}
$model->uploadedBy = Yii::app()->user->getName();
$model->createDate = time();
$model->lastUpdated = time();
$model->fileName = $name;
$model->mimetype = $temp->type;
if (!$model->save()) {
$errors = $model->getErrors();
$error = ArrayUtil::pop(ArrayUtil::pop($errors));
Yii::app()->user->setFlash('top-error', Yii::t('app', 'Attachment failed. ' . $error));
if (Auxlib::isAjax()) {
return print "success";
}
$this->redirect(array($model->associationType . '/' . $model->associationType . '/view', 'id' => $model->associationId));
Yii::app()->end();
} else {
$relatedModel = X2Model::getModelOfTypeWithId($model->associationType, $model->associationId);
if ($relatedModel && $relatedModel->supportsRelationships) {
$rel = new Relationships();
$rel->setFirstModel($model);
$rel->setSecondModel($relatedModel);
$rel->save();
}
}
// handle different upload types
switch ($model->associationType) {
case 'feed':
$this->handleFeedTypeUpload($model, $name);
break;
case 'docs':
if (Auxlib::isAjax()) {
return print "success";
}
$this->redirect(array('/docs/docs/index'));
break;
case 'loginSound':
case 'notificationSound':
if (Auxlib::isAjax()) {
return print "success";
}
$this->redirect(array('/profile/settings', 'id' => Yii::app()->user->getId()));
break;
case 'bg':
case 'bg-private':
$this->redirect(array('/profile/settings', 'bgId' => $model->id));
break;
case 'none':
if (Auxlib::isAjax()) {
return print "success";
}
break;
case 'topicReply':
$this->handleTopicReplyUpload($model, $name);
break;
default:
$this->handleDefaultUpload($model, $name);
break;
}
}
} else {
if (isset($_SERVER['HTTP_REFERER'])) {
if (Auxlib::isAjax()) {
return print "success";
}
$this->redirect($_SERVER['HTTP_REFERER']);
} else {
throw new CHttpException('400', 'Invalid request');
}
}
if (isset($_GET['redirect'])) {
$this->redirect($_SERVER['HTTP_REFERER']);
}
}
}