コード例 #1
0
ファイル: StickySearchUtil.php プロジェクト: youprofit/Zurmo
 /**
  * @param CController $controller
  * @param $stickySearchKey
  * @param RedBeanModel $model
  * @return mixed
  */
 public static function resolveBreadCrumbViewForDetailsControllerAction(CController $controller, $stickySearchKey, RedBeanModel $model)
 {
     assert('is_string($stickySearchKey)');
     if (ArrayUtil::getArrayValue(GetUtil::getData(), 'stickyOffset') !== null && StickySearchUtil::getDataByKey($stickySearchKey) != null) {
         $stickyLoadUrl = Yii::app()->createUrl($controller->getModule()->getId() . '/' . $controller->getId() . '/renderStickyListBreadCrumbContent', array('stickyKey' => $stickySearchKey, 'stickyOffset' => ArrayUtil::getArrayValue(GetUtil::getData(), 'stickyOffset'), 'stickyModelId' => $model->id));
     } else {
         $stickyLoadUrl = null;
     }
     $className = static::resolveStickyDetailsAndRelationsBreadCrumbViewClassName();
     return new $className($controller->getId(), $controller->getModule()->getId(), static::resolveBreadcrumbLinks($model), $controller->getModule()->getModuleLabelByTypeAndLanguage('Plural'), $stickyLoadUrl);
 }
 /**
  * @depends testSuperUserCreateAction
  */
 public function testStickySearchActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     StickySearchUtil::clearDataByKey('GameRewardsSearchView');
     $value = StickySearchUtil::getDataByKey('GameRewardsSearchView');
     $this->assertNull($value);
     //Sort order desc
     $this->setGetArray(array('GameRewardsSearchForm' => array('anyMixedAttributes' => 'xyz', SearchForm::SELECTED_LIST_ATTRIBUTES => array('quantity', 'name')), 'GameReward_sort' => 'name.desc'));
     $this->runControllerWithNoExceptionsAndGetContent('gameRewards/default/');
     $data = StickySearchUtil::getDataByKey('GameRewardsSearchView');
     $compareData = array('dynamicClauses' => array(), 'dynamicStructure' => null, 'anyMixedAttributes' => 'xyz', 'anyMixedAttributesScope' => null, SearchForm::SELECTED_LIST_ATTRIBUTES => array('quantity', 'name'), 'sortAttribute' => 'name', 'sortDescending' => true);
     $this->assertEquals($compareData, $data);
     //Sort order asc
     StickySearchUtil::clearDataByKey('GameRewardsSearchView');
     $this->setGetArray(array('GameRewardsSearchForm' => array('anyMixedAttributes' => 'xyz', SearchForm::SELECTED_LIST_ATTRIBUTES => array('quantity', 'name')), 'GameReward_sort' => 'quantity'));
     $this->runControllerWithNoExceptionsAndGetContent('gameRewards/default/');
     $data = StickySearchUtil::getDataByKey('GameRewardsSearchView');
     $compareData = array('dynamicClauses' => array(), 'dynamicStructure' => null, 'anyMixedAttributes' => 'xyz', 'anyMixedAttributesScope' => null, SearchForm::SELECTED_LIST_ATTRIBUTES => array('quantity', 'name'), 'sortAttribute' => 'quantity', 'sortDescending' => false);
     $this->assertEquals($compareData, $data);
     $this->setGetArray(array('clearingSearch' => true));
     $this->runControllerWithNoExceptionsAndGetContent('gameRewards/default');
     $data = StickySearchUtil::getDataByKey('GameRewardsSearchView');
     $compareData = array('dynamicClauses' => array(), 'dynamicStructure' => null, 'anyMixedAttributesScope' => null, SearchForm::SELECTED_LIST_ATTRIBUTES => array('name', 'cost', 'quantity'));
     $this->assertEquals($compareData, $data);
 }
 /**
  * @depends testListForMarketingAction
  */
 public function testStickySearchActions()
 {
     StickySearchUtil::clearDataByKey('EmailTemplatesSearchView');
     $value = StickySearchUtil::getDataByKey('EmailTemplatesSearchView');
     $this->assertNull($value);
     $this->setGetArray(array('EmailTemplatesSearchForm' => array('anyMixedAttributes' => 'xyz')));
     $content = $this->runControllerWithNoExceptionsAndGetContent('emailTemplates/default/listForMarketing');
     $this->assertContains('No results found', $content);
     $data = StickySearchUtil::getDataByKey('EmailTemplatesSearchView');
     $compareData = array('dynamicClauses' => array(), 'dynamicStructure' => null, 'anyMixedAttributes' => 'xyz', 'anyMixedAttributesScope' => null, 'selectedListAttributes' => null);
     $this->assertEquals($compareData, $data);
     $this->setGetArray(array('EmailTemplatesSearchForm' => array('anyMixedAttributes' => 'Test')));
     $content = $this->runControllerWithNoExceptionsAndGetContent('emailTemplates/default/listForMarketing');
     $this->assertContains('1 result(s)', $content);
     $data = StickySearchUtil::getDataByKey('EmailTemplatesSearchView');
     $compareData = array('dynamicClauses' => array(), 'dynamicStructure' => null, 'anyMixedAttributes' => 'Test', 'anyMixedAttributesScope' => null, 'selectedListAttributes' => null, 'savedSearchId' => null);
     $this->assertEquals($compareData, $data);
     $this->setGetArray(array('clearingSearch' => true));
     $this->runControllerWithNoExceptionsAndGetContent('emailTemplates/default/listForMarketing');
     $data = StickySearchUtil::getDataByKey('EmailTemplatesSearchView');
     $compareData = array('dynamicClauses' => array(), 'dynamicStructure' => null, 'anyMixedAttributesScope' => null, 'selectedListAttributes' => null);
     $this->assertEquals($compareData, $data);
 }
コード例 #4
0
 public function testStickySearchByKeyWithSortDesc()
 {
     $dataArray = $this->getSearchDataForSort();
     $dataCollection = $dataArray['dataCollection'];
     $savedSearch = $dataArray['savedSearch'];
     //Set the sort in $_GET to set the sticky key for it.
     $_GET['AAA_sort'] = 'aaaMember2.desc';
     SavedSearchUtil::setDataByKeyAndDataCollection('abc', $dataCollection, array());
     $stickyData = StickySearchUtil::getDataByKey('abc');
     $compareData = array('dynamicClauses' => array('a', 'b'), 'dynamicStructure' => '1 and 5', 'anyMixedAttributes' => 'abcdef', 'anyMixedAttributesScope' => 'xyz', 'savedSearchId' => $savedSearch->id, SearchForm::SELECTED_LIST_ATTRIBUTES => array('aaaMember', 'aaaMember2'), 'sortAttribute' => 'aaaMember2', 'sortDescending' => true);
     $this->assertEquals($compareData, $stickyData);
     $searchModel = new AAASavedDynamicSearchFormTestModel(new AAA(false));
     $listAttributesSelector = new ListAttributesSelector('AListView', 'TestModule');
     $searchModel->setListAttributesSelector($listAttributesSelector);
     unset($_GET['AAA_sort']);
     SavedSearchUtil::resolveSearchFormByStickyDataAndModel($stickyData, $searchModel);
     $this->assertEquals('aaaMember2', $searchModel->sortAttribute);
     $this->assertNotNull($searchModel->sortDescending);
 }
コード例 #5
0
 private function makeDataCollectionAndResolveSavedSearch($searchModel, $stickySearchKey = null, $setSticky = true)
 {
     $dataCollection = new SearchAttributesDataCollection($searchModel);
     if ($searchModel instanceof SavedDynamicSearchForm) {
         $getData = GetUtil::getData();
         if ($stickySearchKey != null && isset($getData['clearingSearch']) && $getData['clearingSearch']) {
             StickySearchUtil::clearDataByKey($stickySearchKey);
         }
         if ($stickySearchKey != null && null != ($stickySearchData = StickySearchUtil::getDataByKey($stickySearchKey))) {
             SavedSearchUtil::resolveSearchFormByStickyDataAndModel($stickySearchData, $searchModel);
             SavedSearchUtil::resolveSearchFormByStickySortData($getData, $searchModel, $stickySearchData);
             SearchUtil::resolveSearchFormByStickyFilterByStarredData($getData, $searchModel, $stickySearchData);
             SearchUtil::resolveSearchFormByStickyFilteredByData($getData, $searchModel, $stickySearchData);
             SearchUtil::resolveSearchFormByStickyFilteredByData($getData, $searchModel, $stickySearchData);
             $dataCollection = new SavedSearchAttributesDataCollection($searchModel);
         } else {
             SavedSearchUtil::resolveSearchFormByData($getData, $searchModel);
             if ($searchModel->savedSearchId != null) {
                 $dataCollection = new SavedSearchAttributesDataCollection($searchModel);
             }
         }
         if ($stickySearchKey != null && ($setSticky || $searchModel->getKanbanBoard() != null && $searchModel->getKanbanBoard()->getClearSticky())) {
             if ($stickySearchData == null) {
                 $stickySearchData = array();
             }
             SavedSearchUtil::setDataByKeyAndDataCollection($stickySearchKey, $dataCollection, $stickySearchData);
         }
         $searchModel->loadSavedSearchUrl = Yii::app()->createUrl($this->getModule()->getId() . '/' . $this->getId() . '/list/');
     }
     return $dataCollection;
 }
コード例 #6
0
 protected function processSaveSearch($searchForm, $viewClassName)
 {
     $modelClassName = get_class($searchForm->model);
     $moduleClassName = $modelClassName::getModuleClassName();
     //Get sticky data here
     $stickySearchKey = $moduleClassName::getModuleLabelByTypeAndLanguage('Plural') . 'SearchView';
     $stickySearchData = StickySearchUtil::getDataByKey($stickySearchKey);
     $savedSearch = SavedSearchUtil::makeSavedSearchBySearchForm($searchForm, $viewClassName, $stickySearchData);
     if (!$savedSearch->save()) {
         throw new FailedToSaveModelException();
     }
     return $savedSearch;
 }