/** * @param array $uncrytedTicket * @return MMUsers */ public static function createOrUpdateMMUser( $uncrytedTicket ) { $userId = $uncrytedTicket['uuid']; $customerType = $uncrytedTicket['customerType']; if ( isset($uncrytedTicket['userSpeciality']) ) { $userSpeciality = $uncrytedTicket['userSpeciality']; } else { $userSpeciality = $uncrytedTicket['mainSpeciality']; } $state = $uncrytedTicket['state']; $country = eZIni::instance('site.ini')->variable('RegionalSettings','CountryOfRegistration'); $language = $uncrytedTicket['language']; /** * @todo: check $language entry format and parse it if needed to get an iso code on 2 chars */ $iniMapping = eZINI::instance('mercktaxonomymapping.ini'); $taxonomyType = $iniMapping->variable( 'Taxonomy', 'SpecialtiesTaxonomyType'); $specialtiesMappingINI = $iniMapping->variable( 'Taxonomy', 'Specialties' ); $customerTypesMappingINI = $iniMapping->variable( 'Taxonomy', 'CustomerTypes' ); if($taxonomyType != "transitive") { if ( isset( $customerTypesMappingINI[$customerType] ) ) { $customerType = $customerTypesMappingINI[$customerType]; } else { $customerType = $customerTypesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-CT', $userId, $country ); } if ( isset( $specialtiesMappingINI[$userSpeciality] ) ) { $userSpeciality = $specialtiesMappingINI[$userSpeciality]; } else { $userSpeciality = $specialtiesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-SPE', $userId, $country ); } } else { $customerTypesMapping = SolrSafeOperatorHelper::getCustomerTypes(); if ( !isset( $customerTypesMapping["$customerType"] ) ) { // fill with default value $customerType = $customerTypesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-CT', $userId, $country ); } $specialtiesMapping = SolrSafeOperatorHelper::getUserSpecialities(); if ( !isset( $specialtiesMapping[(string)$userSpeciality] ) ) { // fill with default value $userSpeciality = $specialtiesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-SPE', $userId, $country ); } } /** @var MMUsers $user */ $user = MMUsers::fetchByIdAndCountry( $userId, $country ); $isModifiedUser = false; if ( $user ) { if ( $customerType != $user->attribute('customer_type') ) { $user->setAttribute('customer_type', $customerType); $isModifiedUser = true; } if ( $userSpeciality !== $user->attribute('user_speciality') ) { $mainSpeciality = UserSpecialityContentSpeciality::getContentSpeciality ( $userSpeciality ); $defaultAdditionalSpecialities = MMUserLogin::getAddSpecialties($mainSpeciality); $user->setAttribute('user_speciality', $userSpeciality); // mapping main_spe additional spe $preferences = $user->getPreferences(); $userAditionalSpecialities = $preferences['specialities']; array_shift($userAditionalSpecialities); $tmp = array_diff( $userAditionalSpecialities, $defaultAdditionalSpecialities ); if( empty( $tmp ) ) // we don't modify the user spes if he has changed his selection { $preferences["specialities"] = MMUserLogin::getAddSpecialties($mainSpeciality); $user->setPreferences($preferences); } $user->setPreferences($preferences); // The user specialty has been modified, we need to update it for Quiz-type applications of the current cluster if( CacheApplicationTool::buildLocalizedApplicationByIdentifier('train-the-brain') instanceof ApplicationLocalized) { $playerScoring = QuizPlayerScoring::fetchOneBy( array( 'application_id' => (int)$app->applicationObject->id, 'uuid' => $user->attribute( 'uuid' ) ) ); // Checking if the current user has scored at least once for the application if( $playerScoring ) { foreach( FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ) as $k => $t ) { if( ($k . "") === ($userSpeciality . "") ) { // Updating the user specialty id in the player scoring table $playerScoring->setAttribute( 'user_specialty', $t['id'] ); $playerScoring->store(); } } // Scheduling a ranking update QuizPendingRankingUpdate::add( $playerScoring->attribute( 'global_ranking' ), $app->applicationObject->id ); } } $isModifiedUser = true; } if ( $country != $user->attribute('country') ) { $user->setAttribute('country', $country); $isModifiedUser = true; } if( $language != $user->attribute( 'language' ) ) { $user->setAttribute('language', $language ); $isModifiedUser = true; } if ( $state != $user->attribute('state') ) { $user->setAttribute('state', $state); $isModifiedUser = true; } if ( $isModifiedUser ) { $user->setAttribute('date_update', time()); $user->store(); } // set gpnotebook hand shake data in preferences if($user->getGPNotebookHS()) { SolrSafeOperatorHelper::getAndStoreGPNotebookHS(); } } else { $mainSpeciality = UserSpecialityContentSpeciality::getContentSpeciality ( $userSpeciality ); $insertedArray = array ( 'uuid' => $userId, 'customer_type' => $customerType, 'user_speciality' => $userSpeciality, 'country' => $country, 'language' => $language, 'date_update' => time(), 'state' => $state, ); $user = new MMUsers ($insertedArray); $user->store(); // mapping main_spe additional spe $preferences = $user->getPreferences(); $preferences["specialities"] = MMUserLogin::getAddSpecialties($mainSpeciality); $user->setPreferences($preferences); $isModifiedUser = true; } if ( $isModifiedUser ) { // Tag Lyris user to be reimported : $user->tagLyrisToProcess(); } return $user; }