/** * Send the email notifications * * @access public * @param string $template Template name * @param array $users List of users * @param array $data Template data */ public function sendEmails($template, array $users, array $data) { try { $author = ''; if (Session::isOpen() && $this->userSession->isLogged()) { $author = e('%s via Kanboard', $this->user->getFullname($this->session['user'])); } $mailer = Swift_Mailer::newInstance($this->container['mailer']); foreach ($users as $user) { $this->container['logger']->debug('Send email notification to ' . $user['username'] . ' lang=' . $user['language']); $start_time = microtime(true); // Use the user language otherwise use the application language (do not use the session language) if (!empty($user['language'])) { Translator::load($user['language']); } else { Translator::load($this->config->get('application_language', 'en_US')); } // Send the message $message = Swift_Message::newInstance()->setSubject($this->getMailSubject($template, $data))->setFrom(array(MAIL_FROM => $author ?: 'Kanboard'))->setBody($this->getMailContent($template, $data), 'text/html')->setTo(array($user['email'] => $user['name'] ?: $user['username'])); $mailer->send($message); $this->container['logger']->debug('Email sent in ' . round(microtime(true) - $start_time, 6) . ' seconds'); } } catch (Swift_TransportException $e) { $this->container['logger']->error($e->getMessage()); } // Restore locales $this->config->setupTranslations(); }
/** * Get a config variable from the session or the database * * @access public * @param string $name Parameter name * @param string $default_value Default value of the parameter * @return string */ public function get($name, $default_value = '') { if (!Session::isOpen()) { $value = $this->db->table(self::TABLE)->eq('option', $name)->findOneColumn('value'); return $value ?: $default_value; } if (!isset($_SESSION['config'][$name])) { $_SESSION['config'] = $this->getAll(); } if (!empty($_SESSION['config'][$name])) { return $_SESSION['config'][$name]; } return $default_value; }
public function testGetWithSession() { $this->container['session'] = new Session(); $c = new Config($this->container); session_id('test'); $this->assertTrue(Session::isOpen()); $this->assertEquals('', $c->get('board_columns')); $this->assertEquals('test', $c->get('board_columns', 'test')); $this->container['session']['config'] = array('board_columns' => 'foo', 'empty_value' => 0); $this->assertEquals('foo', $c->get('board_columns')); $this->assertEquals('foo', $c->get('board_columns', 'test')); $this->assertEquals('test', $c->get('empty_value', 'test')); session_id(''); unset($this->container['session']); }
/** * Get the list of users to send the notification for a given project * * @access public * @param integer $project_id Project id * @param array $exlude_users List of user_id to exclude * @return array */ public function getUsersList($project_id, array $exclude_users = array()) { // Exclude the connected user if (Session::isOpen()) { $exclude_users[] = $this->acl->getUserId(); } $users = $this->getUsersWithNotification($project_id, $exclude_users); foreach ($users as $index => $user) { $projects = $this->db->table(self::TABLE)->eq('user_id', $user['id'])->findAllByColumn('project_id'); // The user have selected only some projects if (!empty($projects)) { // If the user didn't select this project we remove that guy from the list if (!in_array($project_id, $projects)) { unset($users[$index]); } } } return $users; }
/** * Modify a new user * * @access public * @param array $values Form values * @return array */ public function update(array $values) { $this->prepare($values); $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); // If the user is connected refresh his session if (Session::isOpen() && $this->userSession->getId() == $values['id']) { $this->userSession->refresh(); } return $result; }