public function test_setRead()
 {
     $instance = new $this->myclass($this->conn);
     $msg = new XoopsPrivmessage();
     $msg->setDirty(true);
     $msg->setNew(true);
     $msg->setVar('subject', 'PRIVMESSAGE_DUMMY_FOR_TESTS', true);
     $value = $instance->insert($msg);
     $this->assertTrue(intval($value) > 0);
     $value = $instance->setRead($msg);
     $this->assertSame(true, $value);
 }
Beispiel #2
0
 /**
  * Load messages from the database
  * @param 	object 	$criteria 	{@link CriteriaElement} object
  * @param 	bool 	$id_as_key 	use ID as key into the array?
  * @return 	array	Array of {@link XoopsPrivmessage} objects
  **/
 function &getObjects($criteria = null, $id_as_key = false)
 {
     $ret = array();
     $limit = $start = 0;
     $sql = 'SELECT * FROM ' . $this->db->prefix('priv_msgs');
     if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
         $sql .= ' ' . $criteria->renderWhere();
         $sort = !in_array($criteria->getSort(), array('msg_id', 'msg_time', 'from_userid')) ? 'msg_id' : $criteria->getSort();
         $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
         $limit = $criteria->getLimit();
         $start = $criteria->getStart();
     }
     $result = $this->db->query($sql, $limit, $start);
     if (!$result) {
         return $ret;
     }
     while ($myrow = $this->db->fetchArray($result)) {
         $pm = new XoopsPrivmessage();
         $pm->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] =& $pm;
         } else {
             $ret[$myrow['msg_id']] =& $pm;
         }
         unset($pm);
     }
     return $ret;
 }
 /**
  * Load a {@link XoopsPrivmessage} object
  * @param 	int 	$id ID of the message
  * @return 	object
  **/
 function &get($id)
 {
     $id = intval($id);
     if ($id > 0) {
         $sql = 'SELECT * FROM ' . $this->db->prefix('priv_msgs') . ' WHERE msg_id=' . $id;
         if (!($result = $this->db->query($sql))) {
             return false;
         }
         $numrows = $this->db->getRowsNum($result);
         if ($numrows == 1) {
             $pm = new XoopsPrivmessage();
             $pm->assignVars($this->db->fetchArray($result));
             return $pm;
         }
     }
     return false;
 }
Beispiel #4
0
 /**
  * Mark a message as read
  *
  * @param XoopsPrivmessage $pm {@link XoopsPrivmessage} object
  * @return bool
  **/
 public function setRead(XoopsPrivmessage &$pm)
 {
     $qb = $this->db2->createXoopsQueryBuilder()->update($this->table, 'pm')->set('pm.read_msg', ':readmsg')->where('pm.msg_id = :msgid')->setParameter(':readmsg', 1, \PDO::PARAM_INT)->setParameter(':msgid', $pm->getVar('msg_id'), \PDO::PARAM_INT);
     $result = $qb->execute();
     if (!$result) {
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Send a message to user's email
  * @param  XoopsPrivmessage $pm {@link XoopsPrivmessage} object
  * @param  XoopsUser $user
  * @return bool
  **/
 public function sendEmail(XoopsPrivmessage $pm, XoopsUser $user)
 {
     global $xoopsConfig;
     if (!is_object($user)) {
         $user =& $GLOBALS['xoopsUser'];
     }
     $msg = sprintf(_PM_EMAIL_DESC, $user->getVar('uname'));
     $msg .= "\n\n";
     $msg .= formatTimestamp($pm->getVar('msg_time'));
     $msg .= "\n";
     $from = new XoopsUser($pm->getVar('from_userid'));
     $to = new XoopsUser($pm->getVar('to_userid'));
     $msg .= sprintf(_PM_EMAIL_FROM, $from->getVar('uname') . ' (' . XOOPS_URL . '/userinfo.php?uid=' . $pm->getVar('from_userid') . ')');
     $msg .= "\n";
     $msg .= sprintf(_PM_EMAIL_TO, $to->getVar('uname') . ' (' . XOOPS_URL . '/userinfo.php?uid=' . $pm->getVar('to_userid') . ')');
     $msg .= "\n";
     $msg .= _PM_EMAIL_MESSAGE . ":\n";
     $msg .= "\n" . $pm->getVar('subject') . "\n";
     $msg .= "\n" . strip_tags(str_replace(array('<p>', '</p>', '<br>', '<br>'), "\n", $pm->getVar('msg_text'))) . "\n\n";
     $msg .= "--------------\n";
     $msg .= $xoopsConfig['sitename'] . ': ' . XOOPS_URL . "\n";
     $xoopsMailer =& xoops_getMailer();
     $xoopsMailer->useMail();
     $xoopsMailer->setToEmails($user->getVar('email'));
     $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
     $xoopsMailer->setFromName($xoopsConfig['sitename']);
     $xoopsMailer->setSubject(sprintf(_PM_EMAIL_SUBJECT, $pm->getVar('subject')));
     $xoopsMailer->setBody($msg);
     return $xoopsMailer->send();
 }