本文整理汇总了PHP中X2Model::getLinkedModelMock方法的典型用法代码示例。如果您正苦于以下问题:PHP X2Model::getLinkedModelMock方法的具体用法?PHP X2Model::getLinkedModelMock怎么用?PHP X2Model::getLinkedModelMock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X2Model
的用法示例。
在下文中一共展示了X2Model::getLinkedModelMock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderLink
public function renderLink($field, array $htmlOptions = array())
{
$fieldName = $field->fieldName;
$linkId = '';
$name = '';
$linkSource = null;
// TODO: move this code and duplicate code in X2Model::renderModelInput into a helper
// method. Might be able to use X2Model::getLinkedModel.
if (class_exists($field->linkType)) {
if (!empty($this->owner->{$fieldName})) {
list($name, $linkId) = Fields::nameAndId($this->owner->{$fieldName});
$linkModel = X2Model::getLinkedModelMock($field->linkType, $name, $linkId, true);
} else {
$linkModel = X2Model::model($field->linkType);
}
if ($linkModel instanceof X2Model && $linkModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) {
$linkSource = Yii::app()->controller->createAbsoluteUrl($linkModel->autoCompleteSource);
$linkId = $linkModel->id;
$oldLinkFieldVal = $this->owner->{$fieldName};
$this->owner->{$fieldName} = $name;
}
}
$input = CHtml::hiddenField($field->modelName . '[' . $fieldName . '_id]', $linkId, array());
$input .= CHtml::activeTextField($this->owner, $field->fieldName, array_merge(array('title' => $field->attributeLabel, 'data-x2-link-source' => $linkSource, 'class' => 'x2-mobile-autocomplete', 'autocomplete' => 'off'), $htmlOptions));
return $input;
}
示例2: renderModelInput
public static function renderModelInput(CModel $model, $field, $htmlOptions = array())
{
if (!$field->asa('CommonFieldsBehavior')) {
throw new Exception('$field must have CommonFieldsBehavior');
}
if ($field->required) {
if (isset($htmlOptions['class'])) {
$htmlOptions['class'] .= ' x2-required';
} else {
$htmlOptions = array_merge(array('class' => 'x2-required'), $htmlOptions);
}
}
$fieldName = $field->fieldName;
if (!isset($field)) {
return null;
}
switch ($field->type) {
case 'text':
return CHtml::activeTextArea($model, $field->fieldName, array_merge(array('title' => $field->attributeLabel), array_merge(array('encode' => false), $htmlOptions)));
case 'date':
$oldDateVal = $model->{$fieldName};
$model->{$fieldName} = Formatter::formatDate($model->{$fieldName}, 'medium');
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
$pickerOptions = array('dateFormat' => Formatter::formatDatePicker(), 'changeMonth' => false, 'changeYear' => true);
if (Yii::app()->getLanguage() === 'fr') {
$pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
}
$input = Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => $fieldName, 'mode' => 'date', 'options' => $pickerOptions, 'htmlOptions' => array_merge(array('title' => $field->attributeLabel), $htmlOptions), 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage()), true);
$model->{$fieldName} = $oldDateVal;
return $input;
case 'dateTime':
$oldDateTimeVal = $model->{$fieldName};
$pickerOptions = array('dateFormat' => Formatter::formatDatePicker('medium'), 'timeFormat' => Formatter::formatTimePicker(), 'ampm' => Formatter::formatAMPM(), 'changeMonth' => true, 'changeYear' => true);
if (Yii::app()->getLanguage() === 'fr') {
$pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
}
$model->{$fieldName} = Formatter::formatDateTime($model->{$fieldName});
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
$input = Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => $fieldName, 'mode' => 'datetime', 'options' => $pickerOptions, 'htmlOptions' => array_merge(array('title' => $field->attributeLabel), $htmlOptions), 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage()), true);
$model->{$fieldName} = $oldDateTimeVal;
return $input;
case 'dropdown':
// Note: if desired to translate dropdown options, change the seecond argument to
// $model->module
$om = $field->getDropdownOptions();
$multi = (bool) $om['multi'];
$dropdowns = $om['options'];
$curVal = $multi ? CJSON::decode($model->{$field->fieldName}) : $model->{$field->fieldName};
$ajaxArray = array();
if ($field instanceof Fields) {
$dependencyCount = X2Model::model('Dropdowns')->countByAttributes(array('parent' => $field->linkType));
$fieldDependencyCount = X2Model::model('Fields')->countByAttributes(array('modelName' => $field->modelName, 'type' => 'dependentDropdown', 'linkType' => $field->linkType));
if ($dependencyCount > 0 && $fieldDependencyCount > 0) {
$ajaxArray = array('ajax' => array('type' => 'GET', 'url' => Yii::app()->controller->createUrl('/site/dynamicDropdown'), 'data' => 'js:{
"val":$(this).val(),
"dropdownId":"' . $field->linkType . '",
"field":true, "module":"' . $field->modelName . '"
}', 'success' => '
function(data){
if(data){
data=JSON.parse(data);
if(data[0] && data[1]){
$("#' . $field->modelName . '_"+data[0]).html(data[1]);
}
}
}'));
}
}
$htmlOptions = array_merge($htmlOptions, $ajaxArray, array('title' => $field->attributeLabel));
if ($multi) {
$multiSelectOptions = array();
if (!is_array($curVal)) {
$curVal = array();
}
foreach ($curVal as $option) {
$multiSelectOptions[$option] = array('selected' => 'selected');
}
$htmlOptions = array_merge($htmlOptions, array('options' => $multiSelectOptions, 'multiple' => 'multiple'));
} elseif ($field->includeEmpty) {
$htmlOptions = array_merge($htmlOptions, array('empty' => Yii::t('app', "Select an option")));
}
return CHtml::activeDropDownList($model, $field->fieldName, $dropdowns, $htmlOptions);
case 'dependentDropdown':
return CHtml::activeDropDownList($model, $field->fieldName, array('' => '-'), array_merge(array('title' => $field->attributeLabel), $htmlOptions));
case 'link':
$linkSource = null;
$linkId = '';
$name = '';
if (class_exists($field->linkType)) {
// Create a model for autocompletion:
if (!empty($model->{$fieldName})) {
list($name, $linkId) = Fields::nameAndId($model->{$fieldName});
$linkModel = X2Model::getLinkedModelMock($field->linkType, $name, $linkId, true);
} else {
$linkModel = X2Model::model($field->linkType);
}
if ($linkModel instanceof X2Model && $linkModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) {
$linkSource = Yii::app()->controller->createUrl($linkModel->autoCompleteSource);
$linkId = $linkModel->id;
$oldLinkFieldVal = $model->{$fieldName};
//.........这里部分代码省略.........