/** * Get $iLimit products from the category. * * @param Category $oCategory category. * @param int $iLimit limit to get * * @return array(Product) products from categories. */ public static function getAllFromCategory(Category $oCategory, $iLimit = false) { $sQuery = 'select * from product p, product_category pc '; $sQuery .= ' where pc.product_id = p.id'; $sQuery .= ' and pc.category_id = ' . $oCategory->getId(); $aProducts = array(); foreach (DBOperation::getAll($sQuery) as $aProduct) { $aProducts[] = self::convertToObject($aProduct); } if ($iLimit !== false) { $sQuery .= ' limit ' . $iLimit; } // TODO remove if ($iLimit == false) { if (count($aProducts) < $iLimit) { $iMaxSteps = $iLimit - count($aProducts); for ($iStep = 1; $iStep <= $iMaxSteps; $iStep++) { $aProducts[] = $aProducts[0]; } } } return $aProducts; }
public static function update(Category $oCategory) { $sName = addslashes($oCategory->getName()); $sDescription = addslashes($oCategory->getDescription()); $sImage = addslashes($oCategory->getImage()); // get product id $iCategoryId = $oCategory->getId(); $sQuery = "update category "; $sQuery .= "set name='{$sName}',description='{$sDescription}',image='{$sImage}'"; $sQuery .= " where id = {$iCategoryId}"; $bSuccess = DBOperation::exec($sQuery); if (!$bSuccess) { return false; } return true; }