/**
  * 
  * add item to database from data, init the item on the way by the record.
  * return item id
  */
 public function add($data)
 {
     $catID = UniteFunctionsUG::getVal($data, "catID");
     $type = UniteFunctionsUG::getVal($data, "type");
     $params = "";
     $urlImage = UniteFunctionsUG::getVal($data, "urlImage");
     $urlImage = HelperUG::URLtoRelative($urlImage);
     $urlThumb = UniteFunctionsUG::getVal($data, "urlThumb");
     $urlThumb = HelperUG::URLtoRelative($urlThumb);
     //get max items order
     $items = new UniteGalleryItems();
     $maxOrder = $items->getMaxOrder($catID);
     $arrInsert = array();
     $arrInsert["type"] = $type;
     $arrInsert["published"] = 1;
     $arrInsert["ordering"] = $maxOrder + 1;
     $arrInsert["catid"] = $catID;
     $arrInsert["url_image"] = $urlImage;
     $arrInsert["url_thumb"] = $urlThumb;
     $arrParams = array();
     switch ($type) {
         case self::TYPE_IMAGE:
             $urlImage = UniteFunctionsUG::getVal($data, "urlImage");
             $arrInsert["catid"] = $catID;
             //set params
             $title = HelperUG::getTitleFromUrl($urlImage, $this->itemTitleBase);
             $imageID = UniteFunctionsUG::getVal($data, "imageID", 0);
             $arrInsert["imageid"] = $imageID;
             //get title from attachment
             if (!empty($imageID)) {
                 $data = null;
                 if (method_exists("UniteProviderFunctionsUG", "getImageDataFromImageID")) {
                     $data = UniteProviderFunctionsUG::getImageDataFromImageID($imageID);
                 }
                 //set title from image meta
                 $dataTitle = UniteFunctionsUG::getVal($data, "title");
                 if (!empty($dataTitle)) {
                     $title = $dataTitle;
                 }
                 //set decription from image meta
                 $dataDesc = UniteFunctionsUG::getVal($data, "description");
                 if (!empty($dataDesc)) {
                     $arrParams["ug_item_description"] = $dataDesc;
                 }
             }
             break;
         default:
             //add media item
             $title = UniteFunctionsUG::getVal($data, "title");
             $arrInsert = $this->getAddDataFromMedia($data, $arrInsert);
             break;
     }
     UniteFunctionsUG::validateNotEmpty($title, "title");
     $arrInsert["title"] = $title;
     //add params
     $arrParamsExisting = UniteFunctionsUG::getVal($arrInsert, "params");
     if (is_array($arrParamsExisting)) {
         $arrParams = array_merge($arrParams, $arrParamsExisting);
     }
     $jsonParams = json_encode($arrParams);
     $arrInsert["params"] = $jsonParams;
     //insert the category
     $itemID = $this->db->insert(GlobalsUG::$table_items, $arrInsert);
     $arrInsert["id"] = $itemID;
     $this->initByDBRecord($arrInsert);
     return $itemID;
 }