本文整理汇总了PHP中Fields::nameAndId方法的典型用法代码示例。如果您正苦于以下问题:PHP Fields::nameAndId方法的具体用法?PHP Fields::nameAndId怎么用?PHP Fields::nameAndId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fields
的用法示例。
在下文中一共展示了Fields::nameAndId方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateAttribute
public function validateAttribute($model, $attribute, $params = array())
{
list($name, $id) = Fields::nameAndId($model->{$attribute});
if (!ctype_digit($id)) {
$model->addError($attribute, Yii::t('app', '{attr} does not refer to any existing record', array('{attr}' => $model->getAttributeLabel($attribute))));
}
}
示例2: 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;
}
示例3: actionView
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$type = 'quotes';
$model = $this->getModel($id);
if (!$this->checkPermissions($model, 'view')) {
$this->denied();
}
$quoteProducts = $model->lineItems;
// add quote to user's recent item list
User::addRecentItem('q', $id, Yii::app()->user->getId());
$contactNameId = Fields::nameAndId($model->associatedContacts);
$contactId = $contactNameId[1];
parent::view($model, $type, array('orders' => $quoteProducts, 'contactId' => $contactId));
}
示例4: actionExportModelRecords
/**
* An AJAX called function which exports data to a CSV via pagination.
* This is a generalized version of the Contacts export.
* @param int $page The page of the data provider to export
*/
public function actionExportModelRecords($page, $model)
{
X2Model::$autoPopulateFields = false;
$file = $this->safePath($_SESSION['modelExportFile']);
$staticModel = X2Model::model(str_replace(' ', '', $model));
$fields = $staticModel->getFields();
$fp = fopen($file, 'a+');
// Load data provider based on export criteria
$excludeHidden = !isset($_GET['includeHidden']) || $_GET['includeHidden'] === 'false';
if ($page == 0 && $excludeHidden && isset($_SESSION['exportModelCriteria']) && $_SESSION['exportModelCriteria'] instanceof CDbCriteria) {
// Save hidden condition in criteria
$hiddenConditions = $staticModel->getHiddenCondition();
$_SESSION['exportModelCriteria']->addCondition($hiddenConditions);
}
$dp = new CActiveDataProvider($model, array('criteria' => isset($_SESSION['exportModelCriteria']) ? $_SESSION['exportModelCriteria'] : array(), 'pagination' => array('pageSize' => 100)));
// Flip through to the right page.
$pg = $dp->getPagination();
$pg->setCurrentPage($page);
$dp->setPagination($pg);
$records = $dp->getData();
$pageCount = $dp->getPagination()->getPageCount();
// Retrieve specified export delimeter and enclosure
$delimeter = isset($_GET['delimeter']) ? $_GET['delimeter'] : ',';
$enclosure = isset($_GET['enclosure']) ? $_GET['enclosure'] : '"';
// We need to set our data to be human friendly, so loop through all the
// records and format any date / link / visibility fields.
foreach ($records as $record) {
foreach ($fields as $field) {
$fieldName = $field->fieldName;
if ($field->type == 'date' || $field->type == 'dateTime') {
if (is_numeric($record->{$fieldName})) {
$record->{$fieldName} = Formatter::formatLongDateTime($record->{$fieldName});
}
} elseif ($field->type == 'link') {
$name = $record->{$fieldName};
if (!empty($field->linkType)) {
list($name, $id) = Fields::nameAndId($name);
}
if (!empty($name)) {
$record->{$fieldName} = $name;
}
} elseif ($fieldName == 'visibility') {
switch ($record->{$fieldName}) {
case 0:
$record->{$fieldName} = 'Private';
break;
case 1:
$record->{$fieldName} = 'Public';
break;
case 2:
$record->{$fieldName} = 'User\'s Groups';
break;
default:
$record->{$fieldName} = 'Private';
}
}
}
// Enforce metadata to ensure accuracy of column order, then export.
$combinedMeta = array_combine($_SESSION['modelExportMeta'], $_SESSION['modelExportMeta']);
$recordAttributes = $record->attributes;
if ($model === 'Actions') {
// Export descriptions with Actions
$actionText = $record->actionText;
if ($actionText) {
$actionDescription = $actionText->text;
$recordAttributes = array_merge($recordAttributes, array('actionDescription' => $actionDescription));
}
}
if ($_SESSION['includeTags']) {
$tags = $record->getTags();
$recordAttributes = array_merge($recordAttributes, array('tags' => implode(',', $tags)));
}
$tempAttributes = array_intersect_key($recordAttributes, $combinedMeta);
$tempAttributes = array_merge($combinedMeta, $tempAttributes);
fputcsv($fp, $tempAttributes, $delimeter, $enclosure);
}
unset($dp);
fclose($fp);
if ($page + 1 < $pageCount) {
echo $page + 1;
}
}
示例5: 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};
//.........这里部分代码省略.........
示例6: afterSave
public function afterSave($event)
{
$oldAttributes = $this->owner->getOldAttributes();
$linkFields = Fields::model()->findAllByAttributes(array('modelName' => get_class($this->owner), 'type' => 'link'));
foreach ($linkFields as $field) {
$nameAndId = Fields::nameAndId($this->owner->getAttribute($field->fieldName));
$oldNameAndId = Fields::nameAndId(isset($oldAttributes[$field->fieldName]) ? $oldAttributes[$field->fieldName] : '');
if (!empty($oldNameAndId[1]) && $nameAndId[1] !== $oldNameAndId[1]) {
$oldTarget = X2Model::model($field->linkType)->findByPk($oldNameAndId[1]);
$this->owner->deleteRelationship($oldTarget);
}
$newTarget = X2Model::model($field->linkType)->findByPk($nameAndId[1]);
$this->owner->createRelationship($newTarget);
}
parent::afterSave($event);
}
示例7: checkCondition
/**
* @param Array $condition
* @param Array $params
* @return bool true for success, false otherwise
*/
public static function checkCondition($condition, &$params)
{
if ($condition['type'] === 'workflow_status') {
return self::checkWorkflowStatusCondition($condition, $params);
}
$model = isset($params['model']) ? $params['model'] : null;
$operator = isset($condition['operator']) ? $condition['operator'] : '=';
// $type = isset($condition['type'])? $condition['type'] : null;
$value = isset($condition['value']) ? $condition['value'] : null;
// default to a doing basic value comparison
if (isset($condition['name']) && $condition['type'] === '') {
if (!isset($params[$condition['name']])) {
return false;
}
return self::evalComparison($params[$condition['name']], $operator, $value);
}
switch ($condition['type']) {
case 'attribute':
if (!isset($condition['name'], $model)) {
return false;
}
$attr =& $condition['name'];
if (null === ($field = $model->getField($attr))) {
return false;
}
if ($operator === 'changed') {
return $model->attributeChanged($attr);
}
if ($field->type === 'link') {
list($attrVal, $id) = Fields::nameAndId($model->getAttribute($attr));
} else {
$attrVal = $model->getAttribute($attr);
}
return self::evalComparison($attrVal, $operator, X2Flow::parseValue($value, $field->type, $params), $field);
case 'current_user':
return self::evalComparison(Yii::app()->user->getName(), $operator, X2Flow::parseValue($value, 'assignment', $params));
case 'month':
return self::evalComparison((int) date('n'), $operator, $value);
// jan = 1, dec = 12
// jan = 1, dec = 12
case 'day_of_month':
return self::evalComparison((int) date('j'), $operator, $value);
// 1 through 31
// 1 through 31
case 'day_of_week':
return self::evalComparison((int) date('N'), $operator, $value);
// monday = 1, sunday = 7
// monday = 1, sunday = 7
case 'time_of_day':
// - mktime(0,0,0)
return self::evalComparison(time(), $operator, X2Flow::parseValue($value, 'time', $params));
// seconds since midnight
// case 'current_local_time':
// seconds since midnight
// case 'current_local_time':
case 'current_time':
return self::evalComparison(time(), $operator, X2Flow::parseValue($value, 'dateTime', $params));
case 'user_active':
return CActiveRecord::model('Session')->exists('user=:user AND status=1', array(':user' => X2Flow::parseValue($value, 'assignment', $params)));
case 'on_list':
if (!isset($model, $value)) {
return false;
}
$value = X2Flow::parseValue($value, 'link');
// look up specified list
if (is_numeric($value)) {
$list = CActiveRecord::model('X2List')->findByPk($value);
} else {
$list = CActiveRecord::model('X2List')->findByAttributes(array('name' => $value));
}
return $list !== null && $list->hasRecord($model);
case 'has_tags':
if (!isset($model, $value)) {
return false;
}
$tags = X2Flow::parseValue($value, 'tags');
return $model->hasTags($tags, 'AND');
case 'workflow_status':
if (!isset($model, $condition['workflowId'], $condition['stageNumber'])) {
return false;
}
switch ($operator) {
case 'started_workflow':
return CActiveRecord::model('Actions')->exists('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId']));
case 'started_stage':
return CActiveRecord::model('Actions')->exists('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow AND stageNumber=:stage AND (completeDate IS NULL OR completeDate=0)', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId'], ':stageNumber' => $condition['stageNumber']));
case 'completed_stage':
return CActiveRecord::model('Actions')->exists('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow AND stageNumber=:stage AND completeDate > 0', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId'], ':stageNumber' => $condition['stageNumber']));
case 'completed_workflow':
$stageCount = CActiveRecord::model('WorkflowStage')->count('workflowId=:id', array(':id' => $condition['workflowId']));
$actionCount = CActiveRecord::model('Actions')->count('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId']));
return $actionCount >= $stageCount;
}
return false;
case 'email_open':
//.........这里部分代码省略.........
示例8: array
<?php
//echo $form->label($this->model, 'subject', array('class' => 'x2-email-label'));
echo $form->textField($this->model, 'subject', array('tabindex' => '4', 'class' => 'x2-default-field', 'data-default-text' => CHtml::encode(Yii::t('app', 'Subject'))));
?>
</div>
<?php
if (!$this->disableTemplates) {
?>
<div class="row email-input-row">
<?php
$templateList = Docs::getEmailTemplates($type, $associationType);
$target = $this->model->targetModel;
echo $form->label($this->model, 'template', array('class' => 'x2-email-label'));
if (!isset($this->template) && $target instanceof Quote && isset($target->template) && !isset($this->model->template)) {
// When sending an InlineEmail targeting a Quote
list($templateName, $selectedTemplate) = Fields::nameAndId($target->template);
$this->model->template = $selectedTemplate;
}
echo $form->dropDownList($this->model, 'template', array('0' => Yii::t('docs', 'Custom Message')) + $templateList, array('id' => 'email-template'));
?>
</div>
<?php
}
?>
<div class="row" id="email-message-box">
<?php
echo $form->textArea($this->model, 'message', array('id' => 'email-message', 'style' => 'margin:0;padding:0;'));
?>
</div>
</div>
<div class="row bottom-row-outer">
示例9: getAccountId
public function getAccountId()
{
list($name, $id) = Fields::nameAndId($this->accountName);
return $id;
}
示例10: actionUpdateList
public function actionUpdateList($id)
{
$list = X2List::model()->findByPk($id);
if (!isset($list)) {
throw new CHttpException(400, Yii::t('app', 'This list cannot be found.'));
}
if (!$this->checkPermissions($list, 'edit')) {
throw new CHttpException(403, Yii::t('app', 'You do not have permission to modify this list.'));
}
$contactModel = new Contacts();
$comparisonList = X2List::getComparisonList();
$fields = $contactModel->getFields(true);
if ($list->type == 'dynamic') {
$criteriaModels = X2ListCriterion::model()->findAllByAttributes(array('listId' => $list->id), new CDbCriteria(array('order' => 'id ASC')));
if (isset($_POST['X2List'], $_POST['X2List']['attribute'], $_POST['X2List']['comparison'], $_POST['X2List']['value'])) {
$attributes =& $_POST['X2List']['attribute'];
$comparisons =& $_POST['X2List']['comparison'];
$values =& $_POST['X2List']['value'];
if (count($attributes) > 0 && count($attributes) == count($comparisons) && count($comparisons) == count($values)) {
$list->attributes = $_POST['X2List'];
$list->modelName = 'Contacts';
$list->lastUpdated = time();
if ($list->save()) {
$this->redirect(array('/contacts/contacts/list', 'id' => $list->id));
}
}
}
} else {
//static or campaign lists
if (isset($_POST['X2List'])) {
$list->attributes = $_POST['X2List'];
$list->modelName = 'Contacts';
$list->lastUpdated = time();
$list->save();
$this->redirect(array('/contacts/contacts/list', 'id' => $list->id));
}
}
if (empty($criteriaModels)) {
$default = new X2ListCriterion();
$default->value = '';
$default->attribute = '';
$default->comparison = 'contains';
$criteriaModels[] = $default;
} else {
if ($list->type = 'dynamic') {
foreach ($criteriaModels as $criM) {
if (isset($fields[$criM->attribute])) {
if ($fields[$criM->attribute]->type == 'link') {
$criM->value = implode(',', array_map(function ($c) {
list($name, $id) = Fields::nameAndId($c);
return $name;
}, explode(',', $criM->value)));
}
}
}
}
}
$this->render('updateList', array('model' => $list, 'criteriaModels' => $criteriaModels, 'users' => User::getNames(), 'comparisonList' => $comparisonList, 'listTypes' => array('dynamic' => Yii::t('contacts', 'Dynamic'), 'static' => Yii::t('contacts', 'Static')), 'itemModel' => $contactModel));
}
示例11: getContactId
public function getContactId()
{
list($name, $id) = Fields::nameAndId($this->associatedContacts);
return $id;
}
示例12: testNameAndId
public function testNameAndId()
{
$d = Fields::NAMEID_DELIM;
$nid = array('My Name', 12345);
$this->assertEquals($nid, Fields::nameAndId(implode($d, $nid)));
// This shouldn't affect it...
$nid[0] .= $d;
$this->assertEquals($nid, Fields::nameAndId(implode($d, $nid)));
// Or this...
$nid[0] = $d . $nid[0];
$this->assertEquals($nid, Fields::nameAndId(implode($d, $nid)));
// It should return an array with nameId first and then null for ID:
$nid[1] = null;
$this->assertEquals($nid, Fields::nameAndId($nid[0]));
// Empty in = empty out:
$nid = array(null, null);
$this->assertEquals($nid, Fields::nameAndId(null));
}