/** * Gets a list of block types that are not installed, used to get blocks that can be installed * This function only surveys the web/blocks directory - it's not looking at the package level. * * @return BlockType[] */ public static function getAvailableList() { $blocktypes = array(); $dir = DIR_FILES_BLOCK_TYPES; $db = Loader::db(); $btHandles = $db->GetCol("select btHandle from BlockTypes order by btDisplayOrder asc, btName asc, btID asc"); $aDir = array(); if (is_dir($dir)) { $handle = opendir($dir); while (($file = readdir($handle)) !== false) { if (strpos($file, '.') === false) { $fdir = $dir . '/' . $file; if (is_dir($fdir) && !in_array($file, $btHandles) && file_exists($fdir . '/' . FILENAME_BLOCK_CONTROLLER)) { $bt = BlockType::getByHandle($file); if (!is_object($bt)) { $bt = new BlockTypeEntity(); $bt->setBlockTypeHandle($file); $class = $bt->getBlockTypeClass(); $bta = new $class(); $bt->setBlockTypeName($bta->getBlockTypeName()); $bt->setBlockTypeDescription($bta->getBlockTypeDescription()); $bt->hasCustomViewTemplate = file_exists(DIR_FILES_BLOCK_TYPES . '/' . $file . '/' . FILENAME_BLOCK_VIEW); $bt->hasCustomEditTemplate = file_exists(DIR_FILES_BLOCK_TYPES . '/' . $file . '/' . FILENAME_BLOCK_EDIT); $bt->hasCustomAddTemplate = file_exists(DIR_FILES_BLOCK_TYPES . '/' . $file . '/' . FILENAME_BLOCK_ADD); $bt->installed = false; } else { $bt->installed = true; } $blocktypes[] = $bt; } } } } return $blocktypes; }
public function filterByBlockType(BlockType $bt) { $this->query->select('distinct p.cID'); $btID = $bt->getBlockTypeID(); $this->query->innerJoin('cv', 'CollectionVersionBlocks', 'cvb', 'cv.cID = cvb.cID and cv.cvID = cvb.cvID'); $this->query->innerJoin('cvb', 'Blocks', 'b', 'cvb.bID = b.bID'); $this->query->andWhere('b.btID = :btID'); $this->query->setParameter('btID', $btID); }
/** * Instantiates the block controller. * * @param BlockType $obj |Block $obj */ public function __construct($obj = null) { parent::__construct(); if ($obj instanceof BlockType) { $this->identifier = 'BLOCKTYPE_' . $obj->getBlockTypeID(); $this->btHandle = $obj->getBlockTypeHandle(); } else { if ($obj instanceof Block) { $b = $obj; $this->identifier = 'BLOCK_' . $obj->getBlockID(); $this->bID = $b->getBlockID(); $this->btHandle = $obj->getBlockTypeHandle(); $this->btCachedBlockRecord = $obj->getBlockCachedRecord(); $this->setBlockObject($b); $this->load(); } } $this->set('controller', $this); }
public function addBlockType(BlockTypeEntity $bt) { $db = Loader::db(); $no = $db->GetOne("select count(btID) from BlockTypeSetBlockTypes where btID = ? and btsID = ?", array($bt->getBlockTypeID(), $this->getBlockTypeSetID())); if ($no < 1) { $types = $db->GetOne('select count(btID) from BlockTypeSetBlockTypes where btsID = ?', array($this->getBlockTypeSetID())); $displayOrder = 0; if ($types > 0) { $displayOrder = $db->GetOne('select max(displayOrder) from BlockTypeSetBlockTypes where btsID = ?', array($this->getBlockTypeSetID())); ++$displayOrder; } $db->Execute('insert into BlockTypeSetBlockTypes (btsID, btID, displayOrder) values (?, ?, ?)', array($this->getBlockTypeSetID(), $bt->getBlockTypeID(), $displayOrder)); } }
/** * Gets a full URL to the directory containing all of a block's items, including JavaScript, tools, icons, etc... * * @param \Concrete\Core\Entity\Block\BlockType\BlockType $bt * @param bool|string $file If provided will get the assets url for a file in a block * * @return string $url */ public function getBlockTypeAssetsURL($bt, $file = false) { $ff = ''; if ($file != false) { $ff = '/' . $file; } $url = ''; if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = REL_DIR_APPLICATION . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } elseif ($bt->getPackageID() > 0) { $h = $bt->getPackageHandle(); $dirp = is_dir(DIR_PACKAGES . '/' . $h) ? DIR_PACKAGES . '/' . $h : DIR_PACKAGES_CORE . '/' . $h; if (file_exists($dirp . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = is_dir(DIR_PACKAGES . '/' . $h) ? DIR_REL : ASSETS_URL; $url = $url . '/' . DIRNAME_PACKAGES . '/' . $h . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } } elseif (file_exists(DIR_FILES_BLOCK_TYPES_CORE . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = ASSETS_URL . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } return $url; }