Esempio n. 1
0
 /**
  * Does a local search for persons that match the task constraints
  *
  * @param org_openpsa_projects_task_dba &$task Task object to search prospect resources for
  * @return array of prospect persons (or false on critical failure)
  */
 function find_task_prospects(&$task)
 {
     midcom::get('componentloader')->load_graceful('net.nemein.tag');
     if (!class_exists('net_nemein_tag_handler')) {
         return false;
     }
     $return = array();
     $classes = array('midgard_person', 'midcom_db_person', 'org_openpsa_contacts_person_dba');
     $tag_map = net_nemein_tag_handler::get_object_tags($task);
     if (!is_array($tag_map)) {
         // Critical failure when fetching tags, aborting
         return false;
     }
     $tags = array();
     // Resolve tasks tags (with contexts) into single array of tags without contexts
     foreach ($tag_map as $tagname => $url) {
         $tag = net_nemein_tag_handler::resolve_tagname($tagname);
         $tags[$tag] = $tag;
     }
     $persons = net_nemein_tag_handler::get_objects_with_tags($tags, $classes, 'AND');
     if (!is_array($persons)) {
         return false;
     }
     // Normalize to contacts person class if necessary
     foreach ($persons as $obj) {
         switch (true) {
             case is_a($obj, 'org_openpsa_contacts_person_dba'):
                 $return[] = $obj;
                 break;
             default:
                 try {
                     $tmpobj = new org_openpsa_contacts_person_dba($obj->id);
                 } catch (midcom_error $e) {
                     break;
                 }
                 $return[] = $tmpobj;
                 break;
         }
     }
     // TODO: Check other constraints (available time, country, time zone)
     $this->_find_task_prospects_filter_by_minimum_time_slot($task, $return);
     return $return;
 }
Esempio n. 2
0
 /**
  * Links to other wiki pages tagged with arbitrary tags
  */
 private function _run_macro_tagged($macro_content, $fulltag, $after)
 {
     if (!midcom::get('componentloader')->load_library('net.nemein.tag')) {
         // TODO: do something to explain that we can't load n.n.tag...
         return $fulltag;
     }
     $tags_exploded = explode(',', $macro_content);
     $tags = array();
     foreach ($tags_exploded as $tagname) {
         if (empty($tagname)) {
             continue;
         }
         $tag = net_nemein_tag_handler::resolve_tagname(trim($tagname));
         $tags[$tag] = $tag;
     }
     $classes = array('net_nemein_wiki_wikipage', 'midcom_db_article', 'midgard_article');
     $pages = net_nemein_tag_handler::get_objects_with_tags($tags, $classes, 'OR');
     if (!is_array($pages)) {
         // Failure in tag library
         return $fulltag;
     }
     $nap = new midcom_helper_nav();
     static $node_cache = array();
     $ret = "\n<ul class=\"tagged\">\n";
     usort($pages, array($this, '_code_sort_by_title'));
     foreach ($pages as $page) {
         if (!isset($node_cache[$page->topic])) {
             $node_cache[$page->topic] = $nap->get_node($page->topic);
         }
         $node =& $node_cache[$page->topic];
         if ($node[MIDCOM_NAV_COMPONENT] !== 'net.nemein.wiki') {
             // We only wish to link to wiki pages
             continue;
         }
         $url = $node[MIDCOM_NAV_FULLURL] . "{$page->name}/";
         $ret .= "    <li class=\"page\"><a href=\"{$url}\">{$page->title}</a></li>\n";
     }
     $ret .= "</ul>\n";
     return $ret . $after;
 }