/**
  * @return Editor_Forms_SearchOptions
  */
 protected function buildSearchProfiles()
 {
     $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
     $profiles = $profilesModel->fetchAll($profilesModel->select()->where('tenant=?', $this->_getCurrentTenant()->code));
     $profilesOptions = array();
     $profilesOptions[''] = _('Default');
     foreach ($profiles as $profile) {
         $profilesOptions[$profile->id] = $profile->name;
     }
     $profilesOptions['custom'] = _('Custom');
     $this->addElement('select', 'searchProfileId', array('label' => _('Search Profile'), 'multiOptions' => $profilesOptions));
     $this->addElement('text', 'searchProfileName', array('filters' => array('StringTrim'), 'label' => _('Search Profile Name')));
     $this->addElement('hidden', 'switchProfile', array('value' => 0, 'decorators' => array('ViewHelper')));
     return $this;
 }
        $concept->update([], ['status' => OpenSKOS_Concept_Status::OBSOLETE], true, true);
        $conceptsCounter++;
    }
}
echo $conceptsCounter . ' concepts were updated.' . "\n";
// Profiles and user options
$replaceExpired = function ($statuses) {
    $expiredInd = array_search(OpenSKOS_Concept_Status::_EXPIRED, $statuses);
    if ($expiredInd !== false) {
        $statuses[$expiredInd] = OpenSKOS_Concept_Status::OBSOLETE;
    }
    return $statuses;
};
// Profiles
$profilesCounter = 0;
$profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
foreach ($profilesModel->fetchAll() as $profile) {
    $searchOptions = unserialize($profile->searchOptions);
    if (in_array('expired', $searchOptions['status'])) {
        $searchOptions['status'] = $replaceExpired($searchOptions['status']);
        $profile->setSearchOptions($searchOptions);
        $profile->save();
        $profilesCounter++;
    }
}
echo $profilesCounter . ' profiles were updated.' . "\n";
// Users
$usersCounter = 0;
$usersModel = new OpenSKOS_Db_Table_Users();
foreach ($usersModel->fetchAll() as $user) {
    if ($user->searchOptions !== null) {
Example #3
0
 /**
  * @return Editor_Forms_Search
  */
 protected function buildSearchProfiles()
 {
     $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
     $profiles = $profilesModel->fetchAll($profilesModel->select()->where('tenant=?', $this->_getCurrentTenant()->code));
     $user = OpenSKOS_Db_Table_Users::requireFromIdentity();
     $profilesOptions = array();
     $profilesOptions[''] = _('Default');
     foreach ($profiles as $profile) {
         $profilesOptions[$profile->id] = $profile->name;
     }
     $profilesOptions['custom'] = _('Custom');
     // Check which profiles are allowed for the user.
     foreach (array_keys($profilesOptions) as $profileKey) {
         if (!$user->isAllowedToUseSearchProfile($profileKey)) {
             unset($profilesOptions[$profileKey]);
         }
     }
     $userOptions = $user->getSearchOptions();
     $this->addElement('select', 'searchProfileId', array('label' => _('Search Profile'), 'multiOptions' => $profilesOptions, 'value' => isset($userOptions['searchProfileId']) ? $userOptions['searchProfileId'] : ''));
     $this->addDisplayGroup(array('searchProfileId'), 'search-profile-selector', array('disableDefaultDecorators' => true, 'decorators' => array('FormElements', array('HtmlTag', array('tag' => 'span', 'id' => 'search-profile-selector', 'class' => $profiles->count() < 2 ? 'do-not-show' : '')))));
     return $this;
 }
Example #4
0
 /**
  * Gets the first of the search profiles for the user.
  * @return OpenSKOS_Db_Table_Row_SearchProfile
  */
 public function getFirstDefaultSearchProfile()
 {
     if (!empty($this->defaultSearchProfileIds)) {
         $defaultSearchProfilesIds = explode(', ', $this->defaultSearchProfileIds);
         $profilesModels = new OpenSKOS_Db_Table_SearchProfiles();
         return $profilesModels->find($defaultSearchProfilesIds[0])->current();
     } else {
         return null;
     }
 }
 private function _switchUserToSearchProfile(OpenSKOS_Db_Table_Row_User $user, $profileId)
 {
     //!TODO Consider movin inside the user object.
     if ($user->isAllowedToUseSearchProfile($profileId)) {
         $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
         $profile = $profilesModel->find($profileId)->current();
         if (null !== $profile) {
             $detailedSearchOptions = $profile->getSearchOptions();
         } else {
             $detailedSearchOptions = Editor_Forms_SearchOptions::getDefaultSearchOptions();
         }
         $detailedSearchOptions['searchProfileId'] = $profileId;
         $user->setSearchOptions($detailedSearchOptions);
     }
 }