This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 
<?php defined('C5_EXECUTE') or die("Access Denied.");
/**
 * A block for displaying and linking to search for tags in a page.
 *
 * @package Blocks
 * @subpackage Tags
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2012 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
    
class Concrete5_Controller_Block_Tags extends BlockController {

    protected $btTable = 'btTags';
    protected $btInterfaceWidth = "450";
    protected $btInterfaceHeight = "260";

    protected $btExportPageColumns = array('targetCID');
    
    protected $btCacheBlockRecord = true;
    protected $btCacheBlockOutput = true;
    protected $btCacheBlockOutputOnPost = false;
    protected $btCacheBlockOutputForRegisteredUsers = false;
    protected $btWrapperClass = 'ccm-ui';
    
    public $attributeHandle = 'tags';
    public $displayMode = 'page';
    public $cloudCount = 10;
    public $helpers =  array('navigation'); 
    
    /** 
     * Used for localization. If we want to localize the name/description we have to include this
    */
    public function getBlockTypeDescription() {
        return t("List pages based on type, area.");
    }
    
    public function getBlockTypeName() {
        return t("Tags");
    }
    
    public function add() { 
        $ak = $this->loadAttribute();
        $this->set('ak',$ak);
        if ($this->isValidStack(Page::getCurrentPage())) {
            $this->set('inStackDashboardPage', true);
        }
        $this->set('displayMode','page');
    }
    
    protected function loadAttribute() {
        $ak = CollectionAttributeKey::getByHandle($this->attributeHandle);
        return $ak;
    }
    
    public function edit() { 
        $ak = $this->loadAttribute();
        $this->set('ak',$ak);
        if ($this->isValidStack(Page::getCurrentPage())) {
            $this->set('inStackDashboardPage', true);
        }
    }
    
    public function view() {
        $ak = $this->loadAttribute();
        if($this->displayMode == "cloud") {
            $type = $ak->getAttributeType();
            $controller = $type->getController();
            $controller->setAttributeKey($ak);
            $items = $controller->getOptions();
            $options = new SelectAttributeTypeOptionList();
            if($this->cloudCount > 0 && $items instanceof SelectAttributeTypeOptionList && $items->count()) {
                $i = 1;
                foreach($items as $item) {
                    $options->add($item); 
                    if($i >=$this->cloudCount) { break;}
                    $i++;
                }
            } else {
                $options = $items;
            }
        } else {
            $c = Page::getCurrentPage();
            $av = $c->getAttributeValueObject($ak);
            $controller = $ak->getController();
            $options = $c->getAttribute($ak->getAttributeKeyHandle());
        }
        
        if($this->targetCID > 0) {
            $target = Page::getByID($this->targetCID);
            $this->set('target',$target);
        }       
        
        // grab selected tag, if we're linking to a page with a tag block on it.
        if(is_array($_REQUEST['akID'])) {
            $res = $_REQUEST['akID'][$ak->getAttributeKeyID()]['atSelectOptionID'][0];
            if(is_numeric($res) && $res > 0) {
                $selectedOptionID = $res;
            }
        }
        $this->set('selectedOptionID',$selectedOptionID);
        $this->set('options',$options);
        $this->set('akc',$controller);
        $this->set('ak',$ak);
    }
    
    public function save($args) {
        $ak = $this->loadAttribute();
        if ($_REQUEST['cID']) {
            $c = Page::getByID($_REQUEST['cID'], 'RECENT');
            // We cannot save the attribute in the Stack Dashboard page
            // as there is nothing to attach it to
            if (!$this->isValidStack($c)) {
                $nvc = $c->getVersionToModify();
                $ak->saveAttributeForm($nvc);
                $nvc->refreshCache();
            }
        }
        $args['cloudCount'] = (is_numeric($args['cloudCount'])?$args['cloudCount']:0);
        $args['targetCID'] = (is_numeric($args['targetCID'])?$args['targetCID']:0);
        parent::save($args);
    }

    protected function isValidStack($stack) {
        return $stack->getCollectionParentID() == Page::getByPath(STACKS_PAGE_PATH)->getCollectionID();
    }
}