Created
July 31, 2012 13:53
-
-
Save cebe/3217216 to your computer and use it in GitHub Desktop.
EActiveRecordGraphBehavior draft idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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