Frontend\Modules\Tags\Widgets\Related::getRelated PHP Method

getRelated() private method

Get related "things" based on tags
private getRelated ( )
    private function getRelated()
    {
        // loop tags
        foreach ($this->tags as $tag) {
            // fetch entries
            $items = (array) $this->get('database')->getRecords('SELECT mt.module, mt.other_id
                 FROM modules_tags AS mt
                 INNER JOIN tags AS t ON t.id = mt.tag_id
                 WHERE t.language = ? AND t.tag = ?', array(LANGUAGE, $tag));
            // loop items
            foreach ($items as $item) {
                // loop existing items
                foreach ($this->related as $related) {
                    // already exists
                    if ($item == $related) {
                        continue 2;
                    }
                }
                // add to list of related items
                $this->related[] = $item;
            }
        }
        // loop entries
        foreach ($this->related as $id => $entry) {
            // loop excluded records
            foreach ($this->exclude as $exclude) {
                // check if this entry should be excluded
                if ($entry['module'] == $exclude['module'] && $entry['other_id'] == $exclude['other_id']) {
                    unset($this->related[$id]);
                    continue 2;
                }
            }
            // set module class
            $class = 'Frontend\\Modules\\' . $entry['module'] . '\\Engine\\Model';
            // get module record
            $this->related[$id] = FrontendTagsModel::callFromInterface($entry['module'], $class, 'getForTags', (array) array($entry['other_id']));
            if ($this->related[$id]) {
                $this->related[$id] = array_pop($this->related[$id]);
            }
            // remove empty items
            if (empty($this->related[$id])) {
                unset($this->related[$id]);
            }
        }
        // only show 3
        $this->related = array_splice($this->related, 0, 3);
    }