public function get($args = array()) { global $WPIMLoop; /** * Detect which view, and load the appropriate one */ $default = array('inventory_id' => NULL, 'category_id' => NULL, 'product_id' => NULL, 'category' => NULL, 'order' => 'inventory_number', 'inventory_search' => NULL, 'page' => 0, 'page_size' => self::$config->get('page_size', 20)); if (!is_array($args)) { parse_str($args, $args); } self::$args = wp_parse_args($args, $default); foreach (self::$args as $key => $value) { if (self::request($key)) { self::$args[$key] = self::request($key); } } if (!self::$args['category_id'] && self::$args['category']) { self::$args['category_id'] = self::$args['category']; unset(self::$args['category']); } if (self::$args['category_id'] && !(int) self::$args['category_id']) { $WPIMCategory = new WPIMCategory(); $category = $WPIMCategory->get_id_from_name(self::$args['category_id']); if ($category) { self::$args['category_id'] = $category; } } foreach (self::$filters as $filter => $field) { if (self::request($filter)) { self::$args[$field] = self::request($filter); } } if (self::$args['category_id'] && stripos(self::$args['category_id'], ',')) { self::$args['category_id'] = explode(',', self::$args['category_id']); } if (self::$args['product_id'] && stripos(self::$args['product_id'], ',')) { self::$args['product_id'] = explode(',', self::$args['product_id']); } if (self::$args['order'] && stripos(self::$args['order'], ',')) { self::$args['order'] = explode(',', self::$args['order']); } self::$loop = new WPIMLoop(self::$args); wpinventory_set_loop(self::$loop); self::store_page_state(self::$args['inventory_id']); if (self::$args['inventory_id']) { return self::display_detail(); } else { return self::display_listing(); } }
public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
function wpinventory_get_categories($args = NULL) { $category = new WPIMCategory(); return $category->get_all($args); }
function form($instance) { $default = array('title' => WPIMCore::__('Latest Items'), 'page_id' => '', 'category_id' => '', 'number' => '4'); $instance = wp_parse_args((array) $instance, $default); $WPIMCategories = new WPIMCategory(); $categories = $WPIMCategories->get_all(array('order' => 'sort_order')); $categories_array = array('' => WPIMCore::__('Show All')); foreach ($categories as $cat) { $categories_array[$cat->category_id] = $cat->category_name; } $category_select = WPIMCore::dropdown_array($this->get_field_name('category_id'), $instance['category_id'], $categories_array); echo '<p><label for="' . $this->get_field_name('title') . '">' . WPIMCore::__('Widget Title') . '</label> <input type="text" class="widefat" name="' . $this->get_field_name('title') . '" value="' . $instance['title'] . '" /></p>'; echo '<p><label for="' . $this->get_field_name('number') . '">' . WPIMCore::__('Number of Items') . '</label> <input type="text" class="small-text" name="' . $this->get_field_name('number') . '" value="' . $instance['number'] . '" /></p>'; echo '<p><label for="' . $this->get_field_name('page_id') . '">' . WPIMCore::__('Links to Page') . '</label> ' . wp_dropdown_pages('echo=0&name=' . $this->get_field_name('page_id') . '&selected=' . $instance['page_id'] . '&show_option_none=' . WPIMCore::__('Select...')) . '</p>'; echo '<p><label for="' . $this->get_field_name('category_id') . '">' . WPIMCore::__('Category') . '</label> ' . $category_select . '</p>'; }