本文整理汇总了PHP中create_relationship函数的典型用法代码示例。如果您正苦于以下问题:PHP create_relationship函数的具体用法?PHP create_relationship怎么用?PHP create_relationship使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_relationship函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
function process()
{
//prep site
$this->helper->ensure_type_is_on_site(id_of('publication_type'));
$this->helper->ensure_type_is_on_site(id_of('group_type'));
$this->helper->ensure_nobody_group_is_on_site();
// gather core information
$pub_type_id = id_of('publication_type');
$name = trim(strip_tags($this->get_value('pub_name')));
// populate values array
$values['new'] = 0;
$values['description'] = trim(get_safer_html($this->get_value('pub_description')));
$values['unique_name'] = trim(strip_tags($this->get_value('pub_unique_name')));
$values['state'] = 'Live';
$values['hold_comments_for_review'] = 'no';
$values['posts_per_page'] = turn_into_int($this->get_value('pub_posts_per_page'));
$values['blog_feed_string'] = trim(strip_tags($this->get_value('pub_rss_feed_url')));
$values['publication_type'] = 'Newsletter';
$values['has_issues'] = 'no';
$values['has_sections'] = 'no';
$values['date_format'] = $this->get_value('date_format');
// create the publication
$pub_id = reason_create_entity($this->site_id, $pub_type_id, $this->user_id, $name, $values);
// associate with nobody posting and commenting groups
create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_posting_group'));
create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_commenting_group'));
}
示例2: attach_template
function attach_template($template_id)
{
if($this->test_mode)
{
$this->report .= '<p>Would have attached template id '.$template_id.'</p>';
return true;
}
if(!empty($this->id))
{
$old_template_id = $this->get_template_id();
if($old_template_id != $template_id)
{
if($old_template_id)
{
delete_relationships(
array( 'entity_a' => $this->id , 'entity_b' => $old_template_id , 'type' => relationship_id_of('theme_to_minisite_template') ) );
}
return(create_relationship( $this->id, $template_id, relationship_id_of('theme_to_minisite_template')));
}
else
{
return true;
}
}
else
{
trigger_error('could not add template, as theme does not yet have an id');
return false;
}
}
示例3: link_section_to_parent
protected function link_section_to_parent($section)
{
//echo round(memory_get_usage()/1024,2)."K at point A\n";
if ($template = $this->get_section_parent($section->get_value('parent_template_id'))) {
// echo round(memory_get_usage()/1024,2)."K at point B\n";
if (!($parents = $section->get_right_relationship('course_template_to_course_section'))) {
return create_relationship($template->id(), $section->id(), relationship_id_of('course_template_to_course_section'), false, false);
} else {
if (is_array($parents)) {
$current_template = reset($parents);
// echo round(memory_get_usage()/1024,2)."K at point C\n";
// verify that we have the correct parent, and fix if not.
if ($current_template->get_value('sourced_id') == $template->get_value('sourced_id')) {
return true;
} else {
//$this->errors[] = 'Incorrect template attached to '.$section->get_value('name');
echo 'Incorrect template attached to ' . $section->get_value('name');
}
} else {
//$this->errors[] = 'Non-array '.$parents.' returned from get_right_relationship';
echo 'Non-array ' . $parents . ' returned from get_right_relationship';
}
}
} else {
//$this->errors[] = 'No template found for '.$section->get_value('name');
echo 'No template found for ' . $section->get_value('name');
return false;
}
}
示例4: process
function process()
{
$pub_id = $this->get_value('publication_id');
$issues_to_link = $this->get_value('issues');
foreach ($issues_to_link as $issue_id) {
create_relationship($issue_id, $pub_id, relationship_id_of('issue_to_publication'));
}
// update the publication - set has_issues to "Yes"
reason_update_entity($pub_id, $this->user_id, array('has_issues' => 'yes'));
}
示例5: do_updates
function do_updates($mode, $reason_user_id)
{
if ($mode != 'run' && $mode != 'test') {
trigger_error('$mode most be either "run" or "test"');
return;
}
$messages = array();
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('view_type'));
$es->add_relation('url = "sections_and_issues.php"');
$es->set_num(1);
$view_types = $es->run_one();
if (empty($view_types)) {
if ('test' == $mode) {
echo '<p>Would have added the view type sections_and_issues.php and the Sections and Issues view</p>' . "\n";
return;
} else {
$view_type_id = reason_create_entity(id_of('master_admin'), id_of('view_type'), $reason_user_id, 'News Sections and Issues', array('url' => 'sections_and_issues.php'));
$view_type = new entity($view_type_id);
echo '<p>Added the view type sections_and_issues.php</p>' . "\n";
}
} else {
echo '<p>sections_and_issues.php view type already added</p>' . "\n";
$view_type = current($view_types);
}
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('view'));
$es->add_left_relationship($view_type->id(), relationship_id_of('view_to_view_type'));
$es->set_num(1);
$views = $es->run_one();
if (empty($views)) {
if ('test' == $mode) {
echo '<p>Would have added the Sections and Issues view</p>' . "\n";
} else {
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('field'));
$es->add_relation('entity.name = "status"');
$es->set_num(1);
$fields = $es->run_one();
$view_id = reason_create_entity(id_of('master_admin'), id_of('view'), $reason_user_id, 'News Sections and Issues', array('display_name' => 'Sections and Issues'));
create_relationship($view_id, $view_type->id(), relationship_id_of('view_to_view_type'));
create_relationship($view_id, id_of('news'), relationship_id_of('view_to_type'));
if (!empty($fields)) {
$field = current($fields);
create_relationship($view_id, $field->id(), relationship_id_of('view_columns'));
create_relationship($view_id, $field->id(), relationship_id_of('view_searchable_fields'));
}
echo '<p>Added sections and issue view</p>';
}
} else {
echo '<p>sections and issues view already added.</p>' . "\n";
}
}
示例6: process
function process()
{
$pub_id = $this->get_value('publication_id');
$sections_to_link = $this->get_value('sections');
foreach ($sections_to_link as $section_id) {
create_relationship($section_id, $pub_id, relationship_id_of('news_section_to_publication'));
// old style news would show as many items per section as existed ... we will set the posts_per_section_on_front_page to 1000
// to make sure the publication continues to behave the same way ... not exactly pretty but it works for now.
reason_update_entity($section_id, $this->user_id, array('posts_per_section_on_front_page' => 1000));
}
// update the publication - set has_sections to "Yes"
reason_update_entity($pub_id, $this->user_id, array('has_sections' => 'yes'));
}
示例7: run
/**
* Run the upgrader
* @return string HTML report
*/
public function run()
{
if ($this->_link_in_db()) {
return 'This script has already run';
} else {
if ($id = reason_create_entity(id_of('master_admin'), id_of('admin_link'), $this->user_id(), 'Admin Tools', array('url' => '?cur_module=AdminTools', 'new' => 0))) {
if (create_relationship(id_of('master_admin'), $id, relationship_id_of('site_to_admin_link'))) {
return 'Created the admin tools link and placed on Master Admin sidebar';
} else {
return 'Created the admin tools link but error occurred placing in Master Admin sidebar. You may want to do this manually.';
}
} else {
return 'Error creating the AdminTools link. You may want to add this link manually, by adding an Admin Link in Master Admin to the URL "?cur_module=AdminTools"';
}
}
}
示例8: run
/**
* Lists the current and available themes (if appropriate to do so) otherwise, changes the theme
* if the user has selected a new one
*
* @return void
*/
function run()
{
if (!empty($this->admin_page->request['chosen_theme'])) {
if ($this->self_change) {
//create a relationship of type site_has_had_theme (if needed)
$oldies = $this->get_previously_selected_themes();
$site_type_themes = $this->get_site_type_themes(false);
$e = $this->get_current_theme();
if ($e) {
if (!entity_in_array($oldies, $e->id()) and !entity_in_array($site_type_themes, $e->id())) {
create_relationship($this->admin_page->site_id, $e->id(), relationship_id_of('site_has_had_theme'));
}
}
//do relationship adding/deleting
delete_relationships(array('entity_a' => $this->admin_page->site_id, 'type' => relationship_id_of('site_to_theme')));
create_relationship($this->admin_page->site_id, $this->admin_page->request['chosen_theme'], relationship_id_of('site_to_theme'));
}
$link = $this->admin_page->make_link(array('cur_module' => 'ChooseTheme', 'chosen_theme' => ''));
header('Location: ' . unhtmlentities($link));
} else {
$this->list_available_themes();
}
}
示例9: attach_thumbnail
function attach_thumbnail($media_work, $shim)
{
// create image file in the vimeo temp directory
$image_url = $shim->get_thumbnail($media_work->get_value('entry_id'));
if ($image_url) {
$tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $media_work->get_value('id');
$f = fopen($tmp_path, 'w');
$contents = get_reason_url_contents($image_url);
fwrite($f, $contents);
fclose($f);
$user = new entity($media_work->get_value('created_by'));
$username = $user->get_value('name');
// Create a reason entity out of the temp image file
if (!empty($tmp_path) && file_exists($tmp_path) && $username) {
if ($id = create_image_entity($media_work, $username)) {
reason_include_once('content_managers/image.php3');
$im = new ImageManager();
$im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
$im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
$im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
$im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
$im->load_by_type(id_of('image'), $id, $media_work->get_value('created_by'));
$im->handle_standard_image($id, $tmp_path);
$im->create_default_thumbnail($id);
$values = array();
foreach ($im->get_element_names() as $element_name) {
$values[$element_name] = $im->get_value($element_name);
}
reason_update_entity($id, get_user_id($username), $values, false);
create_relationship($media_work->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
}
}
} else {
echo date(DATE_RFC822) . ': No thumbnail url found for media work with id ' . $media_work->get_value('entry_id') . "\n";
}
}
示例10: create_social_account_type
protected function create_social_account_type()
{
$str = '';
$social_account_type_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Social Account', $this->social_account_type_details);
$str .= '<p>Create social account type entity</p>';
create_default_rels_for_new_type($social_account_type_id);
create_reason_table('social_account', $this->social_account_type_details['unique_name'], $this->user_id());
$ftet = new FieldToEntityTable('social_account', array('account_type' => array('db_type' => 'tinytext'), 'account_id' => array('db_type' => 'tinytext'), 'account_details' => array('db_type' => 'text')));
$ftet->update_entity_table();
ob_start();
$ftet->report();
$str .= ob_get_contents();
ob_end_clean();
create_allowable_relationship(id_of('site'), id_of('social_account_type'), 'site_to_social_account', $this->site_to_social_account_details);
$str .= '<p>Created site to social account relationship.</p>';
create_relationship(id_of('master_admin'), id_of('social_account_type'), relationship_id_of('site_to_type'));
return $str;
}
示例11: foreach
$items = $es->run_one();
$pending_items = $es->run_one($type->id(), 'Pending');
$deleted_items = $es->run_one($type->id(), 'Deleted');
if (!empty($pending_items)) {
$items += $pending_items;
}
if (!empty($deleted_items)) {
$items += $deleted_items;
}
// go through all the entities of those types and create relationships to duplicate the data in the audience fields
foreach ($items as $item) {
$out[] = 'inspecting ' . $item->get_value('name');
if (!$item->has_relation_of_type($rel_name)) {
foreach ($audiences as $audience => $audience_data) {
if ($item->get_value($audience) == 'true') {
create_relationship($item->id(), $audience_ids[$audience], $alrel_id);
$out[] = 'Created rel between ' . $item->get_value('name') . ' and ' . $audience;
$did_creation = true;
}
}
}
}
}
pray($out);
if (isset($did_creation) && $did_creation == true) {
echo '<p>The script needs to run step one again. Please click submit to continue.</p>';
echo '<form>';
echo 'Number to run: <input type="text" name="num" value="100"/><br />';
echo '<input type="submit" name="do_it" value="Do it" />';
echo '</form>';
} else {
示例12: process
function process()
{
$description = trim(tidy($this->get_value('description')));
$content = trim(get_safer_html(tidy($this->get_value('post_content'))));
if(carl_empty_html($description))
{
$words = explode(' ', $content, 31);
unset($words[count($words)-1]);
$description = implode(' ', $words).'…';
$description = trim(tidy($description)); // we're tidying it twice so that if we chop off a closing tag tidy will stitch it back up again
}
if(!empty($this->user_netID))
{
$user_id = make_sure_username_is_user($this->user_netID, $this->site_info->id());
}
else
{
$user_id = $this->site_info->id();
}
if($this->hold_posts_for_review)
{
$status = 'pending';
}
else
{
$status = 'published';
}
$values = array (
'status' => $status,
'release_title' => trim(strip_tags($this->get_value('title'))),
'author' => trim(strip_tags($this->get_value('author'))),
'content' => $content,
'description' => $description,
'datetime' => date('Y-m-d H:i:s', time()),
'keywords' => implode(', ', array(strip_tags($this->get_value('title')), date('Y'), date('F'))),
'show_hide' => 'show',
'new' => 0
);
$this->new_post_id = reason_create_entity(
$this->site_info->id(),
id_of('news'),
$user_id,
$values['release_title'],
$values
);
create_relationship(
$this->new_post_id,
$this->publication->id(),
relationship_id_of('news_to_publication')
);
if ($this->successfully_submitted())
{
if($this->hold_posts_for_review)
{
echo '<p>Posts are being held for review on this publication. Please check back later to see if your post has been published.</p>';
echo '<a href="?">Back to main page</a>';
}
else
{
echo '<p>Your post has been published.</p>';
echo '<a href="'.carl_construct_redirect(array('story_id'=>$this->new_post_id)).'">View it.</a>';
}
}
if($this->get_value('issue'))
{
create_relationship($this->new_post_id, $this->get_value('issue'), relationship_id_of('news_to_issue'));
}
if($this->get_value('section'))
{
create_relationship($this->new_post_id, $this->get_value('section'), relationship_id_of('news_to_news_section'));
}
if($this->get_value('categories'))
{
foreach($this->get_value('categories') as $category_id)
{
// Check to make sure ids posted actually belong to categories in the site
if(array_key_exists($category_id, $this->categories))
{
create_relationship(
$this->new_post_id,
$category_id,
relationship_id_of('news_to_category')
);
}
}
}
$this->show_form = false;
//.........这里部分代码省略.........
示例13: _process_callback
/**
* This callback generates the thumbnail image for the video. It also updates some metadata
* such as duration for the entity.
*/
public function _process_callback()
{
$username = reason_check_authentication();
reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_publication_datetime' => date('Y-m-d H:i:s')), false);
if ($this->manager->get_value('vimeo_url') && $this->manager->get_value('entry_id') != $this->original_entry_id) {
// create image file in the vimeo temp directory
$tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $this->manager->get_value('id');
$f = fopen($tmp_path, 'w');
$image_url = $this->shim->get_thumbnail($this->manager->get_value('entry_id'));
$contents = get_reason_url_contents($image_url);
fwrite($f, $contents);
fclose($f);
// Create a reason entity out of the temp image file
if (!empty($tmp_path) and file_exists($tmp_path) && $username) {
if ($id = $this->create_image_entity($username)) {
$im = new ImageManager();
$im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
$im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
$im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
$im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
$im->load_by_type(id_of('image'), $id, get_user_id($username));
$im->handle_standard_image($id, $tmp_path);
$im->create_default_thumbnail($id);
$values = array();
foreach ($im->get_element_names() as $element_name) {
$values[$element_name] = $im->get_value($element_name);
}
reason_update_entity($id, get_user_id($username), $values, false);
// Remove any existing association with an image and replace it with this new one
delete_relationships(array('entity_a' => $this->manager->get_value('id'), 'type' => relationship_id_of('av_to_primary_image')));
create_relationship($this->manager->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
}
}
// update the duration field of the media work.
$data_obj = $this->shim->get_video_data($this->manager->get_value('entry_id'));
if ($data_obj) {
reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_duration' => format_seconds_as_human_readable(intval($data_obj->duration))), false);
}
}
}
示例14: add_relationship_second_level
function add_relationship_second_level()
{
if (empty($this->admin_page->request['unborrow'])) {
create_relationship($this->admin_page->request[CM_VAR_PREFIX . 'id'], $this->admin_page->id, $this->admin_page->request[CM_VAR_PREFIX . 'rel_id']);
}
}
示例15: move_into_site
function move_into_site($orphan_id, $types, $owner_site_id)
{
if (empty($this->_user_id)) {
trigger_error('Must set user id before calling move_into_site()');
return false;
}
if (!get_owner_site_id($orphan_id)) {
$owns_rel_id = get_owns_relationship_id($types);
// If there is an existing entry in the relationship table, delete it
$q = 'DELETE FROM `relationship` WHERE `entity_b` = "' . reason_sql_string_escape($orphan_id) . '" AND `type` = "' . reason_sql_string_escape($owns_rel_id) . '"';
$r = db_query($q, 'Unable to delete old owns relationship');
// create new ownership entry
create_relationship($owner_site_id, $orphan_id, $owns_rel_id);
} else {
trigger_error($orphan_id . ' not actually an orphan');
return false;
}
}