Source of file TagsObjectindexedlistener.php

Size: 2,491 Bytes - Last Modified: 2016-05-18T03:08:27+02:00

buildproject/core/module_tags/event/TagsObjectindexedlistener.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
<?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2016 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                    *
********************************************************************************************************/

namespace Kajona\Tags\Event;

use Kajona\Search\System\SearchDocument;
use Kajona\System\System\CoreEventdispatcher;
use Kajona\System\System\GenericeventListenerInterface;
use Kajona\System\System\SystemModule;
use Kajona\Tags\System\TagsTag;

/**
 * Takes care of adding assigned tags to the objects' index
 *
 * @package module_tags
 * @author sidler@mulchprod.de
 * @since 4.4
 *
 */
class TagsObjectindexedlistener implements GenericeventListenerInterface
{


    /**
     * Called whenever an object is index and to be added to the search-index.
     * Use this callback to add additional content to the objects search-document.
     *
     * @param string $strEventName
     * @param array $arrArguments
     *
     * @return bool
     */
    public function handleEvent($strEventName, array $arrArguments)
    {

        //unwrap arguments
        /** @var \Kajona\System\System\Model $objObject */
        $objObject = $arrArguments[0];
        /** @var SearchDocument $objSearchDocument */
        $objSearchDocument = $arrArguments[1];

        if (SystemModule::getModuleByName("tags") == null) {
            return true;
        }

        //load tags for the object
        $objTags = TagsTag::getTagsForSystemid($objObject->getSystemid());

        foreach ($objTags as $objOneTag) {
            $objSearchDocument->addContent("tag", $objOneTag->getStrName());
        }

        return true;

    }

    /**
     * Internal init block, called on file-inclusion, e.g. by the class-loader
     *
     * @return void
     */
    public static function staticConstruct()
    {
        CoreEventdispatcher::getInstance()->removeAndAddListener("core.search.objectindexed", new TagsObjectindexedlistener());
    }

}

//static init block on include
TagsObjectindexedlistener::staticConstruct();