Thanks Everett. I have a snippet called scShowAssignments:
<?php
$base_path = $modx->getOption('core_path').'MODXComponents/studentcentre/trunk/core/components/studentcentre/';
$f = $base_path.'snippet.scShowAssignments.php';
if (file_exists($f)) {
include $f;
} else {
$modx->setLogTarget('ECHO');
$modx->log(modX::LOG_LEVEL_ERROR,'scShowAssignments not found at: '.$f);
}
return;
Then at MODXComponents/studentcentre/trunk/core/components/studentcentre/ I have a PHP file called snippet.scShowAssignments.php:
<?php
/*
*
* @package studentcentre
*
*/
$path = MODX_CORE_PATH . 'components/studentcentre/';
$result = $modx->addPackage('studentcentre', $path . 'model/', 'sc_');
if (!$result) {
return 'Failed to add StudentCentre package';
}
// get the logged in student id
if ($modx->user->get('username') != '(anonymous)') {
$studentId = 36; // $modx->user->get('id');
} else {
$url = $modx->makeUrl(55,'','','full');
$modx->sendRedirect($url);
return;
}
$output = '';
// get the collection of student assignments for that student
$c = $modx->newQuery('scStudentAssignment');
//$c->prepare();
//echo $c->toSQL();
$c->where(array(
'student_id:=' => $studentId
));
$c->sortby('status','DESC');
$assignments = $modx->getCollection('scStudentAssignment', $c);
if (count($assignments) > 0) { // if the array is not empty...
// for each assignment, output it's properties along with a link to the assignment
foreach ($assignments as $assignment) {
$fields = $assignment->toArray();
$assignmentUrl = $modx->makeUrl(2658,'',array(
'aid' => $assignment->get('id')
));
$fields['url'] = $assignmentUrl;
$output .= $modx->getChunk('csAssignmentRowTpl', $fields);
}
} else { // if there are no assignments
$msg = $modx->getChunk('csMessageTpl', array(
'class' => 'msg',
'text' => 'Sorry but there are no assignments available to you yet.'
));
return $modx->setPlaceholder('csMessage', $msg);
}
echo $output;
return;
Thoughts?