Skip to content

Instantly share code, notes, and snippets.

@markphi2013
Created September 20, 2013 09:04
Show Gist options
  • Save markphi2013/6634983 to your computer and use it in GitHub Desktop.
Save markphi2013/6634983 to your computer and use it in GitHub Desktop.
user access
public function getProgramStats()
{
$user = $this->Auth->user();
if(isset($this->params['url']['program'])){
$programUrls = $this->Program->find('authorized', array(
'specific_program_access' => 'true',
'user_id' => $user['id'],
'conditions' => array('url'=> $this->params['url']['program'])));
foreach($programUrls as $programUrl)
$programDatabase = $programUrl['Program']['database'];
$programStats = $this->Stats->getProgramStats($programDatabase);
$result = array('status' =>'ok', 'programURL' => $programUrl['Program']['url'], 'programStats' => $programStats);
$this->set(compact('result'));
}
}
@overnin
Copy link

overnin commented Sep 20, 2013

$.ajax({
     type: "GET",
     dataType: "json",
     url: "/programs/getProgramStats.json",
     data: {"program": programUrl},                  #cleaner to have the parameter of the url separate from the url
     success: function(data){
            $("#"+data['programURL']+" .ttc-program-stats").empty().append(generateHtmlProgramStats(data['programStats']))
     },
     timeout: 100,
     error: function(ajaxRequest){
            alert(ajaxRequest.data['program']);
     })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment