Prev | Current Page 408 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

..
if ($this->_mAction == 'delete_cat')
{
$status = Catalog::DeleteCategory($this->_mActionedCategoryId);
if ($status < 0)
$this->mErrorMessage = 'Category not empty';
else
header('Location: ' .
htmlspecialchars_decode(
$this->mLinkToDepartmentCategoriesAdmin));
}
// If editing category's products ...
if ($this->_mAction == 'edit_prod')
{
header('Location: ' .
htmlspecialchars_decode(
Link::ToCategoryProductsAdmin($this->mDepartmentId,
$this->_mActionedCategoryId)));
exit();
}
// Load the list of categories
$this->mCategories =
Catalog::GetDepartmentCategories($this->mDepartmentId);
$this->mCategoriesCount = count($this->mCategories);
}
}
?>
CHAPTER 10 ?–  CATALOG ADMINISTRATION: DEPARTMENTS AND CATEGORIES 300
3. Now, open presentation/link.php, and add the following method at the end of the Link class:
// Create link to the categories administration page
public static function ToDepartmentCategoriesAdmin($departmentId)
{
$link = 'Page=Categories&DepartmentId=' . $departmentId;
return self::ToAdmin($link);
}
4. Open business/catalog.php to add the following business tier methods to the Catalog class:
// Gets categories in a department
public static function GetDepartmentCategories($departmentId)
{
// Build the SQL query
$sql = 'CALL catalog_get_department_categories(:department_id)';
// Build the parameters array
$params = array (':department_id' => $departmentId);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
// Adds a category
public static function AddCategory($departmentId, $categoryName,
$categoryDescription)
{
// Build the SQL query
$sql = 'CALL catalog_add_category(:department_id, :category_name,
:category_description)';
// Build the parameters array
$params = array (':department_id' => $departmentId,
':category_name' => $categoryName,
':category_description' => $categoryDescription);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Updates a category
public static function UpdateCategory($categoryId, $categoryName,
$categoryDescription)
{
// Build the SQL query
$sql = 'CALL catalog_update_category(:category_id, :category_name,
:category_description)';
CHAPTER 10 ?–  CATALOG ADMINISTRATION: DEPARTMENTS AND CATEGORIES 301
// Build the parameters array
$params = array (':category_id' => $categoryId,
':category_name' => $categoryName,
':category_description' => $categoryDescription);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Deletes a category
public static function DeleteCategory($categoryId)
{
// Build the SQL query
$sql = 'CALL catalog_delete_category(:category_id)';
// Build the parameters array
$params = array (':category_id' => $categoryId);
// Execute the query and return the results
return DatabaseHandler::GetOne($sql, $params);
}
5.


Pages:
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
Wzory Umów java grid monitory komputerowe trzpienie frezarskie black jack