Backend\Modules\Tags\Engine\Model::getTags PHP Method

getTags() public static method

Get tags for an item
public static getTags ( string $module, integer $otherId, string $type = 'string', string $language = null ) : mixed
$module string The module wherein will be searched.
$otherId integer The id of the record.
$type string The type of the returnvalue, possible values are: array, string (tags will be joined by ,).
$language string The language to use, if not provided the working language will be used.
return mixed
    public static function getTags($module, $otherId, $type = 'string', $language = null)
    {
        $module = (string) $module;
        $otherId = (int) $otherId;
        $type = (string) \SpoonFilter::getValue($type, array('string', 'array'), 'string');
        $language = $language != null ? (string) $language : BL::getWorkingLanguage();
        // fetch tags
        $tags = (array) BackendModel::getContainer()->get('database')->getColumn('SELECT i.tag
             FROM tags AS i
             INNER JOIN modules_tags AS mt ON i.id = mt.tag_id
             WHERE mt.module = ? AND mt.other_id = ? AND i.language = ?
             ORDER BY i.tag ASC', array($module, $otherId, $language));
        // return as an imploded string
        if ($type == 'string') {
            return implode(',', $tags);
        }
        // return as array
        return $tags;
    }

Usage Example

Example #1
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // get values for the form
     $rbtHiddenValues[] = array('label' => BL::lbl('Hidden'), 'value' => 'Y');
     $rbtHiddenValues[] = array('label' => BL::lbl('Published'), 'value' => 'N');
     $categories = BackendFaqModel::getCategories();
     // create form
     $this->frm = new BackendForm('edit');
     $this->frm->addText('title', $this->record['question'], null, 'inputText title', 'inputTextError title');
     $this->frm->addEditor('answer', $this->record['answer']);
     $this->frm->addRadiobutton('hidden', $rbtHiddenValues, $this->record['hidden']);
     $this->frm->addDropdown('category_id', $categories, $this->record['category_id']);
     $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->record['id']), null, 'inputText tagBox', 'inputTextError tagBox');
     $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true);
 }
All Usage Examples Of Backend\Modules\Tags\Engine\Model::getTags