Skip to content

Instantly share code, notes, and snippets.

@cebe
Created July 31, 2012 13:53
Show Gist options
  • Select an option

  • Save cebe/3217216 to your computer and use it in GitHub Desktop.

Select an option

Save cebe/3217216 to your computer and use it in GitHub Desktop.
EActiveRecordGraphBehavior draft idea
<?php
/**
*
* @author CeBe <[email protected]>
*/
class EActiveRecordGraphBehavior extends CActiveRecordBehavior
{
/**
* @var string name of the relation/edge table
* schema must be:
* fromPk, toPk
*/
public $relationTableName;
public $groupColumn = 'group';
/**
* does a breadth-first search
*
* @param null $depth
*/
public function getNeighbours($depth=null)
{
}
public function addEdgeTo($record)
{
if (!is_array($fromPk=$this->owner->getPrimaryKey())) {
$fromPk = array($this->owner->tableSchema->primaryKey, $fromPk);
}
if (!is_array($toPk=$this->owner->getPrimaryKey())) {
$toPk = array($this->owner->tableSchema->primaryKey, $toPk);
}
$this->dbCommand()->insert($this->relationTableName, array());
}
public function removeEdgeTo($record)
{
}
public function hasConnectionTo($record)
{
}
/**
* @return CDbCommand
*/
private function dbCommand()
{
return $this->owner->dbConnection->createCommand();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment