public static function get_relation_for_user($uid, $type = NULL, $load_attrs = true) { $relation = array('subject_service' => 'internal', 'subject_type' => 'user', 'subject_id' => $uid, 'object_service' => 'typedGroup'); if ($type) { $relation['object_type'] = $type; } $match = parent::load_match($relation, $load_attrs); return $match; }
public static function sync($r) { $match = array('subject_service' => $r['subject_service'], 'subject_type' => $r['subject_type'], 'subject_id' => $r['subject_id'], 'relation_type' => $r['relation_type'], 'object_service' => $r['object_service'], 'object_type' => $r['object_type'], 'object_id' => $r['object_id']); $relations = EntityRelation::load_match($match); if (empty($relations[0])) { // create $id = EntityRelation::create($r); } else { // sync $relations[0]->update($r); $id = $relations[0]->id; } return $id; }