Exemplo n.º 1
0
 /**
  * Utilizes information from the dataCollection object to
  * make a RedBeanDataProvider.  Either looks at saved search information or params in the $_GET array.
  * variables:
  *  modelName_sort
  *  modelName
  *  where modelName is Account for example.
  * Typically utilized by a listView action.
  */
 public function makeRedBeanDataProviderByDataCollection($searchModel, $pageSize, $stateMetadataAdapterClassName = null, $dataCollection = null)
 {
     assert('is_int($pageSize) || $pageSize == null');
     assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
     assert('$dataCollection instanceof SearchAttributesDataCollection || $dataCollection == null');
     $listModelClassName = get_class($searchModel->getModel());
     if ($dataCollection == null) {
         $dataCollection = new SearchAttributesDataCollection($searchModel);
     }
     $searchAttributes = $dataCollection->resolveSearchAttributesFromSourceData();
     $dataCollection->resolveAnyMixedAttributesScopeForSearchModelFromSourceData();
     $dataCollection->resolveSelectedListAttributesForSearchModelFromSourceData();
     $dataCollection->resolveFilterByStarredFromSourceData();
     $dataCollection->resolveKanbanBoardOptionsForSearchModelFromSourceData();
     $sanitizedSearchAttributes = GetUtil::sanitizePostByDesignerTypeForSavingModel($searchModel, $searchAttributes);
     $sortAttribute = $dataCollection->resolveSortAttributeFromSourceData($listModelClassName);
     $sortDescending = $dataCollection->resolveSortDescendingFromSourceData($listModelClassName);
     $metadataAdapter = new SearchDataProviderMetadataAdapter($searchModel, Yii::app()->user->userModel->id, $sanitizedSearchAttributes);
     $metadata = static::resolveDynamicSearchMetadata($searchModel, $metadataAdapter->getAdaptedMetadata(), $dataCollection);
     $this->resolveKanbanBoardMetadataBeforeMakingDataProvider($searchModel, $metadata);
     $this->resolveMetadataBeforeMakingDataProvider($metadata);
     $dataProviderClassName = 'RedBeanModelDataProvider';
     if ($searchModel->filterByStarred) {
         $dataProviderClassName = 'StarredModelDataProvider';
     }
     return RedBeanModelDataProviderUtil::makeDataProvider($metadata, $listModelClassName, $dataProviderClassName, $sortAttribute, $sortDescending, $pageSize, $stateMetadataAdapterClassName);
 }
 /**
  * @param string $key
  * @param SearchAttributesDataCollection $dataCollection
  * @param array $stickyData
  */
 public static function setDataByKeyAndDataCollection($key, SearchAttributesDataCollection $dataCollection, $stickyData)
 {
     assert('is_string($key)');
     assert('is_array($stickyData)');
     $stickyData['dynamicClauses'] = $dataCollection->getSanitizedDynamicSearchAttributes();
     $stickyData['dynamicStructure'] = $dataCollection->getDynamicStructure();
     if ($dataCollection->getFilterByStarred() != null) {
         $stickyData['filterByStarred'] = $dataCollection->getFilterByStarred();
     }
     if ($dataCollection->getFilteredBy() != null) {
         $stickyData['filteredBy'] = $dataCollection->getFilteredBy();
     }
     $anyMixedAttributes = $dataCollection->resolveSearchAttributesFromSourceData();
     if (isset($anyMixedAttributes['anyMixedAttributes'])) {
         $stickyData['anyMixedAttributes'] = $anyMixedAttributes['anyMixedAttributes'];
     } else {
         unset($stickyData['anyMixedAttributes']);
     }
     $dataCollection->resolveAnyMixedAttributesScopeForSearchModelFromSourceData();
     $dataCollection->resolveSelectedListAttributesForSearchModelFromSourceData();
     $dataCollection->resolveKanbanBoardOptionsForSearchModelFromSourceData();
     $stickyData['anyMixedAttributesScope'] = $dataCollection->getAnyMixedAttributesScopeFromModel();
     $stickyData[SearchForm::SELECTED_LIST_ATTRIBUTES] = $dataCollection->getSelectedListAttributesFromModel();
     static::resolveKanbanBoardDataByCollection($dataCollection, $stickyData);
     if ($dataCollection instanceof SavedSearchAttributesDataCollection) {
         $stickyData['savedSearchId'] = $dataCollection->getSavedSearchId();
     }
     // Resolve the sort and desc attribute from source data and set it in sticky array
     $listSortModel = get_class($dataCollection->getModel()->getModel());
     $sortAttribute = $dataCollection->resolveSortAttributeFromSourceData($listSortModel);
     //There are two cases
     //a) When user clicks on sorting in grid view, at that time Model Class inside form is used
     //b) When user save the search, sort attributes are in form model
     if ($sortAttribute == null) {
         $sortAttribute = $dataCollection->resolveSortAttributeFromSourceData(get_class($dataCollection->getModel()));
     }
     if (!empty($sortAttribute)) {
         $stickyData['sortAttribute'] = $sortAttribute;
         if ($dataCollection->resolveSortDescendingFromSourceData($listSortModel)) {
             $stickyData['sortDescending'] = true;
         } else {
             $sortDescending = $dataCollection->resolveSortDescendingFromSourceData(get_class($dataCollection->getModel()));
             if ($sortDescending === true) {
                 $stickyData['sortDescending'] = true;
             } else {
                 $stickyData['sortDescending'] = false;
             }
         }
     }
     StickySearchUtil::setDataByKeyAndData($key, $stickyData);
 }