function setParameters($parm_array) { // Make sure no unsupported parameters are specified $supported_parameters = array('state_group', 'state'); $parm_keys = array_keys($parm_array); $unsupported_list = array_diff($parm_keys, $supported_parameters); if (isset($unsupported_list[0])) { return "Unsupported parameter '{$unsupported_list[0]}' in operation"; } // Fetch state id's from the identifiers $state_group = eZContentObjectStateGroup::fetchByIdentifier($parm_array['state_group']); if ($state_group === false) { return 'Missing or illegal state group identifier'; } $state_group_id = $state_group->attribute('id'); $state = eZContentObjectState::fetchByIdentifier($parm_array['state'], $state_group_id); if ($state === false) { return 'Missing or illegal state identifier'; } $this->state_id = $state->attribute('id'); return true; }
<?php /** * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version 2012.8 * @package kernel */ $Module = $Params['Module']; $GroupIdentifier = $Params['GroupIdentifier']; $StateIdentifier = $Params['StateIdentifier']; $LanguageCode = $Params['Language']; $group = eZContentObjectStateGroup::fetchByIdentifier($GroupIdentifier); if (!is_object($group)) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } $state = $group->stateByIdentifier($StateIdentifier); if (!is_object($state)) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } $currentAction = $Module->currentAction(); if ($currentAction == 'Edit') { return $Module->redirectTo("state/edit/{$GroupIdentifier}/{$StateIdentifier}"); } if ($LanguageCode) { $state->setCurrentLanguage($LanguageCode); } $tpl = eZTemplate::factory(); $tpl->setVariable('group', $group); $tpl->setVariable('state', $state); $Result = array('content' => $tpl->fetch('design:state/view.tpl'), 'path' => array(array('url' => false, 'text' => ezpI18n::tr('kernel/state', 'State')), array('url' => 'state/group/' . $group->attribute('identifier'), 'text' => $group->attribute('identifier')), array('url' => false, 'text' => $state->attribute('identifier'))));
<?php /** * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version 2012.6 * @package kernel */ $GroupIdentifier = $Params['GroupIdentifier']; $Module = $Params['Module']; $group = $GroupIdentifier === null ? new eZContentObjectStateGroup() : eZContentObjectStateGroup::fetchByIdentifier($GroupIdentifier); if (!is_object($group)) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } if ($group->isInternal()) { return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } $tpl = eZTemplate::factory(); $currentAction = $Module->currentAction(); if ($currentAction == 'Cancel') { return $Module->redirectTo('state/groups'); } else { if ($currentAction == 'Store') { $group->fetchHTTPPersistentVariables(); $messages = array(); $isValid = $group->isValid($messages); if ($isValid) { $group->store(); if ($GroupIdentifier === null) { return $Module->redirectTo('state/group/' . $group->attribute('identifier')); } else {
/** * Creates an array with sorting SQL strings to be appended to a query * * @param array|bool $sortList * @param string $treeTableName * @param bool $allowCustomColumns * @return array */ static function createSortingSQLStrings($sortList, $treeTableName = 'ezcontentobject_tree', $allowCustomColumns = false) { $sortingInfo = array('sortCount' => 0, 'sortingFields' => " path_string ASC", 'attributeJoinCount' => 0, 'attributeFromSQL' => "", 'attributeTargetSQL' => "", 'attributeWhereSQL' => ""); if ($sortList and is_array($sortList) and count($sortList) > 0) { if (count($sortList) > 1 and !is_array($sortList[0])) { $sortList = array($sortList); } $sortingFields = ''; $sortCount = 0; $attributeJoinCount = 0; $stateJoinCount = 0; $attributeFromSQL = ""; $attributeWhereSQL = ""; $datatypeSortingTargetSQL = ""; foreach ($sortList as $sortBy) { if (is_array($sortBy) and count($sortBy) > 0) { if ($sortCount > 0) { $sortingFields .= ', '; } $sortField = $sortBy[0]; switch ($sortField) { case 'path': $sortingFields .= 'path_string'; break; case 'path_string': $sortingFields .= 'path_identification_string'; break; case 'published': $sortingFields .= 'ezcontentobject.published'; break; case 'modified': $sortingFields .= 'ezcontentobject.modified'; break; case 'modified_subnode': $sortingFields .= 'modified_subnode'; break; case 'section': $sortingFields .= 'ezcontentobject.section_id'; break; case 'node_id': $sortingFields .= $treeTableName . '.node_id'; break; case 'contentobject_id': $sortingFields .= 'ezcontentobject.id'; break; case 'depth': $sortingFields .= 'depth'; break; case 'class_identifier': $sortingFields .= 'ezcontentclass.identifier'; break; case 'class_name': $classNameFilter = eZContentClassName::sqlFilter(); $sortingFields .= 'contentclass_name'; $datatypeSortingTargetSQL .= ", {$classNameFilter['nameField']} AS contentclass_name"; $attributeFromSQL .= " INNER JOIN {$classNameFilter['from']} ON ({$classNameFilter['where']})"; break; case 'priority': $sortingFields .= $treeTableName . '.priority'; break; case 'name': $sortingFields .= 'ezcontentobject_name.name'; break; case 'attribute': $classAttributeID = $sortBy[2]; if (!is_numeric($classAttributeID)) { $classAttributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier($classAttributeID); } $contentAttributeTableAlias = "a{$attributeJoinCount}"; $datatypeFromSQL = "ezcontentobject_attribute {$contentAttributeTableAlias}"; $datatypeWhereSQL = "\n {$contentAttributeTableAlias}.contentobject_id = ezcontentobject.id AND\n {$contentAttributeTableAlias}.contentclassattribute_id = {$classAttributeID} AND\n {$contentAttributeTableAlias}.version = ezcontentobject.current_version AND"; $datatypeWhereSQL .= eZContentLanguage::sqlFilter($contentAttributeTableAlias, 'ezcontentobject'); $dataType = eZDataType::create(eZContentObjectTreeNode::dataTypeByClassAttributeID($classAttributeID)); if (is_object($dataType) && $dataType->customSorting()) { $params = array(); $params['contentobject_attr_id'] = "{$contentAttributeTableAlias}.id"; $params['contentobject_attr_version'] = "{$contentAttributeTableAlias}.version"; $params['table_alias_suffix'] = "{$attributeJoinCount}"; $sql = $dataType->customSortingSQL($params); $datatypeFromSQL .= " INNER JOIN {$sql['from']} ON ({$sql['where']})"; $datatypeSortingFieldSQL = $sql['sorting_field']; $datatypeSortingTargetSQL .= ', ' . $sql['sorting_field']; } else { // Look up datatype for standard sorting $sortKeyType = eZContentObjectTreeNode::sortKeyByClassAttributeID($classAttributeID); switch ($sortKeyType) { case 'string': $sortKey = 'sort_key_string'; break; case 'int': default: $sortKey = 'sort_key_int'; break; } $datatypeSortingFieldSQL = "a{$attributeJoinCount}.{$sortKey}"; $datatypeSortingTargetSQL .= ', ' . $datatypeSortingFieldSQL; } $sortingFields .= "{$datatypeSortingFieldSQL}"; $attributeFromSQL .= " INNER JOIN {$datatypeFromSQL} ON ({$datatypeWhereSQL})"; $attributeJoinCount++; break; case 'state': $stateGroupID = $sortBy[2]; if (!is_numeric($stateGroupID)) { $stateGroup = eZContentObjectStateGroup::fetchByIdentifier($stateGroupID); if ($stateGroup) { $stateGroupID = $stateGroup->attribute('id'); } else { eZDebug::writeError("Unknown content object state group '{$stateGroupID}'"); continue 2; } } $stateAlias = "s{$stateJoinCount}"; $stateLinkAlias = "sl{$stateJoinCount}"; $sortingFields .= "{$stateAlias}.priority"; $datatypeSortingTargetSQL .= ", {$stateAlias}.priority"; $attributeFromSQL .= " INNER JOIN ezcobj_state {$stateAlias} ON ({$stateAlias}.group_id = {$stateGroupID})" . " INNER JOIN ezcobj_state_link {$stateLinkAlias}" . " ON ({$stateLinkAlias}.contentobject_id = ezcontentobject.id AND {$stateLinkAlias}.contentobject_state_id = {$stateAlias}.id)"; break; default: if ($allowCustomColumns) { $sortingFields .= $sortField; } else { eZDebug::writeWarning('Unknown sort field: ' . $sortField, __METHOD__); continue; } } $sortOrder = true; // true is ascending if (isset($sortBy[1])) { $sortOrder = $sortBy[1]; } $sortingFields .= $sortOrder ? " ASC" : " DESC"; ++$sortCount; } } $sortingInfo['sortCount'] = $sortCount; $sortingInfo['sortingFields'] = $sortingFields; $sortingInfo['attributeTargetSQL'] = $datatypeSortingTargetSQL; $sortingInfo['attributeJoinCount'] = $attributeJoinCount; $sortingInfo['attributeFromSQL'] = $attributeFromSQL; $sortingInfo['attributeWhereSQL'] = $attributeWhereSQL; } else { if ($sortList === array()) { $sortingInfo['sortingFields'] = ''; } } return $sortingInfo; }
$scriptSettings = array(); $scriptSettings['description'] = 'Add the ez_lock system state group'; $scriptSettings['use-session'] = true; $scriptSettings['use-modules'] = true; $scriptSettings['use-extensions'] = true; $script = eZScript::instance($scriptSettings); $script->startup(); $config = ''; $argumentConfig = ''; $optionHelp = false; $arguments = false; $useStandardOptions = true; $options = $script->getOptions($config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions); $script->initialize(); eZContentObjectStateGroup::$allowInternalCUD = true; $lockGroup = eZContentObjectStateGroup::fetchByIdentifier('ez_lock'); if ($lockGroup) { $script->shutdown(1, 'ez_lock state group already exists'); } $db = eZDB::instance(); $db->begin(); $locales = eZContentLanguage::fetchLocaleList(); $localeToUse = false; $localeIDToUse = false; // this script inserts English names, so preferably use an English locale $preferredLocales = array('eng-GB', 'eng-US'); foreach ($preferredLocales as $preferredLocale) { if (in_array($preferredLocale, $locales)) { $localeToUse = $preferredLocale; break; }