/** * findOne can be called in several ways. * * Primary key mode: pass find() a single primary key, and it will return a * single object matching that primary key. * * If you pass findOne() no arguments, the first object of this type will be * returned. * * If you pass findOne() an associative array, it will be turned into a * Horde_Rdo_Query object. * * If you pass findOne() a Horde_Rdo_Query, it will return the first object * matching that query. */ public function findOne($arg = null) { if (is_null($arg)) { $query = null; } elseif (is_scalar($arg)) { $query = array($this->primaryKey => $arg); } else { $query = $arg; } // Build a full Query object, and limit it to one result. $query = Horde_Rdo_Query::create($query, $this); $query->limit(1); $list = new Horde_Rdo_List($query); return $list->current(); }
public function testLimit() { $query = Horde_Rdo_Query::create(4, $this->mapper); $query->limit(10); $this->assertEquals(array('SELECT horde_rdo_test.id, horde_rdo_test.intprop, horde_rdo_test.textprop FROM horde_rdo_test WHERE horde_rdo_test."id" = ? LIMIT 10', array(4)), $query->getQuery()); $query->limit(10, 20); $this->assertEquals(array('SELECT horde_rdo_test.id, horde_rdo_test.intprop, horde_rdo_test.textprop FROM horde_rdo_test WHERE horde_rdo_test."id" = ? LIMIT 20, 10', array(4)), $query->getQuery()); }
/** * Removes categories from a particular stock item. * * @param integer $stock_id The numeric ID of the stock item to update. * @param array $categories The array of categories to remove. * * @return integer the number of categories removed * @throws Sesha_Exception */ public function clearPropertiesForStock($stock_id, $categories = array()) { if ($stock_id instanceof Sesha_Entity_Stock) { $stock_id = $stock_id->stock_id; } if (!is_array($categories)) { $categories = array(0 => array('category_id' => $categories)); } /* Get list of properties for this set of categories. */ try { $properties = $this->getPropertiesForCategories($categories); } catch (Horde_Db_Exception $e) { throw new Sesha_Exception($e); } $vm = $this->_mappers->create('Sesha_Entity_ValueMapper'); $query = Horde_Rdo_Query::create(array('stock_id' => $stock_id), $vm); $query->addTest(array('field' => 'property_id', 'test' => 'IN', 'value' => array_keys($properties))); $count = 0; foreach ($vm->find($query) as $value) { $value->delete(); $count++; } return $count; }
/** * Implementation of the offsetGet() method for ArrayAccess * This method is executed when using isset() or empty() on Horde_Rdo_List objects * @param integer $offset The offset to retrieve. * * @return Horde_Rdo_Base An entity object at the offset position or null */ public function offsetGet($offset) { $query = Horde_Rdo_Query::create($this->_query); $query->limit(1, $offset); return $this->_mapper->find($query)->current(); }