コード例 #1
0
 /**
  * @param $modelClassName
  * @param $partialName
  * @param $pageSize
  * @return array
  * @throws NotImplementedException
  * @throws NotSupportedException
  */
 public static function getByPartialName($modelClassName, $partialName, $pageSize, $autoCompleteOptions = null)
 {
     assert('is_string($modelClassName)');
     assert('is_string($partialName)');
     assert('is_int($pageSize)');
     if ($modelClassName == 'User') {
         return ModelAutoCompleteUtil::getUserResults($partialName, $pageSize, $autoCompleteOptions);
     } elseif ($modelClassName == 'Contact') {
         throw new NotSupportedException();
     } elseif ($modelClassName == 'Person') {
         throw new NotImplementedException();
     } else {
         return ModelAutoCompleteUtil::getGenericResults($modelClassName, $partialName, $pageSize, $autoCompleteOptions);
     }
 }
コード例 #2
0
 protected function renderAutoCompleteResults($modelClassName, $term, $autoCompleteOptions = null)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize', get_class($this->getModule()));
     $autoCompleteResults = ModelAutoCompleteUtil::getByPartialName($modelClassName, $term, $pageSize, $autoCompleteOptions);
     if (empty($autoCompleteResults)) {
         $autoCompleteResults = array(array('id' => null, 'value' => null, 'label' => Zurmo::t('Core', 'No results found')));
     }
     return CJSON::encode($autoCompleteResults);
 }
コード例 #3
0
 /**
  * @depends testGetGlobalSearchResultsByPartialTermUsingScope
  */
 public function testGetGlobalSearchResultsByPartialTermWithRegularUserAndElevationStepsForRegularUser()
 {
     //Unfrozen, there are too many attributes that have to be columns in the database at this point, so
     //now this is just a frozen test.
     if (RedBeanDatabase::isFrozen()) {
         $super = User::getByUsername('super');
         $jimmy = User::getByUsername('jimmy');
         Yii::app()->user->userModel = $super;
         //Jimmy does not have read access, so he should not be able to see any results.
         $this->assertEquals(Right::DENY, $jimmy->getEffectiveRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS));
         $this->assertEquals(Right::DENY, $jimmy->getEffectiveRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS));
         $this->assertEquals(Right::DENY, $jimmy->getEffectiveRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES));
         Yii::app()->user->userModel = $jimmy;
         $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel);
         $this->assertEquals(array(array('href' => '', 'label' => 'No Results Found', 'iconClass' => '')), $data);
         //Give Jimmy access to the module, he still will not be able to see results.
         Yii::app()->user->userModel = $super;
         $jimmy->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
         $jimmy->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
         $jimmy->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS);
         $jimmy->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES);
         $this->assertTrue($jimmy->save());
         Yii::app()->user->userModel = $jimmy;
         $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel);
         $this->assertEquals(array(array('href' => '', 'label' => 'No Results Found', 'iconClass' => '')), $data);
         //Give Jimmy read on 1 model.  The search then should pick up this model.
         Yii::app()->user->userModel = $super;
         $accounts = Account::getByName('The Zoo');
         $this->assertEquals(1, count($accounts));
         $account = $accounts[0];
         $this->assertEquals(Permission::NONE, $account->getEffectivePermissions($jimmy));
         $account->addPermissions($jimmy, Permission::READ);
         $this->assertTrue($account->save());
         ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($account, $jimmy);
         Yii::app()->user->userModel = $jimmy;
         $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel);
         $this->assertEquals(1, count($data));
         $this->assertEquals('The Zoo', $data[0]['label']);
         //Give Jimmy read on 2 more models.  The search then should pick up these models.
         Yii::app()->user->userModel = $super;
         $contacts = Contact::getByName('Big Elephant');
         $this->assertEquals(1, count($contacts));
         $contact = $contacts[0];
         $this->assertEquals(Permission::NONE, $contact->getEffectivePermissions($jimmy));
         $contact->addPermissions($jimmy, Permission::READ);
         $this->assertTrue($contact->save());
         ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($contact, $jimmy);
         $opportunities = Opportunity::getByName('Animal Crackers');
         $this->assertEquals(1, count($opportunities));
         $opportunity = $opportunities[0];
         $this->assertEquals(Permission::NONE, $opportunity->getEffectivePermissions($jimmy));
         $opportunity->addPermissions($jimmy, Permission::READ);
         $this->assertTrue($opportunity->save());
         ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($opportunity, $jimmy);
         Yii::app()->user->userModel = $jimmy;
         $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel);
         $this->assertEquals(3, count($data));
         $this->assertEquals('The Zoo', $data[0]['label']);
         $this->assertEquals('Big Elephant', $data[1]['label']);
         $this->assertEquals('Animal Crackers', $data[2]['label']);
     }
 }
コード例 #4
0
 public function testGetGenericResultSanitizePartialName()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->assertTrue(ZurmoRedBean::$writer->doesTableExist(User::getTableName()));
     AccountTestHelper::createAccountByNameForOwner('Test account', $super);
     AccountTestHelper::createAccountByNameForOwner('Test account 2', $super);
     $term = "Test%');drop TABLE _user-- ";
     $data = ModelAutoCompleteUtil::getByPartialName('Account', $term, 5);
     $this->assertTrue(ZurmoRedBean::$writer->doesTableExist(User::getTableName()));
     $this->assertEmpty($data);
 }
コード例 #5
0
 public function actionAutoCompleteGroupsAndUsers($term)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize', get_class($this->getModule()));
     $groups = ModelAutoCompleteUtil::getByPartialName('Group', $term, $pageSize);
     $users = UserSearch::getUsersByPartialFullNameOrAnyEmailAddress($term, $pageSize, null);
     $autoCompleteResults = array();
     foreach ($groups as $group) {
         $autoCompleteResults[] = array('id' => PushDashboardUtil::GROUP_PREFIX . $group['id'], 'name' => $group['value']);
     }
     foreach ($users as $user) {
         $autoCompleteResults[] = array('id' => PushDashboardUtil::USER_PREFIX . $user->id, 'name' => MultipleContactsForMeetingElement::renderHtmlContentLabelFromUserAndKeyword($user, $term));
     }
     echo CJSON::encode($autoCompleteResults);
 }
コード例 #6
0
 /**
  * Given a name of a customFieldData object and a term to search on return a JSON encoded
  * array of autocomplete search results.
  * @param string $name - Name of CustomFieldData
  * @param string $term - term to search on
  */
 public function actionAutoCompleteCustomFieldData($name, $term)
 {
     assert('is_string($name)');
     assert('is_string($term)');
     $autoCompleteResults = ModelAutoCompleteUtil::getCustomFieldDataByPartialName($name, $term);
     if (count($autoCompleteResults) == 0) {
         $data = Zurmo::t('Core', 'No results found');
         $autoCompleteResults[] = array('id' => '', 'name' => $data);
     }
     echo CJSON::encode($autoCompleteResults);
 }