getProductHasTab1sRelatedByProductId(); if (is_array($tab1)) { $ids = array(); foreach($tab1 as $item) { if (is_object($item) && !is_null($item->getCode())) $ids[] = $item->getCode(); } return implode(',',$ids); } return ''; } public static function setProductTab1(Product $object, $value) { $tab1 = $object->getProductHasTab1sRelatedByProductId(); // usuń w przypadku gdy pole puste if (!strlen(trim($value))) { if (is_array($tab1)) { foreach($tab1 as $item) { $item->delete(); } } return ; } $idsNew = explode(',',$value); foreach ($idsNew as $key=>$itemValue) { if (strlen(trim($itemValue))) { $idsNew[$key] = trim($itemValue); } else { unset($idsNew[$key]); } } $ids = array(); if (is_array($tab1)) { foreach($tab1 as $item) { $ids[] = $item->getCode(); } } $old = array_diff($ids, $idsNew); $idsNew = array_unique(array_diff($idsNew, $ids)); foreach($tab1 as $item) { if (array_search($item->getCode(),$old)!== false) { $item->delete(); } } foreach ($idsNew as $id) { $c = new Criteria(); $c->add(ProductPeer::CODE,$id); $tabs1 = ProductPeer::doSelectOne($c); if (is_object($tabs1) && $object->getId()!=$tabs1->getId()) { $tmp = new ProductHasTab1(); $tmp->setProductId($object->getId()); $tmp->setTab1Id($tabs1->getId()); $tmp->save(); } } } public static function getProductTab2(Product $object) { $tab2 = $object->getProductHasTab2sRelatedByProductId(); if (is_array($tab2)) { $ids = array(); foreach($tab2 as $item) { if (is_object($item) && !is_null($item->getCode())) $ids[] = $item->getCode(); } return implode(',',$ids); } return ''; } public static function setProductTab2(Product $object, $value) { $tab2 = $object->getProductHasTab2sRelatedByProductId(); // usuń w przypadku gdy pole puste if (!strlen(trim($value))) { if (is_array($tab2)) { foreach($tab2 as $item) { $item->delete(); } } return ; } $idsNew = explode(',',$value); foreach ($idsNew as $key=>$itemValue) { if (strlen(trim($itemValue))) { $idsNew[$key] = trim($itemValue); } else { unset($idsNew[$key]); } } $ids = array(); if (is_array($tab2)) { foreach($tab2 as $item) { $ids[] = $item->getCode(); } } $old = array_diff($ids, $idsNew); $idsNew = array_unique(array_diff($idsNew, $ids)); foreach($tab2 as $item) { if (array_search($item->getCode(),$old)!== false) { $item->delete(); } } foreach ($idsNew as $id) { $c = new Criteria(); $c->add(ProductPeer::CODE,$id); $tabs2 = ProductPeer::doSelectOne($c); if (is_object($tabs2) && $object->getId()!=$tabs2->getId()) { $tmp = new ProductHasTab2(); $tmp->setProductId($object->getId()); $tmp->setTab2Id($tabs2->getId()); $tmp->save(); } } } public static function getProductTab3(Product $object) { $tab3 = $object->getProductHasTab3sRelatedByProductId(); if (is_array($tab3)) { $ids = array(); foreach($tab3 as $item) { if (is_object($item) && !is_null($item->getCode())) $ids[] = $item->getCode(); } return implode(',',$ids); } return ''; } public static function setProductTab3(Product $object, $value) { $tab3 = $object->getProductHasTab3sRelatedByProductId(); // usuń w przypadku gdy pole puste if (!strlen(trim($value))) { if (is_array($tab3)) { foreach($tab3 as $item) { $item->delete(); } } return ; } $idsNew = explode(',',$value); foreach ($idsNew as $key=>$itemValue) { if (strlen(trim($itemValue))) { $idsNew[$key] = trim($itemValue); } else { unset($idsNew[$key]); } } $ids = array(); if (is_array($tab3)) { foreach($tab3 as $item) { $ids[] = $item->getCode(); } } $old = array_diff($ids, $idsNew); $idsNew = array_unique(array_diff($idsNew, $ids)); foreach($tab3 as $item) { if (array_search($item->getCode(),$old)!== false) { $item->delete(); } } foreach ($idsNew as $id) { $c = new Criteria(); $c->add(ProductPeer::CODE,$id); $tabs3 = ProductPeer::doSelectOne($c); if (is_object($tabs3) && $object->getId()!=$tabs3->getId()) { $tmp = new ProductHasTab3(); $tmp->setProductId($object->getId()); $tmp->setTab3Id($tabs3->getId()); $tmp->save(); } } } public static function getProductTab4(Product $object) { $tab4 = $object->getProductHasTab4sRelatedByProductId(); if (is_array($tab4)) { $ids = array(); foreach($tab4 as $item) { if (is_object($item) && !is_null($item->getCode())) $ids[] = $item->getCode(); } return implode(',',$ids); } return ''; } public static function setProductTab4(Product $object, $value) { $tab4 = $object->getProductHasTab4sRelatedByProductId(); // usuń w przypadku gdy pole puste if (!strlen(trim($value))) { if (is_array($tab4)) { foreach($tab4 as $item) { $item->delete(); } } return ; } $idsNew = explode(',',$value); foreach ($idsNew as $key=>$itemValue) { if (strlen(trim($itemValue))) { $idsNew[$key] = trim($itemValue); } else { unset($idsNew[$key]); } } $ids = array(); if (is_array($tab4)) { foreach($tab4 as $item) { $ids[] = $item->getCode(); } } $old = array_diff($ids, $idsNew); $idsNew = array_unique(array_diff($idsNew, $ids)); foreach($tab4 as $item) { if (array_search($item->getCode(),$old)!== false) { $item->delete(); } } foreach ($idsNew as $id) { $c = new Criteria(); $c->add(ProductPeer::CODE,$id); $tabs4 = ProductPeer::doSelectOne($c); if (is_object($tabs4) && $object->getId()!=$tabs4->getId()) { $tmp = new ProductHasTab4(); $tmp->setProductId($object->getId()); $tmp->setTab4Id($tabs4->getId()); $tmp->save(); } } } }