Example #1
0
			'to' => 'Blog',
			'local' => array('blogID', 'blogDatePosted', 'blogLanguage'),
			'localAs' => 'blog',
			'foreign' => array('ID', 'datePosted', 'language'),
			'foreignAs' => 'comments',
			'orderBy' => 'timePosted',
			'filter' => 'spamStatus'
		);
	}
}

Model::registerRelation(new BlogHasComments);

class BlogHasAuthor extends One2Many
{
	protected function info()
	{
		return array(
			'from' => 'Blog',
			'to' => 'User',
			'local' => 'authorID',
			'localAs' => 'author',
			'foreign' => 'username',
			'foreignAs' => ''
		);
	}
}

Model::registerRelation(new BlogHasAuthor);

Example #2
0
class IsAMockHasContainer extends One2Many
{
	protected function info()
	{
		return array(
			'from' => 'IsAMockModel',
			'to' => 'SomeContainer',
			'localAs' => 'container',
			'local' => 'containerID',
			'foreign' => 'ID',
			'foreignAs' => 'isas'
		);
	}
}
Model::registerRelation(new IsAMockHasContainer);

/**
 * @property primary; ID String('ID', 32); required
 * @property content String('Text'); required
*/
class SomeContainer extends DBModel
{
	public function __construct()
	{
		parent::__construct();
	}

	public function get($id)
	{
		$q = DB::prepare('SELECT * FROM SomeContainer WHERE ID=:id');
Example #3
0
			'local' => 'authorID',
			'localAs' => 'author',
			'foreign' => 'username',
			'foreignAs' => ''
		);
	}
}

Model::registerRelation(new CommentHasAuthor);

class CommentHasAnonAuthor extends One2Many
{
	protected function info()
	{
		return array(
			'from' => 'Comment',
			'to' => 'AnonProfile',
			'local' => 'anonAuthorID',
			'localAs' => 'anonAuthor',
			'foreign' => 'ID',
			'foreignAs' => ''
		);
	}
}

Model::registerRelation(new CommentHasAnonAuthor);



?>
Example #4
0
			'to' => 'Bar',
			
			'fromLocal' => 'ID',
			'toAs' => 'bars',
			
			'toLocal' => 'ID',
			'fromAs' => 'foos',
			
			'table' => 'FooBars',
			'tableFrom' => 'fooID',
			'tableTo' => 'barID'
		);
	}
}

Model::registerRelation(new FoosHasBars);

class Many2ManyTest extends CoOrgModelTest
{
	const dataset = 'many2many.dataset.xml';
	
	public function testRetrieve()
	{
		$foo = Foo::get('foo3');
		$this->assertEquals(2, count($foo->bars));
		$this->assertEquals('Bar 1', $foo->bars[0]->barbar);
		$this->assertEquals('Bar 2', $foo->bars[1]->barbar);
		
		$bar = Bar::get('bar 1');
		$this->assertNotNull($bar);
		$this->assertEquals(2, count($bar->foos));
Example #5
0
		return array(
			'from' => 'Foo',
			'to' => 'Bar',
			
			'fromLocal' => 'barID',
			'fromForeign' => 'ID',
			'localAs' => 'bar',
			
			'toForeign' => 'ID',
			'toLocal' => 'fooID',
			'foreignAs' => 'foo'
		);
	}
}

Model::registerRelation(new FooHasBar);

class One2OneTest extends CoOrgModelTest
{
	const dataset = 'one2one.dataset.xml';
	
	public function testFoo()
	{
		$foo = Foo::get('someFoo');
		$this->assertNull($foo->bar);
		
		$foo = Foo::get('fooWithBar');
		$this->assertNotNull($foo->bar);
		$this->assertEquals('Some Bar', $foo->bar->barbar);
		
		$foo = Foo::get('someFoo');
Example #6
0
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

  * CoOrg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.

  * You should have received a copy of the GNU Affero General Public License
  * along with CoOrg.  If not, see <http://www.gnu.org/licenses/>.
*/

class PageHasAuthorRelation extends One2Many
{
	protected function info()
	{
		return array(
			'from' => 'Page',
			'to' => 'User',
			'local' => 'authorID',
			'localAs' => 'author',
			'foreign' => 'username',
			'foreignAs' => 'pages'
		);
	}
}

Model::registerRelation(new PageHasAuthorRelation);

?>
Example #7
0
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

  * CoOrg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.

  * You should have received a copy of the GNU Affero General Public License
  * along with CoOrg.  If not, see <http://www.gnu.org/licenses/>.
*/

class MenuHasEntries extends One2Many
{
	protected function info()
	{
		return array(
			'from' => 'MenuEntry',
			'to' => 'Menu',
			'local' => 'menuID',
			'localAs' => 'menu',
			'foreign' => 'name',
			'foreignAs' => 'entries',
			'filter' => 'language',
			'orderBy' => 'sequence'
		);
	}
}

Model::registerRelation(new MenuHasEntries);
Example #8
0
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Affero General Public License for more details.

  * You should have received a copy of the GNU Affero General Public License
  * along with CoOrg.  If not, see <http://www.gnu.org/licenses/>.
*/

class UserHasProfile extends One2One
{
	public function info()
	{
		return array(
			'from' => 'User',
			'to' => 'UserProfile',
			
			'fromLocal' => 'username',
			'fromForeign' => 'username',
			'localAs' => 'profile',
			
			'toLocal' => 'username',
			'toForeign' => 'username',
			'foreignAs' => 'user'
		);
	}
}

Model::registerRelation(new UserHasProfile);

?>