当前位置: 首页>>代码示例>>PHP>>正文


PHP Fields::model方法代码示例

本文整理汇总了PHP中Fields::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Fields::model方法的具体用法?PHP Fields::model怎么用?PHP Fields::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fields的用法示例。


在下文中一共展示了Fields::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionUpdate

 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $users = User::getNames();
     $fields = Fields::model()->findAllByAttributes(array('modelName' => 'Product'));
     foreach ($fields as $field) {
         if ($field->type == 'link') {
             $fieldName = $field->fieldName;
             $type = ucfirst($field->linkType);
             if (is_numeric($model->{$fieldName}) && $model->{$fieldName} != 0) {
                 eval("\$lookupModel={$type}::model()->findByPk(" . $model->{$fieldName} . ");");
                 if (isset($lookupModel)) {
                     $model->{$fieldName} = $lookupModel->name;
                 }
             }
         }
     }
     if (isset($_POST['Product'])) {
         $temp = $model->attributes;
         $model->setX2Fields($_POST['Product']);
         // generate history
         $action = new Actions();
         $action->associationType = 'product';
         $action->associationId = $model->id;
         $action->associationName = $model->name;
         $action->assignedTo = Yii::app()->user->getName();
         $action->completedBy = Yii::app()->user->getName();
         $action->dueDate = time();
         $action->completeDate = time();
         $action->visibility = 1;
         $action->complete = 'Yes';
         $action->actionDescription = "Update: {$model->name}\n            Type: {$model->type}\n            Price: {$model->price}\n            Currency: {$model->currency}\n            Inventory: {$model->inventory}";
         $action->save();
         parent::update($model, $temp, '0');
     }
     $this->render('update', array('model' => $model, 'users' => $users));
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:42,代码来源:ProductsController.php

示例2: nameFields

 public function nameFields()
 {
     if (!isset($this->_nameFields)) {
         $this->_nameFields = array();
         $this->_nameFields[] = Fields::model()->findByAttributes(array('fieldName' => 'firstName', 'modelName' => 'Contacts'));
         $this->_nameFields[] = Fields::model()->findByAttributes(array('fieldName' => 'lastName', 'modelName' => 'Contacts'));
     }
     return $this->_nameFields;
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:9,代码来源:X2ModelTest.php

示例3: queryFields

 protected function queryFields()
 {
     if (!isset(self::$_fields[$this->tableName()])) {
         // only look up fields if they haven't already been looked up
         if (get_class($this) === 'Product' || get_class($this) === 'Quote') {
             self::$_fields[$this->tableName()] = Fields::model()->findAllByAttributes(array('modelName' => get_class($this) . 's'));
         } else {
             self::$_fields[$this->tableName()] = Fields::model()->findAllByAttributes(array('modelName' => get_class($this)));
         }
     }
     //Yii::app()->db->createCommand()->select('*')->from('x2_fields')->where('modelName="'.get_class($this).'"')->queryAll();
 }
开发者ID:netconstructor,项目名称:X2Engine,代码行数:12,代码来源:X2Model.php

示例4: statusList

 public static function statusList()
 {
     $field = Fields::model()->findByAttributes(array('modelName' => 'Quotes', 'fieldName' => 'status'));
     $dropdown = Dropdowns::model()->findByPk($field->linkType);
     return json_decode($dropdown->options);
     /*
     		return array(
     		    'Draft'=>Yii::t('quotes','Draft'),
     		    'Presented'=>Yii::t('quotes','Presented'),
     		    "Issued"=>Yii::t('quotes','Issued'),
     		    "Won"=>Yii::t('quotes','Won')
     		); */
 }
开发者ID:netconstructor,项目名称:X2Engine,代码行数:13,代码来源:Quote.php

示例5: array

 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * X2Engine" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by X2Engine".
 *****************************************************************************************/
?>


<?php 
echo '<div class="form no-border" style="float:left;width:590px;">';
$form = $this->beginWidget('CActiveForm', array('id' => 'accounts-form', 'enableAjaxValidation' => false));
$attributeLabels = $model->attributeLabels();
$fields = Fields::model()->findAllByAttributes(array('modelName' => 'Accounts'));
if (isset($_GET['version'])) {
    $version = $_GET['version'];
    $version = FormVersions::model()->findByAttributes(array('name' => $version));
    $sizes = json_decode($version->sizes, true);
    $positions = json_decode($version->positions, true);
    $tempArr = array();
    foreach ($fields as $field) {
        if (isset($positions[$field->fieldName])) {
            $field->coordinates = $positions[$field->fieldName];
            $field->size = $sizes[$field->fieldName];
            $tempArr[] = $field;
        }
    }
    $fields = $tempArr;
}
开发者ID:dsyman2,项目名称:X2CRM,代码行数:31,代码来源:_form.php

示例6: tearDownAfterClass

 /**
  * Clean up custom field columns 
  */
 public static function tearDownAfterClass()
 {
     $fields = Fields::model()->findAllByAttributes(array('custom' => 1));
     foreach ($fields as $field) {
         assert($field->delete());
     }
     Yii::app()->db->schema->refresh();
     Yii::app()->cache->flush();
     Contacts::model()->refreshMetaData();
     Contacts::model()->resetFieldsPropertyCache();
     AuxLib::debugLogR('Contacts::model ()->getAttributes () = ');
     AuxLib::debugLogR(Contacts::model()->getAttributes());
     parent::tearDownAfterClass();
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:17,代码来源:FieldFormatterTest.php

示例7: createContact

 /**
  * Creates contact record
  *
  * Call this function from createRecords
  */
 public function createContact($model, $oldAttributes, $api)
 {
     $model->createDate = time();
     $model->lastUpdated = time();
     if (empty($model->visibility) && $model->visibility != 0) {
         $model->visibility = 1;
     }
     if ($api == 0) {
         parent::create($model, $oldAttributes, $api);
     } else {
         $lookupFields = Fields::model()->findAllByAttributes(array('modelName' => 'Contacts', 'type' => 'link'));
         foreach ($lookupFields as $field) {
             $fieldName = $field->fieldName;
             if (isset($model->{$fieldName})) {
                 $lookup = X2Model::model(ucfirst($field->linkType))->findByAttributes(array('name' => $model->{$fieldName}));
                 if (isset($lookup)) {
                     $model->{$fieldName} = $lookup->id;
                 }
             }
         }
         return parent::create($model, $oldAttributes, $api);
     }
 }
开发者ID:shayanyi,项目名称:CRM,代码行数:28,代码来源:SiteController.php

示例8: attributeLabels

 /**
  * @return array customized attribute labels (name=>label)
  */
 public function attributeLabels()
 {
     $fields = Fields::model()->findAllByAttributes(array('modelName' => 'Products'));
     $arr = array();
     foreach ($fields as $field) {
         $arr[$field->fieldName] = Yii::t('app', $field->attributeLabel);
     }
     return $arr;
     return array('id' => Yii::t('module', 'ID'), 'name' => Yii::t('module', 'Name'), 'description' => Yii::t('module', 'Description'), 'createDate' => Yii::t('module', 'Create Date'), 'lastUpdated' => Yii::t('module', 'Last Updated'), 'updatedBy' => Yii::t('module', 'Updated By'));
 }
开发者ID:netconstructor,项目名称:X2Engine,代码行数:13,代码来源:Product.php

示例9: array

 * 
 * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 * California 95067, USA. or at email address contact@x2engine.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * X2Engine" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by X2Engine".
 *****************************************************************************************/
// get field names
$fields = Fields::model()->findAllByAttributes(array('modelName' => 'Quote'));
$attributeLabel = array();
$fieldType = array();
foreach ($fields as $field) {
    $attributeLabel[$field->fieldName] = $field->attributeLabel;
    $fieldType[$field->fieldName] = $field->type;
}
?>

<div class="row viewQuote" style="overflow: visible;" >
<?php 
$viewButton = CHtml::link('[' . Yii::t('products', 'View') . ']', Yii::app()->createUrl('/quotes/quotes/view', array('id' => $quote->id)), array('title' => 'View Quote'));
$strict = Yii::app()->params['admin']['quoteStrictLock'];
$updateButton = $canDo['QuickUpdate'] ? ' ' . CHtml::link('[' . Yii::t('products', 'Update') . ']', 'javascript:void(0);', array('title' => 'Update Quote', 'onclick' => "x2.inlineQuotes.toggleUpdateQuote({$quote->id}, {$quote->locked}, " . ($strict ? 'true' : 'false') . ");")) : '';
$deleteButton = $canDo['QuickDelete'] ? ' ' . CHtml::ajaxLink('[' . Yii::t('quotes', 'Delete') . ']', Yii::app()->createUrl('/quotes/quotes/quickDelete', array('id' => $quote->id, 'recordId' => $recordId)), array('success' => "function(html) { x2.inlineQuotes.reloadAll(); }", 'beforeSend' => 'function(){
            return confirm(' . json_encode(Yii::t('quotes', 'Are you sure you want to delete this quote?')) . ');
开发者ID:tymiles003,项目名称:X2CRM,代码行数:31,代码来源:viewQuotes.php

示例10: actionSearch

 /**
  * Search X2Engine for a record.
  *
  * This is the action called by the search bar in the main menu.
  */
 public function actionSearch()
 {
     ini_set('memory_limit', -1);
     $term = isset($_GET['term']) ? $_GET['term'] : "";
     if (empty($term)) {
         $dataProvider = new CArrayDataProvider(array());
         Yii::app()->user->setFlash('error', Yii::t('app', "Search term cannot be empty."));
         $this->render('search', array('dataProvider' => $dataProvider));
     } else {
         if (substr($term, 0, 1) != "#") {
             $modules = Modules::model()->findAllByAttributes(array('searchable' => 1));
             $comparisons = array();
             $other = array();
             foreach ($modules as $module) {
                 $module->name == 'products' ? $type = ucfirst('Product') : ($type = ucfirst($module->name));
                 $module->name == 'quotes' ? $type = ucfirst('Quote') : ($type = $type);
                 $module->name == 'opportunities' ? $type = ucfirst('Opportunity') : ($type = $type);
                 $criteria = new CDbCriteria();
                 $fields = Fields::model()->findAllByAttributes(array('modelName' => $type, 'searchable' => 1));
                 $temp = array();
                 $fieldNames = array();
                 if (count($fields) < 1) {
                     $criteria->compare('id', '<0', true, 'AND');
                 }
                 foreach ($fields as $field) {
                     $temp[] = $field->id;
                     $fieldNames[] = $field->fieldName;
                     $criteria->compare($field->fieldName, $term, true, "OR");
                     if ($field->type == 'phone') {
                         $tempPhone = preg_replace('/\\D/', '', $term);
                         $phoneLookup = PhoneNumber::model()->findByAttributes(array('modelType' => $field->modelName, 'number' => $tempPhone, 'fieldName' => $field->fieldName));
                         if (isset($phoneLookup)) {
                             $criteria->compare('id', $phoneLookup->modelId, true, "OR");
                         }
                     }
                 }
                 if (Yii::app()->user->getName() != 'admin' && X2Model::model($type)->hasAttribute('visibility') && X2Model::model($type)->hasAttribute('assignedTo')) {
                     $condition = 'visibility="1" OR (assignedTo="Anyone" AND visibility!="0")  OR assignedTo="' . Yii::app()->user->getName() . '"';
                     /* x2temp */
                     $groupLinks = Yii::app()->db->createCommand()->select('groupId')->from('x2_group_to_user')->where('userId=' . Yii::app()->user->getId())->queryColumn();
                     if (!empty($groupLinks)) {
                         $condition .= ' OR assignedTo IN (' . implode(',', $groupLinks) . ')';
                     }
                     $condition .= 'OR (visibility=2 AND assignedTo IN
                         (SELECT username FROM x2_group_to_user WHERE groupId IN
                             (SELECT groupId FROM x2_group_to_user WHERE userId=' . Yii::app()->user->getId() . ')))';
                     $criteria->addCondition($condition);
                 }
                 if ($module->name == 'actions') {
                     $criteria->with = array('actionText');
                     $criteria->compare('actionText.text', $term, true, "OR");
                 }
                 if (class_exists($type)) {
                     $arr = X2Model::model($type)->findAll($criteria);
                     $comparisons[$type] = $temp;
                     $other[$type] = $arr;
                 }
             }
             $high = array();
             $medium = array();
             $low = array();
             $userHigh = array();
             $userMedium = array();
             $userLow = array();
             $records = array();
             $userRecords = array();
             $regEx = "/" . preg_quote($term, '/') . "/i";
             foreach ($other as $key => $recordType) {
                 $fieldList = $comparisons[$key];
                 foreach ($recordType as $otherRecord) {
                     if ($key == 'Actions') {
                         if ($otherRecord->hasAttribute('assignedTo') && $otherRecord->assignedTo == Yii::app()->user->getName()) {
                             $userHigh[] = $otherRecord;
                         } else {
                             $high[] = $otherRecord;
                         }
                     } else {
                         foreach ($fieldList as $field) {
                             $fieldRecord = Fields::model()->findByPk($field);
                             $fieldName = $fieldRecord->fieldName;
                             if (preg_match($regEx, $otherRecord->{$fieldName}) > 0) {
                                 switch ($fieldRecord->relevance) {
                                     case "High":
                                         if (!in_array($otherRecord, $high, true) && !in_array($otherRecord, $medium, true) && !in_array($otherRecord, $low, true) && !in_array($otherRecord, $userHigh, true) && !in_array($otherRecord, $userMedium, true) && !in_array($otherRecord, $userLow, true)) {
                                             if ($otherRecord->hasAttribute('assignedTo') && $otherRecord->assignedTo == Yii::app()->user->getName()) {
                                                 $userHigh[] = $otherRecord;
                                             } else {
                                                 $high[] = $otherRecord;
                                             }
                                         }
                                         break;
                                     case "Medium":
                                         if (!in_array($otherRecord, $high, true) && !in_array($otherRecord, $medium, true) && !in_array($otherRecord, $low, true) && !in_array($otherRecord, $userHigh, true) && !in_array($otherRecord, $userMedium, true) && !in_array($otherRecord, $userLow, true)) {
                                             if ($otherRecord->hasAttribute('assignedTo') && $otherRecord->assignedTo == Yii::app()->user->getName()) {
                                                 $userMedium[] = $otherRecord;
//.........这里部分代码省略.........
开发者ID:tymiles003,项目名称:X2CRM,代码行数:101,代码来源:SearchController.php

示例11: actionSearch

 public function actionSearch()
 {
     ini_set('memory_limit', -1);
     $term = $_GET['term'];
     if (substr($term, 0, 1) != "#") {
         /*$contactsCriteria = new CDbCriteria();
         
                                 $contactsCriteria->compare('firstName', $term, true, 'OR');
                                 $contactsCriteria->compare('lastName', $term, true, 'OR');
                                 $contactsCriteria->compare('name', $term, true, 'OR');
                                 $contactsCriteria->compare('backgroundInfo', $term, true, 'OR');
                                 $contactsCriteria->compare('email', $term, true, 'OR');
                                 $contactsCriteria->compare('phone', $term, true, 'OR');
                                 if(is_numeric($term)){
                                     $temp=$term;
                                     $first=substr($temp,0,3);
                                     $second=substr($temp,3,3);
                                     $third=substr($temp,6,4);
         
                                     $contactsCriteria->compare('phone', "($first) $second-$third", true, 'OR');
                                     $contactsCriteria->compare('phone', "$first-$second-$third", true, 'OR');
                                     $contactsCriteria->compare('phone', "$first $second $third", true, 'OR');
         
                                     $contactsCriteria->compare('phone2', "($first) $second-$third", true, 'OR');
                                     $contactsCriteria->compare('phone2', "$first-$second-$third", true, 'OR');
                                     $contactsCriteria->compare('phone2', "$first $second $third", true, 'OR');
         
                                 }
         						
                                 $contacts=Contacts::model()->findAll($contactsCriteria);
         
                                 
                                 $actionsCriteria=new CDbCriteria();
                                 $actionsCriteria->compare('actionDescription',$term,true,'OR');
                                 $actions=Actions::model()->findAll($actionsCriteria);
                                 
                                 $accountsCriteria=new CDbCriteria();
                                 $accountsCriteria->compare("name",$term,true,"OR");
                                 $accountsCriteria->compare("description",$term,true,"OR");
                                 $accountsCriteria->compare('tickerSymbol',$term,true,'OR');
                                 $accounts=Accounts::model()->findAll($accountsCriteria);
                                 
                                 $quotesCriteria=new CDbCriteria();
                                 $quotesCriteria->compare("name",$term,TRUE,"OR");
                                 $quotes=Quote::model()->findAll($quotesCriteria);
                                 
                                 $disallow=array(
                                     'contacts',
                                     'actions',
                                     'accounts',
                                     'quotes',
                                 );*/
         $modules = Modules::model()->findAllByAttributes(array('searchable' => 1));
         $comparisons = array();
         foreach ($modules as $module) {
             $module->name == 'products' ? $type = ucfirst('Product') : ($type = ucfirst($module->name));
             $module->name == 'quotes' ? $type = ucfirst('Quote') : ($type = $type);
             $criteria = new CDbCriteria();
             $fields = Fields::model()->findAllByAttributes(array('modelName' => $type, 'searchable' => 1));
             $temp = array();
             foreach ($fields as $field) {
                 $temp[] = $field->id;
                 $criteria->compare($field->fieldName, $term, true, "OR");
             }
             $arr = CActiveRecord::model($type)->findAll($criteria);
             $comparisons[$type] = $temp;
             $other[$type] = $arr;
         }
         $high = array();
         $medium = array();
         $low = array();
         $records = array();
         $regEx = "/{$term}/i";
         foreach ($other as $key => $recordType) {
             $fieldList = $comparisons[$key];
             foreach ($recordType as $otherRecord) {
                 foreach ($fieldList as $field) {
                     $fieldRecord = Fields::model()->findByPk($field);
                     $fieldName = $fieldRecord->fieldName;
                     if (preg_match($regEx, $otherRecord->{$fieldName}) > 0) {
                         switch ($fieldRecord->relevance) {
                             case "High":
                                 if (!in_array($otherRecord, $high) && !in_array($otherRecord, $medium) && !in_array($otherRecord, $low)) {
                                     $high[] = $otherRecord;
                                 }
                                 break;
                             case "Medium":
                                 if (!in_array($otherRecord, $high) && !in_array($otherRecord, $medium) && !in_array($otherRecord, $low)) {
                                     $medium[] = $otherRecord;
                                 }
                                 break;
                             case "Low":
                                 if (!in_array($otherRecord, $high) && !in_array($otherRecord, $medium) && !in_array($otherRecord, $low)) {
                                     $low[] = $otherRecord;
                                 }
                                 break;
                             default:
                                 $low[] = $otherRecord;
                         }
                     }
//.........这里部分代码省略.........
开发者ID:netconstructor,项目名称:X2Engine,代码行数:101,代码来源:SearchController.php

示例12: array

                <?php 
    echo $form->error($model, 'modelName');
    ?>
            </div>

            <div class="row">
                <?php 
    echo $form->labelEx($model, 'fieldName');
    ?>
                <?php 
    $modelSet = !empty($model->modelName);
    $fieldList = array();
    $fieldOptions = array();
    $customOrMod = false;
    if ($modelSet) {
        $fields = Fields::model()->findAll(array('order' => 'attributeLabel', 'condition' => 'modelName = :mn', 'params' => array(':mn' => $model->modelName)));
        foreach ($fields as $existingField) {
            $name = $existingField->fieldName;
            $fieldList[$name] = $existingField->attributeLabel;
            if ($existingField->custom == 1) {
                $fieldOptions[$name] = array('class' => 'field-option field-custom');
                $customOrMod = true;
            } else {
                if ($existingField->modified == 1) {
                    $fieldOptions[$name] = array('class' => 'field-option field-modified');
                    $customOrMod = true;
                } else {
                    $fieldOptions[$name] = array('class' => 'field-option');
                }
            }
        }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:31,代码来源:createUpdateField.php

示例13: mergeLinkFields

 public function mergeLinkFields(X2Model $model, $logMerge = false)
 {
     $ret = array();
     $linkFields = Fields::model()->findAllByAttributes(array('type' => 'Link', 'linkType' => get_class($model)));
     foreach ($linkFields as $field) {
         if ($logMerge) {
             $ids = Yii::app()->db->createCommand()->select('id')->from(X2Model::model($field->modelName)->tableName())->where($field->fieldName . ' = :id', array(':id' => $model->nameId))->queryColumn();
             if (!empty($ids)) {
                 $ret[$field->modelName]['field'] = $field->fieldName;
                 $ret[$field->modelName]['ids'] = $ids;
             }
         }
         Yii::app()->db->createCommand()->update(X2Model::model($field->modelName)->tableName(), array($field->fieldName => $this->nameId), $field->fieldName . ' = :id', array(':id' => $model->nameId));
     }
     return $ret;
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:16,代码来源:X2Model.php

示例14: testUpdatePermissions

 /**
  * Ensure that view/edit permissions are calculated and updated correctly.
  */
 public function testUpdatePermissions()
 {
     //For some reason, re-using longTimeout preserves the state changes to
     //the private internal variables and makes this test fail, so using
     //shortTimeout role instead.
     $role = $this->role('shortTimeout');
     $initialUsers = $role->getUsers();
     $totalFields = Fields::model()->count();
     //Test no permissions
     $role->setViewPermissions(array());
     $role->setEditPermissions(array());
     $role->save();
     $this->checkPermissionUpdates($role, $totalFields, array(0, 0, $totalFields));
     $this->assertEquals($initialUsers, $role->getUsers());
     //Test all permissions
     $role->setViewPermissions(range(1, $totalFields));
     $role->setEditPermissions(range(1, $totalFields));
     $role->save();
     $this->checkPermissionUpdates($role, $totalFields, array(0, $totalFields, 0));
     $this->assertEquals($initialUsers, $role->getUsers());
     //Test view-only permissions
     $role->setViewPermissions(range(1, $totalFields));
     $role->setEditPermissions(array());
     $role->save();
     $this->checkPermissionUpdates($role, $totalFields, array($totalFields, 0, 0));
     $this->assertEquals($initialUsers, $role->getUsers());
     //Test bad input permissions
     $role->setViewPermissions(array());
     $role->setEditPermissions(range(1, $totalFields));
     $role->save();
     $this->checkPermissionUpdates($role, $totalFields, array(0, 0, $totalFields));
     $this->assertEquals($initialUsers, $role->getUsers());
     //Test random permissions
     $range = range(1, $totalFields);
     shuffle($range);
     $newView = array_slice($range, 0, rand(1, $totalFields - 1));
     shuffle($range);
     $newEdit = array_slice($range, 0, rand(1, $totalFields - 1));
     $edit = array_intersect($newView, $newEdit);
     $view = array_diff($newView, $newEdit);
     $none = array_diff(range(1, $totalFields), $newView);
     //Have to do pre-processing to get accurate counts, but that screws up
     //the same preprocessing happening in the roles model. View = view + edit
     //fixes the double array_intersect creating an empty array.
     $role->setViewPermissions($view + $edit);
     $role->setEditPermissions($edit);
     $role->save();
     $this->checkPermissionUpdates($role, $totalFields, array(count($view), count($edit), count($none)));
     $this->assertEquals($initialUsers, $role->getUsers());
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:53,代码来源:RolesTest.php

示例15: verifyImportMap

 /**
  * Parse the given keys and attributes to ensure required fields are
  * mapped and new fields are to be created. The verified map will be
  * stored in the 'importMap' key for the $_SESSION super global.
  * @param string $model name of the model
  * @param array $keys
  * @param array $attributes
  * @param boolean $createFields whether or not to create new fields
  */
 protected function verifyImportMap($model, $keys, $attributes, $createFields = false)
 {
     if (!empty($keys) && !empty($attributes)) {
         // New import map is the provided data
         $importMap = array_combine($keys, $attributes);
         $conflictingFields = array();
         $failedFields = array();
         // To keep track of fields that were mapped multiple times
         $mappedValues = array();
         $multiMappings = array();
         foreach ($importMap as $key => &$value) {
             if (in_array($value, $mappedValues) && !empty($value) && !in_array($value, $multiMappings)) {
                 // This attribute is mapped to two different fields in X2
                 $multiMappings[] = $value;
             } else {
                 if ($value !== 'createNew') {
                     $mappedValues[] = $value;
                 }
             }
             // Loop through and figure out if we need to create new fields
             $origKey = $key;
             $key = Formatter::deCamelCase($key);
             $key = preg_replace('/\\[W|_]/', ' ', $key);
             $key = mb_convert_case($key, MB_CASE_TITLE, "UTF-8");
             $key = preg_replace('/\\W/', '', $key);
             if ($value == 'createNew' && !$createFields) {
                 $importMap[$origKey] = 'c_' . strtolower($key);
                 $fieldLookup = Fields::model()->findByAttributes(array('modelName' => $model, 'fieldName' => $key));
                 if (isset($fieldLookup)) {
                     $conflictingFields[] = $key;
                     continue;
                 } else {
                     $customFieldLookup = Fields::model()->findByAttributes(array('modelName' => $model, 'fieldName' => $importMap[$origKey]));
                     if (!$customFieldLookup instanceof Fields) {
                         // Create a custom field if one doesn't exist already
                         $columnName = strtolower($key);
                         $field = new Fields();
                         $field->modelName = $model;
                         $field->type = "varchar";
                         $field->fieldName = $columnName;
                         $field->required = 0;
                         $field->searchable = 1;
                         $field->relevance = "Medium";
                         $field->custom = 1;
                         $field->modified = 1;
                         $field->attributeLabel = $field->generateAttributeLabel($key);
                         if (!$field->save()) {
                             $failedFields[] = $key;
                         }
                     }
                 }
             }
         }
         // Check for required attributes that are missing
         $requiredAttrs = Yii::app()->db->createCommand()->select('fieldName, attributeLabel')->from('x2_fields')->where('modelName = :model AND required = 1', array(':model' => str_replace(' ', '', $model)))->query();
         $missingAttrs = array();
         foreach ($requiredAttrs as $attr) {
             // Skip visibility, it can be set for them
             if (strtolower($attr['fieldName']) == 'visibility') {
                 continue;
             }
             // Ignore missing first/last name, this can be inferred from full name
             if ($model === 'Contacts' && ($attr['fieldName'] === 'firstName' || $attr['fieldName'] === 'lastName') && in_array('name', array_values($importMap))) {
                 continue;
             }
             // Otherwise, a required field is missing and should be reported to the user
             if (!in_array($attr['fieldName'], array_values($importMap))) {
                 $missingAttrs[] = $attr['attributeLabel'];
             }
         }
         if (!empty($conflictingFields)) {
             echo CJSON::encode(array("2", implode(', ', $conflictingFields)));
         } else {
             if (!empty($missingAttrs)) {
                 echo CJSON::encode(array("3", implode(', ', $missingAttrs)));
             } else {
                 if (!empty($failedFields)) {
                     echo CJSON::encode(array("1", implode(', ', $failedFields)));
                 } else {
                     if (!empty($multiMappings)) {
                         echo CJSON::encode(array("4", implode(', ', $multiMappings)));
                     } else {
                         echo CJSON::encode(array("0"));
                     }
                 }
             }
         }
         $_SESSION['importMap'] = $importMap;
     } else {
         echo CJSON::encode(array("0"));
         $_SESSION['importMap'] = array();
//.........这里部分代码省略.........
开发者ID:keyeMyria,项目名称:CRM,代码行数:101,代码来源:AdminController.php


注:本文中的Fields::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。