public function testGetTypeDir() { $storage = $this->getMock('Newscoop\\Storage', array('isDir'), array('')); $storage->expects($this->once())->method('isDir')->with($this->equalTo('item'))->will($this->returnValue(TRUE)); $item = new Item('item', $storage); $this->assertEquals('dir', $item->getType()); }
public function testNewItem() { $type = "test type"; $name = "test name"; $number = "test number"; $quantity = "test quantity"; $item = new Item($type, $name, $number, $quantity); $this->assertEquals($name, $item->getName()); $this->assertEquals($number, $item->getNumber()); $this->assertEquals($type, $item->getType()); $this->assertEquals($quantity, $item->getQuantity()); }
/** * Remove item by it Id * @param Item $item */ public function removeById($item) { $tbl = $this->_jbtables->getIndexTable($item->getType()->id); // remove form general index tables if ($tbl && $this->_jbtables->isTableExists($tbl)) { $delete = $this->_getSelect()->delete($this->app->jbtables->getIndexTable($item->getType()->id))->where('item_id = ?', (int) $item->id); $this->_dbHelper->query((string) $delete); } // remove from sku index table $delete = $this->_getSelect()->delete(ZOO_TABLE_JBZOO_SKU)->where('item_id = ?', (int) $item->id); $this->_dbHelper->query((string) $delete); }
/** * Get from item user data * @param Item $item * @return array */ public function getItemUser(Item $item) { $result = array(); $type = $item->getType(); $params = JBModelConfig::model()->getGroup('export.items'); $i = 0; foreach ($type->getElements() as $identifier => $element) { if ($element instanceof ElementJBPrice && !(int) $params->get('fields_full_price')) { continue; } $element->setItem($item); $csvItem = $this->_csvcell->createItem($element, $item, 'user'); $data = $csvItem->toCSV(); if ($data != JBCSVMapperHelper::FIELD_CONTINUE) { $name = $element->config->get('name'); $name = $name ? $name : $element->getElementType(); $name = $name . ' (#' . ++$i . ')'; $result[$name] = (array) $data; } } return $result; }
/** * Get all item from database * @param Item $item * @param Array $data * @param Int $searchMethod * @param Array $params * @return array */ protected function _getFromDatabase(Item $item, $data, $searchMethod, $params) { $selects = array(); $itemType = $item->getType()->id; $tableName = $this->_jbtables->getIndexTable($itemType, 'str'); $columns = $this->_jbtables->getFields($this->_jbtables->getIndexTable($item->getType()->id)); $columns = array_merge($columns, array($this->_jbtables->getFieldName('_itemname'), $this->_jbtables->getFieldName('_itemtype'), $this->_jbtables->getFieldName('_itemcategory'), $this->_jbtables->getFieldName('_itemfrontpage'))); foreach ($data as $elementId => $elemValues) { // no empty values $elemValues = $this->_toCleanArray((array) $elemValues, $searchMethod); if (is_null($elemValues)) { continue; } // check exists fields if (!in_array($elementId, $columns, true)) { continue; } // create empty SQL query $select = $this->_getItemSelect(null, null, 0)->clear('select')->select('tItem.id AS id')->where('tItem.id <> ?', $item->id); // set application if ((int) $params->get('check_app', 0)) { $select->where('tItem.application_id = ?', $item->application_id); } // set item type if ((int) $params->get('check_type', 0)) { $typeKey = $this->_jbtables->getFieldName('_itemtype'); $customTypes = isset($data[$typeKey]) ? $data[$typeKey] : array(); $customTypes = $this->_toCleanArray((array) $customTypes); if (!empty($customTypes)) { $select->where('tItem.type IN (' . implode(',', $customTypes) . ')'); } else { $select->where('tItem.type = ?', $item->getType()->id); } } if ($elementId == $this->_jbtables->getFieldName('_itemname')) { $tableFieldName = 'tItem.name'; } else { if ($elementId == $this->_jbtables->getFieldName('_itemtype')) { $tableFieldName = 'tItem.type'; } else { if ($elementId == $this->_jbtables->getFieldName('_itemtag')) { $select->leftJoin(ZOO_TABLE_TAG . ' AS tTag ON tTag.item_id = tItem.id'); $tableFieldName = 'tTag.name'; } else { if ($elementId == $this->_jbtables->getFieldName('_itemcategory')) { $select->leftJoin(ZOO_TABLE_CATEGORY_ITEM . ' AS tCategoryItem ON tCategoryItem.item_id = tItem.id'); $cleanVavlue = (int) str_replace("'", '', $elemValues[0]); if ($cleanVavlue) { $tableFieldName = 'tCategoryItem.category_id'; } else { $select->leftJoin(ZOO_TABLE_CATEGORY . ' AS tCategory ON tCategoryItem.category_id = tCategory.id'); $tableFieldName = 'tCategory.name'; } } else { if ($elementId == $this->_jbtables->getFieldName('_itemfrontpage')) { $select->leftJoin(ZOO_TABLE_CATEGORY_ITEM . ' AS tCategoryItem ON tCategoryItem.item_id = tItem.id'); $tableFieldName = 'tCategoryItem.category_id'; $elemValues = array(0); } else { $select->leftJoin($tableName . ' AS tIndex ON tIndex.item_id = tItem.id'); $tableFieldName = 'tIndex.' . $elementId; } } } } } $conds = array(); foreach ($elemValues as $elemValue) { if ($searchMethod == 1) { $conds[] = $tableFieldName . ' = ' . $elemValue; } else { $conds[] = $this->_buildLikeBySpaces($elemValue, $tableFieldName); } } if (!empty($conds)) { $select->where('(' . implode(' OR ', $conds) . ')'); } $selects[] = $select->__toString(); } if (!empty($selects)) { $union = '(' . implode(') UNION ALL (', $selects) . ')'; $allSelect = $this->_getSelect()->select('tAll.id')->select('COUNT(tAll.id) AS count')->from('(' . $union . ') AS tAll')->group('tAll.id')->order('count DESC')->limit((int) $params->get('count', 4)); $relevant = (int) $params->get('relevant', 5); if ($relevant > 0) { $allSelect->having('count >= ?', $relevant); } // clean query for optimization $db = JFactory::getDbo(); $db->setQuery($allSelect); $rows = $db->loadAssocList(); return $rows; } return array(); }