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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 
<?php

defined('C5_EXECUTE') or die("Access Denied.");

/**
 * Contains the page type object.
 *
 * @package    Pages
 * @category   Concrete
 * @author     Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */

/**
 * The CollectionType or PageType object represents reusable types of pages that can
 * be added to a Concrete site.
 *
 * @package    Pages
 * @author     Andrew Embler <[email protected]>
 * @category   Concrete
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
class Concrete5_Model_CollectionType extends Object
{

    public $ctID;
    public $addCTUArray = array();
    public $addCTGArray = array();
    public $akIDArray = array();
    public $composerAKIDArray = array();

    /**
     * @description returns a collection type object for the given CollectionType handle
     * @param string $ctHandle
     * @return CollectionType
     */
    public static function getByHandle($ctHandle)
    {
        $db = Loader::db();
        $q = "SELECT PageTypes.ctID, ComposerTypes.ctID as ctIDc, ctHandle, ctIsInternal, ctName, ctIcon, pkgID, ctComposerPublishPageMethod, ctComposerPublishPageTypeID, ctComposerPublishPageParentID from PageTypes left join ComposerTypes on PageTypes.ctID = ComposerTypes.ctID where ctHandle = ?";
        $r = $db->query($q, array($ctHandle));
        if ($r) {
            $row = $r->fetchRow();
            $r->free();
            if (is_array($row)) {
                $ct = new CollectionType;
                $ct->setPropertiesFromArray($row);
                if ($row['ctIDc']) {
                    $ct->ctIncludeInComposer = true;
                }
            }
        }
        return $ct;
    }

    public function setPropertiesFromArray($row)
    {
        if (!$row['ctIcon']) {
            $row['ctIcon'] = FILENAME_COLLECTION_TYPE_DEFAULT_ICON;
        }
        parent::setPropertiesFromArray($row);
    }

    public function getMasterTemplate()
    {
        $db = Loader::db();
        $cID = $db->getOne(
                  "select p.cID from Pages p inner join CollectionVersions cv on p.cID = cv.cID where cv.ctID = ? and cIsTemplate = 1",
                  array($this->ctID));
        return Page::getByID($cID, "RECENT");
    }

    /**
     * Get a collection type by its ID.
     *
     * @param $ctID
     * @return bool|CollectionType
     * @todo refactor to return null on not found.
     */
    public static function getByID($ctID)
    {
        $ctID = intval($ctID);
        $ct = CacheLocal::getEntry('collection_type_by_id', $ctID);
        if (is_object($ct)) {
            return $ct;
        } else {
            if ($ct === -1) {
                return false;
            }
        }

        $db = Loader::db();
        $q = "SELECT PageTypes.ctID, ComposerTypes.ctID as ctIDc, ctHandle, ctIsInternal, ctName, ctIcon, pkgID, ctComposerPublishPageMethod, ctComposerPublishPageTypeID, ctComposerPublishPageParentID from PageTypes left join ComposerTypes on PageTypes.ctID = ComposerTypes.ctID where PageTypes.ctID = ?";
        $r = $db->query($q, array($ctID));
        if ($r) {
            $row = $r->fetchRow();
            $r->free();
            if (is_array($row)) {
                $ct = new CollectionType;
                $ct->setPropertiesFromArray($row);
                if ($row['ctIDc']) {
                    $ct->ctIncludeInComposer = true;
                }
            }
        }
        CacheLocal::set('collection_type_by_id', $ctID, $ct);
        return $ct;
    }

    public function delete()
    {
        $db = Loader::db();
        $template_cID = $db->getOne(
                           "SELECT Pages.cID FROM Pages inner join CollectionVersions cv on Pages.cID = cv.cID WHERE cIsTemplate = 1 and cv.ctID = ?",
                           array($this->ctID));

        if ($template_cID) {
            $template = Page::getByID($template_cID);
            if ($template->getCollectionID() > 1) {
                $template->delete();
            }
        }

        $db->query("DELETE FROM PageTypes WHERE ctID = ?", array($this->ctID));
        $db->query("DELETE FROM PageTypeAttributes WHERE ctID = ?", array($this->ctID));
        $db->query("DELETE FROM ComposerTypes WHERE ctID = ?", array($this->ctID));
        $db->query("DELETE FROM ComposerContentLayout WHERE ctID = ?", array($this->ctID));
    }

    public function getComposerPageTypes()
    {
        $db = Loader::db();
        $ctArray = array();
        $r = $db->Execute('select ctID from ComposerTypes order by ctID asc');
        while ($row = $r->FetchRow()) {
            $ct = CollectionType::getByID($row['ctID']);
            if (is_object($ct)) {
                $ctArray[] = $ct;
            }
        }
        return $ctArray;
    }

    public static function getListByPackage($pkg)
    {
        $db = Loader::db();
        $list = array();
        $r = $db->Execute(
                'select ctID from PageTypes where pkgID = ? order by ctName asc',
                array($pkg->getPackageID()));
        while ($row = $r->FetchRow()) {
            $list[] = CollectionType::getByID($row['ctID']);
        }
        $r->Close();
        return $list;
    }

    public function importComposerSettings(SimpleXMLElement $sx)
    {
        $db = Loader::db();
        if ($sx['method'] == 'PAGE_TYPE') {
            $ctID = ContentImporter::getValue($sx['pagetype']);
            $cta = CollectionType::getByID($ctID);
            $this->saveComposerPublishTargetPageType($cta);
        } else {
            if ($sx['method'] == 'PARENT') {
                $cID = ContentImporter::getValue($sx['parent']);
                $c = Page::getByID($cID);
                $this->saveComposerPublishTargetPage($c);
            } else {
                $this->saveComposerPublishTargetAll();
            }
        }

        if (isset($sx->items)) {
            foreach ($sx->items->children() as $node) {
                $displayOrder = $db->GetOne(
                                   'select max(displayOrder) as displayOrder from ComposerContentLayout where ctID = ?',
                                   array($this->ctID));
                if ($displayOrder !== false) {
                    if ($displayOrder > 0) {
                        $displayOrder++;
                    } else {
                        $displayOrder = 1;
                    }
                } else {
                    $displayOrder = 0;
                }

                if ($node->getName() == 'attributekey') {
                    $ak = CollectionAttributeKey::getByHandle((string)$node['handle']);
                    $v = array($ak->getAttributeKeyID(), $displayOrder, $this->ctID);
                    $db->Execute('insert into ComposerContentLayout (akID, displayOrder, ctID) values (?, ?, ?)', $v);
                }
                if ($node->getName() == 'block') {
                    $mcID = $this->getMasterCollectionID();
                    $bID = $db->GetOne(
                              'select Blocks.bID from CollectionVersionBlocks inner join Blocks on CollectionVersionBlocks.bID = Blocks.bID where cID = ? and Blocks.bName = ?',
                              array(
                                  $mcID,
                                  (string)$node['name']
                              ));
                    $v = array($bID, $displayOrder, (string)$node['composer-template'], $this->ctID);
                    $db->Execute(
                       'insert into ComposerContentLayout (bID, displayOrder, ccFilename, ctID) values (?, ?, ?, ?)',
                       $v);
                }
            }
        }
    }

    public static function exportList($xml)
    {
        $list = self::getList(false, true);
        $nxml = $xml->addChild('pagetypes');
        foreach ($list as $ct) {
            $type = $nxml->addChild('pagetype');
            $type->addAttribute('handle', $ct->getCollectionTypeHandle());
            $type->addAttribute('name', $ct->getCollectionTypeName());
            $type->addAttribute('internal', $ct->isCollectionTypeInternal());
            $type->addAttribute('icon', $ct->getCollectionTypeIcon());
            $type->addAttribute('package', $ct->getPackageHandle());
            if ($ct->isCollectionTypeIncludedInComposer()) {
                $composer = $type->addChild('composer');
                $composer->addAttribute('method', $ct->getCollectionTypeComposerPublishMethod());
                $parent = '';
                $pagetype = '';

                if ($ct->getCollectionTypeComposerPublishPageTypeID() > 0) {
                    $pagetype = ContentExporter::replacePageTypeWithPlaceHolder(
                                               $ct->getCollectionTypeComposerPublishPageTypeID());
                }

                if ($ct->getCollectionTypeComposerPublishPageParentID() > 0) {
                    $parent = ContentExporter::replacePageWithPlaceHolder(
                                             $ct->getCollectionTypeComposerPublishPageParentID());
                }

                $composer->addAttribute('pagetype', $pagetype);
                $composer->addAttribute('parent', $parent);

                $items = $ct->getComposerContentItems();
                if (count($items) > 0) {
                    $itemNode = $composer->addChild('items');
                    foreach ($items as $ci) {
                        $ci->export($itemNode, 'composer');
                    }
                }
            }
            $mcID = $ct->getMasterCollectionID();
            if ($mcID > 0) {
                $mc = Page::getByID($mcID);
                $mc->export($type);
            }
        }
    }

    public static function getList($limiterType = null, $includeInternal = false)
    {
        $db = Loader::db();

        // the purpose for this class? Well, we get an array of collection type objects,
        // we don't do a join because on big sites it's actually slower
        $mcIDs = $db->GetAll(
                    "select p.cID, cv.ctID from Pages p inner join CollectionVersions cv on p.cID = cv.cID where cIsTemplate = 1");
        $masterCollectionIDs = array();
        foreach ($mcIDs as $mc) {
            $masterCollectionIDs[$mc['ctID']] = $mc['cID'];
        }
        if ($includeInternal) {
            $internal = '1=1';
        } else {
            $internal = 'ctIsInternal = 0';
        }
        $q = "select ctID, ctHandle, ctIcon, ctName, ctIsInternal, pkgID from PageTypes where {$internal} order by ctName asc";
        $r = $db->query($q);
        $ctArray = array();
        if ($r) {
            while ($row = $r->fetchRow()) {
                $ct = new CollectionType;
                $row['mcID'] = $masterCollectionIDs[$row['ctID']];
                $ct->setPropertiesFromArray($row);

                if (is_array($limiterType)) {
                    // an array of collection type handles that we should check against
                    if (in_array($row['ctHandle'], $limiterType)) {
                        $ctArray[] = $ct;
                    }
                } else {
                    if (is_object($limiterType)) {
                        $ct->limit($limiterType);
                        $ctArray[] = $ct;
                    } else {
                        $ctArray[] = $ct;
                    }
                }
            }
            $r->free();
        }

        return $ctArray;
    }

    public static function add($data, $pkg = null)
    {
        $db = Loader::db();
        $pkgID = ($pkg == null) ? 0 : $pkg->getPackageID();
        $ctIcon = FILENAME_COLLECTION_TYPE_DEFAULT_ICON;
        if (isset($data['ctIcon'])) {
            $ctIcon = $data['ctIcon'];
        }
        $ctIsInternal = 0;
        if (isset($data['ctIsInternal']) && $data['ctIsInternal']) {
            $ctIsInternal = 1;
        }
        $v = array($data['ctHandle'], $data['ctName'], $ctIcon, $ctIsInternal, $pkgID);
        $q = "insert into PageTypes (ctHandle, ctName, ctIcon, ctIsInternal, pkgID) values (?, ?, ?, ?, ?)";
        $r = $db->prepare($q);
        $res = $db->execute($r, $v);
        if ($res) {
            $ctID = $db->Insert_ID();
            // metadata

            if (is_array($data['akID'])) {
                foreach ($data['akID'] as $ak) {
                    $v2 = array($ctID, $ak);
                    $db->query("insert into PageTypeAttributes (ctID, akID) values (?, ?)", $v2);
                }
            }

            // now that we've created the collection type, we create the master collection
            $dh = Loader::helper('date');
            $cDate = $dh->getSystemDateTime();
            $data['ctID'] = $ctID;
            $cobj = Collection::add($data);
            $cID = $cobj->getCollectionID();

            $mcName = ($data['cName']) ? $data['cName'] : "MC: {$data['ctName']}";
            $mcDescription = $data['cDescription'] ? $data['cDescription'] : "Master Collection For {$data['ctName']}";
            $v2 = array($cID, 1, $pkgID);
            $q2 = "insert into Pages (cID, cIsTemplate, pkgID) values (?, ?, ?)";
            $r2 = $db->prepare($q2);
            $res2 = $db->execute($r2, $v2);
            if ($res2) {
                return CollectionType::getByID($ctID);
            }
        }
    }

    public function getPages()
    {
        // returns an array of pages of this type. Does not check permissions
        // since this can get pretty long it actually returns a limited amount of data;

        $pl = new PageList();
        $pl->filterByCollectionTypeID($this->getCollectionTypeID());
        $pl->ignorePermissions();
        $pl->ignoreAliases();
        $pages = $pl->get();

        return $pages;
    }

    public function resetComposerData()
    {
        $db = Loader::db();
        $db->query("delete from ComposerContentLayout where ctID = ?", array($this->getCollectionTypeID()));
        $db->Execute('delete from ComposerTypes where ctID = ?', array($this->getCollectionTypeID()));
    }

    public function saveComposerAttributeKeys($atids = array())
    {
        $db = Loader::db();
        // we remove those that aren't in the list already
        $ids = $atids;
        $ids[] = -1;
        $v = implode(',', $ids);
        $r = $db->Execute(
                "delete from ComposerContentLayout where akID not in ({$v}) and bID = 0 and ctID = ?",
                array($this->getCollectionTypeID()));

        // now we append the new items
        $displayOrder = $db->GetOne(
                           'select max(displayOrder) from ComposerContentLayout where ctID = ?',
                           array($this->getCollectionTypeID()));
        if ($displayOrder > 0) {
            $displayOrder++;
        } else {
            $displayOrder = 0;
        }

        $existingAKIDs = $db->GetCol(
                            'select akID from ComposerContentLayout where akID > 0 and ctID = ?',
                            array($this->getCollectionTypeID()));
        // this returns all akIDs currently available the composer content layout table for this composer type
        // if something is in the new array but not in the existing one we append

        if (is_array($atids)) {
            foreach ($atids as $ak) {
                if (!in_array($ak, $existingAKIDs)) {
                    $db->Replace(
                       'ComposerContentLayout',
                       array('ctID' => $this->ctID, 'akID' => $ak, 'displayOrder' => $displayOrder),
                       array('ctID', 'akID'),
                       true);
                    $displayOrder++;
                }
            }
        }
    }

    public function saveComposerPublishTargetPage($c)
    {
        $db = Loader::db();
        $db->Execute('delete from ComposerTypes where ctID = ?', array($this->getCollectionTypeID()));
        $db->Replace(
           'ComposerTypes',
           array(
               'ctID'                          => $this->ctID,
               'ctComposerPublishPageMethod'   => 'PARENT',
               'ctComposerPublishPageTypeID'   => 0,
               'ctComposerPublishPageParentID' => $c->getCollectionID()),
           array('ctID'),
           true);
    }

    public function saveComposerPublishTargetPageType($ct)
    {
        $db = Loader::db();
        $db->Execute('delete from ComposerTypes where ctID = ?', array($this->getCollectionTypeID()));
        $db->Replace(
           'ComposerTypes',
           array(
               'ctID'                          => $this->ctID,
               'ctComposerPublishPageMethod'   => 'PAGE_TYPE',
               'ctComposerPublishPageTypeID'   => $ct->getCollectionTypeID(),
               'ctComposerPublishPageParentID' => 0),
           array('ctID'),
           true);
    }

    public function saveComposerPublishTargetAll()
    {
        $db = Loader::db();
        $db->Execute('delete from ComposerTypes where ctID = ?', array($this->getCollectionTypeID()));
        $db->Replace(
           'ComposerTypes',
           array(
               'ctID'                          => $this->ctID,
               'ctComposerPublishPageMethod'   => 'CHOOSE',
               'ctComposerPublishPageTypeID'   => 0,
               'ctComposerPublishPageParentID' => 0),
           array('ctID'),
           true);
    }

    public function saveComposerContentItemOrder($items)
    {
        $db = Loader::db();
        $displayOrder = 0;
        foreach ($items as $it) {
            $bID = $it->bID;
            if (!$bID) {
                $bID = 0;
            }
            $akID = $it->akID;
            if (!$akID) {
                $akID = 0;
            }
            $v = array($displayOrder, $bID, $akID, $this->getCollectionTypeID());
            $db->Execute(
               'update ComposerContentLayout set displayOrder = ? where bID = ? and akID = ? and ctID = ?',
               $v);
            $displayOrder++;
        }
    }

    public function update($data)
    {
        $db = Loader::db();

        $v = array($data['ctName'], $data['ctHandle'], $data['ctIcon'], $this->ctID);
        $r = $db->prepare("update PageTypes set ctName = ?, ctHandle = ?, ctIcon = ? where ctID = ?");
        $res = $db->execute($r, $v);

        // metadata
        $v2 = array($this->getCollectionTypeID());
        $db->query("delete from PageTypeAttributes where ctID = ?", $v2);

        if (is_array($data['akID'])) {
            foreach ($data['akID'] as $ak) {
                $v3 = array($this->getCollectionTypeID(), $ak);
                $db->query("insert into PageTypeAttributes (ctID, akID) values (?, ?)", $v3);
            }
        }

    }

    public function assignCollectionAttribute($ak)
    {
        // object
        $db = Loader::db();
        $db->query(
           "insert into PageTypeAttributes (ctID, akID) values (?, ?)",
           array($this->getCollectionTypeID(), $ak->getAttributeKeyID()));
    }

    public function populateAvailableAttributeKeys()
    {
        $db = Loader::db();
        $v = array($this->getCollectionTypeID());
        $q = 'SELECT pta.akID'
            . ' FROM PageTypeAttributes pta'
            . ' LEFT JOIN (AttributeSetKeys sk INNER JOIN AttributeSets s ON sk.asID = s.asID)'
            . ' ON pta.akID = sk.akID'
            . ' WHERE pta.ctID = ?'
            . ' ORDER BY (s.asID IS NULL), s.asDisplayOrder, sk.displayOrder';
        $r = $db->query($q, $v);
        if ($r) {
            $this->akIDArray = array();
            while ($row = $r->fetchRow()) {
                $this->akIDArray[] = $row['akID'];
            }
        }
    }

    public function getIcons()
    {
        $f = Loader::helper('file');
        Loader::model('file_list');
        Loader::model('file_set');
        $fileList = new FileList();
        $fs = FileSet::getByName('Page Type Icons');
        if (!$fs) {
            return $f->getDirectoryContents(DIR_FILES_COLLECTION_TYPE_ICONS);
        } else {
            $fileList->filterBySet($fs);
            $icons = $fileList->get(100);
            if (!count($icons)) {
                $icons = $f->getDirectoryContents(DIR_FILES_COLLECTION_TYPE_ICONS);
            }
            return $icons;
        }
    }

    public function getAvailableAttributeKeys()
    {
        if (count($this->akIDArray) == 0) {
            $this->populateAvailableAttributeKeys();
        }
        $objArray = array();
        foreach ($this->akIDArray as $akID) {
            $obj = CollectionAttributeKey::getByID($akID);
            if (is_object($obj)) {
                $objArray[] = $obj;
            }
        }
        return $objArray;
    }

    public function getComposerAttributeKeys()
    {
        $db = Loader::db();
        $akIDs = $db->GetCol('select akID from ComposerContentLayout where ctID = ? and akID > 0', array($this->ctID));
        $attribs = array();
        if (is_array($akIDs)) {
            foreach ($akIDs as $akID) {
                $obj = CollectionAttributeKey::getByID($akID);
                if (is_object($obj)) {
                    $attribs[] = $obj;
                }
            }
        }
        return $attribs;
    }

    public function getComposerContentItems()
    {
        $db = Loader::db();
        $r = $db->Execute(
                'select bID, akID, ccFilename from ComposerContentLayout where ctID = ? order by displayOrder asc',
                array($this->ctID));
        $items = array();
        while ($row = $r->FetchRow()) {
            if ($row['akID'] > 0) {
                $obj = CollectionAttributeKey::getByID($row['akID']);
                if (is_object($obj)) {
                    $items[] = $obj;
                }
            } else {
                if ($row['bID'] > 0) {
                    $b = Block::getByID($row['bID']);
                    if (is_object($b)) {
                        $items[] = $b;
                    }
                }
            }
        }
        return $items;
    }

    /**
     *Checks if given attribute key or attribute key id is assigned to this collection type
     */
    public function isAvailableCollectionTypeAttribute($akIDorObject)
    {
        if (is_object($akIDorObject)) {
            $akID = $akIDorObject->getAttributeKeyID();
        } else {
            $akID = $akIDorObject;
        }

        if (count($this->akIDArray) == 0) {
            $this->populateAvailableAttributeKeys();
        }
        return in_array($akID, $this->akIDArray);
    }

    public function canAddSubCollection($obj)
    {
        switch (strtolower(get_class($obj))) {
            case 'group':
                return in_array($obj->getGroupID(), $this->addCTGArray);
                break;
            case 'userinfo':
                return in_array($obj->getUserID(), $this->addCTUArray);
                break;
        }
    }

    /**
     * returns the complete html img tag for this collection type's icon
     */
    public function getCollectionTypeIconImage()
    {
        Loader::helper('concrete/file');
        $html = Loader::helper('html');
        $icon = $this->getCollectionTypeIcon();
        if (is_numeric($icon) && $icon) {
            $f = File::getByID($icon);
            $fv = $f->getApprovedVersion();
            $src = $fv->getRelativePath();
        } else { // retain support for legacy file type images
            $src = REL_DIR_FILES_COLLECTION_TYPE_ICONS . '/' . $icon;
        }
        $iconImg = '<img src="' . $src . '" height="' . COLLECTION_TYPE_ICON_HEIGHT . '" width="' . COLLECTION_TYPE_ICON_WIDTH . '" alt="' . $this->getCollectionTypeName() . '" title="' . $this->getCollectionTypeName() . '" />';

        return $iconImg;
    }

    public function getCollectionTypeID()
    {
        return $this->ctID;
    }

    public function getCollectionTypeName()
    {
        return $this->ctName;
    }

    public function getCollectionTypeHandle()
    {
        return $this->ctHandle;
    }

    public function isCollectionTypeIncludedInComposer()
    {
        return $this->ctIncludeInComposer;
    }

    public function isCollectionTypeInternal()
    {
        return $this->ctIsInternal;
    }

    public function getCollectionTypeComposerPublishMethod()
    {
        return $this->ctComposerPublishPageMethod;
    }

    public function getCollectionTypeComposerPublishPageParentID()
    {
        return $this->ctComposerPublishPageParentID;
    }

    public function getCollectionTypeComposerPublishPageTypeID()
    {
        return $this->ctComposerPublishPageTypeID;
    }

    public function getMasterCollectionID()
    {
        $db = Loader::db();
        $mcID = $db->GetOne(
                   "select p.cID from Pages p inner join CollectionVersions cv on p.cID = cv.cID where cv.ctID = ? and cIsTemplate = 1",
                   array($this->ctID));
        return $mcID;
    }

    public function getCollectionTypeIcon()
    {
        return $this->ctIcon;
    }

    public function getPackageID()
    {
        return $this->pkgID;
    }

    public function getPackageHandle()
    {
        return PackageList::getHandle($this->pkgID);
    }

}