Esempio n. 1
0
 public function convert_from_storage($source)
 {
     if (!$this->storage->object) {
         // That's all folks, no storage object, thus we cannot continue.
         return;
     }
     $tags = net_nemein_tag_handler::get_object_tags($this->storage->object);
     $this->value = net_nemein_tag_handler::tag_array2string($tags);
 }
Esempio n. 2
0
 /**
  * Tags given object with the tags in the string
  *
  * Creates missing tags and tag_links, sets tag_link navorder
  * Deletes tag links from object that are not in the list provided
  *
  * @param object &$object MidCOM DBA object
  * @param array $tags List of tags and urls, tag is key, url is value
  * @return boolean indicating success/failure
  * @todo Set the link->navorder property
  */
 public static function tag_object(&$object, $tags, $component = null)
 {
     if (is_null($component)) {
         $component = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_COMPONENT);
     }
     $existing_tags = net_nemein_tag_handler::get_object_tags($object);
     if (!is_array($existing_tags)) {
         // Major failure when getting existing tags
         debug_add('get_object_tags() reported critical failure, aborting', MIDCOM_LOG_ERROR);
         return false;
     }
     // Determine operations
     $add_tags = array();
     $update_tags = array();
     $remove_tags = array();
     foreach ($tags as $tagname => $url) {
         if (empty($tagname)) {
             unset($tags[$tagname]);
             continue;
         }
         if (!array_key_exists($tagname, $existing_tags)) {
             $add_tags[$tagname] = $url;
         } else {
             if (!empty($url)) {
                 $update_tags[$tagname] = $url;
             }
         }
     }
     foreach ($existing_tags as $tagname => $url) {
         if (!array_key_exists($tagname, $tags)) {
             $remove_tags[$tagname] = true;
         }
     }
     // Excute
     foreach ($remove_tags as $tagname => $bool) {
         self::_remove_tag($tagname, $object->guid);
     }
     foreach ($update_tags as $tagname => $url) {
         self::_update_tag($tagname, $url, $object->guid);
     }
     foreach ($add_tags as $tagname => $url) {
         self::_create_tag($tagname, $url, $object, $component);
     }
     return true;
 }
Esempio n. 3
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. 4
0
    echo "Categories: \n";
    $cats_shown = 0;
    foreach ($categories as $category) {
        $cats_shown++;
        if (substr($category, 0, 5) == 'feed:') {
            continue;
        }
        $category = htmlspecialchars($category);
        echo "{$category}";
        if ($cats_shown < count($categories)) {
            echo ",";
        }
        echo " \n";
    }
}
$tags = net_nemein_tag_handler::get_object_tags($data['article']);
if (count($tags) > 0) {
    echo "<br />Tags: \n";
    $tags_shown = 0;
    foreach ($tags as $tag => $url) {
        $tags_shown++;
        $tag = htmlspecialchars($tag);
        echo "<a href=\"{$url}\" rel=\"tag\">{$tag}</a>";
        if ($tags_shown < count($tags)) {
            echo ",";
        }
        echo " \n";
    }
}
?>
        </div><!-- /tags -->
Esempio n. 5
0
        midcom::get('componentloader')->load_graceful($component);
    }
    // Could not get required class defined, abort
    if (!class_exists($class)) {
        $response->errstr = "Class {$class} could not be loaded";
        $reponse->send();
    }
    $qb = call_user_func(array($class, 'new_query_builder'));
    $qb->add_constraint($id_field, '=', $object_id);
    $results = $qb->execute();
    if ($results === false) {
        $response->errstr = "Error when executing QB";
        $reponse->send();
    }
    $object = $results[0];
    $tags = net_nemein_tag_handler::get_object_tags($object);
    foreach ($tags as $name => $link) {
        $data = array('id' => $name, 'name' => $name, 'color' => '8596b6');
        $items[$name] = $data;
    }
} else {
    if (!class_exists($callback)) {
        // Try auto-load.
        $path = MIDCOM_ROOT . '/' . str_replace('_', '/', $callback) . '.php';
        if (!file_exists($path)) {
            debug_add("Auto-loading of the callback class {$callback} from {$path} failed: File does not exist.", MIDCOM_LOG_ERROR);
            return false;
        }
        require_once $path;
    }
    if (!class_exists($callback)) {
Esempio n. 6
0
 private function _save_to_taglib()
 {
     if ($this->allow_other && !empty($this->others)) {
         $merged = array_merge($this->selection, $this->others);
         foreach ($merged as $k => $tag) {
             $tags[$tag] = '';
         }
     } else {
         if (count($this->selection) == 0) {
             return;
         } else {
             foreach ($this->selection as $k => $tag) {
                 $tags[$tag] = '';
             }
         }
     }
     debug_print_r('new tags to be saved to n.n.tag', $tags);
     $status = net_nemein_tag_handler::tag_object($this->storage->object, $tags);
     if (!$status) {
         debug_print_r('Tried to save the tags', $tags);
         debug_add("for field {$this->name}, but failed. Ignoring silently.", MIDCOM_LOG_WARN);
     }
     $tmp_tags = net_nemein_tag_handler::get_object_tags($this->storage->object);
     $tags = array();
     foreach ($tmp_tags as $name => $url) {
         $tags[$name] = $name;
     }
     debug_print_r("new tags:", $tags);
 }