$status = substr($f_action, 9); foreach ($f_items as $item_id) { $InterviewItem = new InterviewItem(null, $item_id); $InterviewItem->setProperty('status', $status); } break; case 'item_move_up_rel': case 'item_move_down_rel': $f_items = Input::Get('f_items', 'array'); list(,,$dir,) = explode('_', $f_action); foreach ($f_items as $item_id) { $InterviewItem = new InterviewItem(null, $item_id); $InterviewItem->positionRelative($dir); } break; case 'item_move_abs': $f_items = Input::Get('f_items', 'array'); $f_new_pos = Input::Get('f_new_pos', 'int'); foreach ($f_items as $item_id) { $InterviewItem = new InterviewItem(null, $item_id); $InterviewItem->positionAbsolute($f_new_pos); } break;
/** * Move the interview to the given position (i.e. reorder the interview). * @param int $p_moveToPosition * @return boolean */ function positionAbsolute($p_moveToPosition = 1) { global $g_ado_db; // Get the item that is in the location we are moving // this one to. $queryStr = " SELECT position, item_id FROM {$this->m_dbTableName} WHERE fk_interview_id = {$this->m_data['fk_interview_id']} ORDER BY position ASC LIMIT ".($p_moveToPosition - 1).', 1'; $destRow = $g_ado_db->GetRow($queryStr); if (!$destRow) { return false; } if ($destRow['position'] == $this->m_data['position']) { // Move the destination down one. $destItem = new InterviewItem(null, $destRow['item_id']); $destItem->positionRelative("down", 1); return true; } if ($destRow['position'] > $this->m_data['position']) { $operator = '-'; } else { $operator = '+'; } // Reorder all the other items $minItemOrder = min($destRow['position'], $this->m_data['position']); $maxItemOrder = max($destRow['position'], $this->m_data['position']); $queryStr = " UPDATE {$this->m_dbTableName} SET position = position $operator 1 WHERE fk_interview_id = {$this->m_data['fk_interview_id']} AND position >= $minItemOrder AND position <= $maxItemOrder"; $g_ado_db->Execute($queryStr); // Reposition this item. $queryStr = " UPDATE {$this->m_dbTableName} SET position = {$destRow['position']} WHERE item_id = {$this->m_data['item_id']}"; $g_ado_db->Execute($queryStr); $CampCache = CampCache::singleton(); $CampCache->clear('user'); $this->fetch(); return true; } // fn positionAbsolute