Создание информационного элемента

#
Создание информационного элемента
Доброй ночи!
Подскажите пожалуйста, как для определенной информационной системы, создать информационный элемент?
Если в HostCMS 5 это можно было сделать как то так:  

$InformationSystem = new InformationSystem();
$param = array();
$param['information_systems_id'] = 20;
$param['information_items_date'] = '2008-03-14 11:28:12';
$param['information_items_name'] = 'Тестовый элемент';
$param['information_items_description'] = 'Описание тестового элемента ...';
$param['information_items_text'] = 'Текст тестового элемента ...';
$InformationSystem->InsertInformationItem($param);

то как это сделать в 6й версии? Пример кода взят отсюда
Модератор
#
Re: Создание информационного элемента
ORM Вам в помощь: http://www.hostcms.ru/documentation/modules/core/orm/
Если не будет получаться, то покажите Ваш код, будем разбираться вместе.
#
Re: Создание информационного элемента
HostCMS, Спасибо большое!
Я сделал вот так:

$News = Core_Entity::factory('Informationsystem_Item');
$News->informationsystem_id = 20;
$News->id = 001;
$News->name = 'Имя инфо элемента';
$News->description = 'Описание. посмотрим что выйдет';
$News->active = '1';
$News->text = 'Рано еще что то писать здесь';
$News->save();
$News->queryBuilder()
->where('informationsystem_items.informationsystem_id', '=', 20);

$News = $News->findAll();

echo '<pre>';
print_r($News);
echo  '</pre>';

И в итоге получилось то, что нужно. Информационный элемент создался. Но все ли я сделал грамотно?
Модератор
#
Re: Создание информационного элемента
1) $News->id = 001; - не нужно указывать ID, он будет присвоен автоматически.
2) Кроме ->save() можно пользоваться методом ->add() при наличии объекта самой ИС.

$oInformationsystem = Core_Entity::factory('Informationsystem', 20);

$oInformationsystem_Item = Core_Entity::factory('Informationsystem_Item');
$oInformationsystem_Item->name = 'Имя инфо элемента';
$oInformationsystem_Item->description = 'Описание. посмотрим что выйдет';
$oInformationsystem_Item->active = '1';
$oInformationsystem_Item->text = 'Рано еще что то писать здесь';

// Здесь $oInformationsystem_Item будет присвоен informationsystem_id и далее он будет сохранен!
$oInformationsystem->add($oInformationsystem_Item);

// Получаем все элементы из ИС с номером 20
$aInformationsystem_Items = $oInformationsystem->Informationsystem_Items->findAll();

echo '<pre>';
print_r($aInformationsystem_Items);
echo  '</pre>';
Вы только что начали читать предложение, чтение которого вы уже заканчиваете.
#
Re: Создание информационного элемента
alexander.egorov,
А если ещё нужно прикрепить картинку с POST запроса, как это будет выглядеть?
skype: mcross82
#
Re: Создание информационного элемента
А все, сам разобрался.
      
$oInformationsystem = Core_Entity::factory('Informationsystem', 20);

$oInformationsystem_Item = Core_Entity::factory('Informationsystem_Item');
$oInformationsystem_Item->name = 'Имя инфо элемента';
$oInformationsystem_Item->description = 'Описание. посмотрим что выйдет';
$oInformationsystem_Item->active = '1';
$oInformationsystem_Item->text = 'Рано еще что то писать здесь';

// Здесь $oInformationsystem_Item будет присвоен informationsystem_id и далее он будет сохранен!
$oInformationsystem->add($oInformationsystem_Item);
$oInformationsystem_Item->createDir();
      $aFileData = Core_Array::getFiles("image", array());

      // New values of property
      if (is_array($aFileData) && isset($aFileData['name']))
      {
         if (Core_File::isValidExtension($aFileData['name'], array('JPG', 'JPEG', 'GIF', 'PNG')))
         {
            try
            {
               $sLargeImageFile = 'information_items' . $oInformationsystem_Item->id . '.' . Core_File::getExtension($aFileData['name']);

               Core_Image::instance()->resizeImage($aFileData['tmp_name'], $oInformationsystem->image_large_max_width, $oInformationsystem->image_large_max_height, $oInformationsystem_Item->getItemPath() . $sLargeImageFile);
               $oInformationsystem_Item->image_large = $sLargeImageFile;
               $oInformationsystem_Item->setLargeImageSizes();

               Core_Image::instance()->resizeImage($aFileData['tmp_name'], $oInformationsystem->image_small_max_width, $oInformationsystem->image_small_max_height, $oInformationsystem_Item->getItemPath() . 'small_'.$sLargeImageFile);
               $oInformationsystem_Item->image_small = 'small_'.$sLargeImageFile;
               $oInformationsystem_Item->setSmallImageSizes();
            }
            catch (Exception $e) {};
         }
      }

      // Вставляем в дополнительные свойства картинку
      //$oProperty = Core_Entity::factory('Property')->find(Core_Page::instance()->libParams['imagePropertyId']);

      $aFileData = Core_Array::getFiles("property_{$oProperty->id}", array());

      // New values of property
      if (is_array($aFileData) && isset($aFileData['name']))
      {
         foreach ($aFileData['name'] as $key => $sFileName)
         {
            $oFileValue = $oProperty->createNewValue($oInformationsystemItems->id);

            if (Core_File::isValidExtension($sFileName, array('JPG', 'JPEG', 'GIF', 'PNG')))
            {
               $oFileValue->file_name = $sFileName;
               $oFileValue->file_small_name = $sFileName;
               $oFileValue->save();

               try
               {
                  $oInformationsystemItems_Property_List->createPropertyDir($oInformationsystemItems);

                  Core_Image::instance()->resizeImage($aFileData['tmp_name'][$key], $oInformationsystemItems->image_large_max_width, $oInformationsystemItems->image_large_max_height, $oInformationsystemItems_Property_List->getDirPath($oInformationsystemItems) . $oInformationsystemItems_Property_List->getLargeFileName($oInformationsystemItems, $oFileValue, $sFileName));

                  $oFileValue->file = $$oInformationsystemItems_Property_List->getLargeFileName($$oInformationsystemItems, $oFileValue, $sFileName);

                  Core_Image::instance()->resizeImage($aFileData['tmp_name'][$key], $oInformationsystemItems->image_small_max_width, $oInformationsystemItems->image_small_max_height, $oInformationsystemItems_Property_List->getDirPath($oInformationsystemItems) . $oInformationsystemItems_Property_List->getSmallFileName($oInformationsystemItems, $oFileValue, $sFileName));

                  $oFileValue->file_small = $oInformationsystemItems_Property_List->getSmallFileName($oInformationsystemItems, $oFileValue, $sFileName);

                  $oFileValue->save();
               }
               catch (Exception $e) {};
            }
         }
      }

}
skype: mcross82
Авторизация