You are here

public function InstagramUser::__construct in Drupagram 7

Same name and namespace in other branches
  1. 6 drupagram.lib.php \InstagramUser::__construct()

Constructor for InstagramUser

File

./drupagram.lib.php, line 652
Classes to implement the full Instagram API

Class

InstagramUser
Class for containing an individual Instagram user.

Code

public function __construct($values = array()) {
  if (!isset($values) || empty($values)) {
    return FALSE;
  }
  if (!is_array($values)) {
    $values = (array) $values;
  }

  // Filter out null and empty values
  $values = array_filter($values);

  // Turn values into user object attributes
  foreach ($values as $key => $value) {
    switch ($key) {
      case 'counts':
        if (is_array($values['counts']) && !empty($values['counts'])) {
          $this->media_count = isset($values['counts']['media']) ? (int) $values['counts']['media'] : 0;
          $this->follows_count = isset($values['counts']['follows']) ? (int) $values['counts']['follows'] : 0;
          $this->followed_by_count = isset($values['counts']['followed_by']) ? (int) $values['counts']['followed_by'] : 0;
        }
        break;
      default:
        $this->{$key} = $value;
        break;
    }
  }
}