/** * Create a scheduled script that will store the modification made to an eZContentClass. * * @param eZContentClass Content class to be stored. * @param array[eZContentClassAttribute] Attributes of the new content class. * @param array Unordered view parameters */ public function store(eZContentClass $class, array $attributes, array &$unorderedParameters) { $script = eZScheduledScript::create('syncobjectattributes.php', eZINI::instance('ezscriptmonitor.ini')->variable('GeneralSettings', 'PhpCliCommand') . ' extension/ezscriptmonitor/bin/' . eZScheduledScript::SCRIPT_NAME_STRING . ' -s ' . eZScheduledScript::SITE_ACCESS_STRING . ' --classid=' . $class->attribute('id')); $script->store(); $unorderedParameters['ScheduledScriptID'] = $script->attribute('id'); $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_MODIFIED); }
/** * Store the modification made to an eZContentClass. * * @param eZContentClass Content class to be stored. * @param array[eZContentClassAttribute] Attributes of the new content class. * @param array Unordered view parameters */ public function store(eZContentClass $class, array $attributes, array &$unorderedParameters) { $oldClassAttributes = $class->fetchAttributes($class->attribute('id'), true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExists = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($class->fetchAttributes() as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExists = true; break; } } if (!$attributeExists) { foreach (eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID) as $objectAttribute) { $objectAttribute->removeThis($objectAttribute->attribute('id')); } } } $class->storeDefined($attributes); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExists = false; $newClassAttributeID = $newClassAttribute->attribute('id'); foreach ($oldClassAttributes as $oldClassAttribute) { if ($newClassAttributeID == $oldClassAttribute->attribute('id')) { $attributeExists = true; break; } } if (!$attributeExists) { $newClassAttribute->initializeObjectAttributes($objects); } } }
public static function instance(eZContentClass $class) { if (!$class instanceof eZContentClass) { throw new Exception("Class not found (" . __METHOD__ . ")"); } if (!isset(self::$instances[$class->attribute('identifier')])) { self::$instances[$class->attribute('identifier')] = new OCClassExtraParametersManager($class); } return self::$instances[$class->attribute('identifier')]; }
protected function syncGroups() { $remote = $this->getRemote(); if ($remote === null) { throw new Exception("Classe remota non trovata"); } $this->syncAllGroups($remote); $locale = $this->currentClass; /** @var eZContentClassClassGroup[] $localGroups */ $localGroups = $locale->fetchGroupList(); //$localGroupsNames = array(); //$remoteGroupsNames = array(); foreach ($localGroups as $group) { /** @var eZContentClassGroup $classGroup */ $classGroup = eZContentClassGroup::fetchByName($group->attribute('group_name')); if ($classGroup) { eZContentClassClassGroup::removeGroup($this->currentClass->attribute('id'), $this->currentClass->attribute('version'), $classGroup->attribute('id')); } } foreach ($remote->InGroups as $group) { /** @var eZContentClassGroup $classGroup */ $classGroup = eZContentClassGroup::fetchByName($group->GroupName); if ($classGroup) { $ingroup = eZContentClassClassGroup::create($this->currentClass->attribute('id'), $this->currentClass->attribute('version'), $classGroup->attribute('id'), $classGroup->attribute('name')); $ingroup->store(); } } //$groups = $this->currentClass->attribute( 'ingroup_list' ); //if ( count( $groups ) == 0 ) //{ // //@todo //} }
/** * Test that saving a content class in DEFINED version status * correctly manipulate associated class groups * * @link http://issues.ez.no/16197 */ public function testContentClassStillInGroupAfterEdition() { $class = eZContentClass::fetch( $this->class->id ); // This is logic contained in kernel/class/edit.php foreach ( eZContentClassClassGroup::fetchGroupList( $class->attribute( 'id' ), eZContentClass::VERSION_STATUS_DEFINED ) as $classGroup ) { eZContentClassClassGroup::create( $class->attribute( 'id' ), eZContentClass::VERSION_STATUS_TEMPORARY, $classGroup->attribute( 'group_id' ), $classGroup->attribute( 'group_name' ) ) ->store(); } $attributes = $class->fetchAttributes(); $class->setAttribute( 'version', eZContentClass::VERSION_STATUS_TEMPORARY ); $class->NameList->setHasDirtyData(); foreach ( $attributes as $attribute ) { $attribute->setAttribute( 'version', eZContentClass::VERSION_STATUS_TEMPORARY ); if ( $dataType = $attribute->dataType() ) $dataType->initializeClassAttribute( $attribute ); } $class->store( $attributes ); $db = eZDB::instance(); $db->begin(); $class->storeVersioned( $attributes, eZContentClass::VERSION_STATUS_DEFINED ); $db->commit(); $this->assertTrue( eZContentClassClassGroup::classInGroup( $class->attribute( 'id' ), eZContentClass::VERSION_STATUS_DEFINED, 1 ) ); }
static function remove($classID) { $contentClass = eZContentClass::fetch($classID); if ($contentClass == null or !$contentClass->isRemovable()) { return false; } // Remove all objects $contentObjects = eZContentObject::fetchSameClassList($classID); foreach ($contentObjects as $contentObject) { eZContentObjectOperations::remove($contentObject->attribute('id')); } if (count($contentObjects) == 0) { eZContentObject::expireAllViewCache(); } eZContentClassClassGroup::removeClassMembers($classID, 0); eZContentClassClassGroup::removeClassMembers($classID, 1); // Fetch real version and remove it $contentClass->remove(true); // Fetch temp version and remove it $tempDeleteClass = eZContentClass::fetch($classID, true, 1); if ($tempDeleteClass != null) { $tempDeleteClass->remove(true, 1); } return true; }
/** * Adds a translation in language $newLanguageCode for object * * @param string $newLanguageCode * @param mixed $translationData array( attribute identifier => attribute value ) * @return void */ public function addTranslation($newLanguageCode, $translationData) { // Make sure to refresh the objects data. $this->refresh(); $this->object->cleanupInternalDrafts(); $version = $this->object->createNewVersionIn($newLanguageCode); $version->setAttribute('status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT); $version->store(); $newVersion = $this->object->version($version->attribute('version')); $newVersionAttributes = $newVersion->contentObjectAttributes($newLanguageCode); $versionDataMap = self::createDataMap($newVersionAttributes); // Start updating new version $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $db = eZDB::instance(); $db->begin(); $version->store(); // @TODO: Add generic datatype support here foreach ($translationData as $attr => $value) { if ($versionDataMap[$attr]->attribute('data_type_string') == "ezxmltext") { $value = $this->processXmlTextData($value, $versionDataMap[$attr]); } $versionDataMap[$attr]->setAttribute('data_text', $value); $versionDataMap[$attr]->store(); } $db->commit(); //Update the content object name $db->begin(); $this->object->setName($this->class->contentObjectName($this->object, $version->attribute('version'), $newLanguageCode), $version->attribute('version'), $newLanguageCode); $db->commit(); // Finally publish object self::publishContentObject($this->object, $version); }
static function removeGroup( $classID, $classVersion, $selectedGroup ) { $class = eZContentClass::fetch( $classID, true, eZContentClass::VERSION_STATUS_DEFINED ); if ( !$class ) return false; $groups = $class->attribute( 'ingroup_list' ); foreach ( array_keys( $groups ) as $key ) { if ( in_array( $groups[$key]->attribute( 'group_id' ), $selectedGroup ) ) { unset( $groups[$key] ); } } if ( count( $groups ) == 0 ) { return false; } else { foreach( $selectedGroup as $group_id ) { eZContentClassClassGroup::removeGroup( $classID, $classVersion, $group_id ); } } return true; }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $canCreateClassList = $namedParameters['can_create_class_list']; switch ($operatorName) { case 'ezcreateclasslistgroups': $groupArray = array(); $ini = eZINI::instance('websitetoolbar.ini'); foreach ($canCreateClassList as $class) { $contentClass = eZContentClass::fetch($class['id']); if (!$contentClass) { return false; } foreach ($contentClass->fetchGroupList() as $group) { $isHidden = false; if (in_array($contentClass->attribute('identifier'), $ini->variable('WebsiteToolbarSettings', 'HiddenContentClasses'))) { $isHidden = true; } if (array_key_exists($group->attribute('group_id'), $groupArray)) { if (!$isHidden) { $groupArray[$group->attribute('group_id')]['items'][] = $contentClass; } } else { if (!$isHidden) { $groupArray[$group->attribute('group_id')]['items'] = array($contentClass); $groupArray[$group->attribute('group_id')]['group_name'] = $group->attribute('group_name'); } } } } $operatorValue = $groupArray; break; } }
function attribute($attr) { switch ($attr) { case 'contentclass_list': return eZContentClass::fetchList(eZContentClass::VERSION_STATUS_DEFINED, true); break; case 'contentclassattribute_list': // $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ); and $http->hasPostVariable( $postvarname ) if (isset($GLOBALS['eZWaitUntilDateSelectedClass'])) { $classID = $GLOBALS['eZWaitUntilDateSelectedClass']; } else { // if nothing was preselected, we will use the first one: // POSSIBLE ENHANCEMENT: in the common case, the contentclass_list fetch will be called twice $classList = eZWaitUntilDateType::attribute('contentclass_list'); if (isset($classList[0])) { $classID = $classList[0]->attribute('id'); } else { $classID = false; } } if ($classID) { return eZContentClassAttribute::fetchListByClassID($classID); } return array(); break; case 'has_class_attributes': // for the backward compatibility: return 1; break; default: return eZWorkflowEventType::attribute($attr); } }
/** * Creates a user with provided auth data * * @param array $authResult * * @return bool|eZUser */ public static function createUser($authResult) { $ngConnectINI = eZINI::instance('ngconnect.ini'); $siteINI = eZINI::instance('site.ini'); $defaultUserPlacement = $ngConnectINI->variable('LoginMethod_' . $authResult['login_method'], 'DefaultUserPlacement'); $placementNode = eZContentObjectTreeNode::fetch($defaultUserPlacement); if (!$placementNode instanceof eZContentObjectTreeNode) { $defaultUserPlacement = $siteINI->variable('UserSettings', 'DefaultUserPlacement'); $placementNode = eZContentObjectTreeNode::fetch($defaultUserPlacement); if (!$placementNode instanceof eZContentObjectTreeNode) { return false; } } $contentClass = eZContentClass::fetch($siteINI->variable('UserSettings', 'UserClassID')); $userCreatorID = $siteINI->variable('UserSettings', 'UserCreatorID'); $defaultSectionID = $siteINI->variable('UserSettings', 'DefaultSectionID'); $db = eZDB::instance(); $db->begin(); $contentObject = $contentClass->instantiate($userCreatorID, $defaultSectionID); $contentObject->store(); $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => 1, 'parent_node' => $placementNode->attribute('node_id'), 'is_main' => 1)); $nodeAssignment->store(); $currentTimeStamp = eZDateTime::currentTimeStamp(); /** @var eZContentObjectVersion $version */ $version = $contentObject->currentVersion(); $version->setAttribute('modified', $currentTimeStamp); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $dataMap = $version->dataMap(); self::fillUserObject($version->dataMap(), $authResult); if (!isset($dataMap['user_account'])) { $db->rollback(); return false; } $userLogin = '******' . $authResult['login_method'] . '_' . $authResult['id']; $userPassword = (string) rand() . 'ngconnect_' . $authResult['login_method'] . '_' . $authResult['id'] . (string) rand(); $userExists = false; if (eZUser::requireUniqueEmail()) { $userExists = eZUser::fetchByEmail($authResult['email']) instanceof eZUser; } if (empty($authResult['email']) || $userExists) { $email = md5('ngconnect_' . $authResult['login_method'] . '_' . $authResult['id']) . '@localhost.local'; } else { $email = $authResult['email']; } $user = new eZUser(array('contentobject_id' => $contentObject->attribute('id'), 'email' => $email, 'login' => $userLogin, 'password_hash' => md5("{$userLogin}\n{$userPassword}"), 'password_hash_type' => 1)); $user->store(); $userSetting = new eZUserSetting(array('is_enabled' => true, 'max_login' => 0, 'user_id' => $contentObject->attribute('id'))); $userSetting->store(); $dataMap['user_account']->setContent($user); $dataMap['user_account']->store(); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObject->attribute('id'), 'version' => $version->attribute('version'))); if (array_key_exists('status', $operationResult) && $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE) { $db->commit(); return $user; } $db->rollback(); return false; }
function className() { if ($this->ClassName === null) { $contentClass = eZContentClass::fetch($this->attribute('contentclass_id')); $this->ClassName = $contentClass->attribute('name'); } return $this->ClassName; }
public function execute($process, $event) { $processParameters = $process->attribute('parameter_list'); $object = eZContentObject::fetch($processParameters['object_id']); $targetClassIdentifier = $object->contentClass()->attribute('identifier'); $iniGroups = eZINI::instance('ngindexer.ini')->groups(); $targets = array(); foreach ($iniGroups as $iniGroupName => $iniGroup) { $iniGroupNameArray = explode('/', $iniGroupName); if (is_array($iniGroupNameArray) && count($iniGroupNameArray) == 3) { $class = eZContentClass::fetchByIdentifier($iniGroupNameArray[0]); if ($class instanceof eZContentClass) { $classAttribute = $class->fetchAttributeByIdentifier($iniGroupNameArray[1]); if ($classAttribute instanceof eZContentClassAttribute) { $indexTarget = isset($iniGroup['IndexTarget']) ? trim($iniGroup['IndexTarget']) : ''; $referencedClassIdentifiers = isset($iniGroup['ClassIdentifiers']) && is_array($iniGroup['ClassIdentifiers']) ? $iniGroup['ClassIdentifiers'] : null; if ($referencedClassIdentifiers != null && (empty($referencedClassIdentifiers) || in_array($targetClassIdentifier, $referencedClassIdentifiers))) { switch ($indexTarget) { case 'parent': case 'parent_line': $children = eZContentObjectTreeNode::subTreeByNodeID(array('ClassFilterType' => 'include', 'ClassFilterArray' => array($iniGroupNameArray[0]), 'Depth' => $indexTarget == 'parent' ? 1 : false), $object->mainNode()->attribute('node_id')); if (is_array($children)) { $targets = array_merge($targets, $children); } break; case 'children': $parentNode = $object->mainNode()->fetchParent(); if ($parentNode->classIdentifier() == $iniGroupNameArray[0]) { $targets[] = $parentNode; } break; case 'subtree': $path = $object->mainNode()->fetchPath(); foreach ($path as $pathNode) { if ($pathNode->classIdentifier() == $iniGroupNameArray[0]) { $targets[] = $parentNode; } } break; default: continue; } } } } } } $filteredTargets = array(); foreach ($targets as $target) { $objectID = $target->attribute('contentobject_id'); $version = $target->object()->attribute('current_version'); if (!isset($filteredTargets[$objectID])) { $filteredTargets[$objectID] = $version; eZContentOperationCollection::registerSearchObject($objectID, $version); } } return eZWorkflowType::STATUS_ACCEPTED; }
private function attribute_migrate($classIdentifier, $srcAttribute, $conversion, $destAttribute) { $contentClass = eZContentClass::fetchByIdentifier($classIdentifier); if (!$contentClass) { throw new Exception("Failed to instantiate content class [" . $classIdentifier . "]"); } $classDataMap = $contentClass->attribute("data_map"); if (!isset($classDataMap[$srcAttribute])) { throw new Exception("Content class '" . $classIdentifier . "' does not contain this attribute: [" . $srcAttribute . "]"); } if (!isset($classDataMap[$destAttribute])) { throw new Exception("Content class '" . $classIdentifier . "' does not contain this attribute: [" . $destAttribute . "]"); } $classId = $contentClass->attribute("id"); $objects = eZContentObject::fetchSameClassList($classId, false); $numObjects = count($objects); $conversionFunc = null; switch ($conversion) { default: echo "This mapping is not supported: [" . $conversion . "]\n"; return; break; case "rot13": $conversionFunc = "convertStringToRot13"; break; case "time2integer": $conversionFunc = "convertTimeToInteger"; break; case "trim": $conversionFunc = "convertTrim"; break; case "date2ts": $conversionFunc = "dateToTS"; break; } foreach ($objects as $n => $object) { $object = eZContentObject::fetch($object["id"]); if ($object) { // copy data with conversion $dataMap = $object->DataMap(); $src = $dataMap[$srcAttribute]; $dest = $dataMap[$destAttribute]; $dest->fromString(eep::$conversionFunc($src->toString())); $dest->store(); // publish to get changes recognized, eg object title updated eep::republishObject($object->attribute("id")); } echo "Percent complete: " . sprintf("% 3.3f", ($n + 1.0) / $numObjects * 100.0) . "%\r"; // clear caches unset($GLOBALS["eZContentObjectContentObjectCache"]); unset($GLOBALS["eZContentObjectDataMapCache"]); unset($GLOBALS["eZContentObjectVersionCache"]); unset($object); } echo "\n"; }
function updateClass($classId, $scheduledScript) { $cli = eZCLI::instance(); /* // If the class is not stored yet, store it now $class = eZContentClass::fetch( $classId, true, eZContentClass::VERSION_STATUS_TEMPORARY ); if ( $class ) { $cli->output( "Storing class" ); $class->storeDefined( $class->fetchAttributes() ); } */ // Fetch the stored class $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); if (!$class) { $cli->error('No class in a modified version status with ID: ' . $classId); return; } // Fetch attributes and definitions $attributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); $oldClassAttributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExist = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($attributes as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExist = true; } } if (!$attributeExist) { foreach (eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID) as $objectAttribute) { $objectAttribute->removeThis($objectAttribute->attribute('id')); } } } $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExist = false; foreach ($oldClassAttributes as $oldClassAttribute) { if ($oldClassAttribute->attribute('id') == $newClassAttribute->attribute('id')) { $attributeExist = true; break; } } if (!$attributeExist) { $objects = null; $newClassAttribute->initializeObjectAttributes($objects); } } if ($scheduledScript !== false) { $scheduledScript->updateProgress(100); } }
private function contentClassList() { $db = eZDB::instance(); $query = "SELECT ezcontentclass.id\n FROM ezcontentclass,\n ezcontentclass_attribute ezcontentclass_attribute1,\n ezcontentclass_attribute ezcontentclass_attribute2\n WHERE ezcontentclass.version='0' AND\n ezcontentclass.id=ezcontentclass_attribute1.contentclass_id AND\n ezcontentclass_attribute1.is_information_collector='0' AND\n ezcontentclass.id=ezcontentclass_attribute2.contentclass_id AND\n ezcontentclass_attribute2.is_information_collector='0' AND\n ezcontentclass_attribute1.contentclass_id=ezcontentclass_attribute2.contentclass_id AND\n ezcontentclass_attribute1.data_type_string='ezxmltext' AND\n ezcontentclass_attribute2.data_type_string='eztext'"; $contentClassArray = $db->arrayQuery($query); $retArray = array(); foreach ($contentClassArray as $contentClass) { $retArray[] = eZContentClass::fetch($contentClass['id']); } return $retArray; }
/** * @return string */ protected function getForm() { $classKeyArray = array(array('class_identifier', $this->contentClass->attribute('identifier'))); $tpl = eZTemplate::factory(); $tpl->setVariable('class', $this->contentClass); $tpl->setVariable('remote_class_id', $this->remoteContentClassDefinition->ID); $tpl->setVariable('client', $this); $attributeFields = array(); $dataMap = $this->contentClass->attribute('data_map'); $disabled = array(); if (eZINI::instance('ocsearchtools.ini')->hasVariable('RemoteClassSearchFormSettings', 'DisabledAttributes')) { $disabled = eZINI::instance('ocsearchtools.ini')->variable('RemoteClassSearchFormSettings', 'DisabledAttributes'); } /** @var $dataMap eZContentClassAttribute[] */ foreach ($dataMap as $attribute) { if (!in_array($this->contentClass->attribute('identifier') . '/' . $attribute->attribute('identifier'), $disabled) && $attribute->attribute('is_searchable')) { if (isset($this->remoteContentClassDefinition->DataMap[0]->{$attribute->attribute('identifier')})) { $attribute->setAttribute('data_type_string', $this->remoteContentClassDefinition->DataMap[0]->{$attribute->attribute('identifier')}->DataTypeString); $inputField = OCRemoteClassSearchFormAttributeField::instance($attribute, $this->remoteContentClassDefinition->DataMap[0]->{$attribute->attribute('identifier')}, $this); $keyArray = array(array('class_identifier', $this->contentClass->attribute('identifier')), array('attribute_identifier', $inputField->contentClassAttribute->attribute('identifier'))); $tpl = eZTemplate::factory(); $tpl->setVariable('class', $this->contentClass); $tpl->setVariable('attribute', $inputField->contentClassAttribute); $tpl->setVariable('input', $inputField); $res = eZTemplateDesignResource::instance(); $res->setKeys($keyArray); $templateName = $inputField->contentClassAttribute->attribute('data_type_string'); $attributeFields[$inputField->attribute('id')] = $tpl->fetch('design:class_search_form/datatypes/' . $templateName . '.tpl'); } } } $tpl->setVariable('attribute_fields', $attributeFields); $parameters = array('action' => 'search'); $tpl->setVariable('parameters', $parameters); $formAction = $this->attributes['definition']['ClientBasePath']; eZURI::transformURI($formAction); $tpl->setVariable('form_action', $formAction); $res = eZTemplateDesignResource::instance(); $res->setKeys($classKeyArray); return $tpl->fetch('design:repository/contentclass_client/remote_class_search_form.tpl'); }
/** * Test scenario for issue #13712: Multiprice datatype shows wrong price after multiple calls in template * * Test Outline * ------------ * 1. Create a euro currency * 2. Create a VAT type of 10 % * 3. Create a content class with an attribute of the datatype ezmultiprice * 4. Create a content object of this content class and set a custom price ex. VAT with the VAT type of 10% that we created * 5. Subsequently retrieve the attribute 'inc_vat_price_list' * * @result: the returned eZMultiPriceData instances differ on each call, their values are increased each time with VAT * @expected: the returned eZMultiPriceData instances are equal * @link http://issues.ez.no/13712 * @group issue_13712 */ public function testMultipleCallsToCalculatedPrice() { $currencyCode = 'EUR'; // create currency $currencyParams = array('code' => $currencyCode, 'symbol' => false, 'locale' => 'eng-GB', 'custom_rate_value' => 0, 'rate_factor' => 1); $currency = eZCurrencyData::create($currencyCode, '€', 'eng-GB', 0, 0, 1); $currency->store(); $currencyID = $currency->attribute('id'); $this->assertInternalType('integer', $currencyID); // create VAT type $row = array('name' => 'Test', 'percentage' => 10.0); $vatType = new eZVatType($row); $vatType->store(); $vatTypeID = $vatType->attribute('id'); $this->assertInternalType('integer', $vatTypeID); $class = eZContentClass::create(false, array('name' => 'eZMultiPrice::testMultipleCallsToCalculatedPrice', 'identifier' => 'ezmultiprice_test')); $class->store(); $classID = $class->attribute('id'); $this->assertInternalType('integer', $classID); $attributes = $class->fetchAttributes(); // add class attributes $newAttribute = eZContentClassAttribute::create($classID, 'ezmultiprice', array('name' => 'Test', 'identifier' => 'test')); $dataType = $newAttribute->dataType(); $dataType->initializeClassAttribute($newAttribute); $newAttribute->setAttribute(eZMultiPriceType::DEFAULT_CURRENCY_CODE_FIELD, $currencyCode); $newAttribute->setAttribute(eZMultiPriceType::VAT_ID_FIELD, $vatTypeID); $newAttribute->store(); $attributes[] = $newAttribute; $class->storeDefined($attributes); $contentObject = $class->instantiate(); $version = $contentObject->currentVersion(); $dataMap = $version->dataMap(); $multiPrice = $dataMap['test']->content(); $multiPrice->setAttribute('selected_vat_type', $vatTypeID); $multiPrice->setAttribute('is_vat_included', eZMultiPriceType::EXCLUDED_VAT); $multiPrice->setCustomPrice($currencyCode, 100); $multiPrice->updateAutoPriceList(); $dataMap['test']->setContent($multiPrice); $dataMap['test']->setAttribute('data_text', $vatTypeID . ',' . eZMultiPriceType::EXCLUDED_VAT); $dataMap['test']->store(); // test values $firstIncVatPriceList = $multiPrice->attribute('inc_vat_price_list'); $this->assertArrayHasKey('EUR', $firstIncVatPriceList); $firstCallValue = $firstIncVatPriceList['EUR']->attribute('value'); $secondIncVatPriceList = $multiPrice->attribute('inc_vat_price_list'); $this->assertArrayHasKey('EUR', $secondIncVatPriceList); $secondCallValue = $secondIncVatPriceList['EUR']->attribute('value'); $this->assertEquals($firstCallValue, $secondCallValue); $thirdIncVatPriceList = $multiPrice->attribute('inc_vat_price_list'); $this->assertArrayHasKey('EUR', $thirdIncVatPriceList); $thirdCallValue = $thirdIncVatPriceList['EUR']->attribute('value'); $this->assertEquals($firstCallValue, $thirdCallValue); }
function className() { if ($this->ClassName === null) { $contentClass = eZContentClass::fetch($this->attribute('contentclass_id')); if (!$contentClass instanceof eZContentClass) { eZDebug::writeError('Unable to find eZContentClass #' . $this->attribute('contentclass_id'), __METHOD__); return null; } $this->ClassName = $contentClass->attribute('name'); } return $this->ClassName; }
/** * Ritorna l'elengo dei tag disponibili * * @return eZTagsObject[] */ public static function notificationAvailableTags() { $class = eZContentClass::fetchByIdentifier(self::CLASS_IDENTIFIER); if ($class instanceof eZContentClass) { $classAttribute = $class->fetchAttributeByIdentifier(self::TAG_ATTRIBUTE_IDENTIFIER); if ($classAttribute instanceof eZContentClassAttribute) { $tagRoot = eZTagsObject::fetch(intval($classAttribute->attribute(eZTagsType::SUBTREE_LIMIT_FIELD))); return $tagRoot->getChildren(); } } return array(); }
public static function fetchMapMarkers($parentNodeId, $childrenClassIdentifiers) { foreach ($childrenClassIdentifiers as $key => $value) { if (empty($value)) { unset($childrenClassIdentifiers[$key]); } } $sortBy = array('name' => 'asc'); $result = array(); if ($parentNode = self::getNode($parentNodeId)) { if (!empty($childrenClassIdentifiers)) { $childrenClassTypes = (array) eZContentClass::fetchList(0, true, false, null, null, $childrenClassIdentifiers); } else { $childrenClassTypes = self::getChildrenClasses($parentNodeId); } // ricavo gli attributi delle classi $geoAttributes = array(); foreach ($childrenClassTypes as $classType) { if ($classType instanceof eZContentClass) { $geoAttributes = array_merge($geoAttributes, eZContentClassAttribute::fetchFilteredList(array('contentclass_id' => $classType->attribute('id'), 'version' => $classType->attribute('version'), 'data_type_string' => 'ezgmaplocation'))); } } if (count($geoAttributes)) { // imposto i filtri di ricerca $geoFields = $geoFieldsNames = array(); foreach ($geoAttributes as $geoAttribute) { if ($geoAttribute instanceof eZContentClassAttribute) { $geoFields[$geoAttribute->attribute('identifier')] = $geoAttribute->attribute('name'); $geoFieldsNames[] = "subattr_{$geoAttribute->attribute('identifier')}___coordinates____gpt"; } } $childrenParameters = array('SearchSubTreeArray' => array($parentNode->attribute('node_id')), 'Filter' => array('-meta_id_si:' . $parentNode->attribute('contentobject_id')), 'SearchLimit' => 1000, 'AsObjects' => false, 'SortBy' => $sortBy, 'FieldsToReturn' => $geoFieldsNames); // cerco i figli $solr = new OCSolr(); $children = $solr->search('', $childrenParameters); if ($children['SearchCount'] > 0) { foreach ($children['SearchResult'] as $item) { foreach ($geoFieldsNames as $geoFieldsName) { @(list($longitude, $latitude) = explode(',', $item['fields'][$geoFieldsName][0])); if (intval($latitude) > 0 && intval($longitude) > 0) { $href = isset($item['main_url_alias']) ? $item['main_url_alias'] : $item['main_url_alias_ms']; eZURI::transformURI($href, false, 'full'); $popup = isset($item['name']) ? $item['name'] : $item['name_t']; $id = isset($item['id_si']) ? $item['id_si'] : $item['id']; $result[] = array('id' => $id, 'type' => null, 'lat' => floatval($latitude), 'lon' => floatval($longitude), 'lng' => floatval($longitude), 'popupMsg' => $popup, 'title' => $popup, 'description' => "<h3><a href='{$href}'>{$popup}</a></h3>", 'urlAlias' => $href, 'objectID' => $id); } } } } } } return array('result' => $result); }
function initSettings($parameters) { $siteINI = eZINI::instance(); $classIdentifier = 'template_look'; //get the class $class = eZContentClass::fetchByIdentifier($classIdentifier, true, eZContentClass::VERSION_STATUS_TEMPORARY); if (!$class) { $class = eZContentClass::fetchByIdentifier($classIdentifier, true, eZContentClass::VERSION_STATUS_DEFINED); if (!$class) { eZDebug::writeError("Warning, DEFINED version for class identifier {$classIdentifier} does not exist."); return; } } $classId = $class->attribute('id'); $this->Settings['template_look_class_id'] = $classId; $objects = eZContentObject::fetchSameClassList($classId); if (!count($objects)) { eZDebug::writeError("Object of class {$classIdentifier} does not exist."); return; } $templateLookObject = $objects[0]; $this->Settings['template_look_object'] = $templateLookObject; $this->Settings['template_look_object_id'] = $templateLookObject->attribute('id'); if (!is_array($parameters)) { return; } $this->addSetting('admin_account_id', eZSiteInstaller::getParam($parameters, 'object_remote_map/1bb4fe25487f05527efa8bfd394cecc7', '')); $this->addSetting('guest_accounts_id', eZSiteInstaller::getParam($parameters, 'object_remote_map/5f7f0bdb3381d6a461d8c29ff53d908f', '')); $this->addSetting('anonymous_accounts_id', eZSiteInstaller::getParam($parameters, 'object_remote_map/15b256dbea2ae72418ff5facc999e8f9', '')); $this->addSetting('package_object', eZSiteInstaller::getParam($parameters, 'package_object', false)); $this->addSetting('design_list', eZSiteInstaller::getParam($parameters, 'design_list', array())); $this->addSetting('main_site_design', strtolower($this->solutionName())); $this->addSetting('extension_list', array('ezwt', 'ezstarrating', 'ezgmaplocation', strtolower($this->solutionName()))); $this->addSetting('version', $this->solutionVersion()); $this->addSetting('locales', eZSiteInstaller::getParam($parameters, 'all_language_codes', array())); // usual user siteaccess like 'ezwebin_site' $this->addSetting('user_siteaccess', eZSiteInstaller::getParam($parameters, 'user_siteaccess', '')); // usual admin siteaccess like 'ezwebin_site_admin' $this->addSetting('admin_siteaccess', eZSiteInstaller::getParam($parameters, 'admin_siteaccess', '')); // extra siteaccess based on languages info, like 'eng', 'rus', ... $this->addSetting('language_based_siteaccess_list', $this->languageNameListFromLocaleList($this->setting('locales'))); $this->addSetting('user_siteaccess_list', array_merge(array($this->setting('user_siteaccess')), $this->setting('language_based_siteaccess_list'))); $this->addSetting('all_siteaccess_list', array_merge($this->setting('user_siteaccess_list'), array($this->setting('admin_siteaccess')))); $this->addSetting('access_type', eZSiteInstaller::getParam($parameters, 'site_type/access_type', '')); $this->addSetting('access_type_value', eZSiteInstaller::getParam($parameters, 'site_type/access_type_value', '')); $this->addSetting('admin_access_type_value', eZSiteInstaller::getParam($parameters, 'site_type/admin_access_type_value', '')); $this->addSetting('host', eZSiteInstaller::getParam($parameters, 'host', '')); $siteaccessUrls = array('admin' => $this->createSiteaccessUrls(array('siteaccess_list' => array($this->setting('admin_siteaccess')), 'access_type' => $this->setting('access_type'), 'access_type_value' => $this->setting('admin_access_type_value'), 'host' => $this->setting('host'), 'host_prepend_siteaccess' => false)), 'user' => $this->createSiteaccessUrls(array('siteaccess_list' => array($this->setting('user_siteaccess')), 'access_type' => $this->setting('access_type'), 'access_type_value' => $this->setting('access_type_value'), 'host' => $this->setting('host'), 'host_prepend_siteaccess' => false)), 'translation' => $this->createSiteaccessUrls(array('siteaccess_list' => $this->setting('language_based_siteaccess_list'), 'access_type' => $this->setting('access_type'), 'access_type_value' => $this->setting('access_type_value') + 1, 'host' => $this->setting('host'), 'exclude_port_list' => array($this->setting('admin_access_type_value'), $this->setting('access_type_value'))))); $this->addSetting('siteaccess_urls', $siteaccessUrls); $this->addSetting('primary_language', eZSiteInstaller::getParam($parameters, 'all_language_codes/0', '')); $this->addSetting('var_dir', eZSiteInstaller::getParam($parameters, 'var_dir', 'var/' . $this->setting('user_siteaccess'))); }
/** * Regression test for issue #15155 * * @link http://issues.ez.no/15155 */ public function testIssue15155() { // figure out the max versions for images $contentINI = eZINI::instance('content.ini'); $versionlimit = $contentINI->variable('VersionManagement', 'DefaultVersionHistoryLimit'); $limitList = eZContentClass::classIDByIdentifier($contentINI->variable('VersionManagement', 'VersionHistoryClass')); $classID = 5; // image class, can remain hardcoded, I guess foreach ($limitList as $key => $value) { if ($classID == $key) { $versionlimit = $value; } } if ($versionlimit < 2) { $versionlimit = 2; } $baseImagePath = dirname(__FILE__) . '/ezimagealiashandler_regression_issue15155.png'; $parts = pathinfo($baseImagePath); $imagePattern = $parts['dirname'] . DIRECTORY_SEPARATOR . $parts['filename'] . '_%s_%d.' . $parts['extension']; $toDelete = array(); // Create version 1 $imagePath = sprintf($imagePattern, md5(1), 1); copy($baseImagePath, $imagePath); $toDelete[] = $imagePath; $image = new ezpObject('image', 43); $image->name = __FUNCTION__; $image->image = $imagePath; $image->publish(); $image->refresh(); $contentObjectID = $image->object->attribute('id'); $dataMap = eZContentObject::fetch($contentObjectID)->dataMap(); $originalAliases[1] = $image->image->imageAlias('original'); for ($i = 2; $i <= 20; $i++) { // Create a new image file $imagePath = sprintf($imagePattern, md5($i), $i); copy($baseImagePath, $imagePath); $toDelete[] = $imagePath; $newVersion = $image->createNewVersion(); $dataMap = $newVersion->dataMap(); $dataMap['image']->fromString($imagePath); ezpObject::publishContentObject($image->object, $newVersion); $image->refresh(); $originalAliases[$i] = $image->image->imageAlias('original'); if ($i > $versionlimit) { $removeVersion = $i - $versionlimit; $aliasPath = $originalAliases[$removeVersion]['url']; $this->assertFalse(file_exists($aliasPath), "Alias {$aliasPath} for version {$removeVersion} should have been removed"); } } array_map('unlink', $toDelete); $image->purge(); }
function &classAttributes() { if (isset($this->ClassID) and $this->ClassID) { $contentClass = eZContentClass::fetch($this->ClassID); if ($contentClass) { $attributes = $contentClass->fetchAttributes(); } else { $attributes = null; } } else { $attributes = null; } return $attributes; }
public static function getAllClassesXML() { $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = true; $root = $dom->createElement('classes'); $dom->appendChild($root); $classes = eZContentClass::fetchList(); foreach ($classes as $class) { $classNode = eZContentClassPackageHandler::classDOMTree($class); $classNode = $dom->importNode($classNode, true); $root->appendChild($classNode); } return $dom; }
public static function getObjectsWithCollectedInformation($offset = 0, $limit = 10) { $db = eZDB::instance(); $objects = $db->arrayQuery('SELECT DISTINCT ezinfocollection.contentobject_id, ezcontentobject.name, ezcontentobject_tree.main_node_id, ezcontentclass.*, ezcontentclass.identifier AS class_identifier FROM ezinfocollection, ezcontentobject, ezcontentobject_tree, ezcontentclass WHERE ezinfocollection.contentobject_id=ezcontentobject.id AND ezcontentobject.contentclass_id=ezcontentclass.id AND ezinfocollection.contentobject_id=ezcontentobject_tree.contentobject_id', array('limit' => (int) $limit, 'offset' => (int) $offset)); foreach (array_keys($objects) as $i) { $collections = eZInformationCollection::fetchCollectionsList((int) $objects[$i]['contentobject_id'], false, false, false, false, false); $class = new eZContentClass($objects[$i]); $objects[$i]['class_name'] = $class->attribute('name'); $first = $collections[0]['created']; $last = $first; for ($j = 0; $j < count($collections); $j++) { $current = $collections[$j]['created']; if ($current < $first) { $first = $current; } if ($current > $last) { $last = $current; } } $objects[$i]['first_collection'] = $first; $objects[$i]['last_collection'] = $last; $objects[$i]['collections'] = count($collections); } return $objects; }
/** * Unit test for eZContentClass::versionHistoryLimit() with object parameters * * Replica of testVersionHistoryLimit() but you cannot make calls * to the eZ API which relies on a database, as this is not present * in the provider methods. */ public function testVersionHistoryLimitWithObjectParameter() { // different custom limits (article: 13, image: 6) and object as a parameter $INISettings = array(array('VersionHistoryClass', array('article' => 13, 'image' => 6))); $class = eZContentClass::fetchByIdentifier('image'); $expectedLimit = 6; // change the INI limit settings foreach ($INISettings as $settings) { list($INIVariable, $INIValue) = $settings; ezpINIHelper::setINISetting('content.ini', 'VersionManagement', $INIVariable, $INIValue); } $limit = eZContentClass::versionHistoryLimit($class); self::assertEquals($expectedLimit, $limit); ezpINIHelper::restoreINISettings(); }
private function updateContentObject(eZContentObject $eZContentObject) { $mainNodeID = $eZContentObject->mainNodeID(); $parentNodeID = eZContentObjectTreeNode::getParentNodeId($mainNodeID); $classIdentifier = $eZContentObject->ClassIdentifier; $remoteID = $eZContentObject->RemoteID; if (!eZContentClass::fetchByIdentifier($classIdentifier)) { throw new Exception("La classe" . $classIdentifier . "non esiste in questa installazione"); } $params = array(); $params['class_identifier'] = $classIdentifier; $params['remote_id'] = $remoteID; $params['parent_node_id'] = $parentNodeID; $params['attributes'] = $this->getAttributesStringArray($eZContentObject); $result = eZContentFunctions::updateAndPublishObject($eZContentObject, $params); return $result; }
function modify( $tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters ) { $parentNodeID = $namedParameters['parent_node_id']; switch ( $operatorName ) { case 'ezkeywordlist': { include_once( 'lib/ezdb/classes/ezdb.php' ); $db = eZDB::instance(); if( $parentNodeID ) { $node = eZContentObjectTreeNode::fetch( $parentNodeID ); if ( $node ) $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute( 'path_string' ) . "%'"; $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int)$parentNodeID; } $limitation = false; $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( eZContentObjectTreeNode::getLimitationList( $limitation ) ); // eZContentObjectTreeNode::classIDByIdentifier() might need to be used for eZ Publish < 4.1 $classIDs = eZContentClass::classIDByIdentifier( $namedParameters['class_identifier'] ); $operatorValue = $db->arrayQuery( "SELECT DISTINCT ezkeyword.keyword FROM ezkeyword JOIN ezkeyword_attribute_link ON ezkeyword.id = ezkeyword_attribute_link.keyword_id JOIN ezcontentobject_attribute ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id JOIN ezcontentobject ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id JOIN ezcontentobject_name ON ezcontentobject.id = ezcontentobject_name.contentobject_id JOIN ezcontentobject_tree ON ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version $sqlPermissionChecking[from] WHERE " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' ) . " AND " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . ( empty( $classIDs ) ? '' : ( ' AND ' . $db->generateSQLINStatement( $classIDs, 'ezkeyword.class_id' ) ) ) . " $pathString $parentNodeIDSQL " . ( $namedParameters['depth'] > 0 ? ("AND ezcontentobject_tree.depth=" . (int)$namedParameters['depth']) : '' ) . " " . eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ) . " $sqlPermissionChecking[where] ORDER BY ezkeyword.keyword ASC" ); } break; } }
function getClassConstraintListAsArray($class_identifier = false, $contentclass_id = false, $debug = false) { //todo debug if (!$contentclass_id && !$class_identifier) { return; } if ($contentclass_id && $class_identifier) { return; } $ezobjectrelationlist = eZContentClassAttribute::fetchFilteredList(array('data_type_string' => 'ezobjectrelationlist')); $return = array(); if ($contentclass_id) { foreach ($ezobjectrelationlist as $attribute) { if ($attribute->attribute('contentclass_id') == $contentclass_id) { $attributeContent = $attribute->content(); if (!empty($attributeContent['class_constraint_list'])) { $return = array_merge($return, $attributeContent['class_constraint_list']); } } } if (!empty($return)) { return $return; } else { return false; } } if ($class_identifier) { foreach ($ezobjectrelationlist as $attribute) { $attributeContent = $attribute->content(); if (!empty($attributeContent['class_constraint_list'])) { if (in_array($class_identifier, $attributeContent['class_constraint_list'])) { $class = eZContentClass::fetch($attribute->attribute('contentclass_id')); $classIdentifier = eZContentClass::classIdentifierByID($attribute->attribute('contentclass_id')); $return[$classIdentifier][] = array('class_id' => $attribute->attribute('contentclass_id'), 'class_name' => $class->attribute('name'), 'attribute_identifier' => $attribute->attribute('identifier'), 'attribute_name' => $attribute->attribute('name'), 'class_constraint_list' => $attributeContent['class_constraint_list'], 'search_filter' => $classIdentifier . '/' . $attribute->attribute('identifier') . '/main_node_id'); } } } //eZDebug::writeNotice( $return, __METHOD__ ); if (!empty($return)) { return $return; } else { return false; } } return false; }