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 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Controller_Dashboard_Files_Attributes extends Controller {
    
    public $helpers = array('form');
    
    public function __construct() {
        parent::__construct();
        $otypes = AttributeType::getList('file');
        $types = array();
        foreach($otypes as $at) {
            $types[$at->getAttributeTypeID()] = $at->getAttributeTypeDisplayName();
        }
        $this->set('types', $types);
    }
    
    public function delete($akID, $token = null){
        try {
            $ak = FileAttributeKey::getByID($akID); 
                
            if(!($ak instanceof FileAttributeKey)) {
                throw new Exception(t('Invalid attribute ID.'));
            }
    
            $valt = Loader::helper('validation/token');
            if (!$valt->validate('delete_attribute', $token)) {
                throw new Exception($valt->getErrorMessage());
            }
            
            $ak->delete();
            
            $this->redirect("/dashboard/files/attributes", 'attribute_deleted');
        } catch (Exception $e) {
            $this->set('error', $e);
        }
    }
    
    public function select_type() {
        $atID = $this->request('atID');
        $at = AttributeType::getByID($atID);
        $this->set('type', $at);
    }
    
    public function view() {
        $attribs = FileAttributeKey::getList();
        $this->set('attribs', $attribs);
    }
    
    public function on_start() {
        $this->set('category', AttributeKeyCategory::getByHandle('file'));
    }
    
    public function add() {
        $this->select_type();
        $type = $this->get('type');
        $cnt = $type->getController();
        $e = $cnt->validateKey($this->post());
        if ($e->has()) {
            $this->set('error', $e);
        } else {
            $type = AttributeType::getByID($this->post('atID'));
            $ak = FileAttributeKey::add($type, $this->post());
            $this->redirect('/dashboard/files/attributes/', 'attribute_created');
        }
    }

    public function attribute_deleted() {
        $this->set('message', t('File Attribute Deleted.'));
    }
    
    public function attribute_created() {
        $this->set('message', t('File Attribute Created.'));
    }

    public function attribute_updated() {
        $this->set('message', t('File Attribute Updated.'));
    }
    
    public function edit($akID = 0) {
        if ($this->post('akID')) {
            $akID = $this->post('akID');
        }
        $key = FileAttributeKey::getByID($akID);
        if (!is_object($key) || $key->isAttributeKeyInternal()) {
            $this->redirect('/dashboard/files/attributes');
        }
        $type = $key->getAttributeType();
        $this->set('key', $key);
        $this->set('type', $type);
        
        if ($this->isPost()) {
            $cnt = $type->getController();
            $cnt->setAttributeKey($key);
            $e = $cnt->validateKey($this->post());
            if ($e->has()) {
                $this->set('error', $e);
            } else {
                $type = AttributeType::getByID($this->post('atID'));
                $key->update($this->post());
                $this->redirect('/dashboard/files/attributes', 'attribute_updated');
            }
        }
    }
    
}