示例#1
0
 /**
  * Returns all the nodes that have been attached to the specified
  * parent node.
  * @param RedBean_OODBBean $parent
  * @return array $childObjects
  */
 public function children(RedBean_OODBBean $parent)
 {
     $idfield = $this->writer->getIDField($parent->getMeta("type"));
     try {
         $ids = $this->writer->selectByCrit($idfield, $parent->getMeta("type"), $this->property, intval($parent->{$idfield}));
     } catch (RedBean_Exception_SQL $e) {
         return array();
     }
     return $this->oodb->batch($parent->getMeta("type"), $ids);
 }
 /**
  * Gets related beans of type $type for bean $bean
  * @param RedBean_OODBBean $bean
  * @param string $type
  * @return array $ids
  */
 public function related(RedBean_OODBBean $bean, $type, $getLinks = false)
 {
     $table = $this->getTable(array($bean->getMeta("type"), $type));
     $idfield = $this->writer->getIDField($bean->getMeta("type"));
     if ($type == $bean->getMeta("type")) {
         // echo "<b>CROSS</b>";
         $type .= "2";
         $cross = 1;
     } else {
         $cross = 0;
     }
     if (!$getLinks) {
         $targetproperty = $type . "_id";
     } else {
         $targetproperty = "id";
     }
     $property = $bean->getMeta("type") . "_id";
     try {
         if ($cross) {
             $sqlFetchKeys = $this->writer->selectByCrit($targetproperty, $table, $property, $bean->{$idfield}, true);
         } else {
             $sqlFetchKeys = $this->writer->selectByCrit($targetproperty, $table, $property, $bean->{$idfield});
         }
         return $sqlFetchKeys;
     } catch (RedBean_Exception_SQL $e) {
         if ($e->getSQLState() != "42S02" && $e->getSQLState() != "42S22") {
             throw $e;
         }
         return array();
     }
 }
 /**
  *
  * @param RedBean_OODBBean $parent
  * @return array $childObjects
  */
 public function children(RedBean_OODBBean $parent)
 {
     $idfield = $this->writer->getIDField($parent->getMeta("type"));
     try {
         /*
         $ids = $this->adapter->getCol("SELECT `".$idfield."` FROM
         	`".$parent->getMeta("type")."`
         	WHERE `".$this->property."` = ".intval( $parent->$idfield )."
         ");
         */
         /*
         		$ids = $this->adapter->getCol($this->writer->buildSimpleQuery(
         			"select",array($idfield),$parent->getMeta("type"),
         			array("name"=>$this->property,
         				  "value"=>intval($parent->$idfield),
         				  "operator"=>"=","structure"=>"")
         		));
         */
         $ids = $this->writer->selectByCrit($idfield, $parent->getMeta("type"), $this->property, intval($parent->{$idfield}));
     } catch (RedBean_Exception_SQL $e) {
         return array();
     }
     return $this->oodb->batch($parent->getMeta("type"), $ids);
 }
示例#4
0
 /**
  * Returns all beans that are linked to the given bean.
  * @param RedBean_OODBBean $bean
  * @param string $typeName
  * @return array $beans
  */
 public function getKeys(RedBean_OODBBean $bean, $typeName)
 {
     $fieldName = $this->getLinkField($typeName);
     $id = (int) $bean->{$fieldName};
     $ids = $this->writer->selectByCrit($this->writer->getIDField($this->writer->getFormattedTableName($typeName)), $typeName, $bean->getMeta("type") . "_id", $bean->id);
     return $ids;
 }