/**
  * Check to see if a user has visited a specific unit.
  *
  * Better to use Course_Completion[] class. But keeping this method for legacy.
  *
  * @see Course_Completion
  *
  * @param int $unit_ID
  * @param string $user_ID
  *
  * @return bool True if user has accessed the course at least once.
  */
 function is_unit_visited($unit_ID = 0, $user_ID = '')
 {
     if ($user_ID == '') {
         $user_ID = $this->ID;
     }
     $get_old_values = get_user_option('visited_units', $user_ID);
     $get_old_values = explode('|', $get_old_values);
     if (cp_in_array_r($unit_ID, $get_old_values)) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 function set_unit_visited($user_ID, $unit_ID)
 {
     $global_option = !is_multisite();
     $get_old_values = get_user_option('visited_units');
     $get_new_values = explode('|', $get_old_values);
     if (!cp_in_array_r($unit_ID, $get_new_values)) {
         $get_old_values = $get_old_values . '|' . $unit_ID;
         update_user_option($user_ID, 'visited_units', $get_old_values, $global_option);
     }
 }
Ejemplo n.º 3
0
function cp_in_array_r($needle, $haystack, $strict = false)
{
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || is_array($item) && cp_in_array_r($needle, $item, $strict)) {
            return true;
        }
    }
    return false;
}