Array ('self' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Sets parent filter to Module Root when "all" special used
*
* @param kEvent $event
*/
function SetCustomQuery(&$event)
{
parent::SetCustomQuery($event);
if ($this->Application->IsAdmin()) {
return ;
}
$object =& $event->getObject();
/* @var $object kDBList */
if ($event->Special == 'top-level-children') {
$page =& $this->Application->recallObject($event->Prefix); // don't use special to get current cms page
/* @var $page kDBItem */
$subsection_count = (int)$page->GetDBField('NumberOfSubsToShow');
$event->setEventParam('per_page', $subsection_count == 0 ? -1 : $subsection_count);
$object->addFilter('status_filter', '%1$s.Status = 1 AND %1$s.IsMenu = 1');
}
if (in_array($event->Special, Array('case-study-front', 'case-study-sidebox', 'case-study-all', 'case-study-scroller'))) {
$object->removeFilter('parent_filter');
$case_study_cat = $this->Application->ConfigValue('CaseStudiesCategoryID');
$object->addFilter('case_study_filter', '%1$s.ParentId = '.$case_study_cat);
// $object->addFilter('status_filter', '%1$s.Status = 4');
$object->AddOrderField('Featured', 'desc');
$object->AddOrderField('CaseStudyReleaseDate', 'desc');
$object->AddOrderField('CategoryId', 'desc');
}
$mode = $this->Application->GetVar('mode');
if ($event->Special == 'case-study-sidebox' || $mode == 'case-study-sidebox') {
// if this is tag page, get case studies taged with current tag
$tag =& $this->Application->recallObject('tag');
if ($tag->IsLoaded()) {
$tag_pages = implode(',', explode('|', substr($tag->GetDBField('CategoryIds'), 1, -1)));
$object->addFilter('tagrelated_case_studies', $tag_pages ? '%1$s.CategoryId IN ('.$tag_pages.')' : 'FALSE');
}
else {
// get case studies tagged with the same tags as current page' primary tag
$page_id = $this->Application->GetVar('m_cat_id');
if ($mode) {
$page_id = $this->Application->GetVar('related_page');
}
$sql = 'SELECT CategoryIds
FROM '.TABLE_PREFIX.'Tags
WHERE PrimaryCategoryId = '.$page_id; // `CategoryIds` LIKE \'%|'.$this->Application->GetVar('m_cat_id').'|%\''; //
$referenceing_pages = $this->Conn->GetCol($sql);
if ($referenceing_pages) {
$referenceing_pages = array_unique(explode('|', substr(str_replace('||', '|', implode($referenceing_pages)), 1, -1)));
}
$object->addFilter('not_current_case_study', '%1$s.CategoryId != '.$page_id);
$object->addFilter('related_case_studies', $referenceing_pages ? '%1$s.CategoryId IN ('.implode(',', $referenceing_pages).')' : 'FALSE');
}
}
if ($event->Special == 'tagrelated') {
$tag =& $this->Application->recallObject('tag');
$related_pages = implode(',', explode('|', substr($tag->GetDBField('CategoryIds'), 1, -1)));
$object->removeFilter('parent_filter');
$object->removeFilter('status_filter');
$case_study_cat = $this->Application->ConfigValue('CaseStudiesCategoryID');
$object->addFilter('no_case_study_filter', '%1$s.ParentId != '.$case_study_cat);
$object->addFilter('related_filter', $related_pages ? '%1$s.CategoryId IN ('.$related_pages.')' : 'FALSE');
}
if ($event->Special == 'xmlsitemap') {
$root_category = $this->Application->findModule('Name', 'Core', 'RootCat');
$object->addFilter('parent_filter', '(%1$s.ParentPath LIKE "|'.$root_category.'|%") AND (%1$s.CategoryId <> '.$root_category.')');
$object->addFilter('status_filter', 'Status = ' . STATUS_ACTIVE);
$object->addFilter('exclude_fromsitemap', 'ExcludeFromSitemap != 1');
$object->ClearOrderFields();
$object->AddOrderField('CategoryId');
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function SetPagination(&$event)
{
if ($event->Special == 'case-study-scroller') {
$start = $this->Application->GetVar('start');
$number = $this->Application->GetVar('number');
$object =& $event->getObject();
/* @var $object kDBList */
$object->SetPerPage($number);
$object->Offset = $start;
return ;
}
parent::SetPagination($event);
}
/**
* Makes required mofification to structure config
*
* @param kEvent $event
*/
function OnAfterConfigRead(&$event)
{
parent::OnAfterConfigRead($event);
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$fields['LargeIcon'] = Array(
'type' => 'string',
'max_len' => 255,
'formatter' => 'kUploadFormatter',
'upload_dir' => IMAGES_PATH,
'not_null' => 1,
'default' => '',
'multiple' => 1,
'direct_links' => 1,
'file_types' => '*.jpg;*.gif;*.png',
'files_description' => '!la_Image_Files!',
);
$fields['IntroBlock'] = Array(
'type' => 'int',
'formatter' => 'kOptionsFormatter',
'options' => Array(1 => 'la_Enabled', 0 => 'la_Disabled'),
'use_phrases' => 1,
'not_null' => 1,
'default' => 0,
);
$fields['SmallIcon'] = $fields['LargeIcon'];
$fields['Featured'] = Array(
'type' => 'int',
'formatter' => 'kOptionsFormatter',
'options' => Array(1 => 'la_Yes', 0 => 'la_No'),
'use_phrases' => 1,
'not_null' => 1,
'default' => 0,
);
$fields['CaseStudyTitle'] = Array(
'type' => 'string',
'max_len' => 255,
'not_null' => 1,
'default' => '',
);
$fields['CaseStudyReleaseDate'] = Array(
'type' => 'int',
'default' => null,
'time_format' => '',
'input_time_format' => '',
'formatter' => 'kDateFormatter',
);
$fields['CaseStudyLogo'] = $fields['LargeIcon'];
$fields['TagName'] = $fields['CaseStudyTitle'];
$fields['Definition'] = Array(
'type' => 'string',
'formatter' => 'kMultiLanguage',
'not_null' => 1,
'default' => '',
);
$fields['Weight'] = Array(
'type' => 'int',
'not_null' => 1,
'default' => 0,
);
$fields['ReferenceURL'] = $fields['CaseStudyTitle'];
$fields['URL'] = $fields['CaseStudyTitle'];
$fields['SmallDescription'] = $fields['Definition'];
$fields['CSSClassName'] = Array(
'type' => 'string',
'formatter' => 'kOptionsFormatter',
'options' => Array(
'blue-gradient' => 'blue-gradient',
'magenta-gradient' => 'magenta-gradient',
'green-gradient' => 'green-gradient',
'dark-blue-gradient' => 'dark-blue-gradient',
),
'not_null' => 1,
'default' => '',
);
$fields['ShowTopBlock'] = $fields['IntroBlock'];
$fields['ShowBottomBlock'] = $fields['IntroBlock'];
$fields['NumberOfSubsToShow'] = Array(
'type' => 'int',
'not_null' => 1,
'default' => 0,
);
$fields['SideBar'] = Array(
'type' => 'string',
'formatter' => 'kOptionsFormatter',
'options' => Array(
'1' => 'la_CustomCMSBlock',
'2' => 'la_CaseStudies',
'3' => 'la_Testimonials',
'4' => 'la_ContactUs',
'5' => 'la_Blogs',
'6' => 'la_Tags',
),
'default' => '|2|3|4|5|6|',
'use_phrases' => 1,
'not_null' => 1,
);
$fields['PrimaryTags'] = Array(
'type' => 'string',
'not_null' => 1,
'default' => '',
);
$fields['ExcludeFromSitemap'] = Array (
'type' => 'int',
'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
'not_null' => 1, 'default' => 0
);
$fields['ReferenceTags'] = $fields['PrimaryTags'];
$this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
$grids = $this->Application->getUnitOption($event->Prefix, 'Grids');
$fields_new = Array(
'LargeIcon' => Array( 'title' => 'la_col_LargeIcon','filter_block' => 'grid_like_filter'),
'IntroBlock' => Array( 'title' => 'la_col_IntroBlock','filter_block' => 'grid_options_filter'),
'SmallIcon' => Array( 'title' => 'la_col_SmallIcon','filter_block' => 'grid_like_filter'),
'Featured' => Array( 'title' => 'la_col_Featured','filter_block' => 'grid_options_filter'),
'CaseStudyTitle' => Array( 'title' => 'la_col_CaseStudyTitle','filter_block' => 'grid_like_filter'),
'CaseStudyReleaseDate' => Array( 'title' => 'la_col_CaseStudyReleaseDate','filter_block' => 'grid_date_range_filter'),
'CaseStudyLogo' => Array( 'title' => 'la_col_CaseStudyLogo','filter_block' => 'grid_like_filter'),
'TagName' => Array( 'title' => 'la_col_TagName','filter_block' => 'grid_like_filter'),
'Weight' => Array( 'title' => 'la_col_Weight','filter_block' => 'grid_range_filter'),
'ReferenceURL' => Array( 'title' => 'la_col_ReferenceURL','filter_block' => 'grid_like_filter'),
'URL' => Array( 'title' => 'la_col_URL','filter_block' => 'grid_like_filter'),
'CSSClassName' => Array( 'title' => 'la_col_CSSClassName','filter_block' => 'grid_options_filter'),
'ShowTopBlock' => Array( 'title' => 'la_col_ShowTopBlock','filter_block' => 'grid_options_filter'),
'ShowBottomBlock' => Array( 'title' => 'la_col_ShowBottomBlock','filter_block' => 'grid_options_filter'),
'NumberOfSubsToShow' => Array( 'title' => 'la_col_NumberOfSubsectionsToShow','filter_block' => 'grid_range_filter'),
'Status' => Array( 'title' => 'la_col_Status','filter_block' => 'grid_options_filter'),
);
$grids['Default']['Fields'] = array_merge_recursive2($grids['Default']['Fields'], $fields_new);
$grids['DefaultShowAll']['Fields'] = array_merge_recursive2($grids['DefaultShowAll']['Fields'], $fields_new);
$this->Application->setUnitOption($event->Prefix, 'Grids', $grids);
}
/**
* Checks what ever to use specific to project fields during category editing
*
* @return bool
*/
function _useSpecificFields()
{
return $this->Application->ConfigValue('AdminConsoleInterface') != 'demo';
}
/**
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
parent::OnBeforeItemCreate($event);
if (!$this->_useSpecificFields()) {
return ;
}
$this->_setDesignByParentID($event);
$this->_setRequirementByDesign($event);
$this->_checkPrimaryTagUnique($event);
$this->NormalizeTags($event);
}
/**
*
* @param kEvent $event
*/
function OnBeforeItemUpdate(&$event)
{
parent::OnBeforeItemUpdate($event);
if (!$this->_useSpecificFields()) {
return ;
}
$this->_setDesignByParentID($event);
$this->_setRequirementByDesign($event);
$this->_checkPrimaryTagUnique($event);
$this->NormalizeTags($event);
}
/**
*
* @param kEvent $event
*/
function OnAfterItemUpdate(&$event)
{
parent::OnAfterItemUpdate($event);
if (!$this->_useSpecificFields()) {
return ;
}
$object =& $event->getObject();
/* @var $object kDBItem */
if (!$object->IsTempTable()) {
$this->_updateTags($event);
}
}
/**
*
* @param kEvent $event
*/
function OnAfterItemCreate(&$event)
{
parent::OnAfterItemUpdate($event);
if (!$this->_useSpecificFields()) {
return ;
}
$object =& $event->getObject();
/* @var $object kDBItem */
if (!$object->IsTempTable()) {
$this->_updateTags($event);
}
}
function OnAfterItemLoad(&$event)
{
parent::OnAfterItemLoad($event);
if (!$this->_useSpecificFields()) {
return ;
}
$this->RestoreTags($event);
}
/**
*
* @param kEvent $event
*/
function OnAfterItemDelete(&$event)
{
parent::OnAfterItemDelete($event);
if (!$this->_useSpecificFields()) {
return ;
}
$this->_updateTags($event);
}
/**
*
* @param kEvent $event
*/
function OnSave(&$event)
{
parent::OnSave($event);
if ($this->_useSpecificFields()) {
$this->_updateTags($event);
}
$this->UpdateOpenerStack();
}
/**
* If current page was renamed and it was in the opener stack - update it
* otherwise redirect will go to non-existent page
*
* @param string $t
* @param Array $params
* @param string $pass
*/
function UpdateOpenerStack()
{
if (!($filename_change = $this->Application->GetVar('FilenameChanged'))) {
return;
}
if (!isset($wid)) $wid = $this->Application->GetVar('m_wid');
$stack_name = rtrim('opener_stack_'.$wid, '_');
$opener_stack = $this->Application->RecallVar($stack_name);
$opener_stack = $opener_stack ? unserialize($opener_stack) : Array();
$last = array_pop($opener_stack);
if (!$last) return ;
list($file, $q_string) = explode('|', $last);
$q_string = str_replace('/'.$filename_change['from'], '/'.$filename_change['to'], $q_string);
array_push($opener_stack, $file.'|'.$q_string);
$this->Application->StoreVar($stack_name, serialize($opener_stack));
}
function NormalizeTags(&$event)
{
$object =& $event->getObject();
$object->SetDBField('PrimaryTags', $this->CompactCommaSpaces($object->GetDBField('PrimaryTags')));
$object->SetDBField('ReferenceTags', $this->CompactCommaSpaces($object->GetDBField('ReferenceTags')));
}
function RestoreTags(&$event)
{
$object =& $event->getObject();
$object->SetDBField('PrimaryTags', $this->RestoreCommaSpaces($object->GetDBField('PrimaryTags')));
$object->SetDBField('ReferenceTags', $this->RestoreCommaSpaces($object->GetDBField('ReferenceTags')));
}
function CompactCommaSpaces($string)
{
$tags = explode(',', $string);
if (!$tags) return '';
$normalized = array();
foreach ($tags as $tag) {
$normalized[] = trim($tag);
}
return implode(',', $normalized);
}
function RestoreCommaSpaces($string)
{
return implode(', ', explode(',', $string));
}
/**
*
* @param kEvent $event
*/
function _updateTags(&$event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$tag_helper =& $this->Application->RecallObject('TagHelper');
/* @var $tag_helper TagHelper */
$tag_helper->UpdateTags($object);
}
/**
* Set design if it is determined by parent template
*
* @param kEvent $event
*/
function _setDesignByParentID(&$event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
if ($object->GetDBField('ParentId') == $this->Application->ConfigValue('CaseStudiesCategoryID')) {
$object->SetDBField('Template', DESIGN_CASE_STUDY);
}
}
/**
* Set Required fields and default values for unused fields
*
* @param kEvent $event
*/
function _setRequirementByDesign(&$event)
{
if ($this->Application->GetVar('_skip_requried_by_design_')) return;
$cms_helper =& $this->Application->RecallObject('CMSHelper');
/* @var $cms_helper CMSHelper */
$a_mapping =& $cms_helper->GetFieldsMapping();
$a_requirement_mapping = $cms_helper->GetRequirementMapping();
$a_all_design_fields = $cms_helper->GetAllFields();
$object =& $event->getObject();
/* @var $object kDBItem */
$design = $object->GetDBField('Template');
if (isset($a_requirement_mapping[$design])) {
foreach ($a_requirement_mapping[$design] AS $field) {
$object->setRequired($field);
}
}
foreach ($a_all_design_fields AS $field) {
if (!in_array($field, $a_mapping[$design])) {
$object->SetDBField($field, isset($object->Fields[$field]['default']) ? $object->Fields[$field]['default'] : '');
}
}
}
/**
* Validate PrimaryTags field
*
* @param kEvent $event
*/
function _checkPrimaryTagUnique(&$event)
{
$tag_helper =& $this->Application->recallObject('TagHelper');
/* @var $tag_helper TagHelper */
$object =& $event->getObject();
/* @var $object kDBItem */
$tag_helper->CheckPrimaryTagUnique('PrimaryTags', $object);
}
/**
* Suggest tag values
*
* @param kEvent $event
*/
function OnSuggestValues(&$event)
{
$field = $this->Application->GetVar('field');
$tag_value = $this->Application->GetVar('cur_value');
// search like tags
$sql = 'SELECT TagName
FROM '.TABLE_PREFIX.'Tags
WHERE TagName LIKE \''.$tag_value.'%\'
ORDER BY TagName';
$a_tags = $this->Conn->GetCol($sql);
$items = '';
foreach ($a_tags AS $tag) {
$items .= '- '.$tag.'
';
}
header('Content-type: text/xml');
print ''.$items.'';
$event->status = erSTOP;
}
/**
* Enter description here...
*
* @param kEvent $event
* @return int
*/
function getPassedId(&$event)
{
if ($event->Special == 'case-study-next' || $event->Special == 'case-study-prev') {
$current_study =& $this->Application->recallObject('st');
/* @var $current_study kDBItem */
$current_is_featured = $current_study->GetDBField('Featured');
$current_release_date = $current_study->GetDBField('CaseStudyReleaseDate');
$study_list =& $this->Application->recallObject('st.case-study-front', 'st_List');
/* @var $study_list kDBList */
$sign = $event->Special == 'case-study-next' ? '<' : '>';
$sql = 'SELECT %1$s.CategoryId
FROM %1$s
LEFT JOIN '.TABLE_PREFIX.'PermCache ON '.TABLE_PREFIX.'PermCache.CategoryId = %1$s.CategoryId
WHERE (
%1$s.Featured '.$sign.' '.$current_is_featured.'
OR (%1$s.Featured = '.$current_is_featured.' AND %1$s.CaseStudyReleaseDate '.$sign.' '.$current_release_date.')
OR (%1$s.Featured = '.$current_is_featured.' AND %1$s.CaseStudyReleaseDate = '.$current_release_date.' AND %1$s.CategoryId '.$sign.' '.$current_study->GetID().')
)
AND
%1$s.CategoryId != '.$current_study->GetID().'
AND ('.$study_list->GetWhereClause().')
ORDER BY '. ($sign == '<' ? 'Featured DESC, CaseStudyReleaseDate DESC, CategoryId DESC' : 'Featured ASC, CaseStudyReleaseDate ASC, CategoryId ASC');
$sql = str_replace('%1$s', $current_study->TableName, $sql);
return $this->Conn->GetOne($sql);
}
return parent::getPassedId($event);
}
/**
* Returns default design based on given virtual template (used from kApplication::Run)
*
* @return string
*/
function GetDesignTemplate($t = null)
{
if (!isset($t)) {
$t = $this->Application->GetVar('t');
}
$page =& $this->Application->recallObject($this->Prefix . '.-virtual', null, Array ('page' => $t));
if ($page->isLoaded()) {
$real_t = $page->GetDBField('CachedTemplate');
$this->Application->SetVar('m_cat_id', $page->GetDBField('CategoryId') );
if ($page->GetDBField('FormId')) {
$this->Application->SetVar('form_id', $page->GetDBField('FormId'));
}
}
else {
// custom: begin
if ($this->Application->IsAdmin()) {
$real_t = $this->_getDefaultDesign();
}
else {
$not_found = $this->Application->ConfigValue('ErrorTemplate');
$real_t = $not_found ? $not_found : 'error_notfound';
$this->Application->SetVar('t', $real_t);
$this->Application->removeObject('st.-virtual');
header('HTTP/1.0 404 Not Found');
return $this->GetDesignTemplate();
}
// custom: end
}
// $this->Application->SetVar('t', $t);
return $real_t;
}
/**
* Enter description here...
*
* @param kEvent $event
* @param string $type
*/
function customProcessing(&$event, $type)
{
parent::customProcessing($event, $type);
if ($type == 'after' && in_array($event->Name, array('OnPreSave', 'OnPreSaveCreated', 'OnSave', 'OnUpdate'))) {
$object =& $event->getObject();
if ($object->GetDBField('Filename') != $object->GetOriginalField('Filename') && $object->GetOriginalField('Filename') != '') {
$this->Application->SetVar('FilenameChanged', array('from' => $object->GetOriginalField('Filename'), 'to' => $object->GetDBField('Filename')));
}
}
}
/**
* Sets page name to requested field in case when:
* 1. page was auto created (through theme file rebuld)
* 2. requested field is emtpy
* 3. the value was the same as Name field (so we update target field to keep it the same) AND it was NOT changed (custom)
*
* @param kDBItem $object
* @param string $field
* @author Alex
*/
function _saveTitleField(&$object, $field)
{
$value = $object->GetField($field, 'no_default');
$ml_formatter =& $this->Application->recallObject('kMultiLanguage');
/* @var $ml_formatter kMultiLanguage */
$src_field = $ml_formatter->LangFieldName('Name');
$dst_field = $ml_formatter->LangFieldName($field);
if ($value == '' || preg_match('/^_Auto: (.*)/', $value) || ($object->GetOriginalField($src_field) == $value && $object->GetOriginalField($dst_field) == $value)) {
$object->SetField($dst_field, $object->GetField($src_field));
}
}
/**
* Processes OnMassMoveUp, OnMassMoveDown events
*
* @param kEvent $event
*/
function OnChangePriority(&$event)
{
parent::OnChangePriority($event);
$this->Application->StoreVar('RefreshStructureTree', 1);
$event->CallSubEvent('OnResetMenuCache');
}
/**
* Completely recalculates priorities in current category
*
* @param kEvent $event
*/
function OnRecalculatePriorities(&$event)
{
parent::OnRecalculatePriorities($event);
$this->Application->StoreVar('RefreshStructureTree', 1);
$event->CallSubEvent('OnResetMenuCache');
}
}