Created
September 12, 2012 18:46
-
-
Save justinhillsjohnson/3709004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//acquire all loaded resource ID's | |
$resources = unserialize(base64_decode($modx->runSnippet('get_resources_snippet'))); | |
$output = ''; | |
$workList = ''; | |
$downloadSection = ''; | |
//get client data | |
$clientDataArray = array( | |
'id' => $resources['client'], | |
'deleted' => false | |
); | |
$clientData = $modx->getObject('modResource', $clientDataArray); | |
//get campaign list data | |
$campaignQuery = $modx->newQuery('modResource'); | |
$campaignDataCriteria = array( | |
'parent:IN' => array($resources['client']), | |
'deleted' => false, | |
'pagetitle:!=' => 'featured articles' | |
); | |
$campaignQuery->where($campaignDataCriteria); | |
$campaignQuery->sortby('menuindex','ASC'); | |
$campaignData = $modx->getCollection('modResource', $campaignQuery); | |
//get all TV data | |
$campaignThumbImageTV = $modx->getObject('modTemplateVar', array('name' => 'campaign_thumb_image')); | |
$campaignDefaultWorkTV = $modx->getObject('modTemplateVar', array('name' => 'default_work')); | |
$workContentTypeTV = $modx->getObject('modTemplateVar', array('name' => 'work_content_type')); | |
$workHeroVideoTV = $modx->getObject('modTemplateVar', array('name' => 'work_hero_video')); | |
$workHeroImageTV = $modx->getObject('modTemplateVar', array('name' => 'work_hero_image')); | |
$workThumbImageTV = $modx->getObject('modTemplateVar', array('name' => 'work_thumb_image')); | |
$iphoneURLTV = $modx->getObject('modTemplateVar', array('name' => 'iphone_app_link')); | |
$androidURLTV = $modx->getObject('modTemplateVar', array('name' => 'android_app_link')); | |
$campaignCount = 0; | |
foreach($campaignData as $campaign){ | |
echo "view_unpublished: " . $campaign->checkPolicy('view_unpublished'); | |
echo "sdfasdf: " . $campaign->checkPolicy('fsadf'); | |
$campaignDefaultWork = isset($campaignDefaultWorkTV) ? $campaignDefaultWorkTV->getValue($campaign->id) : ''; | |
$iphoneURL = isset($iphoneURLTV) ? $iphoneURLTV->getValue($campaign->id) : ''; | |
$androidURL = isset($androidURLTV) ? $androidURLTV->getValue($campaign->id) : ''; | |
$workCount = 0; | |
//get campaign works list data | |
$workQuery = $modx->newQuery('modResource'); | |
$workDataCriteria = array( | |
'parent:IN' => array($campaign->id), | |
'deleted' => false | |
); | |
$workQuery->where($workDataCriteria); | |
$workQuery->sortby('menuindex','ASC'); | |
$workData = $modx->getCollection('modResource', $workQuery); | |
foreach($workData as $work){ | |
$workContentType = isset($workContentTypeTV) ? $workContentTypeTV->getValue($work->id) : ''; | |
$workHeroVideoURL = isset($workHeroVideoTV) ? $workHeroVideoTV->getValue($work->id) : ''; | |
$workHeroImageURL = isset($workHeroImageTV) ? $workHeroImageTV->getValue($work->id) : ''; | |
//set work state | |
if($modx->resource->get('template') == 4 && $campaign->id == $resources['campaign']){ | |
$workState = $work->id == $modx->resource->id ? 'active' : ''; | |
} else if($campaignDefaultWork !== '') { | |
$workState = $work->id == $campaignDefaultWork ? 'active' : ''; | |
} else { | |
$workState = $workCount === 0 ? 'active' : ''; | |
} | |
//set media hero and work media id's based on current template | |
if($workContentType === 'Video' && $workHeroVideoURL !== ''){ | |
//store first work as a fallback - video | |
if($workCount === 0){ | |
$heroContentFallback = $modx->getChunk('work_video_chunk', array( | |
'video_id' => $workHeroVideoURL | |
)); | |
} | |
if($modx->resource->get('template') == 4 && $campaign->id == $resources['campaign']){ | |
if($work->id == $modx->resource->id){ | |
$heroContent = $modx->getChunk('work_video_chunk', array( | |
'video_id' => $workHeroVideoURL | |
)); | |
} | |
} else { | |
if($work->id == $campaignDefaultWork){ | |
$heroContent = $modx->getChunk('work_video_chunk', array( | |
'video_id' => $workHeroVideoURL | |
)); | |
} else if($campaignDefaultWork === '') { | |
$heroContent = $heroContentFallback; | |
} | |
} | |
$workMediaID = $workHeroVideoURL; | |
} else if($workContentType === 'Image' && $workHeroImageURL !== ''){ | |
//store first work as a fallback - image | |
if($workCount === 0){ | |
$heroContentFallback = $modx->getChunk('work_image_chunk', array( | |
'image_url' => $workHeroImageURL, | |
'image_title' => $work->pagetitle | |
)); | |
} | |
if($modx->resource->get('template') == 4 && $campaign->id == $resources['campaign']){ | |
if($work->id == $modx->resource->id){ | |
$heroContent = $modx->getChunk('work_image_chunk', array( | |
'image_url' => $workHeroImageURL, | |
'image_title' => $work->pagetitle | |
)); | |
} | |
} else { | |
if($work->id == $campaignDefaultWork){ | |
$heroContent = $modx->getChunk('work_image_chunk', array( | |
'image_url' => $workHeroImageURL, | |
'image_title' => $work->pagetitle | |
)); | |
} else if($campaignDefaultWork === '') { | |
$heroContent = $heroContentFallback; | |
} | |
} | |
$workMediaID = '/upload/' . $workHeroImageURL; | |
} | |
$workList .= $modx->getChunk('work_list_chunk', array( | |
'work_active' => $workState, | |
'work_title' => str_replace(array("'", "‘"), "’", $work->pagetitle), | |
'work_description' => str_replace(array("'", "‘"), "’", $work->description), | |
'work_url' => 'clients/' . $clientData->alias . '/' . $campaign->alias . '/' . $work->alias, | |
'work_image' => $workThumbImageTV->getValue($work->id), | |
'work_type' => strtolower($workContentType), | |
'work_media_id' => $workMediaID | |
)); | |
$workCount++; | |
} | |
//package download details | |
$iphoneLink = $iphoneURL !== '' ? '<a class="apple" data-track="track_download" target="_blank" data-name="'. $campaign->alias .'" href="' . $iphoneURL . '">Download from iTunes</a>' : null; | |
$androidLink = $androidURL !== '' ? '<a class="android" data-track="track_download" target="_blank" data-name="'. $campaign->alias .'" href="' . $androidURL . '">Download from Android Marketplace</a>' : null; | |
if(isset($iphoneLink) || isset($androidLink)){ | |
$downloadSection = $modx->getChunk('download_section_chunk', array( | |
'iphone_link' => $iphoneLink, | |
'android_link' => $androidLink | |
)); | |
} | |
//set all campaign details | |
$campaignOutput = $modx->getChunk('campaign_info_chunk', array( | |
'client' => str_replace(array("'", "‘"), "’", $clientData->pagetitle), | |
'campaign_name' => str_replace(array("'", "‘"), "’", $campaign->pagetitle), | |
'description' => str_replace(array("'", "‘"), "’", $campaign->description), | |
'download_section' => $downloadSection, | |
'hero_content' => $heroContent, | |
'work_list' => $workList | |
)); | |
//set active campaign state | |
if($resources['campaign'] !== ''){ | |
$campaignState = $campaign->id == $resources['campaign'] ? 'active' : 'inactive'; | |
} else { | |
$campaignState = $campaignCount === 0 ? 'active' : 'inactive'; | |
} | |
//output campaign list | |
$output .= $modx->getChunk('campaign_list_chunk', array( | |
'id' => $campaign->alias, | |
'image' => $campaignThumbImageTV->getValue($campaign->id), | |
'title' => str_replace("'", "’", $campaign->pagetitle), | |
'url' => 'clients/' . $clientData->alias . '/' . $campaign->alias, | |
'state' => $campaignState, | |
'campaign_details' => $campaignOutput | |
)); | |
$workList = ''; | |
$downloadSection = ''; | |
$campaignCount++; | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment