本文整理汇总了PHP中R::clearRelations方法的典型用法代码示例。如果您正苦于以下问题:PHP R::clearRelations方法的具体用法?PHP R::clearRelations怎么用?PHP R::clearRelations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::clearRelations方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tag
public static function tag(RedBean_OODBBean $bean, $tagList = null)
{
if (is_null($tagList)) {
$tags = R::related($bean, "tag");
$foundTags = array();
foreach ($tags as $tag) {
$foundTags[] = $tag->title;
}
if (self::$flagUseLegacyTaggingAPI) {
return implode(",", $foundTags);
}
return $foundTags;
}
if ($tagList !== false && !is_array($tagList)) {
$tags = explode(",", (string) $tagList);
} else {
$tags = $tagList;
}
R::clearRelations($bean, "tag");
if ($tagList === false) {
return;
}
foreach ($tags as $tag) {
$t = R::findOne("tag", " title = ? ", array($tag));
if (!$t) {
$t = R::dispense("tag");
$t->title = $tag;
R::store($t);
}
R::associate($bean, $t);
}
}
示例2: tag
/**
* Tags a bean or returns tags associated with a bean.
* If $tagList is null or omitted this method will return a
* comma separated list of tags associated with the bean provided.
* If $tagList is a comma separated list (string) of tags all tags will
* be associated with the bean.
* You may also pass an array instead of a string.
*
* @param RedBean_OODBBean $bean bean
* @param mixed $tagList tags
*
* @return string $commaSepListTags
*/
public static function tag( RedBean_OODBBean $bean, $tagList = null ) {
if (is_null($tagList)) {
$tags = R::related( $bean, "tag");
$foundTags = array();
foreach($tags as $tag) {
$foundTags[] = $tag->title;
}
return implode(",",$foundTags);
}
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
if (is_array($tags)) {
foreach($tags as $tag) {
if (preg_match("/\W/",$tag)) throw new RedBean_Exception("Invalid Tag. Tags may only contain alpha-numeric characters");
}
}
R::clearRelations( $bean, "tag" );
if ($tagList===false) return;
foreach($tags as $tag) {
$t = R::findOne("tag"," title = ? ",array($tag));
if (!$t) {
$t = R::dispense("tag");
$t->title = $tag;
R::store($t);
}
R::associate( $bean, $t );
}
}
示例3: array
$t->role = 'teacher';
$s->role = 'student';
$s2->role = 'student';
$s->name = 'a';
$s2->name = 'b';
R::associate($t, $s);
R::associate($t, $s2);
$students = R::related($t, 'person', ' "role" = ? ORDER BY "name" ', array("student"));
$s = array_shift($students);
$s2 = array_shift($students);
asrt($s->name, 'a');
asrt($s2->name, 'b');
$s = R::relatedOne($t, 'person', ' role = ? ORDER BY "name" ', array("student"));
asrt($s->name, 'a');
//empty classroom
R::clearRelations($t, 'person', $s2);
$students = R::related($t, 'person', ' role = ? ORDER BY "name" ', array("student"));
asrt(count($students), 1);
$s = reset($students);
asrt($s->name, 'b');
function getList($beans, $property)
{
$items = array();
foreach ($beans as $bean) {
$items[] = $bean->{$property};
}
sort($items);
return implode(",", $items);
}
testpack("unrelated");
$pdo->Execute("DROP TABLE person_person");
示例4: testRelationsVariation
/**
* Misc Test relations...
*
* @return void
*/
public function testRelationsVariation()
{
$track = R::dispense('track');
$album = R::dispense('cd');
$track->name = 'a';
$track->ordernum = 1;
$track2 = R::dispense('track');
$track2->ordernum = 2;
$track2->name = 'b';
R::associate($album, $track);
R::associate($album, $track2);
$tracks = R::related($album, 'track');
$track = array_shift($tracks);
$track2 = array_shift($tracks);
$ab = $track->name . $track2->name;
asrt($ab == 'ab' || $ab == 'ba', TRUE);
$t = R::dispense('person');
$s = R::dispense('person');
$s2 = R::dispense('person');
$t->name = 'a';
$t->role = 'teacher';
$s->role = 'student';
$s2->role = 'student';
$s->name = 'a';
$s2->name = 'b';
$role = R::$writer->esc('role');
R::associate($t, $s);
R::associate($t, $s2);
$students = R::related($t, 'person', sprintf(' %s = ? ', $role), array("student"));
$s = array_shift($students);
$s2 = array_shift($students);
asrt($s->name == 'a' || $s2->name == 'a', TRUE);
asrt($s->name == 'b' || $s2->name == 'b', TRUE);
// Empty classroom
R::clearRelations($t, 'person');
R::associate($t, $s2);
$students = R::related($t, 'person', sprintf(' %s = ? ', $role), array("student"));
asrt(count($students), 1);
$s = reset($students);
asrt($s->name, 'b');
}