本文整理汇总了PHP中entity_selector::add_rel_sort_field方法的典型用法代码示例。如果您正苦于以下问题:PHP entity_selector::add_rel_sort_field方法的具体用法?PHP entity_selector::add_rel_sort_field怎么用?PHP entity_selector::add_rel_sort_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entity_selector
的用法示例。
在下文中一共展示了entity_selector::add_rel_sort_field方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* Make sure that the model is configured with a valid URL.
*
* @return string json
*/
function build()
{
if ($site_id = $this->config('site_id')) {
$s = get_microtime();
$es = new entity_selector();
$es->add_type(id_of('social_account_type'));
$es->add_right_relationship($site_id, relationship_id_of('site_to_social_account'));
$es->add_rel_sort_field($site_id, relationship_id_of('site_to_social_account'));
$es->set_order('rel_sort_order ASC');
$es->limit_tables();
$es->limit_fields();
if ($results = $es->run_one()) {
$result_keys = array_keys($results);
$sih = reason_get_social_integration_helper();
foreach ($result_keys as $id) {
// get the integrator if it supports the SocialAccountProfileLinks interface
if ($integrator = $sih->get_social_account_integrator($id, 'SocialAccountProfileLinks')) {
$profile_links[$id]['icon'] = $integrator->get_profile_link_icon($id);
$profile_links[$id]['text'] = $integrator->get_profile_link_text($id);
$profile_links[$id]['href'] = $integrator->get_profile_link_href($id);
}
}
if (!empty($profile_links)) {
return $profile_links;
}
}
return false;
} else {
trigger_error('The ReasonSocialProfileLinksModel must be provided with the configuration parameter site_id.', FATAL);
}
}
示例2: run
function run()
{
$site_id = $this->site_id;
$es = new entity_selector($site_id);
$es->add_type(id_of('google_map_type'));
$es->add_right_relationship($this->cur_page->id(), relationship_id_of('page_to_google_map'));
$es->add_rel_sort_field($this->cur_page->id(), relationship_id_of('page_to_google_map'));
$es->set_order('rel_sort_order');
$gmaps = $es->run_one();
draw_google_map($gmaps);
}
示例3: foreach
function setup_associated_items()
{
// populate associated entity selector from scratch
$ass_es = new entity_selector();
$ass_es->add_type($this->type_id);
if ($this->rel_direction == 'a_to_b') {
$ass_es->add_right_relationship($this->admin_page->id, $this->admin_page->rel_id);
} else {
$ass_es->add_left_relationship($this->admin_page->id, $this->admin_page->rel_id);
}
$ass_es->add_right_relationship_field('owns', 'entity', 'id', 'site_owner_id');
if ($this->rel_direction == 'a_to_b' && $this->check_is_rel_sortable()) {
$this->columns['rel_sort_order'] = true;
$ass_es->add_field('relationship', 'id', 'rel_id');
$ass_es->add_rel_sort_field($this->admin_page->id);
$ass_es->set_order('relationship.rel_sort_order ASC');
if ($this->_cur_user_has_edit_privs() && !$this->get_relationship_lock_state()) {
$this->alter_order_enable = true;
}
} else {
$ass_es->add_field('relationship', 'site', 'rel_site_id');
}
if ($this->assoc_viewer_order_by($ass_es)) {
$this->alter_order_enable = false;
}
$this->ass_vals = $ass_es->run_one();
// check sharing on associated entities
foreach ($this->ass_vals as $k => $val) {
// setup sharing value
if ($this->site_id == $val->get_value('site_owner_id')) {
$this->ass_vals[$k]->set_value('sharing', 'owns');
} else {
$this->ass_vals[$k]->set_value('sharing', $this->check_borrow_status($k));
}
}
// this verifies and updates the associated items rel_sort_order if this is an a to b relationship
if ($this->rel_direction == 'a_to_b' && $this->check_is_rel_sortable()) {
if (count($this->ass_vals) == 1 && isset($this->columns['rel_sort_order'])) {
unset($this->columns['rel_sort_order']);
}
if ($ass_es->orderby == 'relationship.rel_sort_order ASC') {
$rel_update_array = $this->validate_rel_sort_order($this->ass_vals, true);
} else {
$rel_update_array = $this->validate_rel_sort_order($this->ass_vals);
}
if (count($rel_update_array) > 0) {
foreach ($rel_update_array as $k => $v) {
update_relationship($k, array('rel_sort_order' => $v));
}
}
}
}
示例4: get_image
public function get_image()
{
if (!isset($this->_image)) {
$es = new entity_selector();
$es->add_type(id_of('image'));
$es->add_right_relationship($this->_event->id(), relationship_id_of('event_to_image'));
$es->add_rel_sort_field($this->_event->id(), relationship_id_of('event_to_image'));
$es->set_order('rel_sort_order ASC');
$es->set_num(1);
$images = $es->run_one();
if (!empty($images)) {
$this->_image = current($images);
} else {
$this->_image = false;
}
}
return $this->_image;
}
示例5: array
function init_from_database()
{
if (!empty($this->site_id) && !empty($this->page_id)) {
$es = new entity_selector($this->site_id);
$es->add_type(id_of('quote_type'));
$es->limit_tables(array('meta'));
$es->limit_fields('meta.description');
$es->add_right_relationship($this->page_id, relationship_id_of('page_to_quote'));
$es->add_rel_sort_field($this->page_id, relationship_id_of('page_to_quote'), 'rel_sort_order');
$es->set_order('rel_sort_order ASC');
$result = $es->run_one();
$result_array = $result ? $result : array();
$extra_results = $this->init_from_categories($result);
$this->quote_pool = $result + $extra_results;
$this->add_quote_divider_value($this->quote_pool);
$this->set_cache();
} else {
$this->quote_pool = false;
// nothing in the quote pool since we are missing a site id or page id
}
}
示例6: ISNULL
function get_item_media($item)
{
if (!isset($this->_item_media[$item->id()]))
{
$es = new entity_selector();
$es->set_env( 'site' , $this->site_id );
$es->description = 'Selecting media for news item';
$es->add_type( id_of('av') );
$es->add_right_relationship( $item->id(), relationship_id_of('news_to_media_work') );
$es->add_rel_sort_field( $item->id(), relationship_id_of('news_to_media_work') );
$es->set_order('rel_sort_order');
$es->add_relation( 'show_hide.show_hide = "show"' );
$es->add_relation( '(media_work.transcoding_status = "ready" OR ISNULL(media_work.transcoding_status) OR media_work.transcoding_status = "")' );
$this->_item_media[$item->id()] = $es->run_one();
}
return $this->_item_media[$item->id()];
}
示例7: array
function get_blurbs_for_page($page, $count)
{
$cache = array();
if (!isset($cache[$page->id()])) {
$es = new entity_selector();
$es->add_type(id_of('text_blurb'));
$es->add_right_relationship($page->id(), relationship_id_of('minisite_page_to_text_blurb'));
$es->add_rel_sort_field($page->id(), relationship_id_of('minisite_page_to_text_blurb'), 'rel_sort_order');
$es->set_order('rel_sort_order ASC');
$es->set_num((int) $count);
$cache[$page->id()] = $es->run_one();
}
return $cache[$page->id()];
}
示例8:
function get_images_in_new_order($page_id)
{
$es = new entity_selector();
$es->add_type(id_of('image'));
$es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image'));
$es->add_rel_sort_field($page_id, relationship_id_of('minisite_page_to_image'), 'rel_sort_order');
$es->add_field('relationship', 'id', 'rel_id');
$es->set_order('rel_sort_order ASC, dated.datetime ASC, meta.description ASC, entity.id ASC');
return $es->run_one();
}
示例9: array
/**
* Get the categories to use
* @return array of entities
*/
function _get_categories()
{
if(is_null($this->_categories))
{
$this->_categories = array();
if(!empty($this->params['category_unique_names']))
{
foreach($this->params['category_unique_names'] as $uname)
{
$id = id_of($uname);
if($id)
{
$this->_categories[$id] = new entity($uname);
}
}
}
else
{
switch($this->params['mode'])
{
case 'page':
$es = new entity_selector();
$es->add_type(id_of('category_type'));
$es->add_right_relationship($this->page_id,relationship_id_of('page_to_category'));
$es->add_rel_sort_field( $this->page_id, relationship_id_of('page_to_category') );
$es->set_order('rel_sort_order');
$this->_categories = $es->run_one();
break;
case 'site':
$es = new entity_selector($this->site_id);
$es->add_type(id_of('category_type'));
$this->_categories = $es->run_one();
break;
default:
trigger_error('Mode not "page" or "site"; not able to get categories');
$this->_categories = array();
}
}
}
return $this->_categories;
}
示例10: array
/**
* Get the media works for a given event entity
*
* @param object $e event entity
* @return array media work entities
*/
function get_event_media_works($e)
{
static $cache = array();
if(empty($cache[$e->id()]))
{
$es = new entity_selector();
$es->add_type( id_of('av'));
$es->add_right_relationship( $e->id(), relationship_id_of('event_to_media_work'));
$es->add_rel_sort_field($e->id(), relationship_id_of('event_to_media_work'));
$es->set_order('rel_sort_order ASC');
$es->add_relation( 'show_hide.show_hide = "show"' );
$es->add_relation( '(media_work.transcoding_status = "ready" OR ISNULL(media_work.transcoding_status) OR media_work.transcoding_status = "")' );
$cache[$e->id()] = $es->run_one();
}
return $cache[$e->id()];
}
示例11: array
/**
* Build the feature set
*/
function _build_features()
{
$es1 = new entity_selector( $this->site_id );
$es1->add_type( id_of('feature_type') );
$es1->add_right_relationship( $this->page_id, relationship_id_of('page_to_feature'));
$es1->add_rel_sort_field( $this->page_id, relationship_id_of('page_to_feature') );
$es1->set_order('rel_sort_order ASC');
if($this->params['max'] != 0)
{
$es1->set_num($this->params['max']);
}
$features = $es1->run_one();
if(empty($features))
{
return null;
}
$es2 = new entity_selector( $this->site_id );
$es2->add_type( id_of('image') );
$es2->add_right_relationship_field( 'feature_to_image','entity','id','feature_id', array_keys($features) );
$es2->enable_multivalue_results();
$images = $es2->run_one();
if ($images)
{
foreach ($images as $image_id => $image)
{
$features_with_image = $image->get_value('feature_id');
$features_with_image = (!is_array($features_with_image)) ? array($features_with_image) : $features_with_image; // force to array
foreach ($features_with_image as $feature_id)
{
$feature_extra[$feature_id]['image_id'][] = $image_id;
}
}
}
$es3 = new entity_selector( $this->site_id );
$es3->add_type( id_of('av') );
$es3->add_right_relationship_field( 'feature_to_media_work','entity','id','av_id', array_keys($features) );
$es3->enable_multivalue_results();
$media_works = $es3->run_one();
if ($media_works)
{
foreach ($media_works as $media_work_id => $media_work)
{
$features_with_media_work = $media_work->get_value('av_id');
$features_with_media_work = (!is_array($features_with_media_work)) ? array($features_with_media_work) : $features_with_media_work; // force to array
foreach ($features_with_media_work as $feature_id)
{
$feature_extra[$feature_id]['av_id'][] = $media_work_id;
}
}
}
// augment our features with images and media works
foreach($features as $feature_id => $feature)
{
if (isset($feature_extra[$feature_id]['image_id']))
{
$value = (count($feature_extra[$feature_id]['image_id']) == 1) ? reset($feature_extra[$feature_id]['image_id']) : $feature_extra[$feature_id]['image_id'];
$features[$feature_id]->set_value('image_id',$value);
}
else $features[$feature_id]->set_value('image_id',"none");
if (isset($feature_extra[$feature_id]['av_id']))
{
$value = (count($feature_extra[$feature_id]['av_id']) == 1) ? reset($feature_extra[$feature_id]['av_id']) : $feature_extra[$feature_id]['av_id'];
$features[$feature_id]->set_value('av_id',$value);
}
else $features[$feature_id]->set_value('av_id',"none");
}
//shuffle the features if set to true
//note that keys are preserved in the new
//shuffled feature array
if($this->params['shuffle']==true)
{
$shuffled_results=array();
$temps=array();
$temps=$features;
shuffle($temps);
foreach($temps as $temp)
{
$id=$temp->get_value('id');
$shuffled_results[$id]=$temp;
}
$features=$shuffled_results;
}
//pick a random media work or image from each features list of images.
foreach($features as $id=>$r)
{
$num_imgs=0;
$num_mdia=0;
$i=0;
if($features[$id]->has_value('image_id'))
{
$img_id=$features[$id]->get_value('image_id');
//.........这里部分代码省略.........
示例12: entity
/**
* prep_for_run returns the array describing which relationships need to be updated, and also verifies that the entity that is
* being moved is in the same row position it was prior to the request (gracefully handles double clicks and the like)
*
* @return mixed array describing new sort orders according to relationship id, or false
*/
function prep_for_run()
{
$e = new entity($this->entity_id);
$type_id = $e->get_value('type');
// performs an appropriate entity selection - populates class variables with specifics for run method.
$es = new entity_selector($this->site_id);
$es->add_type($type_id);
$es->set_sharing('owns,borrows');
$es->add_field('relationship', 'id', 'relationship_id');
$es->add_right_relationship($this->left_entity_id, $this->al_relationship_id);
$es->add_rel_sort_field($this->left_entity_id);
if ($this->direction == 'moveup') {
$es->set_order('rel_sort_order DESC');
} else {
$es->set_order('rel_sort_order ASC');
}
$result = $es->run_one();
$resultcount = count($result);
$read_next = false;
$rowcounter = 0;
foreach ($result as $k => $v) {
if ($read_next == true) {
$new_rel_sort_order = $v->get_value('rel_sort_order');
$relationship_id_2 = $v->get_value('relationship_id');
break;
} elseif ($k == $this->entity_id) {
if ($this->direction == 'moveup' && $this->row_id == $resultcount - $rowcounter || $this->direction == 'movedown' && $this->row_id == $rowcounter + 1) {
$old_rel_sort_order = $v->get_value('rel_sort_order');
$relationship_id_1 = $v->get_value('relationship_id');
$read_next = true;
} else {
trigger_error('There was a problem modifying the relationship sort order - the entity being moved does not have the same location as when the request was initiated. This can happen from multiple clicks or when multiple people are modifying the sort order.');
return false;
}
} else {
unset($result[$k]);
$rowcounter++;
}
}
if (is_numeric($relationship_id_1) && is_numeric($relationship_id_2) && is_numeric($new_rel_sort_order) && is_numeric($old_rel_sort_order)) {
return array($relationship_id_1 => $new_rel_sort_order, $relationship_id_2 => $old_rel_sort_order);
} else {
return false;
}
}
示例13: foreach
function _get_av_items()
{
$works_es = new entity_selector($this->site_id);
$works_es->add_type(id_of('av'));
$works_es->set_num($this->num_works);
$works_es->add_relation('show_hide.show_hide = "show"');
$works_es->set_order('media_work.media_publication_datetime DESC');
if (!empty($this->_page_id)) {
$works_es->add_right_relationship($this->_page_id, relationship_id_of('minisite_page_to_av'));
if ($this->rel_sort) {
$works_es->add_rel_sort_field($this->_page_id, relationship_id_of('minisite_page_to_av'));
$works_es->set_order('rel_sort_order ASC');
}
}
$media_works = $works_es->run_one();
foreach ($media_works as $work) {
$es = new entity_selector();
$es->add_type(id_of('av_file'));
$es->add_right_relationship($work->id(), relationship_id_of('av_to_av_file'));
if ($work->get_value('integration_library')) {
$es->set_num(1);
if ($work->get_value('av_type') == 'Video') {
$es->set_order('av.height DESC');
$es->add_relation('av.mime_type = "video/mp4"');
} elseif ($work->get_value('av_type') == 'Audio') {
$es->add_relation('av.mime_type = "audio/mpeg"');
}
}
$media_files = $es->run_one();
if (!empty($media_files)) {
foreach ($media_files as $media_file) {
$media_file->set_value('work_publication_datetime', $work->get_value('media_publication_datetime'));
$media_file->set_value('work_name', $work->get_value('name'));
$media_file->set_value('work_description', $work->get_value('description'));
$media_file->set_value('author', $work->get_value('author'));
$media_file->set_value('integration_library', $work->get_value('integration_library'));
$media_file->set_value('work_id', $work->id());
$this->items[$media_file->id()] = $media_file;
}
}
}
}
示例14: list
function do_associate()
{
list($entity_a, $entity_b, $rel_info) = $this->get_entities();
if (!$this->_cur_user_has_privs($entity_a, $entity_b, $rel_info)) {
return false;
}
//put entity id into site id rather than site id if entity_a is owned by this site
$own = $entity_a->get_owner();
if ($this->admin_page->site_id == $own->id()) {
$site_id = 0;
} else {
$site_id = $this->admin_page->site_id;
}
if ($rel_info['connections'] == 'one_to_many') {
$this->remove_relationships($entity_a, $rel_info);
}
// check whether the allowable relationship is sortable. insert appropriate increment for rel_sort_order
if ($rel_info['is_sortable'] == 'yes') {
$es = new entity_selector();
$es->add_type($rel_info['relationship_b']);
$es->set_sharing('owns,borrows');
$es->add_right_relationship($entity_a->id(), $rel_info['id']);
$es->add_rel_sort_field($entity_a->id());
$es->set_order('rel_sort_order DESC');
$es->set_num(1);
$result = $es->run_one();
if (count($result) == 1) {
$e = current($result);
$new_rel_sort = $e->get_value('rel_sort_order') + 1;
} else {
$new_rel_sort = 1;
}
}
if (isset($new_rel_sort)) {
create_relationship($entity_a->id(), $entity_b->id(), $rel_info['id'], array('site' => $site_id, 'rel_sort_order' => $new_rel_sort), true);
} else {
create_relationship($entity_a->id(), $entity_b->id(), $rel_info['id'], array('site' => $site_id), true);
}
}
示例15: foreach
/**
* Grab categories and for each page category, build a reference to a subset of the page assets
*
* Takes an array in this form:
*
* <code>
* array( $asset_id=>$asset, $asset_id=>$asset, ...);
* </code>
*
* Returns an array in this form:
*
* <code>
* array(
* $category_id => array( $asset_id=>$asset, $asset_id=>$asset, ...),
* $category_id => array( $asset_id=>$asset, $asset_id=>$asset, ...),
* ...
* );
* </code>
*
* @param array $page_assets
* @return array assets by category
*/
function &init_by_category(&$page_assets)
{
$assets_by_category = false;
$cat_es = new entity_selector($this->site_id);
$cat_es->set_env('site', $this->site_id);
$cat_es->add_type(id_of('category_type'));
$cat_es->limit_tables('entity');
$cat_es->limit_fields('entity.name');
$cat_es->add_right_relationship($this->page_id, relationship_id_of('page_to_category'));
$cat_es->add_rel_sort_field($this->page_id, relationship_id_of('page_to_category'));
$cat_es->set_order('rel_sort_order');
$result = $cat_es->run_one();
if ($result) {
$asset_ids = array_keys($page_assets);
$cat_ids = array_keys($result);
foreach ($asset_ids as $asset_id) {
$item =& $page_assets[$asset_id];
$asset_cat_ids = is_array($item->get_value('cat_id')) ? $item->get_value('cat_id') : array($item->get_value('cat_id'));
$cat_intersect = array_intersect($asset_cat_ids, $cat_ids);
if (!empty($cat_intersect)) {
foreach ($cat_intersect as $cat_id) {
$stack[$cat_id][$asset_id] =& $item;
}
unset($this->assets[$asset_id]);
// it is in at least one category - zap from main asset list
}
}
foreach ($cat_ids as $cat_id) {
if (isset($stack[$cat_id])) {
$assets_by_category[$cat_id] =& $stack[$cat_id];
}
}
} else {
}
return $assets_by_category;
}