/** * Store the content. */ function storeObjectAttribute($contentObjectAttribute) { $paex = $contentObjectAttribute->content(); if (!$paex instanceof eZPaEx) { // create a default paex object $paex = eZPaEx::create($contentObjectAttribute->attribute("contentobject_id")); } $paex->store(); $contentObjectAttribute->setContent($paex); }
/** * Get actual values for PaEx data for the given contentobject id. * If not defined for the given coID, use defaults. * * @param int $ezcoid Contentobject id (user id) to get PaEx for * @param bool $checkIfUserHasDatatype See if user has paex datatype, default false * @return eZPaEx|null Actual PaEx applicable data, null if $checkIfUserHasDatatype = true * and object does not have ezpaex datatype */ static function getPaEx($ezcoid, $checkIfUserHasDatatype = false) { $currentPaex = eZPaEx::fetch($ezcoid); // If we don't have paex object for the current object id, create a default one if (!$currentPaex instanceof eZPaEx) { // unless user does not have paex datatype if ($checkIfUserHasDatatype) { //eZContentObject::fetch( $ezcoid ); $paexDataTypeCount = eZPersistentObject::count(eZContentObjectAttribute::definition(), array('contentobject_id' => $ezcoid, 'data_type_string' => ezpaextype::DATA_TYPE_STRING), 'id'); if (!$paexDataTypeCount) { eZDebug::writeDebug("User id {$ezcoid} does not have paex datatype", __METHOD__); return null; } } return eZPaEx::create($ezcoid); } // Get default paex values from ini to use in case there is anyone missing in the object $ini = eZINI::instance('mbpaex.ini'); $iniPasswordValidationRegexp = $ini->variable('mbpaexSettings', 'PasswordValidationRegexp'); $iniDefaultPasswordLifeTime = $ini->variable('mbpaexSettings', 'DefaultPasswordLifeTime'); $iniExpirationNotification = $ini->variable('mbpaexSettings', 'ExpirationNotification'); // If still any empty values in the paex object, set defaults from ini if (!$currentPaex->hasRegexp()) { $currentPaex->setAttribute('passwordvalidationregexp', $iniPasswordValidationRegexp); eZDebug::writeDebug('Regexp empty, used default: "' . $iniPasswordValidationRegexp . '"', 'eZPaEx::getPaEx'); } if (!$currentPaex->hasLifeTime()) { $currentPaex->setAttribute('passwordlifetime', $iniDefaultPasswordLifeTime); eZDebug::writeDebug('PasswordLifeTime empty, used default: "' . $iniDefaultPasswordLifeTime . '"', 'eZPaEx::getPaEx'); } if (!$currentPaex->hasNotification()) { $currentPaex->setAttribute('expirationnotification', $iniExpirationNotification); eZDebug::writeDebug('ExpirationNotification empty, used default: "' . $iniPasswordValidationRegexp . '"', 'eZPaEx::getPaEx'); } eZDebug::writeDebug('PasswordLastUpdated value: "' . $currentPaex->attribute('password_last_updated') . '"', 'eZPaEx::getPaEx'); return $currentPaex; }
/** * Unit test for eZPaEx::fetch() **/ public function testFetch() { // Create a user $user = self::createUser(__FUNCTION__); $contentObjectID = $user->attribute('id'); // Try fetching this user's ID. Should fail. $this->assertNull(eZPaEx::fetch($contentObjectID), "eZPaEx::fetch() should be null as the object hasn't been created yet"); // Create & store the PaEx eZPaEx::create($contentObjectID)->store(); // Try fetching it again $this->assertType('eZPaEx', eZPaEx::fetch($contentObjectID)); }