예제 #1
0
 public function execute(&$params)
 {
     // make sure this is a valid model type
     if (!is_subclass_of($this->config['modelClass'], 'X2Model')) {
         return array(false, "");
     }
     if (!isset($this->config['attributes']) || empty($this->config['attributes'])) {
         return array(false, "");
     }
     // verify that if create relationship option was set, that a relationship can be made
     if ($this->parseOption('createRelationship', $params)) {
         $acceptedModelTypes = X2Model::getModelTypesWhichSupportRelationships();
         if (!in_array($this->config['modelClass'], $acceptedModelTypes)) {
             return array(false, Yii::t('x2flow', 'Relationships cannot be made with records ' . 'of type {type}.', array('{type}' => $this->config['modelClass'])));
         }
         if (!isset($params['model'])) {
             // no model passed to trigger
             return array(false, '');
         }
         if (!in_array(get_class($params['model']), $acceptedModelTypes)) {
             return array(false, Yii::t('x2flow', 'Relationships cannot be made with records ' . 'of type {type}.', array('{type}' => get_class($params['model']))));
         }
     }
     $model = new $this->config['modelClass']();
     $model->setScenario('X2FlowCreateAction');
     if ($this->setModelAttributes($model, $this->config['attributes'], $params) && $model->save()) {
         if ($this->parseOption('createRelationship', $params)) {
             Relationships::create(get_class($params['model']), $params['model']->id, get_class($model), $model->id);
         }
         return array(true, Yii::t('studio', 'View created record: ') . $model->getLink());
     } else {
         $errors = $model->getErrors();
         return array(false, array_shift($errors));
     }
 }
예제 #2
0
파일: upload.php 프로젝트: dsyman2/X2CRM
?>
</span>
		</div>
		<div class="tableWrapper">
			<table>
				<tbody>
					<tr class="formSectionRow">
						<td style="">
							<div class="formItem leftLabel">
								<label><?php 
echo Yii::t('media', 'Association Type');
?>
</label>
								<div class="formInputBox" style="height: auto;">
									<?php 
$linkableModels = X2Model::getModelTypesWhichSupportRelationships(true);
$this->widget('MultiTypeAutocomplete', array('selectName' => 'Media[associationType]', 'hiddenInputName' => 'Media[associationId]', 'selectValue' => '', 'options' => array_merge(array('' => Yii::t('app', 'None')), array_diff_key($linkableModels, array_flip(array('Media', 'Groups', 'X2List', 'Actions', 'Reports'))), array('bg' => Yii::t('app', 'Background'))), 'staticOptions' => array('', 'bg'), 'htmlOptions' => array('class' => 'media-association-type')));
//                                    echo $form->dropDownList($model,'associationType',
//										array(
//											'none'=>Yii::t('actions','None'),
//											'contacts'=>Yii::t('actions','Contact'),
//											'opportunities'=>Yii::t('actions','Opportunity'),
//											'accounts'=>Yii::t('actions','Account'),
//											'bg'=>Yii::t('media', 'Background'),
//										), array('onChange'=>'showAssociationAutoComplete(this)'));
?>
								</div>
							</div>
							
						</td>
					</tr>
예제 #3
0
 /**
  * Ensure that type corresponds to child of X2Model which supports relationships 
  */
 public function validateType($attr)
 {
     $value = $this->{$attr};
     $validTypes = X2Model::getModelTypesWhichSupportRelationships(true);
     if (!class_exists($value) || !isset($validTypes[$value])) {
         $this->addError($attr, Yii::t('app', 'Invalid record type'));
     }
 }
예제 #4
0
 public function getViewFileParams()
 {
     if (!isset($this->_viewFileParams)) {
         $linkableModels = X2Model::getModelTypesWhichSupportRelationships(true);
         asort($linkableModels);
         // used to instantiate html dropdown
         $linkableModelsOptions = $linkableModels;
         $hasUpdatePermissions = $this->checkModuleUpdatePermissions();
         $this->_viewFileParams = array_merge(parent::getViewFileParams(), array('model' => $this->model, 'modelName' => get_class($this->model), 'linkableModelsOptions' => $linkableModelsOptions, 'hasUpdatePermissions' => $hasUpdatePermissions, 'height' => $this->getWidgetProperty('height')));
     }
     return $this->_viewFileParams;
 }