/** * Initializes this component. * * @param Connector $connector The connector signed in. * @param string $login The login of the user to load data, if null, it will take the signed in user. * @throws \Exception If the Connector is not signed in. */ public function __construct(Connector $connector, $login = null) { $connector->checkSignedIn(); $this->connector = $connector; // Retrieving information about the specified user or signed in user if ($login == null) { $url = str_replace('{LOGIN}', $this->connector->getUser()->getLogin(), self::URL_NETSOUL); } else { $url = str_replace('{LOGIN}', $login, self::URL_NETSOUL); } $response = $this->connector->request($url); $this->data = DataExtractor::retrieve($response); // Parsing the data $logs = array(); foreach ($this->data as $log) { // Building the dates $datetime = null; if ($timestamp = DataExtractor::extract($log, array(0))) { $datetime = new \DateTime(); $datetime->setTimestamp($timestamp); } // Building the log $log = array('timestamp' => $timestamp, 'datetime' => $datetime, 'time_active' => DataExtractor::extract($log, array(1)), 'time_inactive' => DataExtractor::extract($log, array(2)), 'timeout_active' => DataExtractor::extract($log, array(3)), 'timeout_inactive' => DataExtractor::extract($log, array(4)), 'time_average' => DataExtractor::extract($log, array(5))); // Adding the log the temporary array $logs[$log['timestamp']] = $log; } // Replace the temporary array $this->data = $logs; }
/** * Initializes this component. * * @param Connector $connector The Connector signed in. * @param int $school_year The school year. * @param string $code_module The module code. * @param string $code_instance The instance code. */ public function __construct(Connector $connector, $school_year, $code_module, $code_instance) { $connector->checkSignedIn(); $this->connector = $connector; // Retrieving information about the module $url = str_replace(array('{SCHOOL_YEAR}', '{CODE_MODULE}', '{CODE_INSTANCE}'), array($school_year, $code_module, $code_instance), self::URL_MODULE); $response = $this->connector->request($url); $this->data = DataExtractor::retrieve($response); }
/** * Initializes this component. * * @param Connector $connector The connector signed in. * @param string $login The login of the user to load data, if null, it will take the signed in user. * @throws \Exception If the Connector is not signed in. */ public function __construct(Connector $connector, $login = null) { $connector->checkSignedIn(); $this->connector = $connector; // Retrieving information about the specified user or signed in user if ($login == null) { $url = self::URL_SIGNED_IN_USER; } else { $url = str_replace('{LOGIN}', $login, self::URL_USER); } $response = $this->connector->request($url); $this->data = DataExtractor::retrieve($response); }
/** * Obtains the users registered to this event. * * @param bool $as_object Whether the return type is an array of logins or an array of object User. * @return array */ public function getRegisteredUsers($as_object = false) { if ($this->registered_users_login == null) { $this->registered_users_login = array(); $url = str_replace(array('{SCHOOL_YEAR}', '{CODE_MODULE}', '{CODE_INSTANCE}', '{CODE_ACTIVITY}', '{CODE_EVENT}'), array($this->getSchoolYear(), $this->getModuleCode(), $this->getInstanceCode(), $this->getActivityCode(), $this->getEventCode()), self::URL_USER_REGISTERED); $response = $this->connector->request($url); $registered_users = DataExtractor::retrieve($response); foreach ($registered_users as $registered_user) { $this->registered_users_login[$registered_user['login']] = $registered_user['login']; } } if ($as_object) { if ($this->registered_users == null) { $this->registered_users = array(); foreach ($this->registered_users_login as $login) { $this->registered_users[$login] = new User($this->connector, $login); } } return $this->registered_users; } return $this->registered_users_login; }