当前位置: 首页>>代码示例>>PHP>>正文


PHP Catalog::load_categories方法代码示例

本文整理汇总了PHP中Catalog::load_categories方法的典型用法代码示例。如果您正苦于以下问题:PHP Catalog::load_categories方法的具体用法?PHP Catalog::load_categories怎么用?PHP Catalog::load_categories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Catalog的用法示例。


在下文中一共展示了Catalog::load_categories方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Catalog

	/**
	 * Set
	 *
	 * @since 1.1
	 *
	 * @return void Description...
	 **/
	function init_positions () {
		$db =& DB::get();
		// Load the entire catalog structure and update the category positions
		$Catalog = new Catalog();
		$Catalog->outofstock = true;

		$filters['columns'] = "cat.id,cat.parent,cat.priority";
		$Catalog->load_categories($filters);

		foreach ($Catalog->categories as $Category)
			if (!isset($Category->_priority) // Check previous priority and only save changes
					|| (isset($Category->_priority) && $Category->_priority != $Category->priority))
				$db->query("UPDATE $Category->_table SET priority=$Category->priority WHERE id=$Category->id");

	}
开发者ID:robbiespire,项目名称:paQui,代码行数:22,代码来源:Categorize.php

示例2: Catalog

	/**
	 * Updates category slug and rebuilds changed URIs
	 *
	 * Generates the slug if empty. Checks for duplicate slugs
	 * and adds a numeric suffix to ensure a unique slug.
	 *
	 * If the slug changes, the category uri is rebuilt and
	 * and all descendant category uri's are rebuilt and updated.
	 * 
	 * @since 1.1
	 *
	 * @return boolean successfully updated
	 **/
	function update_slug () {
		$db = DB::get();

		if (empty($this->slug)) {
			$name = !empty($_POST['name'])?$_POST['name']:$this->name;
			$this->slug = sanitize_title_with_dashes($name);
		}

		if (empty($this->slug)) return false; // No slug for this category, bail

		$uri = $this->uri;
		$parent = !empty($_POST['parent'])?$_POST['parent']:$this->parent;
		if ($parent > 0) {

			$Catalog = new Catalog();
			$Catalog->load_categories(array(
				'columns' => "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug",
				'where' => array(),
				'joins' => array(),
				'orderby' => false,
				'order' => false,
				'outofstock' => true
			));

			$paths = array();
			if (!empty($this->slug)) $paths = array($this->slug);  // Include self

			$parentkey = -1;
			// If we're saving a new category, lookup the parent
			if ($parent > 0) {
				array_unshift($paths,$Catalog->categories['_'.$parent]->slug);
				$parentkey = $Catalog->categories['_'.$parent]->parent;
			}

			while (isset($Catalog->categories['_'.$parentkey])
					&& $category_tree = $Catalog->categories['_'.$parentkey]) {
				array_unshift($paths,$category_tree->slug);
				$parentkey = '_'.$category_tree->parent;
			}
			if (count($paths) > 1) $this->uri = join("/",$paths);
			else $this->uri = $paths[0];
		} else $this->uri = $this->slug; // end if ($parent > 0)

		// Check for an existing category uri
		$exclude_category = !empty($this->id)?"AND id != $this->id":"";
		$existing = $db->query("SELECT uri FROM $this->_table WHERE uri='$this->uri' $exclude_category LIMIT 1");
		if ($existing) {
			$suffix = 2;
			while($existing) {
				$altslug = preg_replace('/\-\d+$/','',$this->slug)."-".$suffix++;
				$uris = explode('/',$this->uri);
				array_splice($uris,-1,1,$altslug);
				$alturi = join('/',$uris);
				$existing = $db->query("SELECT uri FROM $this->_table WHERE uri='$alturi' $exclude_category LIMIT 1");
			}
			$this->slug = $altslug;
			$this->uri = $alturi;
		}

		if ($uri == $this->uri) return true;

		// Update children uris
		$this->load_children(array(
			'columns' 	=> 'cat.id,cat.parent,cat.uri',
			'where' 	=> array("(cat.uri like '%$uri%' OR cat.parent='$this->id')","cat.id <> '$this->id'")
		));
		if (empty($this->children)) return true;

		$categoryuri = explode('/',$this->uri);
		foreach ($this->children as $child) {
			$childuri = explode('/',$child->uri);
			$changed = reset(array_diff($childuri,$categoryuri));
			array_splice($childuri,array_search($changed,$childuri),1,end($categoryuri));
			$updateduri = join('/',$childuri);
			$db->query("UPDATE $this->_table SET uri='$updateduri' WHERE id='$child->id' LIMIT 1");
		}

	}
开发者ID:robbiespire,项目名称:paQui,代码行数:91,代码来源:Category.php

示例3: ajax

 /**
  * ajax ()
  * Handles AJAX request processing */
 function ajax()
 {
     if (!isset($_REQUEST['action']) || !defined('DOING_AJAX')) {
         return;
     }
     if (isset($_POST['action'])) {
         switch ($_POST['action']) {
             // Upload an image in the product editor
             case "shopp_add_image":
                 $this->Flow->add_images();
                 exit;
                 break;
                 // Upload a product download file in the product editor
             // Upload a product download file in the product editor
             case "shopp_add_download":
                 $this->Flow->product_downloads();
                 exit;
                 break;
         }
     }
     if ((!is_user_logged_in() || !current_user_can('manage_options')) && strpos($_GET['action'], 'wp_ajax_shopp_') !== false) {
         die('-1');
     }
     if (empty($_GET['action'])) {
         return;
     }
     switch ($_GET['action']) {
         // Add a category in the product editor
         case "wp_ajax_shopp_add_category":
             check_admin_referer('shopp-ajax_add_category');
             if (!empty($_GET['name'])) {
                 $Catalog = new Catalog();
                 $Catalog->load_categories();
                 $Category = new Category();
                 $Category->name = $_GET['name'];
                 $Category->slug = sanitize_title_with_dashes($Category->name);
                 $Category->parent = $_GET['parent'];
                 // Work out pathing
                 $paths = array();
                 if (!empty($Category->slug)) {
                     $paths = array($Category->slug);
                 }
                 // Include self
                 $parentkey = -1;
                 // If we're saving a new category, lookup the parent
                 if ($Category->parent > 0) {
                     array_unshift($paths, $Catalog->categories[$Category->parent]->slug);
                     $parentkey = $Catalog->categories[$Category->parent]->parent;
                 }
                 while ($category_tree = $Catalog->categories[$parentkey]) {
                     array_unshift($paths, $category_tree->slug);
                     $parentkey = $category_tree->parent;
                 }
                 if (count($paths) > 1) {
                     $Category->uri = join("/", $paths);
                 } else {
                     $Category->uri = $paths[0];
                 }
                 $Category->save();
                 echo json_encode($Category);
             }
             exit;
             break;
         case "wp_ajax_shopp_edit_slug":
             check_admin_referer('shopp-ajax_edit_slug');
             if (!current_user_can('manage_options')) {
                 die("-1");
             }
             switch ($_REQUEST['type']) {
                 case "category":
                     $Category = new Category($_REQUEST['id']);
                     if (empty($_REQUEST['slug'])) {
                         $_REQUEST['slug'] = $Category->name;
                     }
                     $Category->slug = sanitize_title_with_dashes($_REQUEST['slug']);
                     if ($Category->save()) {
                         echo apply_filters('editable_slug', $Category->slug);
                     } else {
                         echo '-1';
                     }
                     break;
                 case "product":
                     $Product = new Product($_REQUEST['id']);
                     if (empty($_REQUEST['slug'])) {
                         $_REQUEST['slug'] = $Product->name;
                     }
                     $Product->slug = sanitize_title_with_dashes($_REQUEST['slug']);
                     if ($Product->save()) {
                         echo apply_filters('editable_slug', $Product->slug);
                     } else {
                         echo '-1';
                     }
                     break;
             }
             exit;
             break;
             // Upload a product download file in the product editor
//.........这里部分代码省略.........
开发者ID:kennethreitz-archive,项目名称:wordpress-skeleton,代码行数:101,代码来源:Shopp.php

示例4: array

 /**
  * Category flow handlers
  **/
 function categories_list($workflow = false)
 {
     global $Shopp;
     $db = DB::get();
     if (!current_user_can(SHOPP_USERLEVEL)) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $defaults = array('pagenum' => 1, 'per_page' => 20, 's' => '');
     $args = array_merge($defaults, $_GET);
     extract($args, EXTR_SKIP);
     $pagenum = absint($pagenum);
     if (empty($pagenum)) {
         $pagenum = 1;
     }
     if (!$per_page || $per_page < 0) {
         $per_page = 20;
     }
     $start = $per_page * ($pagenum - 1);
     $filters = array();
     // $filters['limit'] = "$start,$per_page";
     if (!empty($s)) {
         $filters['where'] = "cat.name LIKE '%{$s}%'";
     } else {
         $filters['where'] = "true";
     }
     $table = DatabaseObject::tablename(Category::$table);
     $Catalog = new Catalog();
     $Catalog->outofstock = true;
     if ($workflow) {
         $filters['columns'] = "cat.id,cat.parent";
         $results = $Catalog->load_categories($filters, false, true);
         return array_slice($results, $start, $per_page);
     } else {
         $filters['columns'] = "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug,cat.spectemplate,cat.facetedmenus,count(DISTINCT pd.id) AS total";
         $Catalog->load_categories($filters);
         $Categories = array_slice($Catalog->categories, $start, $per_page);
     }
     $count = $db->query("SELECT count(*) AS total FROM {$table}");
     $num_pages = ceil($count->total / $per_page);
     $page_links = paginate_links(array('base' => add_query_arg(array('edit' => null, 'pagenum' => '%#%')), 'format' => '', 'total' => $num_pages, 'current' => $pagenum));
     include "{$this->basepath}/core/ui/categories/categories.php";
 }
开发者ID:kennethreitz-archive,项目名称:wordpress-skeleton,代码行数:45,代码来源:Flow.php

示例5: array

	function category_children () {
		check_admin_referer('wp_ajax_ecart_category_children');

		if (empty($_GET['parent'])) die('0');
		$parent = $_GET['parent'];

		$columns = array('id','parent','priority','name','uri','slug');

		$filters['columns'] = 'cat.'.join(',cat.',$columns);
		$filters['parent'] = $parent;

		$Catalog = new Catalog();
		$Catalog->outofstock = true;
		$Catalog->load_categories($filters);

		$columns[] = 'depth';
		foreach ($Catalog->categories as &$Category) {
			$properties = get_object_vars($Category);
			foreach ($properties as $property => $value)
				if (!in_array($property,$columns)) unset($Category->$property);
		}

		die(json_encode($Catalog->categories));
	}
开发者ID:robbiespire,项目名称:paQui,代码行数:24,代码来源:Ajax.php


注:本文中的Catalog::load_categories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。