public static function getByHandle($akHandle) { $ak = CacheLocal::getEntry('user_attribute_key_by_handle', $akHandle); if (is_object($ak)) { return $ak; } else if ($ak == -1) { return false; } $ak = -1; $db = Loader::db(); $q = "SELECT ak.akID FROM AttributeKeys ak INNER JOIN AttributeKeyCategories akc ON ak.akCategoryID = akc.akCategoryID WHERE ak.akHandle = ? AND akc.akCategoryHandle = 'user'"; $akID = $db->GetOne($q, array($akHandle)); if ($akID > 0) { $ak = UserAttributeKey::getByID($akID); } CacheLocal::set('user_attribute_key_by_handle', $akHandle, $ak); if ($ak === -1) { return false; } return $ak; }
public static function getByHandle($akHandle) { $ak = CacheLocal::getEntry('file_attribute_key_by_handle', $akHandle); if (is_object($ak)) { return $ak; } else { if ($ak == -1) { return false; } } $ak = -1; $db = Loader::db(); $q = "SELECT ak.akID FROM AttributeKeys ak INNER JOIN AttributeKeyCategories akc ON ak.akCategoryID = akc.akCategoryID WHERE ak.akHandle = ? AND akc.akCategoryHandle = 'file'"; $akID = $db->GetOne($q, array($akHandle)); if ($akID > 0) { $ak = self::getByID($akID); } else { // else we check to see if it's listed in the initial registry $ia = FileTypeList::getImporterAttribute($akHandle); if (is_object($ia)) { // we create this attribute and return it. $at = AttributeType::getByHandle($ia->akType); $args = array('akHandle' => $akHandle, 'akName' => $ia->akName, 'akIsSearchable' => 1, 'akIsAutoCreated' => 1, 'akIsEditable' => $ia->akIsEditable); $ak = FileAttributeKey::add($at, $args); } } CacheLocal::set('file_attribute_key_by_handle', $akHandle, $ak); if ($ak === -1) { return false; } return $ak; }
public static function getByName($stackName, $cvID = 'RECENT') { $cID = CacheLocal::getEntry('stack_by_name', $stackName); if (!$cID) { $db = Loader::db(); $cID = $db->GetOne('select cID from Stacks where stName = ?', array($stackName)); CacheLocal::set('stack_by_name', $stackName, $cID); } if ($cID) { return self::getByID($cID, $cvID); } }
/** * @param int $cID Collection ID of a page * @param string $versionOrig ACTIVE or RECENT * @param string $class * @return Page */ public static function getByID($cID, $version = 'RECENT', $class = 'Page') { $c = CacheLocal::getEntry('page', $cID . ':' . $version); if ($c instanceof $class) { return $c; } $where = "where Pages.cID = ?"; $c = new $class(); $c->populatePage($cID, $where, $version); // must use cID instead of c->getCollectionID() because cID may be the pointer to another page CacheLocal::set('page', $cID . ':' . $version, $c); return $c; }
public static function get($pkgIsInstalled = 1) { $pkgList = CacheLocal::getEntry('pkgList', $pkgIsInstalled); if ($pkgList != false) { return $pkgList; } $db = Loader::db(); $r = $db->query("select pkgID, pkgName, pkgIsInstalled, pkgDescription, pkgVersion, pkgHandle, pkgDateInstalled from Packages where pkgIsInstalled = ? order by pkgID asc", array($pkgIsInstalled)); $list = new PackageList(); while ($row = $r->fetchRow()) { $pkg = new Package(); $pkg->setPropertiesFromArray($row); $list->add($pkg); } CacheLocal::set('pkgList', $pkgIsInstalled, $list); return $list; }
public static function getList() { $gaItemTemplateTypeList = CacheLocal::getEntry('gaItemTemplateTypeList', false); if ($gaItemTemplateTypeList != false) { return $gaItemTemplateTypeList; } $db = Loader::db(); $list = array(); $r = $db->Execute('select gatTypeID from GatheringItemTemplateTypes order by gatTypeID asc'); while ($row = $r->FetchRow()) { $type = static::getByID($row['gatTypeID']); if (is_object($type)) { $list[] = $type; } } $r->Close(); CacheLocal::set('gaItemTemplateTypeList', false, $list); return $list; }
public static function getByHandle($akHandle) { $ak = CacheLocal::getEntry('form_attribute_key_by_handle', $akHandle); if (is_object($ak)) { return $ak; } else { if ($ak == -1) { return false; } } $ak = new FormAttributeKey(); $ak->load($akHandle, 'akHandle'); if ($ak->getAttributeKeyID() < 1) { $ak = -1; } CacheLocal::set('form_attribute_key_by_handle', $akHandle, $ak); if ($ak === -1) { return false; } return $ak; }
static final function getByID($peID) { $obj = CacheLocal::getEntry('permission_access_entity', $peID); if ($obj instanceof PermissionAccessEntity) { return $obj; } $db = Loader::db(); $r = $db->GetRow('select petID, peID from PermissionAccessEntities where peID = ?', array($peID)); if (is_array($r)) { $pt = PermissionAccessEntityType::getByID($r['petID']); if (!is_object($pt)) { return false; } $class = Loader::helper('text')->camelcase($pt->getAccessEntityTypeHandle()); $class .= 'PermissionAccessEntity'; $obj = new $class(); $r['petHandle'] = $pt->getAccessEntityTypeHandle(); $obj->setPropertiesFromArray($r); $obj->load(); } CacheLocal::set('permission_access_entity', $peID, $obj); return $obj; }
/** * Gets or creates if necessary an Area for the given Page, Handle * @param Page|Collection $c * @param string $arHandle * @param boolean $arIsGlobal * @return Area */ public static function getOrCreate(&$c, $arHandle, $arIsGlobal = 0) { /* different than get(), getOrCreate() is called by the templates. If no area record exists for the permissions cID / handle combination, we create one. This is to make our lives easier */ $area = self::get($c, $arHandle, $arIsGlobal); if (is_object($area)) { if ($area->isGlobalArea() == $arIsGlobal) { return $area; } else { if (!$area->isGlobalArea() && !$arIsGlobal) { return $area; } } } $cID = $c->getCollectionID(); $db = Loader::db(); if (!$arIsGlobal) { $arIsGlobal = 0; } $db->Replace('Areas', array('cID' => $cID, 'arHandle' => $arHandle, 'arIsGlobal' => $arIsGlobal), array('arHandle', 'cID'), true); if ($arIsGlobal) { // we create a stack for it Stack::getOrCreateGlobalArea($arHandle); } $area = self::get($c, $arHandle); // we're assuming the insert succeeded $area->rescanAreaPermissionsChain(); // we need to update the local cache $globalCache = $arIsGlobal ? ':1' : ''; CacheLocal::set('area', $c->getCollectionID() . ':' . $arHandle . $globalCache, $area); return $area; }
/** * 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 getAccessListItems($accessType = PermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array()) { if (count($this->paIDList) > 0) { $q = 'select paID, peID, pdID, accessType from PermissionAccessList where paID in (' . implode(',', $this->paIDList) . ')'; return $this->deliverAccessListItems($q, $accessType, $filterEntities); } else { $filter = $accessType . ':'; foreach($filterEntities as $pae) { $filter .= $pae->getAccessEntityID() . ':'; } $filter = trim($filter, ':'); $items = CacheLocal::getEntry('permission_access_list_items', $this->getPermissionAccessID() . $filter . strtolower(get_class($this->pk))); if (is_array($items)) { return $items; } $q = 'select paID, peID, pdID, accessType from PermissionAccessList where paID = ' . $this->getPermissionAccessID(); $items = $this->deliverAccessListItems($q, $accessType, $filterEntities); CacheLocal::set('permission_access_list_items', $this->getPermissionAccessID() . $filter . strtolower(get_class($this->pk)), $items); return $items; } }
/** * returns the FileVersion object for the provided fvID * if none provided returns the approved version * @param int $fvID * @return FileVersion */ public function getVersion($fvID = null) { if ($fvID == null) { $fvID = $this->fvID; // approved version } $fv = CacheLocal::getEntry('file', $this->getFileID() . ':' . $fvID); if ($fv === -1) { return false; } if ($fv) { return $fv; } $db = Loader::db(); $row = $db->GetRow("select * from FileVersions where fvID = ? and fID = ?", array($fvID, $this->fID)); $row['fvAuthorName'] = $db->GetOne("select uName from Users where uID = ?", array($row['fvAuthorUID'])); $fv = new FileVersion(); $row['fslID'] = $this->fslID; $fv->setPropertiesFromArray($row); CacheLocal::set('file', $this->getFileID() . ':' . $fvID, $fv); return $fv; }
public static function getByID($bID, $c = null, $a = null) { if ($c == null && $a == null) { $cID = 0; $arHandle = ""; $cvID = 0; $b = CacheLocal::getEntry('block', $bID); } else { if (is_object($a)) { $arHandle = $a->getAreaHandle(); } else { if ($a != null) { $arHandle = $a; $a = Area::getOrCreate($c, $a); } } $cID = $c->getCollectionID(); $cvID = $c->getVersionID(); $b = CacheLocal::getEntry('block', $bID . ':' . $cID . ':' . $cvID . ':' . $arHandle); } if ($b instanceof Block) { return $b; } $db = Loader::db(); $b = new Block(); if ($c == null && $a == null) { // just grab really specific block stuff $q = "select bID, bIsActive, BlockTypes.btID, Blocks.btCachedBlockRecord, BlockTypes.btHandle, BlockTypes.pkgID, BlockTypes.btName, bName, bDateAdded, bDateModified, bFilename, Blocks.uID from Blocks inner join BlockTypes on (Blocks.btID = BlockTypes.btID) where bID = ?"; $b->isOriginal = 1; $v = array($bID); } else { $b->arHandle = $arHandle; $b->a = $a; $b->cID = $cID; $b->c = $c ? $c : ''; $vo = $c->getVersionObject(); $cvID = $vo->getVersionID(); $v = array($b->arHandle, $cID, $cvID, $bID); $q = "select CollectionVersionBlocks.isOriginal, Blocks.btCachedBlockRecord, BlockTypes.pkgID, CollectionVersionBlocks.cbOverrideAreaPermissions, CollectionVersionBlocks.cbDisplayOrder, Blocks.bIsActive, Blocks.bID, Blocks.btID, bName, bDateAdded, bDateModified, bFilename, btHandle, Blocks.uID from CollectionVersionBlocks inner join Blocks on (CollectionVersionBlocks.bID = Blocks.bID) inner join BlockTypes on (Blocks.btID = BlockTypes.btID) where CollectionVersionBlocks.arHandle = ? and CollectionVersionBlocks.cID = ? and (CollectionVersionBlocks.cvID = ? or CollectionVersionBlocks.cbIncludeAll=1) and CollectionVersionBlocks.bID = ?"; } $r = $db->query($q, $v); $row = $r->fetchRow(); if (is_array($row)) { $b->setPropertiesFromArray($row); $r->free(); $bt = BlockType::getByID($b->getBlockTypeID()); $class = $bt->getBlockTypeClass(); if ($class == false) { // we can't find the class file, so we return return false; } $b->instance = new $class($b); if ($c != null || $a != null) { CacheLocal::set('block', $bID . ':' . $cID . ':' . $cvID . ':' . $arHandle, $b); } else { $ca = new Cache(); CacheLocal::set('block', $bID, $b); } return $b; } }
/** * Gets the Area object for the given page and area handle * @param Page|Collection $c * @param string $arHandle * @param int|null $arIsGlobal * @return Area */ public static function get(&$c, $arHandle, $arIsGlobal = null) { if (!is_object($c)) { return false; } // Right now we are splitting the cache to deal with times when Areas // get converted to GlobalAreas and back the other way $globalCache = $arIsGlobal ? ':1' : ''; $a = CacheLocal::getEntry('area', $c->getCollectionID() . ':' . $arHandle . $globalCache); if ($a instanceof Area) { return $a; } $db = Loader::db(); // First, we verify that this is a legitimate area $v = array($c->getCollectionID(), $arHandle); $q = "select arID, arOverrideCollectionPermissions, arInheritPermissionsFromAreaOnCID, arIsGlobal from Areas where cID = ? and arHandle = ?"; $arRow = $db->getRow($q, $v); if ($arRow['arID'] > 0) { $area = new Area($arHandle); $area->arID = $arRow['arID']; $area->arOverrideCollectionPermissions = $arRow['arOverrideCollectionPermissions']; $area->arIsGlobal = $arRow['arIsGlobal']; $area->arInheritPermissionsFromAreaOnCID = $arRow['arInheritPermissionsFromAreaOnCID']; $area->cID = $c->getCollectionID(); $area->c = &$c; CacheLocal::set('area', $c->getCollectionID() . ':' . $arHandle . $globalCache, $area); return $area; } }
public static function loadAll() { $cl = new CacheLocal(); $db = Loader::db(); $permissionkeys = array(); $e = $db->Execute('select pkID, pkName, pkDescription, pkHandle, pkCategoryHandle, pkCanTriggerWorkflow, pkHasCustomClass, PermissionKeys.pkCategoryID, pkCategoryHandle, PermissionKeys.pkgID from PermissionKeys inner join PermissionKeyCategories on PermissionKeyCategories.pkCategoryID = PermissionKeys.pkCategoryID'); while ($r = $e->FetchRow()) { $class = Loader::helper('text')->camelcase($r['pkCategoryHandle']) . 'PermissionKey'; if ($r['pkHasCustomClass']) { $class = Loader::helper('text')->camelcase($r['pkHandle']) . $class; } $pk = new $class(); $pk->setPropertiesFromArray($r); $permissionkeys[$r['pkHandle']] = $pk; $permissionkeys[$r['pkID']] = $pk; } CacheLocal::set('permission_keys', false, $permissionkeys); return $permissionkeys; }
/** * List the block IDs in a collection or area within a collection * @param string $arHandle. If specified, returns just the blocks in an area * @return array */ public function getBlockIDs($arHandle = false) { $blockIDs = CacheLocal::getEntry('collection_block_ids', $this->getCollectionID() . ':' . $this->getVersionID()); $blocks = array(); if (!is_array($blockIDs)) { $v = array($this->getCollectionID(), $this->getVersionID()); $db = Loader::db(); $q = "select Blocks.bID, CollectionVersionBlocks.arHandle from CollectionVersionBlocks inner join Blocks on (CollectionVersionBlocks.bID = Blocks.bID) inner join BlockTypes on (Blocks.btID = BlockTypes.btID) where CollectionVersionBlocks.cID = ? and (CollectionVersionBlocks.cvID = ? or CollectionVersionBlocks.cbIncludeAll=1) order by CollectionVersionBlocks.cbDisplayOrder asc"; $r = $db->GetAll($q, $v); $blockIDs = array(); if (is_array($r)) { foreach($r as $bl) { $blockIDs[strtolower($bl['arHandle'])][] = $bl; } } CacheLocal::set('collection_block_ids', $this->getCollectionID() . ':'. $this->getVersionID(), $blockIDs); } if ($arHandle != false) { $blockIDsTmp = $blockIDs[strtolower($arHandle)]; $blockIDs = $blockIDsTmp; } else { $blockIDsTmp = $blockIDs; $blockIDs = array(); foreach($blockIDsTmp as $arHandle => $row) { foreach($row as $brow) { if (!in_array($brow, $blockIDs)) { $blockIDs[] = $brow; } } } } return $blockIDs; }
/** * Gets the BlockType for a given Block Type ID * @param int $btID * @return BlockType */ public static function getByID($btID) { $bt = CacheLocal::getEntry('blocktype', $btID); if ($bt === -1) { return false; } else if (!is_object($bt)) { $where = 'btID = ?'; $bt = BlockType::get($where, array($btID)); if (is_object($bt)) { CacheLocal::set('blocktype', $btID, $bt); } else { CacheLocal::set('blocktype', $btID, -1); } } $bt->controller = Loader::controller($bt); return $bt; }
public static function getByID($gID) { $db = Loader::db(); $g = CacheLocal::getEntry('group', $gID); if (is_object($g)) { return $g; } $row = $db->getRow("select * from Groups where gID = ?", array($gID)); if (isset($row['gID'])) { $g = new Group(); $g->setPropertiesFromArray($row); CacheLocal::set('group', $gID, $g); return $g; } }