JoomlaCamp 2018 Essen - 03.02.2017 in Essen

Datensätze gleichzeitig aktualisieren

    Datensätze gleichzeitig aktualisieren

    Guten Tag, ich habe eine Tabelle wo Tag´s gespeichert werden. Die Tag´s werden auf der Seite über die item_id dem jeweiligen Produkt angezeigt. Nun möchte ich zu jedem Datensatz einen Tag hinzufügen ohne für jeden Datensatz eine eigene Eingabe vorzunehmen (ca. 800 item_id´s). Unter phpmyadmin hat man die Möglichkeit einzelne Eingaben zu machen. Gibt es eine Eingabe für WERT die zu allen item_id´s einen Tag hinzufügt?

    Hier mal ein Beispiel was ich meine. Wenn ich z.B. das Wort "Beispiel" in alle item_id´s gleichzeitig schreiben möchte was müsste ich bei WERT eingeben? (Falls das überhaupt geht) Oder kann man das anders löen?




    Vielen Dank für eure Hilfe!
    Also in der view.html.php steht jetzt:

    Quellcode

    1. protected function addToolbar()
    2. {
    3. JToolbarHelper::title(JText::_('COM_ADMIN_HELP'), 'support help_header');
    4. JToolbarHelper::custom('viewname.deinTask', 'DeinIcon', 'DeinIcon', 'Werte für Tags setzen', true);
    5. }


    Ich habe dazu auch das hier gelesen. Verstehe ich allerdings nicht.
    So der Button ist schon mal da :)

    Dazu muss man in ZOO Code 1) in administrator/components/com_zoo/views/tag/tmpl/default.php eintragen

    Der Code 2) gehört dann wohl in administrator/components/com_zoo/controllers/tag.php wo er allerdings einen white screen verursacht.

    Das lag wohl auch daran das bei &view=deinView); ein (') fehlte &view=deinView');

    Jetzt gibt es nur noch ärger wegen "public function TaskName()". Irgendwie will der nicht funktionieren in der tag.php (Code im Spoiler)

    Spoiler anzeigen

    PHP-Quellcode

    1. <?php
    2. /**
    3. * @package com_zoo
    4. * @author YOOtheme http://www.yootheme.com
    5. * @copyright Copyright (C) YOOtheme GmbH
    6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
    7. */
    8. /*
    9. Class: TagController
    10. The controller class for tag
    11. */
    12. class TagController extends AppController {
    13. public $application;
    14. public function __construct($default = array()) {
    15. parent::__construct($default);
    16. // set table
    17. $this->table = $this->app->table->tag;
    18. // get application
    19. $this->application = $this->app->zoo->getApplication();
    20. // set base url
    21. $this->baseurl = $this->app->link(array('controller' => $this->controller), false);
    22. }
    23. public function display($cachable = false, $urlparams = false) {
    24. // set toolbar items
    25. $this->app->system->application->JComponentTitle = $this->application->getToolbarTitle(JText::_('Tags'));
    26. $this->app->toolbar->deleteList();
    27. $this->app->zoo->toolbarHelp();
    28. $this->app->html->_('behavior.tooltip');
    29. // get request vars
    30. $state_prefix = $this->option.'_'.$this->application->id.'.tags.';
    31. $filter_order = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_order', 'filter_order', '', 'cmd');
    32. $filter_order_Dir = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_order_Dir', 'filter_order_Dir', 'desc', 'word');
    33. $limit = $this->app->system->application->getUserStateFromRequest('global.list.limit', 'limit', $this->app->system->config->get('list_limit'), 'int');
    34. $limitstart = $this->app->system->application->getUserStateFromRequest($state_prefix.'limitstart', 'limitstart', 0, 'int');
    35. $search = $this->app->system->application->getUserStateFromRequest($state_prefix.'search', 'search', '', 'string');
    36. $search = $this->app->string->strtolower($search);
    37. // is filtered ?
    38. $this->is_filtered = !empty($search);
    39. // in case limit has been changed, adjust limitstart accordingly
    40. $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
    41. // get data
    42. $filter = ($filter_order) ? $filter_order . ' ' . $filter_order_Dir : '';
    43. $count = (int) $this->table->count($this->application->id, $search);
    44. $limitstart = $limitstart > $count ? floor($count / $limit) * $limit : $limitstart;
    45. $this->tags = $this->table->getAll($this->application->id, $search, '', $filter, $limitstart, $limit);
    46. $this->pagination = $this->app->pagination->create($count, $limitstart, $limit);
    47. // table ordering and search filter
    48. $this->lists['order_Dir'] = $filter_order_Dir;
    49. $this->lists['order'] = $filter_order;
    50. $this->lists['search'] = $search;
    51. // display view
    52. $this->getView()->display();
    53. }
    54. public function remove() {
    55. // init vars
    56. $tags = $this->app->request->get('cid', 'array', array());
    57. if (count($tags) < 1) {
    58. $this->app->error->raiseError(500, JText::_('Select a tag to delete'));
    59. }
    60. try {
    61. // delete tags
    62. $this->table->delete($tags, $this->application->id);
    63. // set redirect message
    64. $msg = JText::_('Tag Deleted');
    65. } catch (AppException $e) {
    66. // raise notice on exception
    67. $this->app->error->raiseWarning(0, JText::_('Error Deleting Tag').' ('.$e.')');
    68. $msg = null;
    69. }
    70. $this->setRedirect($this->baseurl, $msg);
    71. }
    72. public function update() {
    73. // init vars
    74. $old = $this->app->request->getString('old');
    75. $new = $this->app->request->getString('new');
    76. $msg = null;
    77. try {
    78. // update tag
    79. if (!empty($new) && $old != $new) {
    80. $this->table->update($this->application->id, $old, $new);
    81. // set redirect message
    82. $msg = JText::_('Tag Updated Successfully');
    83. }
    84. } catch (AppException $e) {
    85. // raise notice on exception
    86. $this->app->error->raiseWarning(0, JText::_('Error Updating Tag').' ('.$e.')');
    87. }
    88. $this->setRedirect($this->baseurl, $msg);
    89. }
    90. }
    91. /*
    92. Class: TagControllerException
    93. */
    94. class TagControllerException extends AppException {}
    Ich poste einfachmal die beiden Dateien:

    administrator/components/com_zoo/controllers/tag.php

    Spoiler anzeigen

    PHP-Quellcode

    1. <?php
    2. /**
    3. * @package com_zoo
    4. * @author YOOtheme http://www.yootheme.com
    5. * @copyright Copyright (C) YOOtheme GmbH
    6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
    7. */
    8. /**
    9. * The general helper class for tags
    10. *
    11. * @package Component.Helpers
    12. * @since 2.0
    13. */
    14. class TagHelper extends AppHelper {
    15. /**
    16. * Loads and gets a list of tags in JSON format
    17. *
    18. * @param int $application_id
    19. * @param string $tag
    20. *
    21. * @return string Tags in JSON format
    22. * @since 2.0
    23. */
    24. public function loadtags($application_id, $tag) {
    25. $tags = array();
    26. if (!empty($tag)) {
    27. // get tags
    28. $tag_objects = $this->app->table->tag->getAll($application_id, $tag, '', 'a.name asc');
    29. foreach ($tag_objects as $tag) {
    30. $tags[] = $tag->name;
    31. }
    32. }
    33. return json_encode($tags);
    34. }
    35. }


    administrator/components/com_zoo/views/tag/tmpl/default.php

    Spoiler anzeigen

    PHP-Quellcode

    1. <?php
    2. /**
    3. * @package com_zoo
    4. * @author YOOtheme http://www.yootheme.com
    5. * @copyright Copyright (C) YOOtheme GmbH
    6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
    7. */
    8. // no direct access
    9. defined('_JEXEC') or die('Restricted access');
    10. // add js
    11. $this->app->document->addScript('assets:js/tag.js');
    12. // filter output
    13. foreach ($this->tags as $tag) {
    14. JFilterOutput::objectHTMLSafe($tag, ENT_QUOTES);
    15. }
    16. ?>
    17. <form class="tags-default" action="<?php echo $this->app->link(array('controller' => $this->controller)); ?>" method="post" name="adminForm" id="adminForm" accept-charset="utf-8">
    18. <?php echo $this->partial('menu'); ?>
    19. <div class="box-bottom">
    20. <?php if ($this->is_filtered || count($this->tags) > 0) :?>
    21. <ul class="filter">
    22. <li class="filter-left">
    23. <input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="rounded" />
    24. <button onclick="this.form.submit();"><?php echo JText::_('Search'); ?></button>
    25. <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_('Reset'); ?></button>
    26. </li>
    27. <?php if ($this->app->joomla->version->isCompatible('3.0')) : ?>
    28. <li class="filter-right">
    29. <?php echo str_replace(array('input-mini', 'size="1"'), '', $this->pagination->getLimitBox()); ?>
    30. </li>
    31. <?php endif ?>
    32. </ul>
    33. <?php endif;
    34. if(count($this->tags) > 0) : ?>
    35. <table class="list stripe">
    36. <thead>
    37. <tr>
    38. <th class="checkbox">
    39. <input type="checkbox" class="check-all" />
    40. </th>
    41. <th class="name" colspan="2">
    42. <?php echo $this->app->html->_('grid.sort', 'Name', 'a.name', @$this->lists['order_Dir'], @$this->lists['order']); ?>
    43. </th>
    44. <th class="items" colspan="1">
    45. <?php echo $this->app->html->_('grid.sort', 'Items', 'items', @$this->lists['order_Dir'], @$this->lists['order']); ?>
    46. </th>
    47. </tr>
    48. </thead>
    49. <tfoot>
    50. <tr>
    51. <td colspan="4">
    52. <?php echo $this->pagination->getListFooter(); ?>
    53. </td>
    54. </tr>
    55. </tfoot>
    56. <tbody>
    57. <?php foreach ($this->tags as $tag) : ?>
    58. <?php $link_items = $this->app->link(array('controller' => 'item','filter_category_id' => '-1', 'filter_type' => '', 'filter_author_id' => '', 'search' => $tag->name)); ?>
    59. <tr>
    60. <td class="checkbox">
    61. <input type="checkbox" name="cid[]" value="<?php echo $tag->name; ?>" />
    62. </td>
    63. <td class="icon"></td>
    64. <td class="name">
    65. <span class="edit-tag">
    66. <a href="#" title="<?php echo JText::_('Edit Tag');?>"><?php echo $tag->name; ?></a>
    67. </span>
    68. </td>
    69. <td class="items">
    70. <a href="<?php echo $link_items; ?>"><?php echo $tag->items; ?></a>
    71. </td>
    72. </tr>
    73. <?php endforeach; ?>
    74. </tbody>
    75. </table>
    76. <?php elseif($this->is_filtered) :
    77. $title = JText::_('SEARCH_NO_TAG').'!';
    78. $message = null;
    79. echo $this->partial('message', compact('title', 'message'));
    80. else :
    81. $title = JText::_('NO_TAGS_YET').'!';
    82. $message = JText::_('TAG_MANAGER_DESCRIPTION');
    83. echo $this->partial('message', compact('title', 'message'));
    84. endif;
    85. ?>
    86. </div>
    87. <input type="hidden" name="controller" value="<?php echo $this->controller; ?>" />
    88. <input type="hidden" name="task" value="" />
    89. <input type="hidden" name="boxchecked" value="0" />
    90. <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
    91. <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
    92. <input type="hidden" name="changeapp" value="<?php echo $this->application->id; ?>" />
    93. <?php echo $this->app->html->_('form.token'); ?>
    94. <script type="text/javascript">
    95. jQuery(function($) {
    96. $('#adminForm').BrowseTags({ msgSave: '<?php echo JText::_('Save'); ?>', msgCancel: '<?php echo JText::_('Cancel'); ?>' });
    97. });
    98. </script>
    99. </form>
    100. <?php echo ZOO_COPYRIGHT;

forum.joomla.de is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.