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


PHP Item::getById方法代码示例

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


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

示例1: testDownCasts

 public function testDownCasts()
 {
     $possibleDerivationPaths = array(array('SecurableItem', 'OwnedSecurableItem', 'Account'), array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact'), array('SecurableItem', 'OwnedSecurableItem', 'Opportunity'));
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $account = AccountTestHelper::createAccountByNameForOwner('Waggle', $super);
     $contact = ContactTestHelper::createContactByNameForOwner('Noddy', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Noddy', $super);
     $accountItem = Item::getById($account->getClassId('Item'));
     $contactItem = Item::getById($contact->getClassId('Item'));
     $opportunityItem = Item::getById($opportunity->getClassId('Item'));
     $this->assertTrue($accountItem->isSame($account));
     $this->assertTrue($contactItem->isSame($contact));
     $this->assertTrue($opportunityItem->isSame($opportunity));
     $this->assertFalse($accountItem instanceof Account);
     $this->assertFalse($contactItem instanceof Contact);
     $this->assertFalse($opportunityItem instanceof Opportunity);
     $account2 = $accountItem->castDown($possibleDerivationPaths);
     $this->assertEquals('Account', get_class($account2));
     //Demonstrate a single array, making sure it casts down properly.
     $accountItem2 = Item::getById($account->getClassId('Item'));
     $account3 = $accountItem2->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Account')));
     $this->assertEquals('Account', get_class($account3));
     $contact2 = $contactItem->castDown($possibleDerivationPaths);
     $opportunity2 = $opportunityItem->castDown($possibleDerivationPaths);
     $this->assertTrue($account2->isSame($account));
     $this->assertTrue($contact2->isSame($contact));
     $this->assertTrue($opportunity2->isSame($opportunity));
     $this->assertTrue($account2 instanceof Account);
     $this->assertTrue($contact2 instanceof Contact);
     $this->assertTrue($opportunity2 instanceof Opportunity);
     $account2 = AccountTestHelper::createAccountByNameForOwner('Waggle2', $super);
     //By adding a second contact with a relation to the account2, we can demonstrate a bug with how castDown works.
     //Since contacts can in fact be attached to accounts via account_id, if a contact exists connected to the account
     //we are trying to cast down, then this will cast down even though it shouldn't.
     $contact2 = ContactTestHelper::createContactWithAccountByNameForOwner('MrWaggle2', $super, $account2);
     try {
         $account2CastedDown = $account2->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact')));
         $this->fail();
     } catch (NotFoundException $e) {
         //success
     }
     //Now try to forget the account and retrieve it.
     $account2Id = $account2->id;
     $account2->forget();
     unset($account2);
     $account2 = Account::getById($account2Id);
     try {
         $account2CastedDown = $account2->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact')));
         $this->fail();
     } catch (NotFoundException $e) {
         //success
     }
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:54,代码来源:ActivityTest.php

示例2: resolveConversationHasManyParticipantsFromPost

 /**
  * Based on the post data, resolve the conversation participants. While this is being resolved also
  * resolve the correct read/write permissions.
  * @param Conversation $conversation
  * @param array $postData
  * @param object $explicitReadWriteModelPermissions - ExplicitReadWriteModelPermissions model
  * @return Array of persons who have been added as participants
  */
 public static function resolveConversationHasManyParticipantsFromPost(Conversation $conversation, $postData, $explicitReadWriteModelPermissions)
 {
     assert('$explicitReadWriteModelPermissions instanceof ExplicitReadWriteModelPermissions');
     $newPeopleIndexedByItemId = array();
     if (isset($postData['itemIds']) && strlen($postData['itemIds']) > 0) {
         $itemIds = explode(",", $postData['itemIds']);
         // Not Coding Standard
         foreach ($itemIds as $itemId) {
             if ($itemId != $conversation->owner->getClassId('Item')) {
                 $newPeopleIndexedByItemId[$itemId] = static::castDownItem(Item::getById((int) $itemId));
             }
         }
         if ($conversation->conversationParticipants->count() > 0) {
             $participantsToRemove = array();
             foreach ($conversation->conversationParticipants as $index => $existingParticipantModel) {
                 if (!isset($newPeopleIndexedByItemId[$existingParticipantModel->person->getClassId('Item')])) {
                     $participantsToRemove[] = $existingParticipantModel;
                 } else {
                     unset($newPeopleIndexedByItemId[$existingParticipantModel->person->getClassId('Item')]);
                 }
             }
             foreach ($participantsToRemove as $participantModelToRemove) {
                 $conversation->conversationParticipants->remove($participantModelToRemove);
                 $person = static::castDownItem($participantModelToRemove->person);
                 if ($person instanceof Permitable) {
                     $explicitReadWriteModelPermissions->addReadWritePermitableToRemove($person);
                 }
             }
         }
         //Now add missing participants
         foreach ($newPeopleIndexedByItemId as $personOrUserModel) {
             $conversation->conversationParticipants->add(static::makeConversationParticipantByPerson($personOrUserModel));
             if ($personOrUserModel instanceof Permitable) {
                 $explicitReadWriteModelPermissions->addReadWritePermitable($personOrUserModel);
             }
         }
     } else {
         //remove all participants
         $conversation->conversationParticipants->removeAll();
         $explicitReadWriteModelPermissions->removeAllReadWritePermitables();
     }
     return $newPeopleIndexedByItemId;
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:51,代码来源:ConversationParticipantsUtil.php

示例3: testCastDown

 /**
  * Should not throw exception, should cast down ok
  * @depends testWebsiteCanBeSavedWithoutUrlScheme
  */
 public function testCastDown()
 {
     $user = User::getByUsername('steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = 'Account';
     $this->assertTrue($account->save());
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('Account');
     $itemId = $account->getClassId('Item');
     $item = Item::getById($itemId);
     $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
     $this->assertEquals('Account', get_class($castedDownModel));
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:17,代码来源:AccountTest.php

示例4: testCastDown

 /**
  * Should not throw exception, should cast down ok
  */
 public function testCastDown()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $startStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $meeting = new Meeting();
     $meeting->name = 'aTest';
     $meeting->startDateTime = $startStamp;
     $this->assertTrue($meeting->save());
     $itemId = $meeting->getClassId('Item');
     $item = Item::getById($itemId);
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('Meeting');
     $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
     $this->assertEquals('Meeting', get_class($castedDownModel));
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:17,代码来源:MeetingTest.php

示例5: testManyToManyRelationInTheMiddleOfTheInheritanceHierarchy

 public function testManyToManyRelationInTheMiddleOfTheInheritanceHierarchy()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $accounts = Account::getByName('anAccount');
     $possibleDerivationPaths = array(array('SecurableItem', 'OwnedSecurableItem', 'Account'), array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact'), array('SecurableItem', 'OwnedSecurableItem', 'Opportunity'));
     $model = new TestManyManyRelationToItemModel();
     $model->items->add($accounts[0]);
     $this->assertTrue($model->save());
     $item = Item::getById($model->items[0]->getClassId('Item'));
     $this->assertTrue($item instanceof Item);
     $this->assertFalse($item instanceof Account);
     $this->assertTrue($item->isSame($accounts[0]));
     $account2 = $item->castDown($possibleDerivationPaths);
     $this->assertTrue($account2->isSame($accounts[0]));
     $id = $model->id;
     unset($model);
     RedBeanModel::forgetAll();
     $model = TestManyManyRelationToItemModel::getById($id);
     $this->assertEquals(1, $model->items->count());
     $this->assertTrue($model->items[0] instanceof Item);
     $this->assertFalse($model->items[0] instanceof Account);
     $this->assertTrue($model->items[0]->isSame($accounts[0]));
     $account3 = $model->items[0]->castDown($possibleDerivationPaths);
     $this->assertTrue($account3->isSame($accounts[0]));
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:25,代码来源:TaskTest.php

示例6: update

 public function update()
 {
     $item = new Item($this->db);
     if ($this->f3->exists('POST.update')) {
         $item->edit($this->f3->get('POST.tok'));
         //get id getIdByTok
         $getIdByTok = new Item($this->db);
         $getIdByTok->getIdByTok($this->f3->get('POST.tok'));
         $iid = $this->f3->get('ID.id');
         //del tags
         $tgs = new Tag2Item($this->db);
         $tgs->getByItemId($iid);
         if (count($tgs->getByItemId($iid)) > 0) {
             foreach ($tgs->getByItemId($iid) as $t) {
                 $itemid = $t['id'];
                 $delti = new Tag2Item($this->db);
                 $delti->delete($itemid);
             }
         }
         //update tags
         $tags = explode(',', $this->f3->get('POST.tags'));
         foreach ($tags as $t) {
             $t = trim($t);
             if ($t != '') {
                 $this->f3->clear('TAGS');
                 $ifexists = new Tag($this->db);
                 $ifexists->getByName(strtolower($t));
                 if ($this->f3->exists('TAGS.id')) {
                     $tid = $this->f3->get('TAGS.id');
                 } else {
                     //insert new tag
                     $newtag = new Tag($this->db);
                     $newtag->title = strtolower(preg_replace('|[^0-9a-z \\-\\/+]|', '', $t));
                     $newtag->label = preg_replace('|[^0-9A-Za-z \\-\\/+]|', '', $t);
                     $newtag->url = toUrl($t);
                     //get unique tok
                     $utok = new Tag($this->db);
                     $randtok = rand(100000000, 999999999);
                     while ($utok->tagcountByTok($randtok) > 0) {
                         $randtok = rand(100000000, 999999999);
                     }
                     $newtag->tok = $randtok;
                     $newtag->add();
                     $tid = $newtag->_id;
                 }
                 //add to Tag2Item
                 $t2i = new Tag2Item($this->db);
                 //insert lastinsertedid
                 $t2i->tid = $tid;
                 $t2i->iid = $iid;
                 $t2i->add();
             }
         }
         $this->f3->set('COOKIE.message', 'The bookmark has been successfully saved!');
         $this->f3->set('COOKIE.messagetype', 'alert-success hide5s');
         $this->f3->reroute('/');
     } else {
         $item->getById($this->f3->get('PARAMS.tok'));
         $this->f3->set('item', $item);
         $this->f3->set('active', $this->f3->get('PARAMS.tok'));
         $this->f3->set('page_head', 'Update Item');
         //template
         $this->f3->set('view', 'item/update.htm');
         $tgs = new TagList($this->db);
         $this->f3->set('tgs', $tgs->getitemtags($this->f3->get('POST.tok')));
         $this->f3->set('ctrcount', count($tgs->getitemtags($this->f3->get('POST.tok'))));
         //menu
         $this->f3->set('topmenu', 'i');
         //breadcrumbs
         $this->f3->set('breadcrumb', array(array("url" => NULL, "name" => "Update bookmark")));
     }
 }
开发者ID:Mumcio,项目名称:bookmark-manager,代码行数:72,代码来源:ItemController.php


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