function scan_subgalleries($node) { $mc = org_routamc_gallery_photolink_dba::new_collector('node', $node); $mc->add_value_property('photo'); $mc->add_constraint('censored', '=', 0); $mc->add_order('photo.taken', 'DESC'); $mc->set_limit(1); $mc->execute(); $photolinks = $mc->list_keys(); foreach ($photolinks as $guid => $array) { $id = $mc->get_subkey($guid, 'photo'); $photo = new org_routamc_photostream_photo_dba($id); return $photo; } $mc = midcom_db_topic::new_collector('up', $node); $mc->add_value_property('id'); $mc->add_constraint('up', '=', $node); $mc->add_constraint('component', '=', 'org.routamc.gallery'); $mc->add_constraint('metadata.navnoentry', '=', 0); $mc->add_order('score'); $mc->execute(); $nodes = $mc->list_keys(); foreach ($nodes as $guid => $array) { $id = $mc->get_subkey($guid, 'id'); $link = $this->_scan_subgalleries($id); if ($link) { return $link; } } return false; }
public function test_get_objects() { $mc = midcom_db_topic::new_collector('id', self::$_topic->id); $objects = $mc->get_objects(); $this->assertEquals(1, sizeof($objects)); $this->assertEquals(self::$_topic->guid, $objects[0]->guid); }
/** * Get topic guid statically * * used by get_parent_guid_uncached_static * * @param int $parent_id id of topic to get the guid for */ private static function _get_parent_guid_uncached_static_topic($parent_id) { if (empty($parent_id)) { return null; } $mc_parent = midcom_db_topic::new_collector('id', $parent_id); if (!$mc_parent->execute()) { // Error return null; } $mc_parent_keys = $mc_parent->list_keys(); $parent_guid = key($mc_parent_keys); if ($parent_guid === false) { // Error return null; } return $parent_guid; }
/** * Prepare event listing query builder that takes all configured filters into account * * @access static */ static function prepare_event_qb(&$data, &$config) { // Load filters $filters = fi_kilonkipinat_events_viewer::prepare_filters($config); $qb = fi_kilonkipinat_events_event_dba::new_query_builder(); if (!$_MIDGARD['user']) { $qb->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC); } // Add node or root event constraints if ($config->get('list_from_master')) { // List under an event tree by up field $qb->add_constraint('up', 'INTREE', $data['master_event']); } else { $list_from_folders = $config->get('list_from_folders'); if ($list_from_folders) { // We have specific folders to list from, therefore list from them and current node $guids = explode('|', $config->get('list_from_folders')); $guids_array = array(); $guids_array[] = $data['content_topic']->guid; foreach ($guids as $guid) { if (!$guid || !mgd_is_guid($guid)) { // Skip empty and broken guids continue; } $guids_array[] = $guid; } /** * Ref #1776, expands GUIDs before adding them as constraints, should save query time */ $topic_ids = array(); $topic_ids[] = $data['content_topic']->id; if (!empty($guids_array)) { $mc = midcom_db_topic::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc->add_constraint('guid', 'IN', $guids_array); $mc->add_value_property('id'); $mc->execute(); $keys = $mc->list_keys(); foreach ($keys as $guid => $dummy) { $topic_ids[] = $mc->get_subkey($guid, 'id'); } unset($mc, $keys, $guid, $dummy); } $qb->add_constraint('topic', 'IN', $topic_ids); } else { // List from current node only $qb->add_constraint('topic', '=', $data['content_topic']->id); } } // Add filtering constraint if (isset($filters['type_filter'])) { $qb->add_constraint('type', '=', (int) $filters['type_filter']); } if (isset($filters['other'])) { // Handle other direct field mapping constraints foreach ($filters['other'] as $field => $filter) { $qb->add_constraint($field, '=', $filter); } } // Handle category filter if (isset($filters['category_filter'])) { $qb->add_constraint('category', 'LIKE', "%|{$filters['category_filter']}|%"); } return $qb; }
<?php // Available request keys: article, datamanager, edit_url, delete_url, create_urls $view = $data['view_article']; ?> <h1>&(view['title']:h);</h1> &(view['content']:h); <br /> <?php $topic = new midcom_db_topic(); $topic->get_by_path('/kkp_root/extranet/tiedotteet/lippukuntapostit'); $mc = midcom_db_topic::new_collector('up', $topic->id); $mc->add_constraint('component', '=', 'net.nehmer.blog'); $mc->add_value_property('name'); $mc->execute(); $keys = $mc->list_keys(); $counter = 0; foreach ($keys as $guid => $blog_topic) { $counter++; $topic_name = $mc->get_subkey($guid, 'name'); $dl_path = '/midcom-substyle-dl_frontpage/extranet/tiedotteet/lippukuntapostit/' . $topic_name . '/latest/4'; if ($counter % 2 != 0) { ?> <div class="content_fp_lift_container_left"> <?php } else { ?> <div class="content_fp_lift_container_right">
/** * Sets the constraints for QB for articles, supports article links etc.. * * @param midgard_query_builder $qb reference to the QB object * @param array $data reference to the request_data array */ public static function article_qb_constraints(&$qb, &$data, $handler_id) { $config =& $data['config']; // GUIDs of topics to list articles from. $guids_array = array(); $guids_array[] = $data['content_topic']->guid; // Resolve any other topics we may need $list_from_folders = $config->get('list_from_folders'); if ($list_from_folders) { // We have specific folders to list from, therefore list from them and current node $guids = explode('|', $config->get('list_from_folders')); foreach ($guids as $guid) { if (!$guid || !mgd_is_guid($guid)) { // Skip empty and broken guids continue; } $guids_array[] = $guid; } } /** * Ref #1776, expands GUIDs before adding them as constraints, should save query time */ $topic_ids = array(); $topic_ids[] = $data['content_topic']->id; if (!empty($guids_array)) { $mc = midcom_db_topic::new_collector('metadata.deleted', false); $mc->add_constraint('guid', 'IN', $guids_array); $topic_ids = $mc->get_values('id'); unset($mc); } // Include the article links to the indexes if enabled if ($config->get('enable_article_links')) { $mc = net_nehmer_blog_link_dba::new_collector('topic', $data['content_topic']->id); $mc->add_constraint('topic', '=', $data['content_topic']->id); $mc->add_order('metadata.published', 'DESC'); $mc->set_limit((int) $config->get('index_entries')); // Get the results $mc->execute(); $links = $mc->get_values('article'); $qb->begin_group('OR'); $qb->add_constraint('id', 'IN', $links); $qb->add_constraint('topic', 'IN', $topic_ids); $qb->end_group(); } else { $qb->add_constraint('topic', 'IN', $topic_ids); } if (count($topic_ids) > 1 && ($list_from_folders_categories = $config->get('list_from_folders_categories'))) { // TODO: check schema storage to get fieldname $multiple_categories = true; if (isset($data['schemadb']['default']) && isset($data['schemadb']['default']->fields['list_from_folders_categories']) && array_key_exists('allow_multiple', $data['schemadb']['default']->fields['list_from_folders_categories']['type_config']) && !$data['schemadb']['default']->fields['list_from_folders_categories']['type_config']['allow_multiple']) { $multiple_categories = false; } debug_add("multiple_categories={$multiple_categories}"); $qb->begin_group('OR'); $list_from_folders_categories = explode(',', $list_from_folders_categories); $is_content_topic = true; foreach ($topic_ids as $topic_id) { if ($is_content_topic) { $qb->add_constraint('topic', '=', $topic_id); $is_content_topic = false; continue; } $qb->begin_group('AND'); $qb->add_constraint('topic', '=', $topic_id); $qb->begin_group('OR'); foreach ($list_from_folders_categories as $category) { if ($category = trim($category)) { if ($multiple_categories) { $qb->add_constraint('extra1', 'LIKE', "%|{$category}|%"); } else { $qb->add_constraint('extra1', '=', $category); } } } $qb->end_group(); $qb->end_group(); } $qb->end_group(); } // Hide the articles that have the publish time in the future and if // the user is not administrator if ($config->get('enable_scheduled_publishing') && !midcom::get('auth')->admin) { // Show the article only if the publishing time has passed or the viewer // is the author $qb->begin_group('OR'); $qb->add_constraint('metadata.published', '<', gmdate('Y-m-d H:i:s')); if (midcom::get('auth')->user && isset(midcom::get('auth')->user->guid)) { $qb->add_constraint('metadata.authors', 'LIKE', '|' . midcom::get('auth')->user->guid . '|'); } $qb->end_group(); } $qb->add_constraint('up', '=', 0); }
/** * The handle callback populates root group information */ public function _on_can_handle($argc, $argv) { if ($this->_config->get('root_group') === 0) { $this->_request_data['root_group'] = 0; } else { $root_group = org_openpsa_products_product_group_dba::get_cached($this->_config->get('root_group')); $this->_request_data['root_group'] = $root_group->id; } if ($argc >= 1) { $mc = midcom_db_topic::new_collector('up', $this->_topic->id); $mc->add_constraint('name', '=', $argv[0]); $mc->execute(); $keys = $mc->list_keys(); if (count($keys) > 0) { // the values are dummy... return false; } } return true; }
/** * Small helper to determine a topic's parent id without loading the full object * * @param integer $topic_id The topic ID * @return integer The parent ID or false */ private function _get_parent_id($topic_id) { $mc = midcom_db_topic::new_collector('id', $topic_id); $result = $mc->get_values('up'); if (empty($result)) { return false; } return array_shift($result); }