Exemple #1
0
 /**
  * Возвращает настройки всех полей типа «файл» указанного компонента
  *
  * @param int|string $component_id
  * @return array
  */
 protected function get_all_fields($component_id)
 {
     if (!isset($this->fields_settings[$component_id])) {
         $this->fields_settings[$component_id] = array();
         $component = new nc_component($component_id);
         foreach ($component->get_fields() as $field) {
             if ($field['type'] == NC_FIELDTYPE_FILE) {
                 $this->fields_settings[$component_id][$field['name']] = $field;
             }
         }
     }
     return $this->fields_settings[$component_id];
 }
Exemple #2
0
/**
 * @param int|string $component_id          ID/тип компонента (например: 'User', 'Template', 123)
 * @param int|int[] $object_id_or_ids       ID или массив с ID объектов
 * @param string|null $returned_field_name  Если указано — вернуть значения только для указанного поля
 * @return array|null|nc_multifield
 *    Если $object_ids — массив, то массив с массивом nc_multifield для каждого объекта (ключ — ID объекта).
 *    Если $object_ids — число, то массив с полями для указанного объекта.
 *    Если $object_ids — число и указано $field_name — объект nc_multifile.
 *    Если у компонента нет полей типа MULTIFILE — NULL.
 */
function nc_get_multifile_field_values($component_id, $object_id_or_ids, $returned_field_name = null)
{
    $object_ids = (array) $object_id_or_ids;
    $component = new nc_component($component_id);
    $fields = $component->get_fields(NC_FIELDTYPE_MULTIFILE, false);
    if ($returned_field_name) {
        // fetch data for a single field only
        $returned_field_id = array_search($returned_field_name, $fields);
        $fields = array($returned_field_id => $fields[$returned_field_id]);
    }
    if (!$fields) {
        return null;
    }
    /** @var nc_multifield[][] $results */
    $result = array();
    foreach ($object_ids as $object_id) {
        foreach ($fields as $field_name) {
            $result[$object_id][$field_name] = new nc_multifield($field_name);
        }
    }
    $rows = (array) nc_db()->get_results("SELECT `Field_ID`,\n                `Message_ID`,\n                `Priority`,\n                `Name`,\n                `Size`,\n                `Path`,\n                `Preview`,\n                `ID`\n           FROM `Multifield`\n          WHERE `Message_ID` IN (" . join(",", array_map('intval', $object_ids)) . ")\n            AND `Field_ID` IN (" . join(",", array_keys($fields)) . ")\n          ORDER BY `Priority`", ARRAY_A);
    foreach ($rows as $row) {
        $object_id = $row['Message_ID'];
        $field_name = $fields[$row['Field_ID']];
        $result[$object_id][$field_name]->add_record($row);
    }
    if (!is_array($object_id_or_ids)) {
        if ($returned_field_name) {
            return $result[$object_id_or_ids][$returned_field_name];
        } else {
            return $result[$object_id_or_ids];
        }
    } else {
        return $result;
    }
}
Exemple #3
0
/**
 *
 * @global type $db
 * @global type $nc_core
 * @param string $type - Тип поля - поле системной таблицы, поле виджета, поле компонента
 * @param type $FieldID
 * @param type $Id
 * @param type $systemTableId
 * @return array $options - Массив значения для выпадающего списка
 */
function GetTransliterateOptions($type = '', $FieldID = 0, $Id = 0, $systemTableId = 0)
{
    global $db, $nc_core;
    $options = array();
    switch ($type) {
        case "system":
            if ($FieldID == 0) {
                //add new field to system table
                $systemTableId = $Id;
            }
            $component = new nc_component(0, $systemTableId);
            foreach ($component->get_fields() as $field) {
                if ($field['type'] == NC_FIELDTYPE_STRING && $field['id'] != $FieldID) {
                    $options[$field['name']] = $field['description'] != '' ? $field['description'] : $field['name'];
                }
            }
            break;
        case "widget":
            //для виджетов пока отключена транслитерация, код ниже полностью рабочий
            /*
                  if ($FieldID == 0) {
             $Widget_Class_ID = $Id;
                  } else {
             $sql = "SELECT `Widget_Class_ID` FROM `Field` WHERE `Field_ID` = {$FieldID} LIMIT 1";
             $Widget_Class_ID = $db->get_var($sql);
                  }
                  $results = $db->get_results(
                   "SELECT `Field_ID` as `id`,
                                 `Field_Name` as `name`,
                                 `TypeOfData_ID` as `type`,
                                 `Description` AS `description`
                            FROM `Field`
                           WHERE `Checked` = 1  AND `Widget_Class_ID` = '" . $Widget_Class_ID . "' ORDER BY `Priority`", ARRAY_A);
            
                  foreach ($results as $res) {
             if ($res['type'] == NC_FIELDTYPE_STRING && $res['id'] != $FieldID) {
               $options[$res['name']] = $res['description'] != '' ? $res['description'] : $res['name'];
             }
                  }
            */
            break;
        default:
            $options = array('Keyword' => CONTROL_CONTENT_SUBDIVISION_FUNCS_MAINDATA_KEYWORD);
            if ($FieldID > 0) {
                $sql = "SELECT `Class_ID` FROM `Field` WHERE Field_ID='" . $FieldID . "' LIMIT 1";
                $result = $db->get_row($sql, ARRAY_A);
                $classId = $result['Class_ID'];
            } else {
                //add new field to component
                $classId = $Id;
            }
            $component = $nc_core->get_component($classId);
            foreach ($component->get_fields() as $field) {
                if ($field['type'] == NC_FIELDTYPE_STRING && $field['id'] != $FieldID) {
                    $options[$field['name']] = $field['description'] != '' ? $field['description'] : $field['name'];
                }
            }
            break;
    }
    return $options;
}