public function tag($type = FALSE, $tags = '', $item_id = NULL, $category_id = NULL) { if (!$type) { return FALSE; } if (!isset($this->tag_types[$type])) { $this->tag_types = array_merge($this->tag_types, $this->ci->tag_type_m->get(array('name' => $type, 'array_key' => 'name'))); } $tag_type = $this->tag_types[$type]; $return_tag_ids = array(); if ($tags !== '') { // Check if tag type requires any chars to be removed if (isset($tag_type['remove_chars'])) { // Format remove chars to support replacement $removes = explode('\',', substr($tag_type['remove_chars'], 1, -1)); $tags = str_replace($removes, '', (string) $tags); } // Explode tag string by predefined delimiter $ex = explode($tag_type['delimiter'], $tags); foreach ($ex as $k => $tag) { // Check store's cache before asking DB if (array_key_exists($tag, $this->_tag_cache)) { $otag = $this->_tag_cache[$tag]; } else { $otag = $this->ci->tag_m->get(array('value' => $tag, 'single' => TRUE)); } if ($otag !== FALSE) { //$price = $this->ci->price_m->get(array('id'=>$otag['price_id'])); $this->ci->tag_m->update(array('numItems' => $otag['numItems'] + 1), array('id' => $otag['id'])); $tag_id = $otag['id']; // $this->_tag_cache[$otag['value']] = array('id'=>$tag_id,'numItems'=>$otag['numItems']+1); } else { // Set up a base price grouping for the tag $price_id = $this->ci->price_m->insert(array('min' => '0.00')); // Add the tag and link it to its new price grouping $tag_id = $this->ci->tag_m->insert(array('value' => $tag, 'tag_type_id' => $tag_type['id'], 'price_id' => $price_id)); $this->_tag_cache[$tag] = array('id' => $tag_id, 'numItems' => 1); } $return_tag_ids[] = $tag_id; parent::linkItemToTag($item_id, $tag_id); } return $return_tag_ids; //$this->tag_group($ex); } return array(); }