/** * Prepares and shows the devices list (cmd-my-devices) * * @param array args (not used) */ public function get_my_devices_list(array $args) { // check if is logged in if (!$this->mvc->authentication->is_user()) { return; } // check if user has at least one provider $this->data['user_has_provider'] = com_meego_devprogram_provutils::user_has_providers(); if (!$this->data['user_has_provider']) { return false; } // get own devices // and the ones that belong to providers the user is also member of $this->data['my_devices'] = com_meego_devprogram_devutils::get_devices_of_current_user(); }
/** * Prepares and shows the program list page (cmd-my-programs) * * @param array args (not used) */ public function get_my_programs_list(array $args) { // check if is logged in if (!$this->mvc->authentication->is_user()) { return; } $this->data['user_has_device'] = com_meego_devprogram_devutils::user_has_device(); if (!$this->data['user_has_device']) { return false; } $this->data['my_programs'] = com_meego_devprogram_progutils::get_open_programs_of_current_user(); }
/** * Retrieves programs of the currently loged in user * * @return array an array of com_meego_devprogram_programs objects * null if user is not logged in */ public static function get_open_programs_of_current_user() { $programs = array(); // retrieve the user's guid based on the login name $user = self::require_login(); if (!is_object($user)) { return null; } // all devices from this user and by fellow members of the same provider $memberships = com_meego_devprogram_membutils::get_memberships_of_current_user(); foreach ($memberships as $membership) { // check status if ($membership->status == CMD_MEMBERSHIP_APPROVED) { // get device objects $devices = com_meego_devprogram_devutils::get_devices(array('provider' => $membership->provider)); // find all programs belonging all devices found before foreach ($devices as $device) { $filters = array('status' => CMD_PROGRAM_OPEN, 'device' => $device->id); $programs = array_merge($programs, self::get_programs($filters)); } } } return $programs; }
/** * Finds devices that belong to the given provider * * @param integer id of the provider * @return boolean true: if provider has devices; false otherwise */ public function has_provider_devices($id = 0) { $retval = false; if ($id) { $filters = array('provider' => $id); $devices = com_meego_devprogram_devutils::get_devices($filters); if (count($devices)) { $retval = true; } unset($filters, $devices); } return $retval; }