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


PHP Fields::nameId方法代码示例

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


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

示例1: testMassUpdateNameId

 public function testMassUpdateNameId()
 {
     $contact = $this->contact('testAnyone');
     // First, need to break all the nameIds...
     Contacts::model()->updateAll(array('nameId' => null));
     // Try with the mass update method, one ID:
     X2Model::massUpdateNameId('Contacts', array($contact->id));
     $contact->refresh();
     $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId);
     // Again, but with the "ids" parameter an int instead of an array
     X2Model::massUpdateNameId('Contacts', $contact->id);
     $contact->refresh();
     $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId);
     // Try again, multiple records:
     $contact2 = $this->contact('testUser');
     Contacts::model()->updateAll(array('nameId' => null));
     X2Model::massUpdateNameId('Contacts', array($contact->id, $contact2->id));
     $contact->refresh();
     $contact2->refresh();
     $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId);
     $this->assertEquals(Fields::nameId($contact2->name, $contact2->id), $contact2->nameId);
     // Try one last time, all records:
     Contacts::model()->updateAll(array('nameId' => null));
     X2Model::massUpdateNameId('Contacts');
     $contact->refresh();
     $contact2->refresh();
     $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId);
     $this->assertEquals(Fields::nameId($contact2->name, $contact2->id), $contact2->nameId);
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:29,代码来源:X2ModelTest.php

示例2: updateNameId

 /**
  * Sets the nameId field appropriately.
  *
  * The model must be inserted already, so that its primary key can
  * be used.
  * @param bool $save If true, update the model when done.
  */
 public function updateNameId($save = false)
 {
     if (!$this->hasAttribute('nameId')) {
         return;
     }
     $this->_oldAttributes['nameId'] = $this->nameId;
     $this->nameId = Fields::nameId($this->name, $this->id);
     if ($save) {
         $that = $this;
         $this->runWithoutBehavior('X2FlowTriggerBehavior', function () use($that) {
             $that->updateByPk($that->id, array('nameId' => $that->nameId));
         });
     }
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:21,代码来源:X2Model.php

示例3: testAfterSave

 public function testAfterSave()
 {
     $contact = $this->contact('testAnyone');
     $account = $this->account('account1');
     $account2 = $this->account('account2');
     $this->assertFalse($contact->relationships->hasRelationship($account));
     $contact->company = Fields::nameId($account->name, $account->id);
     $this->assertSaves($contact);
     $this->assertTrue($contact->relationships->hasRelationship($account));
     //Contact needs to be reloaded to refresh oldAttributes for afterSave
     $contact = Contacts::model()->findByPk($contact->id);
     $contact->company = Fields::nameId($account2->name, $account2->id);
     $this->assertSaves($contact);
     $this->assertFalse($contact->relationships->hasRelationship($account));
     $this->assertTrue($contact->relationships->hasRelationship($account2));
     $contact = Contacts::model()->findByPk($contact->id);
     $contact->company = NULL;
     $this->assertSaves($contact);
     $this->assertFalse($contact->relationships->hasRelationship($account));
     $this->assertFalse($contact->relationships->hasRelationship($account2));
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:21,代码来源:RelationshipsBehaviorTest.php

示例4: assertActionAssociation

 /**
  * Assert that an Action's association* fields are properly set
  * @param Actions $action
  * @param X2Model $association
  */
 protected function assertActionAssociation(Actions $action, X2Model $association)
 {
     $associationNameId = Fields::nameId($association->name, $association->id);
     $this->assertEquals(lcfirst(get_class($association)), $action->associationType);
     $this->assertEquals($association->id, $action->associationId);
     $this->assertEquals($associationNameId, $action->associationName);
 }
开发者ID:shayanyi,项目名称:CRM,代码行数:12,代码来源:AdminControllerTest.php

示例5: actionCreateRecords

 public function actionCreateRecords()
 {
     $contact = new Contacts();
     $account = new Accounts();
     $opportunity = new Opportunity();
     $users = User::getNames();
     if (isset($_POST['Contacts']) && isset($_POST['Accounts']) && isset($_POST['Opportunity'])) {
         $contact->setX2Fields($_POST['Contacts']);
         $account->setX2Fields($_POST['Accounts']);
         $opportunity->setX2Fields($_POST['Opportunity']);
         $validAccount = true;
         if ($account->validate() == false) {
             $validAccount = false;
             // validate other models so that the user gets feedback
             $contact->validate();
             $opportunity->validate();
         }
         if ($validAccount) {
             $allValid = true;
             $a = $this->createAccount($account, $account->attributes, '1');
             // Contact and Opportunity require Account id for lookup field
             $contact->company = Fields::nameId($account->name, $account->id);
             if ($contact->validate() == false) {
                 $allValid = false;
             }
             $c = $this->createContact($contact, $contact->attributes, '1');
             $opportunity->accountName = Fields::nameId($account->name, $account->id);
             $opportunity->contactName = Fields::nameId($contact->name, $contact->id);
             if ($opportunity->validate() == false) {
                 $allValid = false;
             }
             $o = $this->createOpportunity($opportunity, $opportunity->attributes, '1');
             if ($allValid && $c && $a && $o) {
                 // all records created?
                 Relationships::create('Contacts', $contact->id, 'Accounts', $account->id);
                 Relationships::create('Opportunity', $opportunity->id, 'Contacts', $contact->id);
                 Relationships::create('Opportunity', $opportunity->id, 'Accounts', $account->id);
                 if (isset($_GET['ret'])) {
                     if ($_GET['ret'] == 'contacts') {
                         $this->redirect(array("/contacts/contacts/view", 'id' => $contact->id));
                     } else {
                         if ($_GET['ret'] == 'accounts') {
                             $this->redirect(array("/accounts/accounts/view", 'id' => $account->id));
                         } else {
                             if ($_GET['ret'] == 'opportunities') {
                                 $this->redirect(array("/opportunities/opportunities/view", 'id' => $opportunity->id));
                             }
                         }
                     }
                 } else {
                     $this->redirect(array("/contacts/contacts/view", $contact->id));
                 }
             } else {
                 // otherwise clean up
                 $types = array('account' => 'Accounts', 'contact' => 'Contacts', 'opportunity' => 'Opportunity');
                 foreach ($types as $model => $type) {
                     if (${$model} && isset(${$model}->id)) {
                         $modelId = ${$model}->id;
                         ${$model}->delete();
                         // delete all new actions and events from creating/deleting records
                         foreach (array('Actions', 'Events') as $meta) {
                             X2Model::model($meta)->deleteAllByAttributes(array('associationId' => $modelId, 'associationType' => $type));
                         }
                     }
                 }
             }
         }
     }
     $this->render('createRecords', array('contact' => $contact, 'account' => $account, 'opportunity' => $opportunity, 'users' => $users));
 }
开发者ID:shayanyi,项目名称:CRM,代码行数:70,代码来源:SiteController.php

示例6: testNameId

 public function testNameId()
 {
     $d = Fields::NAMEID_DELIM;
     $this->assertEquals('My Name' . $d . '12345', Fields::nameId('My Name', 12345));
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:5,代码来源:FieldsTest.php

示例7: assertCRUD

 /**
  * Test the creation, reading, updating and deletion of records through the 
  * API, and validation errors.
  */
 public function assertCRUD()
 {
     $urlParam = $this->urlParam;
     $urlParam['{action}'] = 'create';
     $param = $this->param;
     $modelAttrs = array('Accounts' => array('name' => 'ApiAccount', 'type' => 'business', 'assignedTo' => 'testuser'), 'Actions' => array('assignedTo' => 'testuser', 'dueDate' => time() + 86400), 'Contacts' => array('firstName' => 'ApiContactFirstName', 'lastName' => 'ApiContactLastName', 'email' => 'apiemail@address.com', 'visibility' => 1, 'assignedTo' => 'admin'), 'Docs' => array('name' => 'Excellent birds', 'subject' => 'Test subject', 'text' => 'Vel lorem risus, massa, sociis sagittis! Turpis magna sed, tristique? Pid massa integer facilisis...'), 'Opportunity' => array('name' => 'Falling snow', 'description' => 'Urna dolor? Sed tortor arcu mid porttitor egestas pulvinar etiam, diam? Aliquam, cras ultricies elementum?...', 'assignedTo' => 'testuser'), 'Product' => array('name' => 'Excellent snow', 'description' => "Enim amet! Porttitor, amet pulvinar augue sed auctor, phasellus pellentesque nunc nunc amet proin...", 'type' => 'watch it fall'), 'Services' => array('contactId' => $this->contacts('testUser')->id, 'description' => 'This is the picture! (of the error). Fix it.', 'impact' => '1 - Severe', 'status' => 'new'));
     $classModulesMap = array_combine(array_keys($modelAttrs), array_keys($modelAttrs));
     $classModulesMap['Product'] = 'Products';
     $classModulesMap['Opportunity'] = 'Opportunities';
     // Stash models in here:
     $models = array();
     // Users to try the actions for:
     $n_users = count($this->users);
     $i = 0;
     foreach ($this->users as $userParam) {
         $param = array('user' => $userParam['username'], 'userKey' => $userParam['userKey']);
         $apiModel = $this->newModel($userParam['username'], $userParam['userKey']);
         $i++;
         foreach ($modelAttrs as $class => $attrs) {
             //			echo "Testing creation of $class record through API\n";
             $urlParam['{model}'] = $class;
             $ch = $this->getCurlHandle($urlParam, array_merge($param, $attrs));
             $cr = curl_exec($ch);
             file_put_contents('api_response.html', $cr);
             $authAction = $classModulesMap[$class] . 'Create';
             $this->assertResponseCodeIs(200, $ch, 'Failed create operation. Response = ' . $cr);
             $access = $this->assertAuthControlCorrectness($authAction, $ch, $apiModel);
             if ($access) {
                 $userAttrs = array();
                 foreach (array('createdBy', 'updatedBy') as $name) {
                     if (X2Model::model($class)->hasAttribute($name)) {
                         $userAttrs[$name] = $param['user'];
                     }
                 }
                 if ($class == 'Services') {
                     // Test setting a linktype field and having it turn into a nameId reference:
                     $attrs['contactId'] = Fields::nameId($this->contacts('testUser')->name, $this->contacts('testUser')->id);
                 }
                 $models[$class] = X2Model::model($class)->findByAttributes(array_merge($attrs, $userAttrs));
                 $this->assertTrue((bool) $models[$class], "Model of class {$class} not created properly when user = {$param['user']}. The response was: {$cr}.");
                 foreach ($attrs as $attr => $value) {
                     $this->assertEquals($value, $models[$class]->{$attr});
                 }
                 // Test that createDate was set properly:
                 if ($models[$class]->hasAttribute('createDate')) {
                     $this->assertNotNull($models[$class]->createDate);
                 }
             }
         }
     }
     // We've got our models. Now let's test finding by attributes ("lookup"):
     $urlParam['{action}'] = 'view';
     // We're going to need primary keys for the direct "view" read action:
     $pkValues = array();
     foreach ($this->users as $userParam) {
         $param = array('user' => $userParam['username'], 'userKey' => $userParam['userKey']);
         $apiModel = $this->newModel($userParam['username'], $userParam['userKey']);
         foreach ($modelAttrs as $class => $attrs) {
             $urlParam['{model}'] = $class;
             $ch = $this->getCurlHandle($urlParam, array_merge($param, array('id' => $models[$class]->id)));
             $cr = curl_exec($ch);
             file_put_contents('api_response.html', $cr);
             $authAction = $classModulesMap[$class] . 'View';
             $access = $this->assertAuthControlCorrectness($authAction, $ch, $apiModel);
             if ($access) {
                 $this->assertResponseCodeIs(200, $ch);
                 $queriedModel = CJSON::decode($cr);
                 // Response must be valid JSON:
                 $this->assertEquals('array', gettype($queriedModel));
                 $models[$class]->refresh();
                 // Test that the attributes are all equal. This is pretty much overkill.
                 foreach ($queriedModel as $attr => $value) {
                     $this->assertEquals($models[$class]->{$attr}, $value, "Failed asserting attribute equality for {$class}.{$attr}");
                 }
                 // This will be useful for the next tests (lookup by pk, update & delete):
                 $pkValues[$class] = $models[$class]->primaryKey;
             }
         }
     }
     // Test "view": lookup by ID. We already know that access control for the
     // "view" action is already correct; it was tested just previously. So
     // this test shall use the admin user:
     $urlParam['{action}'] = 'view';
     $param = array('user' => $userParam['username'], 'userKey' => $userParam['userKey']);
     foreach ($pkValues as $class => $pk) {
         $urlParam['{model}'] = $class;
         $get = array();
         if (is_array($pk)) {
             // Composite primary key
             $get = array_merge($get, $pk);
         } else {
             // Single-column primary key
             $get[$models[$class]->tableSchema->primaryKey] = $pk;
         }
         $urlParam['{params}'] = '?' . http_build_query($get, '', '&');
         $ch = $this->getCurlHandle($urlParam, $param);
//.........这里部分代码省略.........
开发者ID:dsyman2,项目名称:X2CRM,代码行数:101,代码来源:ApiControllerTest.php


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