/** * List discussions, filtered by various criteria * @params array $filters The array of filters allowed keys * 'state' => array('Y', 'D', 'R') * * Allowed states * Y => OK, * D => Declined * R => awaiting approval * defaults to 'R' - passing an empty array means 'all' * 'category' => The category id to filter for * 'user' => A user's numeric id to filter for */ public function listDiscussions(array $filters = array()) { $filters = array_merge(array('state' => array('Y'), 'limit' => array()), $filters); $dm = $this->_mappers->create('Dolcore_Rdo_DiscussionMapper'); $query = new Horde_Rdo_Query($dm); if ($filters['category']) { $query->addTest('kategorie_id', '=', $filters['category']); } if ($filters['user']) { $query->addTest('benutzer_id', '=', $filters['user']); } if (count($filters['state'])) { $query->addTest('checked', 'IN', $filters['state']); } $query->sortBy('erstelldatum DESC'); return $dm->find($query); }
/** * Authentication handler * * On failure, Horde_Auth_Exception should pass a message string (if any) * in the message field, and the Horde_Auth::REASON_* constant in the code * field (defaults to Horde_Auth::REASON_MESSAGE). * * @param string $userID The userID to check. * @param array $credentials An array of login credentials. * * @throws Horde_Auth_Exception */ protected function _authenticate($userID, $credentials) { $um = $this->_mappers->create('Dolcore_Rdo_UserMapper'); if ($this->exists($userID) == false) { throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN); } $user = $um->findOne(array('nickname' => $userID)); $pass = Horde_Auth::getCryptedPassword($credentials['password'], substr($credentials['password'], 0, 2), 'crypt', false); if ($pass != $user->passwort) { throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN); } return true; }
/** * get any number of pastes from a bin, ordered by date, narrowed by limit and offset * @param string $bin A paste bin to query * @param integer $limit a maximum of pastes to retrieve (optional, default to null = all) * @param integer start a number of pastes to skip before retrieving (optional, default to null = begin with first) * @return array a list of pastes */ public function getPastes($bin, $limit = null, $start = null) { $pm = $this->_mappers->create('Pastie_Entity_PasteMapper'); $query = new Horde_Rdo_Query($pm); $query->sortBy('paste_timestamp DESC'); if ($limit !== null) { if ($start === null) { $start = 0; } $query->limit($limit, $start); } $pastes = array(); foreach ($pm->find($query) as $paste) { $pastes[$paste['paste_uuid']] = $this->_fromBackend($paste); } return $pastes; }
/** * Update an instance of $this->_classname from a set of data. * * @param Horde_Rdo_Base $object The object to update * @param array $fields Field names/default values for the object */ public function mapFields($object, $fields = array()) { $relationships = array(); foreach ($fields as $fieldName => &$fieldValue) { if (strpos($fieldName, '@') !== false) { list($rel, $field) = explode('@', $fieldName, 2); $relationships[$rel][$field] = $fieldValue; unset($fields[$fieldName]); } if (isset($this->fields[$fieldName])) { $fieldName = $this->fields[$fieldName]; } $column = $this->tableDefinition->getColumn($fieldName); if ($column) { $fieldValue = $column->typeCast($fieldValue); } } $object->setFields($fields); if (count($relationships)) { foreach ($this->relationships as $relationship => $rel) { if (isset($rel['mapper'])) { if ($this->_factory) { $m = $this->_factory->create($rel['mapper']); } else { $m = new $rel['mapper']($this->adapter); } } else { $m = $this->tableToMapper($relationship); if (is_null($m)) { // @TODO Throw an exception? continue; } } // Don't check the table only. If there was a match for LEFT // JOINs, there may be a "empty" result if (isset($relationships[$m->table], $relationships[$m->table][$m->primaryKey])) { $object->{$relationship} = $m->map($relationships[$m->table]); } } } }
/** * Inventory search * @param array filters a list of filter hashes, each having keys * string type ('note', 'stock_name', 'stock_id', 'categories', 'values') * string test * boolean exact (only search for full words, default to null) * mixed value (string for note, stock_name) * For the 'values' structure, value, value is a map of [values] and optional [property]} * @return array List of Stock items */ public function findStock($filters = array()) { $sm = $this->_mappers->create('Sesha_Entity_StockMapper'); if (empty($filters)) { return iterator_to_array($sm->find()); } $query = new Horde_Rdo_Query($sm); $query->combineWith('OR'); foreach ($filters as $filter) { switch ($filter['type']) { case 'note': case 'stock_name': case 'stock_id': $filter_values = is_array($filter['value']) ? $filter['value'] : array($filter['value']); $filter_test = empty($filter['test']) ? 'LIKE' : $filter['test']; $filter_field = $filter['type']; if ($filter_field == 'stock_id') { $filter_test = '='; } foreach ($filter_values as $filter_value) { if (strlen($filter_value)) { if ($filter_test == 'LIKE' && empty($filter['exact'])) { $filter_value = '%' . $filter_value . '%'; } $query->addTest($filter_field, $filter_test, $filter_value); } } break; case 'categories': $cm = $this->_mappers->create('Sesha_Entity_CategoryMapper'); $categories = is_array($filter['value']) ? $filter['value'] : array($filter['value']); $items = array(); foreach ($categories as $category) { if ($category instanceof Sesha_Entity_Category) { $category_id = $category->category_id; } else { $category_id = $category; $category = $cm->findOne($category_id); } foreach ($category->stock as $item) { /* prevent duplicates when an item has several * categories */ $items[$item->stock_id] = $item; } } if (count($filters == 1)) { return $items; } $query->addTest('stock_id', $filter['test'] ? $filter['test'] : 'IN', array_keys($items)); break; case 'values': $vm = $this->_mappers->create('Sesha_Entity_ValueMapper'); $items = array(); foreach ($filter['value'] as $propTest) { $values = is_array($propTest['values']) ? $propTest['values'] : array($propTest['values']); // Find all Value objects which match any of the $value[values] foreach ($values as $filter_value) { $valueQuery = new Horde_Rdo_Query($vm); if ($propTest['property']) { $valueQuery->addTest('property_id', '=', $propTest['property']); } if (empty($filter['exact'])) { $filter_value = '%' . $filter_value . '%'; } $valueQuery->addTest('txt_datavalue', 'LIKE', $filter_value); foreach ($vm->find($valueQuery) as $value) { // prevent doubles $items[$value->stock_id] = $value->stock; } } } if (count($filters == 1)) { return $items; } $query->addTest('stock_id', $filter['test'] ? $filter['test'] : 'IN', array_keys($items)); break; } } return iterator_to_array($sm->find($query)); }
public function listAllCategories() { $cm = $this->_mappers->create('Dolcore_Rdo_CategoryMapper'); return $cm->find(); }