private static function ProcessCustomField(array $p_comparisonOperation, $p_languageId = null) { global $g_ado_db; $fieldName = $p_comparisonOperation['left']; $fieldParts = preg_split('/\./', $fieldName); if (count($fieldParts) > 1) { $fieldName = $fieldParts[1]; $articleType = $fieldParts[0]; $field = new ArticleTypeField($articleType, $fieldName); if (!$field->exists()) { return null; } $fields = array($field); } else { $articleType = null; $fields = ArticleTypeField::FetchFields($fieldName, $articleType, null, false, false, false, true, true); if (count($fields) == 0) { return null; } } $queries = array(); foreach ($fields as $fieldObj) { $query .= ' SELECT NrArticle FROM `X' . $fieldObj->getArticleType() . '` WHERE ' . $fieldObj->getName() . ' ' . $p_comparisonOperation['symbol'] . " '" . $g_ado_db->escape($p_comparisonOperation['right']) . "'"; if (!is_null($p_languageId)) { $query .= " AND IdLanguage = '" . $g_ado_db->escape($p_languageId) . "'"; } $query .= "\n"; $queries[] = $query; } if (count($queries) == 0) { return null; } return implode(" union\n", $queries); }
/** * Saves the ordering of all the fields. Accepts an NUMERIC array of * ORDERRANK => FIELDNAME. (see getOrders) * * @param array orderArray */ public function setOrders($orderArray) { global $g_ado_db; foreach ($orderArray as $order => $field) { $field = new ArticleTypeField($this->m_data['type_name'], $field); if ($field->exists()) { $field->setProperty('field_weight', $order); } } }
if (!SecurityToken::isValid()) { camp_html_display_error($translator->trans('Invalid security token!')); exit; } // Check permissions if (!$g_user->hasPermission('ManageArticleTypes')) { camp_html_display_error($translator->trans("You do not have the right to reassign article type fields.", array(), 'article_type_fields')); exit; } $articleTypeName = Input::Get('f_article_type'); $fieldName = trim(Input::Get('f_field_name')); $fieldType = trim(Input::Get('f_article_field_type')); $field = new ArticleTypeField($articleTypeName, $fieldName); $correct = true; $errorMsgs = array(); if (!$field->exists()) { $errorMsgs[] = $translator->trans('The field $1 does not exist.', array('$1' => '<B>' . urlencode($fieldName) . '</B>'), 'article_type_fields'); $correct = false; } if (array_search($fieldType, $field->getConvertibleToTypes()) === false) { $errorMsgs[] = $translator->trans('Can not convert the field $1 from $2 to type $3.', array('$1' => $fieldName, '$2' => $field->getType(), '$3' => $fieldType), 'article_type_fields'); $correct = false; } if ($correct) { $field->setType($fieldType); $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheService->clearNamespace('article_type'); camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName)); } $crumbs = array(); $crumbs[] = array($translator->trans('Configure'), "");
if (!$valid) { $correct = false; $errorMsgs[] = getGS('The $1 field may only contain letters and underscore (_) character.', '<B>' . getGS('Name') . '</B>'); } if ($correct) { $old_articleTypeField = new ArticleTypeField($articleTypeName, $f_oldName); if (!$old_articleTypeField->exists()) { $correct = false; $errorMsgs[] = getGS('The field $1 does not exist.', '<B>'.htmlspecialchars($f_oldName).'</B>'); } } if ($correct) { $articleTypeField = new ArticleTypeField($articleTypeName, $f_name); if ($articleTypeField->exists()) { $correct = false; $errorMsgs[] = getGS('The field $1 already exists.', '<B>'. htmlspecialchars($f_name). '</B>'); } } if ($correct) { $article = new MetaArticle(); if ($article->has_property($f_name) || method_exists($article, $f_name)) { $correct = false; $errorMsgs[] = getGS("The property '$1' is already in use.", $f_name); } } if ($correct) { $old_articleTypeField->rename($f_name);
$fieldType = trim(Input::Get('f_article_field_type')); $rootTopicId = Input::Get('f_root_topic_id', 'int', 0); $isContent = Input::Get('f_is_content'); $precision = Input::Get('f_precision'); $editorSize = Input::Get('f_editor_size'); $editorSizeCustom = Input::Get('f_editor_size_custom'); $maxsize = Input::Get('f_maxsize'); $eventColor = Input::Get('f_event_color'); $field = new ArticleTypeField($articleTypeName, $fieldName); $correct = true; $errorMsgs = array(); if (!ArticleType::IsValidFieldName($fieldName)) { $errorMsgs[] = $translator->trans('The $1 must not be void and may only contain letters and underscore (_) character.', array('$1' => $translator->trans('Name')), 'article_type_fields'); $correct = false; } if ($field->exists()) { $errorMsgs[] = $translator->trans('The field $1 already exists.', array('$1' => '<B>' . urlencode($fieldName) . '</B>'), 'article_type_fields'); $correct = false; } $validTypes = array_keys(ArticleTypeField::DatabaseTypes()); if (!in_array($fieldType, $validTypes)) { $errorMsgs[] = $translator->trans('Invalid field type.', array(), 'article_type_fields'); $correct = false; } $article = new MetaArticle(); if ($article->has_property($fieldName) || method_exists($article, $fieldName)) { $correct = false; $errorMsgs[] = $translator->trans("The property \$1 is already in use.", array('$1' => $fieldName), 'article_type_fields'); } if ($correct) { if ($editorSize == 'small') {
/** * Action for setting article type filtering. * * @return bool **/ public static function SetTypeFilter($p_article_type, $p_filter_value) { $p_filter_value = (bool) trim('' . $p_filter_value); $field = new ArticleTypeField($p_article_type, 'NULL'); if (!$field->exists()) { return getGS('No such article type'); } $res = $field->setFilter($p_filter_value); if (!$res) { return getGS('Filter not saved'); } return getGS('Filter saved'); }
/** * Action for setting article type filtering. * * @return bool **/ public static function SetTypeFilter($p_article_type, $p_filter_value) { $translator = \Zend_Registry::get('container')->getService('translator'); $p_filter_value = (bool) trim('' . $p_filter_value); $field = new ArticleTypeField($p_article_type, 'NULL'); if (!$field->exists()) { return $translator->trans('No such article type', array(), 'api'); } $res = $field->setFilter($p_filter_value); if (!$res) { return $translator->trans('Filter not saved', array(), 'api'); } return $translator->trans('Filter saved', array(), 'api'); }
/** * Rename the article type. This will move the entire table in the * database and update ArticleTypeMetadata. Usually, one wants to * just rename the Display Name, which is done via SetDisplayName * * @param $p_newName */ public function rename($p_newName) { global $g_ado_db; if (!ArticleType::isValidFieldName($p_newName)) { return false; } $metadata = new ArticleTypeField($p_newName, 'NULL'); if ($metadata->exists()) { return false; } $oldName = $this->m_name; $oldNameEsc = $g_ado_db->escape($this->m_name); $newNameEsc = $g_ado_db->escape($p_newName); $queryStr = "RENAME TABLE `" . $this->m_dbTableName . "` TO `X$p_newName`"; $success = $g_ado_db->Execute($queryStr); if ($success) { $queryStr = "UPDATE ArticleTypeMetadata SET type_name = '$newNameEsc' " . "WHERE type_name = '$oldNameEsc'"; $success = $g_ado_db->Execute($queryStr); } if ($success) { $queryStr = "UPDATE Articles SET Type = '$newNameEsc' WHERE Type = '$oldNameEsc'"; $success = $g_ado_db->Execute($queryStr); } if ($success) { $this->m_name = $p_newName; $this->m_dbTableName = 'X'. $p_newName; if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logText = getGS('The article type "$1" has been renamed to "$2".', $oldName, $p_newName); Log::Message($logText, null, 62); } else { $queryStr = "RENAME TABLE `X$p_newName` TO `" . $this->m_dbTableName . "`"; $g_ado_db->Execute($queryStr); $queryStr = "UPDATE ArticleTypeMetadata SET type_name = '$oldName' " . "WHERE type_name = '$newNameEsc'"; $g_ado_db->Execute($queryStr); $queryStr = "UPDATE Articles SET Type = '$oldName' WHERE Type = '$newNameEsc'"; $g_ado_db->Execute($queryStr); } return $success; } // fn rename