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

callFromInterface() public static method

Calls a method that has to be implemented though the tags interface
public static callFromInterface ( string $module, string $class, string $method, mixed $parameter = null ) : mixed
$module string The module wherein to search.
$class string The class that should contain the method.
$method string The method to call.
$parameter mixed The parameters to pass.
return mixed
    public static function callFromInterface($module, $class, $method, $parameter = null)
    {
        // check to see if the interface is implemented
        if (in_array('Frontend\\Modules\\Tags\\Engine\\TagsInterface', class_implements($class))) {
            // return result
            return call_user_func(array($class, $method), $parameter);
        } else {
            throw new FrontendException('To use the tags module you need
                to implement the FrontendTagsInterface
                in the model of your module
                (' . $module . ').');
        }
    }

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);
         }
     }
 }
All Usage Examples Of Frontend\Modules\Tags\Engine\Model::callFromInterface