From: Michael J. Rubinsky Date: Sun, 25 Jan 2009 21:21:18 +0000 (-0500) Subject: Very initial tagger stuff before I loose it. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2a9fa482e924aafca455684f8650ac5ced81f561;p=horde.git Very initial tagger stuff before I loose it. --- diff --git a/kronolith/calendars/edit.php b/kronolith/calendars/edit.php index 7ac53f358..dadbdcaf8 100644 --- a/kronolith/calendars/edit.php +++ b/kronolith/calendars/edit.php @@ -53,6 +53,8 @@ if ($form->validate($vars)) { $vars->set('name', $calendar->get('name')); $vars->set('description', $calendar->get('desc')); +$tags = new Kronolith_Tagger(); +$vars->set('tags', implode(',', array_values($tags->getTags($calendar->getName(), 'calendar')))); $title = $form->getTitle(); require KRONOLITH_TEMPLATES . '/common-header.inc'; require KRONOLITH_TEMPLATES . '/menu.inc'; diff --git a/kronolith/imple.php b/kronolith/imple.php index 46b468df0..f9b0245a4 100644 --- a/kronolith/imple.php +++ b/kronolith/imple.php @@ -27,7 +27,6 @@ $imple = Kronolith_Imple::factory($impleName); if (!$imple) { exit; } - $args = array(); foreach ($path as $pair) { if (strpos($pair, '=') === false) { diff --git a/kronolith/js/src/calendar-panel.js b/kronolith/js/src/calendar-panel.js index 408bd87c8..96fac0c24 100644 --- a/kronolith/js/src/calendar-panel.js +++ b/kronolith/js/src/calendar-panel.js @@ -13,6 +13,10 @@ function sbarToggle() new Ajax.Request(KronolithVar.pref_api_url, { parameters: { app: 'kronolith', pref: 'show_panel', value: pref_value } }); } +function removeTag(tagid) +{ + +} document.observe('dom:loaded', function() { $$('#pageControlsInner .checkbox').invoke('observe', 'click', function() { Views.invalidate(); diff --git a/kronolith/js/tagactions.js b/kronolith/js/tagactions.js new file mode 100755 index 000000000..2963adce5 --- /dev/null +++ b/kronolith/js/tagactions.js @@ -0,0 +1,38 @@ +function addTag() +{ + if (!$('addtag').value.blank()) { + var params = new Object(); + params.requestType="TagActions/action=add/gallery=" + tagActions.gallery + "/tags=" + $('addtag').value; + new Ajax.Updater({success:'tags'}, + tagActions.url, + { + method: 'post', + parameters: params, + onComplete: function() {$('addtag').value = "";} + } + ); + } + + return true; +} + +function removeTag(resource, type, tagid, endpoint) +{ + var params = new Object(); + params.imple = "TagActions/action=remove/resource=" + resource + "/type=" + type + "/tags=" + tagid; + new Ajax.Updater({success:'tags-' + resource}, + endpoint, + { + method: 'post', + parameters: params + } + ); + return true; +} + +// Since onsubmit is never called when submitting programatically we +// can use this function to add tags when we press enter on the tag form. +function submitcheck() +{ + return !addTag(); +} \ No newline at end of file diff --git a/kronolith/lib/Forms/CreateCalendar.php b/kronolith/lib/Forms/CreateCalendar.php old mode 100644 new mode 100755 index e00f70573..b30db8a3c --- a/kronolith/lib/Forms/CreateCalendar.php +++ b/kronolith/lib/Forms/CreateCalendar.php @@ -32,7 +32,7 @@ class Kronolith_CreateCalendarForm extends Horde_Form { $this->addVariable(_("Name"), 'name', 'text', true); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); - + $this->addVariable(_("Tags"), 'tags', 'text', false); $this->setButtons(array(_("Create"))); } @@ -45,6 +45,8 @@ class Kronolith_CreateCalendarForm extends Horde_Form { } $calendar->set('name', $this->_vars->get('name')); $calendar->set('desc', $this->_vars->get('description')); + $tagger = new Kronolith_Tagger(); + $tagger->tag($calendar->getName(), explode(',', $this->_vars->get('tags')), 'calendar'); return $GLOBALS['kronolith_shares']->addShare($calendar); } diff --git a/kronolith/lib/Forms/EditCalendar.php b/kronolith/lib/Forms/EditCalendar.php index 94aefa2ff..03464e3b2 100644 --- a/kronolith/lib/Forms/EditCalendar.php +++ b/kronolith/lib/Forms/EditCalendar.php @@ -39,7 +39,7 @@ class Kronolith_EditCalendarForm extends Horde_Form { $this->addHidden('', 'c', 'text', true); $this->addVariable(_("Name"), 'name', 'text', true); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); - + $this->addVariable(_("Tags"), 'tags', 'text', false); $this->setButtons(array(_("Save"))); } @@ -49,7 +49,8 @@ class Kronolith_EditCalendarForm extends Horde_Form { $new_name = $this->_vars->get('name'); $this->_calendar->set('name', $new_name); $this->_calendar->set('desc', $this->_vars->get('description')); - + $tagger = new Kronolith_Tagger(); + $tagger->tag($this->_calendar->getName(), explode(',', $this->_vars->get('tags')), 'calendar'); if ($original_name != $new_name) { $result = $GLOBALS['kronolith_driver']->rename($original_name, $new_name); if (is_a($result, 'PEAR_Error')) { diff --git a/kronolith/lib/Imple/TagActions.php b/kronolith/lib/Imple/TagActions.php new file mode 100644 index 000000000..115698085 --- /dev/null +++ b/kronolith/lib/Imple/TagActions.php @@ -0,0 +1,57 @@ +_params) == 0) { + return; + } + Horde::addScriptFile('tagactions.js'); + $dom_id = $this->_params['triggerId']; + $action = $this->_params['action']; + $content_id = $this->_params['resource']; + $content_type = $this->_params['type']; + $tag_id = $this->_params['tagId']; + $endpoint = Horde::url('imple.php', true); + + if ($action == 'add') { + $js = "Event.observe('" . $dom_id . "', 'click', function(event) {addTag(); Event.stop(event)});"; + } elseif ($action == 'delete') { + $js = "Event.observe('" . $dom_id . "', 'click', function(event) {removeTag('" . $content_id . "', '" . $content_type . "', " . $tag_id . ", '" . $endpoint . "'); Event.stop(event)});"; + } + Kronolith::addInlineScript($js, 'window'); + } + + public function handle($args) + { + global $ansel_storage; + + $request = $args['action']; + $content = array('id' => $args['resource'], 'type' => $args['type']); + $tags = $args['tags']; + + /* Get the resource owner */ + /* Perms checks */ + + switch ($request) { + case 'add': + break; + case 'remove': + $tagger = new Kronolith_Tagger(); + //$tagger-> + + + break; + } + } + + private function _getTagHtml($tags, $hasEdit) + { + } + +} diff --git a/kronolith/lib/Tagger.php b/kronolith/lib/Tagger.php new file mode 100644 index 000000000..079565042 --- /dev/null +++ b/kronolith/lib/Tagger.php @@ -0,0 +1,94 @@ +get('fileroot', 'content') . '/lib/'); + +class Kronolith_Tagger { + + protected static $_type_ids = array(); + protected static $_tagger; + + public function __construct() + { + if (is_null(self::$_tagger)) { + // Set up the context for the tagger and related content classes + $GLOBALS['conf']['sql']['adapter'] = $GLOBALS['conf']['sql']['phptype'] == 'mysqli' ? + 'mysqli' : + 'pdo_' . $GLOBALS['conf']['sql']['phptype']; + + Horde_Db::setAdapter(Horde_Db_Adapter::factory($GLOBALS['conf']['sql'])); + + $context = array('dbAdapter' => Horde_Db::getAdapter()); + $user_mgr = new Content_Users_Manager($context); + $type_mgr = new Content_Types_Manager($context); + + // Objects_Manager requires a Types_Manager + $context['typeManager'] = $type_mgr; + $object_mgr = new Content_Objects_Manager($context); + + // Create the Content_Tagger + $context['userManager'] = $user_mgr; + $context['objectManager'] = $object_mgr; + + self::$_tagger = new Content_Tagger($context); + $types = $type_mgr->ensureTypes(array('calendar', 'event')); + self::$_type_ids = array('calendar' => $types[0], 'event' => $types[1]); + } + } + + /** + * Tag a kronolith object with any number of tags. + * + * @param string $localId The identifier of the kronolith object. + * @param mixed $tags Either a single tag string or an array of tags. + * @param string $content_type The type of object we are tagging (event/calendar). + * + * @return void + */ + public function tag($localId, $tags, $content_type = 'event') + { + self::$_tagger->tag(Auth::getAuth(), + array('object' => $localId, + 'type' => self::$_type_ids[$content_type]), + $tags); + } + + /** + * Retrieve the tags on a given object(s) + */ + public function getTags($localId, $type = 'event') + { + if (!is_array($localId)) { + $localId = array($localId); + } + $tags = array(); + foreach ($localId as $id) { + $tags = $tags + self::$_tagger->getTags(array('objectId' => array('object' => $id, 'type' => $type))); + } +var_dump($tags); + return $tags; + } + + public function untag($localId, $tag, $content_type = 'event') + { + //self::$_tagger-> + } + + /** + * tag search - return all types of content we care about tagged with + * the passed in tags + * + * @param array $tags An array of tag ids. + */ + public function search($tags, $content_type = null) + { + $this->getObjects(array('tagId' => $tags, '')); + } + +} diff --git a/kronolith/templates/panel.inc b/kronolith/templates/panel.inc index a9d353da4..b717e3cc6 100644 --- a/kronolith/templates/panel.inc +++ b/kronolith/templates/panel.inc @@ -16,6 +16,8 @@ foreach (Kronolith::listCalendars() as $id => $cal) { $shared_calendars[$id] = $cal; } } + +$tagger = new Kronolith_Tagger(); ?>
@@ -41,7 +43,21 @@ foreach (Kronolith::listCalendars() as $id => $cal) {