コード例 #1
0
 public function testGetItemIdsByModelAndUser()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $headquarters = Account::getByName('Headquarters');
     $headquarters = $headquarters[0];
     $division1 = Account::getByName('Division1');
     $division1 = $division1[0];
     $division2 = Account::getByName('Division2');
     $division2 = $division2[0];
     $ceo = Contact::getByName('ceo ceoson');
     $ceo = $ceo[0];
     $div1President = Contact::getByName('div1 President div1 Presidentson');
     $div1President = $div1President[0];
     $div2President = Contact::getByName('div2 President div2 Presidentson');
     $div2President = $div2President[0];
     $opportunity = Opportunity::getByName('big opp');
     $opportunity = $opportunity[0];
     $opportunityDiv1 = Opportunity::getByName('div1 small opp');
     $opportunityDiv1 = $opportunityDiv1[0];
     $opportunityDiv2 = Opportunity::getByName('div2 small opp');
     $opportunityDiv2 = $opportunityDiv2[0];
     //Headquarter rollup should include all items created so far.
     $this->assertEquals(2, $headquarters->accounts->count());
     $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($headquarters, $super);
     $compareItemIds = array();
     $this->assertEquals(9, count($itemIds));
     $this->assertTrue(in_array($headquarters->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($division1->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($division2->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($div1President->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($div2President->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($opportunityDiv1->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($opportunityDiv2->getClassId('Item'), $itemIds));
     //Ceo rollup would only include the ceo and his opportunity
     $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($ceo, $super);
     $compareItemIds = array();
     $this->assertEquals(2, count($itemIds));
     $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds));
     //Big Opp rollup will only include big opp and ceo
     $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($opportunity, $super);
     $compareItemIds = array();
     $this->assertEquals(2, count($itemIds));
     $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds));
     //Division 1 rollup will only include things related to division 1
     $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($division1, $super);
     $compareItemIds = array();
     $this->assertEquals(3, count($itemIds));
     $this->assertTrue(in_array($division1->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($div1President->getClassId('Item'), $itemIds));
     $this->assertTrue(in_array($opportunityDiv1->getClassId('Item'), $itemIds));
 }
コード例 #2
0
 /**
  * @param string $uniquePageId
  * @param LatestActivitiesConfigurationForm $form
  * @return RedBeanModelsDataProvider
  */
 protected function getDataProvider($uniquePageId, $form)
 {
     assert('is_string($uniquePageId)');
     assert('$form instanceOf LatestActivitiesConfigurationForm');
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('subListPageSize');
     $filteredMashableModelClassNames = LatestActivitiesUtil::resolveMashableModelClassNamesByFilteredBy(array_keys($form->mashableModelClassNamesAndDisplayLabels), $form->filteredByModelName);
     $relationItemId = (int) $this->params['relationModel']->getClassId('Item');
     if ($form->rollup) {
         $relationItemsIds = ModelRollUpUtil::getItemIdsByModelAndUser($this->params['relationModel'], Yii::app()->user->userModel);
     } else {
         $relationItemsIds = array($relationItemId);
     }
     $modelClassNamesAndSearchAttributeData = LatestActivitiesUtil::getSearchAttributesDataByModelClassNamesAndRelatedItemIds($filteredMashableModelClassNames, $relationItemsIds, $form->ownedByFilter);
     $modelClassNamesAndSortAttributes = LatestActivitiesUtil::getSortAttributesByMashableModelClassNames($filteredMashableModelClassNames);
     return new RedBeanModelsDataProvider($uniquePageId, $modelClassNamesAndSortAttributes, true, $modelClassNamesAndSearchAttributeData, array('pagination' => array('pageSize' => $pageSize)));
 }