Controls mapping of entity obects (instances of Horde_Rdo_Base) from and to Horde_Db_Adapters. Public properties: $adapter - Horde_Db_Adapter that stores this Mapper's objects. $inflector - The Horde_Support_Inflector this mapper uses to singularize and pluralize PHP class, database table, and database field/key names. $table - The Horde_Db_Adapter_Base_TableDefinition object describing the main table of this entity.
Inheritance: implements Countable
Example #1
0
 /**
  * Implementation of count() for Countable
  *
  * @return integer Number of elements in the list
  */
 public function count()
 {
     if (is_null($this->_count)) {
         $this->_count = $this->_mapper->count($this->_query);
     }
     return $this->_count;
 }
Example #2
0
 /**
  * Deletes a stock item from the backend. $object can be either a
  * primary key, an Rdo_Query object, or a Sesha_Entity_Stock object.
  * This also cleans up attached attributes and categories
  *
  * @param string|Sesha_Entity_Stock|Horde_Rdo_Query $object The Rdo object,
  * Horde_Rdo_Query, or unique id to delete.
  *
  * @return integer Number of objects deleted.
  */
 public function delete($object)
 {
     if (!$object instanceof Sesha_Entity_Stock) {
         $object = $this->findOne($object);
     }
     foreach ($object->values as $value) {
         $value->delete();
     }
     $object->removeRelation('categories');
     return parent::delete($object);
 }
Example #3
0
 /**
  * @param Horde_Rdo_Mapper $mapper Rdo mapper base class
  *
  * @return Horde_Rdo_Query Return the query object for fluent chaining.
  */
 public function setMapper($mapper)
 {
     if ($mapper === $this->mapper) {
         return $this;
     }
     $this->mapper = $mapper;
     // Fetch all non-lazy-loaded fields for the mapper.
     $this->setFields($mapper->fields, $mapper->table . '.');
     // Add all non-lazy relationships.
     foreach ($mapper->relationships as $relationship => $rel) {
         if (isset($rel['mapper'])) {
             // @TODO - should be getting this instance from somewhere
             // else external, and not passing the adapter along
             // automatically.
             $m = new $rel['mapper']($this->mapper->adapter);
         } else {
             $m = $this->mapper->tableToMapper($relationship);
             if (is_null($m)) {
                 throw new Horde_Rdo_Exception('Unable to find a Mapper class for eager-loading relationship ' . $relationship);
             }
         }
         // Add the fields for this relationship to the query.
         $m->tableAlias = $this->_alias($m->table);
         $this->addFields($m->fields, $m->tableAlias . '.@');
         $args = array('mapper' => $m, 'type' => $rel['type']);
         switch ($rel['type']) {
             case Horde_Rdo::ONE_TO_ONE:
             case Horde_Rdo::MANY_TO_ONE:
                 if (isset($rel['query'])) {
                     $args['query'] = $this->_fillJoinPlaceholders($m, $mapper, $rel['query']);
                 } else {
                     $args['query'] = array($mapper->table . '.' . $rel['foreignKey'] => new Horde_Rdo_Query_Literal($m->table . '.' . $m->tableDefinition->getPrimaryKey()));
                 }
                 if (isset($rel['join_type'])) {
                     $args['join_type'] = $rel['join_type'];
                 }
                 $this->addRelationship($relationship, $args);
                 break;
             case Horde_Rdo::ONE_TO_MANY:
             case Horde_Rdo::MANY_TO_MANY:
                 //@TODO
         }
     }
     return $this;
 }