// Do not show any icons if no grade (no record in DB to match)
// TODO: change edit/hide/etc. links to use itemid and userid to allow creating of new grade objects
if (!empty($grade->id) && $USER->gradeediting) {
- $studentshtml .= $this->get_icons($element, null, true, $item);
+ $states = array('is_hidden' => $item->hidden,
+ 'is_locked' => $item->locked,
+ 'is_editable' => $item->gradetype != GRADE_TYPE_NONE && !$grade->locked && !$item->locked);
+ $studentshtml .= $this->get_icons($element, null, true, $states);
}
// if in editting mode, we need to print either a text box
* @param object $object
* @param array $icons An array of icon names that this function is explicitly requested to print, regardless of settings
* @param bool $limit If true, use the $icons array as the only icons that will be printed. If false, use it to exclude these icons.
- * @param object $parent_object An optional parent object (like grade_item if $element is grade_grades)
- * that can be checked for hidden or locked status
+ * @param object $states An optional array of states (hidden, locked, editable), shortcuts to increase performance.
* @return string HTML
*/
- function get_icons($element, $icons=null, $limit=true, $parent_object=null) {
+ function get_icons($element, $icons=null, $limit=true, $states=array()) {
global $CFG;
global $USER;
- // If no parent object is given, we need to let the element load its parent object to get hidden, locked and editable status
- $check_parent = empty($parent_object);
-
// Load language strings
$stredit = $this->get_lang_string("edit");
$streditcalculation= $this->get_lang_string("editcalculation", 'grades');
$object = $element['object'];
$type = $element['type'];
+ if (empty($states)) {
+ $states['is_hidden'] = $object->is_hidden();
+ $states['is_locked'] = $object->is_locked();
+ $states['is_editable'] = $object->is_editable();
+ }
+
// Add mock attributes in case the object is not of the right type
if ($type != 'grade') {
$object->feedback = '';
// Prepare image strings
$edit_icon = '';
- if ((!$check_parent && $parent_object->is_editable()) || $object->is_editable($parent_object)) {
+ if ($states['is_editable']) {
if ($type == 'category') {
$edit_icon = '<a href="'. GRADE_EDIT_URL . '/category.php?courseid='.$object->courseid.'&id='.$object->id.'">'
. '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
$edit_icon = '<a href="'. GRADE_EDIT_URL . '/item.php?courseid='.$object->courseid.'&id='.$object->id.'">'
. '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
. $stredit.'" title="'.$stredit.'" /></a>'. "\n";
- } else if ($type == 'grade' and ($object->is_editable() or empty($object->id))) {
+ } else if ($type == 'grade' and ($states['is_editable'] or empty($object->id))) {
// TODO: change link to use itemid and userid to allow creating of new grade objects
$edit_icon = '<a href="'. GRADE_EDIT_URL . '/grade.php?courseid='.$object->courseid.'&id='.$object->id.'">'
. '<img ' . $overlib . ' src="'.$CFG->pixpath.'/t/edit.gif"'
// Prepare Hide/Show icon state
$hide_show = 'hide';
- if (!$check_parent && $parent_object->is_hidden()) {
- $hide_show = 'show';
- } elseif ($object->is_hidden($parent_object)) {
+ if ($states['is_hidden']) {
$hide_show = 'show';
}
// Prepare lock/unlock string
$lock_unlock = 'lock';
- if ((!$check_parent && $parent_object->is_locked()) || $object->is_locked($parent_object)) {
+ if ($states['is_locked']) {
$lock_unlock = 'unlock';
}
// remove incorrect params - warn developer if needed
foreach ($params as $var=>$value) {
- if (!array_key_exists($var, $classvars) or in_array($var, $instance->nonfields)) {
+ if (!in_array($var, array_keys($classvars)) or in_array($var, $instance->nonfields)) {
debugging("Incorrect property name $var for class $classname");
continue;
}
function set_properties(&$instance, $params) {
$classvars = (array)$instance;
foreach ($params as $var => $value) {
- if (array_key_exists($var, $classvars)) {
+ if (in_array($var, array_keys($classvars))) {
$instance->$var = $value;
}
}