Frontend\Modules\Tags\Engine\Model::getModulesForTag PHP Method

getModulesForTag() public static method

Get the modules that used a tag.
public static getModulesForTag ( integer $id ) : array
$id integer The id of the tag.
return array
    public static function getModulesForTag($id)
    {
        return (array) FrontendModel::getContainer()->get('database')->getColumn('SELECT module
             FROM modules_tags
             WHERE tag_id = ?
             GROUP BY module
             ORDER BY module ASC', array((int) $id));
    }

Usage Example

Example #1
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // fetch record
     $this->record = FrontendTagsModel::get($this->URL->getParameter(1));
     // validate record
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // fetch modules
     $this->modules = FrontendTagsModel::getModulesForTag($this->record['id']);
     // loop modules
     foreach ($this->modules as $module) {
         // get the ids of the items linked to the tag
         $otherIds = (array) $this->get('database')->getColumn('SELECT other_id
              FROM modules_tags
              WHERE module = ? AND tag_id = ?', array($module, $this->record['id']));
         // set module class
         $class = 'Frontend\\Modules\\' . $module . '\\Engine\\Model';
         // get the items that are linked to the tags
         $items = (array) FrontendTagsModel::callFromInterface($module, $class, 'getForTags', $otherIds);
         // add into results array
         if (!empty($items)) {
             $this->results[] = array('name' => $module, 'label' => FL::lbl(\SpoonFilter::ucfirst($module)), 'items' => $items);
         }
     }
 }