コード例 #1
0
 /**
  * Returns a ShopCategory selected by its ID from the database.
  *
  * Returns null if the Category does not exist.
  * @static
  * @param   integer       $category_id  The Shop Category ID
  * @return  ShopCategory                The Shop Category object on success,
  *                                      false on failure, or null otherwise.
  * @global  ADONewConnection  $objDatabase    Database connection object
  * @author  Reto Kohli <*****@*****.**>
  */
 static function getById($category_id)
 {
     global $objDatabase;
     $category_id = intval($category_id);
     if ($category_id <= 0) {
         return null;
     }
     $arrSql = \Text::getSqlSnippets('`category`.`id`', FRONTEND_LANG_ID, 'Shop', array('name' => self::TEXT_NAME, 'description' => self::TEXT_DESCRIPTION));
     $query = "\n            SELECT `category`.`id`,\n                   `category`.`parent_id`,\n                   `category`.`active`,\n                   `category`.`ord`,\n                   `category`.`picture`,\n                   `category`.`flags`, " . $arrSql['field'] . "\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories` AS `category`" . $arrSql['join'] . "\n             WHERE `category`.`id`={$category_id}";
     $objResult = $objDatabase->Execute($query);
     if (!$objResult) {
         return self::errorHandler();
     }
     if ($objResult->EOF) {
         return null;
     }
     $id = $objResult->fields['id'];
     $strName = $objResult->fields['name'];
     if ($strName === null) {
         $objText = \Text::getById($id, 'Shop', self::TEXT_NAME);
         if ($objText) {
             $strName = $objText->content();
         }
     }
     $strDescription = $objResult->fields['description'];
     if ($strDescription === null) {
         $objText = \Text::getById($id, 'Shop', self::TEXT_DESCRIPTION);
         if ($objText) {
             $strDescription = $objText->content();
         }
     }
     //DBG::log("ShopCategory::getById($category_id): Loaded '$strName' / '$strDescription'");
     $objCategory = new ShopCategory($strName, $strDescription, $objResult->fields['parent_id'], $objResult->fields['active'], $objResult->fields['ord'], $category_id);
     $objCategory->picture($objResult->fields['picture']);
     $objCategory->flags($objResult->fields['flags']);
     return $objCategory;
 }
コード例 #2
0
ファイル: ShopManager.class.php プロジェクト: Niggu/cloudrexx
 /**
  * Insert or update a ShopCategory with data provided in the request.
  * @return  boolean                 True on success, null on noop,
  *                                  false otherwise.
  * @author  Reto Kohli <*****@*****.**> (parts)
  */
 function store_category()
 {
     global $_ARRAYLANG;
     if (empty($_POST['bcategory'])) {
         //DBG::log("store_category(): Nothing to do");
         return null;
     }
     $category_id = intval($_POST['category_id']);
     $name = contrexx_input2raw($_POST['name']);
     $active = isset($_POST['active']);
     $virtual = isset($_POST['virtual']);
     $parentid = intval($_POST['parent_id']);
     $picture = contrexx_input2raw($_POST['image_href']);
     $long = contrexx_input2raw($_POST['desc']);
     $objCategory = null;
     if ($category_id > 0) {
         // Update existing ShopCategory
         $objCategory = ShopCategory::getById($category_id);
         if (!$objCategory) {
             return \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_CATEGORY_MISSING'], $category_id));
         }
         // Check validity of the IDs of the category and its parent.
         // If the values are identical, leave the parent ID alone!
         if ($category_id != $parentid) {
             $objCategory->parent_id($parentid);
         }
         $objCategory->name($name);
         $objCategory->description($long);
         $objCategory->active($active);
     } else {
         // Add new ShopCategory
         $objCategory = new ShopCategory($name, $long, $parentid, $active, 0);
     }
     // Ignore the picture if it's the default image!
     // Storing it would be pointless, and we should
     // use the picture of a contained Product instead.
     if ($picture && ($picture == self::$defaultImage || !self::moveImage($picture))) {
         $picture = '';
     }
     $objCategory->picture($picture);
     $objCategory->virtual($virtual);
     if (!$objCategory->store()) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_DATABASE_QUERY_ERROR']);
     }
     if ($picture) {
         //DBG::log("store_category(): Making thumb");
         $objImage = new \ImageManager();
         if (!$objImage->_createThumbWhq(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopPath() . '/', \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/', $picture, \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_width', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_height', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_quality', 'Shop'))) {
             \Message::warning($_ARRAYLANG['TXT_SHOP_ERROR_CREATING_CATEGORY_THUMBNAIL']);
         }
     }
     // Avoid showing/editing the modified ShopCategory again.
     // view_categories() tests the $_REQUEST array!
     unset($_REQUEST['category_id']);
     return \Message::ok($_ARRAYLANG['TXT_SHOP_CATEGORY_STORED_SUCCESSFULLY']);
 }