public function isAllowedToView(User_Model_User $user) { // Check level $selectedLevels = Zend_Json::decode($this->level); if (!empty($selectedLevels) && is_array($selectedLevels)) { // Get user level $levelIdentity = null; if (!$user->getIdentity()) { $levelIdentity = Engine_Api::_()->getDbtable('levels', 'authorization')->getPublicLevel()->level_id; } else { $levelIdentity = $user->level_id; } if (in_array($levelIdentity, $selectedLevels)) { return true; } } // Check network if ($user->getIdentity()) { $selectedNetworks = Zend_Json::decode($this->network); if (!empty($selectedNetworks) && is_array($selectedNetworks)) { $userNetworks = Engine_Api::_()->getDbtable('membership', 'network')->getMembershipsOfIds($user, null); if (count(array_intersect($userNetworks, $selectedNetworks)) > 0) { return true; } } } return false; }
public function getSpecialAlbum(User_Model_User $user, $type) { if (!in_array($type, array('wall', 'profile', 'message'))) { throw new Album_Model_Exception('Unknown special album type'); } $select = $this->select()->where('owner_type = ?', $user->getType())->where('owner_id = ?', $user->getIdentity())->where('type = ?', $type)->order('album_id ASC')->limit(1); $album = $this->fetchRow($select); // Create wall photos album if it doesn't exist yet if (null === $album) { $translate = Zend_Registry::get('Zend_Translate'); $album = $this->createRow(); $album->owner_type = 'user'; $album->owner_id = $user->getIdentity(); $album->title = $translate->_(ucfirst($type) . ' Photos'); $album->type = $type; if ($type == 'message') { $album->search = 0; } else { $album->search = 1; } $album->save(); // Authorizations if ($type != 'message') { $auth = Engine_Api::_()->authorization()->context; $auth->setAllowed($album, 'everyone', 'view', true); $auth->setAllowed($album, 'everyone', 'comment', true); } } return $album; }
public function closeConversation(User_Model_User $user, $other_user_id) { $other_user_id = (int) $other_user_id; // Close sender $this->update(array('sender_deleted' => 1), array('sender_id = ?' => $user->getIdentity(), 'recipient_id = ?' => $other_user_id)); // Close recipient $this->update(array('recipient_deleted' => 1), array('recipient_id = ?' => $user->getIdentity(), 'sender_id = ?' => $other_user_id)); }
public function activateDefaultPlan(User_Model_User $user) { $packagesTable = Engine_Api::_()->getDbtable('packages', 'payment'); $gatewaysTable = Engine_Api::_()->getDbtable('gateways', 'payment'); // Have any gateways or packages been added yet? if ($gatewaysTable->getEnabledGatewayCount() <= 0 || $packagesTable->getEnabledNonFreePackageCount() <= 0) { return false; } // See if they've had a plan before $hasSubscription = (bool) $this->select()->from($this, new Zend_Db_Expr('TRUE'))->where('user_id = ?', $user->getIdentity())->limit(1)->query()->fetchColumn(); if ($hasSubscription) { return false; } // Get the default package $package = $packagesTable->fetchRow(array('`default` = ?' => true, 'enabled = ?' => true, 'price <= ?' => 0)); if (!$package) { return false; } // Create the default subscription $subscription = $this->createRow(); $subscription->setFromArray(array('package_id' => $package->package_id, 'user_id' => $user->getIdentity(), 'status' => 'initial', 'active' => false, 'creation_date' => new Zend_Db_Expr('NOW()'))); $subscription->save(); // Set active $subscription->setActive(true); $subscription->onPaymentSuccess(); return $subscription; }
public function check(User_Model_User $user) { // No CLI if ('cli' === PHP_SAPI) { return; } // Prepare $id = (int) $user->getIdentity(); // Get ip address $db = $this->getAdapter(); $ipObj = new Engine_IP(); $ipExpr = new Zend_Db_Expr($db->quoteInto('UNHEX(?)', bin2hex($ipObj->toBinary()))); // Run update first $count = $this->update(array('active' => date('Y-m-d H:i:s')), array('user_id = ?' => $id, 'ip = ?' => $ipExpr, 'active > ?' => new Zend_Db_Expr('DATE_SUB(NOW(),INTERVAL 20 MINUTE)'))); // Run insert if update doesn't do anything if ($count < 1) { if ($this->getAdapter() instanceof Zend_Db_Adapter_Mysqli || $this->getAdapter() instanceof Engine_Db_Adapter_Mysql || $this->getAdapter() instanceof Zend_Db_Adapter_Pdo_Mysql) { $sql = 'INSERT IGNORE INTO `' . $this->info('name') . '` (`user_id`, `ip`, `active`) VALUES (?, UNHEX(?), ?)'; $sql = $this->getAdapter()->quoteInto($sql, $id, null, 1); $sql = $this->getAdapter()->quoteInto($sql, bin2hex($ipObj->toBinary()), null, 1); $sql = $this->getAdapter()->quoteInto($sql, date('Y-m-d H:i:s'), null, 1); $this->getAdapter()->query($sql); } else { $this->insert(array('user_id' => $id, 'ip' => $ipExpr, 'active' => date('Y-m-d H:i:s'))); } } return $this; }
public function getOutboxCountSelect(User_Model_User $user) { $rName = Engine_Api::_()->getDbtable('recipients', 'messages')->info('name'); $cName = $this->info('name'); $select = new Zend_Db_Select($this->getAdapter()); $select->from($cName, new Zend_Db_Expr('COUNT(1) AS zend_paginator_row_count'))->joinRight($rName, "`{$rName}`.`conversation_id` = `{$cName}`.`conversation_id`", null)->where("`{$rName}`.`user_id` = ?", $user->getIdentity())->where("`{$rName}`.`outbox_deleted` = ?", 0); return $select; }
/** * Check if a action is enabled * * @param User_Model_User $user User to check for * @param string $type Action type * @return bool Enabled */ public function checkEnabledAction(User_Model_User $user, $type) { $canDisable = Engine_Api::_()->getApi('settings', 'core')->getSetting('activity.publish', true); if (!$canDisable) { return true; } $val = $this->select()->from($this->info('name'), 'publish')->where('user_id = ?', $user->getIdentity())->where('type = ?', $type)->limit(1)->query()->fetchColumn(0); return false === $val || $val; }
public function getRequest(User_Model_User $user) { $select = $this->select(); if ($user) { $select->where("user_id = ? ", $user->getIdentity()); $select->where("user_approved = ? ", '0'); } return $this->fetchAll($select); }
/** * Check if a notification is enabled * * @param User_Model_User $user User to check for * @param string $type Notification type * @return bool Enabled */ public function checkEnabledNotification(User_Model_User $user, $type) { $select = $this->select()->where('user_id = ?', $user->getIdentity())->where('type = ?', $type)->limit(1); $row = $this->fetchRow($select); if (null === $row) { return true; } return (bool) $row->email; }
public function getSpecialAlbum(User_Model_User $user, $type) { if (!in_array($type, array('wall', 'profile', 'message'))) { throw new Advalbum_Model_Exception('Unknown special album type'); } $select = $this->select()->where('owner_type = ?', $user->getType())->where('owner_id = ?', $user->getIdentity())->where('type = ?', $type)->order('album_id ASC')->limit(1); $album = $this->fetchRow($select); // Create wall photos album if it doesn't exist yet if (null === $album) { $translate = Zend_Registry::get('Zend_Translate'); $album = $this->createRow(); $album->owner_type = 'user'; $album->owner_id = $user->getIdentity(); $album->title = $translate->_(ucfirst($type) . ' Photos'); $album->type = $type; $album->save(); } return $album; }
public function setSetting(User_Model_User $user, $key, $value) { if (null === $value) { $this->delete(array('user_id = ?' => $user->getIdentity(), 'name = ?' => $key)); } else { if (null === ($prev = $this->getSetting($user, $key)) || false === $prev) { $this->insert(array('user_id' => $user->getIdentity(), 'name' => $key, 'value' => $value)); } else { $this->update(array('value' => $value), array('user_id = ?' => $user->getIdentity(), 'name = ?' => $key)); } } return $this; }
public function check(User_Model_User $user, $rooms = array()) { if (!is_array($rooms)) { return; } foreach ($rooms as $index => $room_id) { if (!is_numeric($room_id)) { unset($rooms[$index]); } } if (empty($rooms)) { return; } $this->update(array('date' => date('Y-m-d H:i:s')), array('user_id = ?' => $user->getIdentity(), 'room_id IN(?)' => $rooms)); }
public function getSaveFeeds(User_Model_User $user, $types, $params = array()) { $limit = (!empty($params['limit']) ? $params['limit'] : 15) * 2; $max_id = $params['max_id']; $select = $this->select()->where('user_id = ?', $user->getIdentity())->where('action_type IN(?)', (array) $types)->limit($limit); if (null !== $max_id) { $select->where('action_id <= ?', $max_id); } $data = $select->query()->fetchAll(); $settings = array(); foreach ($data as $row) { $settings[] = $row['action_id']; } return $settings; }
public function getKey(User_Model_User $user, $type = null, $expires = 0) { $select = $this->select()->where('user_id = ?', $user->getIdentity()); if (null !== $type) { $select->where('type = ?', $type); } if (!$expires) { $select->where('expires = ?', 0); } else { $select->where('expires > ?', time()); } $row = $this->fetchRow($select); if (null === $row) { return $this->createKey($user, $type, $expires); } else { return $row; } }
public function check(User_Model_User $user) { // Prepare $id = (int) $user->getIdentity(); $ip = ip2long($_SERVER['REMOTE_ADDR']); // Run update first $count = $this->update(array('active' => date('Y-m-d H:i:s')), array('user_id = ?' => $id, 'ip = ?' => $ip)); // Run insert if update doesn't do anything if ($count < 1) { if ($this->getAdapter() instanceof Zend_Db_Adapter_Mysqli || $this->getAdapter() instanceof Engine_Db_Adapter_Mysql || $this->getAdapter() instanceof Zend_Db_Adapter_Pdo_Mysql) { $sql = 'INSERT IGNORE INTO `' . $this->info('name') . '` (`user_id`, `ip`, `active`) VALUES (?, ?, ?)'; $sql = $this->getAdapter()->quoteInto($sql, $id, null, 1); $sql = $this->getAdapter()->quoteInto($sql, $ip, null, 1); $sql = $this->getAdapter()->quoteInto($sql, date('Y-m-d H:i:s'), null, 1); $this->getAdapter()->query($sql); } else { $this->insert(array('user_id' => $id, 'ip' => $ip, 'active' => date('Y-m-d H:i:s'))); } } return $this; }
protected function _finishPayment($state = 'active') { $viewer = Engine_Api::_()->user()->getViewer(); $user = $this->_user; // No user? if (!$this->_user) { return $this->_helper->redirector->gotoRoute(array(), 'default', true); } // Log the user in, if they aren't already if (($state == 'active' || $state == 'free') && $this->_user && !$this->_user->isSelf($viewer) && !$viewer->getIdentity()) { Zend_Auth::getInstance()->getStorage()->write($this->_user->getIdentity()); Engine_Api::_()->user()->setViewer(); $viewer = $this->_user; } // Handle email verification or pending approval if ($viewer->getIdentity() && !$viewer->enabled) { Engine_Api::_()->user()->setViewer(null); Engine_Api::_()->user()->getAuth()->getStorage()->clear(); $confirmSession = new Zend_Session_Namespace('Signup_Confirm'); $confirmSession->approved = $viewer->approved; $confirmSession->verified = $viewer->verified; $confirmSession->enabled = $viewer->enabled; return $this->_helper->_redirector->gotoRoute(array('action' => 'confirm'), 'user_signup', true); } // Clear session $errorMessage = $this->_session->errorMessage; $userIdentity = $this->_session->user_id; $this->_session->unsetAll(); $this->_session->user_id = $userIdentity; $this->_session->errorMessage = $errorMessage; // Redirect if ($state == 'free') { return $this->_helper->redirector->gotoRoute(array(), 'default', true); } else { return $this->_helper->redirector->gotoRoute(array('action' => 'finish', 'state' => $state)); } }
public function getBenefitStatus(User_Model_User $user = null) { // Get benefit setting $benefitSetting = Engine_Api::_()->getApi('settings', 'core')->getSetting('payment.benefit'); if (!in_array($benefitSetting, array('all', 'some', 'none'))) { $benefitSetting = 'all'; } switch ($benefitSetting) { default: case 'all': return true; break; case 'some': if (!$user) { return false; } return (bool) $this->select()->from($this, new Zend_Db_Expr('TRUE'))->where('user_id = ?', $user->getIdentity())->where('type = ?', 'payment')->where('status = ?', 'okay')->limit(1); break; case 'none': return false; break; } return false; }
public function getSpecialAlbum(User_Model_User $user, $type) { if (!in_array($type, array('comment'))) { throw new Album_Model_Exception('Unknown special album type'); } if (Engine_Api::_()->hasModuleBootstrap('sitealbum')) { $table = Engine_Api::_()->getDbtable('albums', 'sitealbum'); } else { if (Engine_Api::_()->hasModuleBootstrap('advalbum')) { $table = Engine_Api::_()->getDbtable('albums', 'advalbum'); } else { $table = Engine_Api::_()->getDbtable('albums', 'album'); } } $select = $table->select()->where('owner_type = ?', $user->getType())->where('owner_id = ?', $user->getIdentity())->where('type = ?', $type)->order('album_id ASC')->limit(1); $album = $table->fetchRow($select); // Create wall photos album if it doesn't exist yet if (null === $album) { $translate = Zend_Registry::get('Zend_Translate'); $album = $table->createRow(); $album->owner_type = 'user'; $album->owner_id = $user->getIdentity(); $album->title = $translate->_(ucfirst(str_replace("_", " ", $type)) . ' Photos'); $album->type = $type; $album->search = 1; $album->save(); // Authorizations $auth = Engine_Api::_()->authorization()->context; $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone'); foreach ($roles as $i => $role) { $auth->setAllowed($album, $role, 'view', true); $auth->setAllowed($album, $role, 'comment', true); } } return $album; }
public function removeUserLists(User_Model_User $user) { Engine_Api::_()->getItemTable('user_list')->delete(array('owner_id = ?' => $user->getIdentity())); }
public function checkSubscription(User_Model_User $user, User_Model_User $subscriber) { return (bool) $this->select()->from($this, new Zend_Db_Expr('TRUE'))->where('user_id = ?', $user->getIdentity())->where('subscriber_user_id = ?', $subscriber->getIdentity())->query()->fetchColumn(); }
public function vote(User_Model_User $user, $option) { $table = Engine_Api::_()->getDbTable('votes', 'poll'); $row = $table->fetchRow(array('poll_id = ?' => $this->getIdentity(), 'user_id = ?' => $user->getIdentity())); if (null === $row) { $row = $table->createRow(); $row->setFromArray(array('poll_id' => $this->getIdentity(), 'user_id' => $user->getIdentity(), 'creation_date' => date("Y-m-d H:i:s"))); } $row->poll_option_id = $option; $row->modified_date = date("Y-m-d H:i:s"); $row->save(); // We also have to update the poll_options table $optionsTable = Engine_Api::_()->getDbtable('options', 'poll'); $optionsTable->update(array('votes' => new Zend_Db_Expr('votes + 1')), array('poll_id = ?' => $this->getIdentity(), 'poll_option_id = ?' => $option)); // Recheck all options? /* // Note: this doesn't seem to work because we're in a transaction -_- $subselect = $table->select() ->from($table, 'COUNT(*)') ->where('poll_id = ?', $this->getIdentity()) ->where('poll_option_id = ?', new Zend_Db_Expr($optionsTable->info('name') . '.poll_option_id')) ; $optionsTable->update(array( 'votes' => $subselect, ), array( 'poll_id = ?' => $this->getIdentity(), )); * */ // Update internal vote count $this->vote_count = new Zend_Db_Expr('vote_count + 1'); $this->save(); }
public function vote(User_Model_User $user, $option) { $votesTable = Engine_Api::_()->getDbTable('pollVotes', 'advgroup'); $optionsTable = Engine_Api::_()->getDbtable('pollOptions', 'advgroup'); // Get poll option if (is_numeric($option)) { $option = $optionsTable->find((int) $option)->current(); } if (!$option instanceof Zend_Db_Table_Row_Abstract) { throw new Engine_Exception('Missing or invalid poll option'); } // Check for existing vote $vote = $votesTable->fetchRow(array('poll_id = ?' => $this->getIdentity(), 'user_id = ?' => $user->getIdentity())); // New vote is the same as old vote, ignore if ($vote && $option->poll_option_id == $vote->poll_option_id) { return $this; } if (!$vote) { // Vote did not exist // Create vote $vote = $votesTable->createRow(); $vote->setFromArray(array('poll_id' => $this->getIdentity(), 'user_id' => $user->getIdentity(), 'poll_option_id' => $option->poll_option_id, 'creation_date' => date("Y-m-d H:i:s"), 'modified_date' => date("Y-m-d H:i:s"))); $vote->save(); // Increment new option count $optionsTable->update(array('votes' => new Zend_Db_Expr('votes + 1')), array('poll_id = ?' => $this->getIdentity(), 'poll_option_id = ?' => $vote->poll_option_id)); // Update internal vote count $this->vote_count = new Zend_Db_Expr('vote_count + 1'); $this->save(); } else { // Vote did exist // Decrement old option count $optionsTable->update(array('votes' => new Zend_Db_Expr('votes - 1')), array('poll_id = ?' => $this->getIdentity(), 'poll_option_id = ?' => $vote->poll_option_id)); // Change vote $vote->poll_option_id = $option->poll_option_id; $vote->modified_date = date("Y-m-d H:i:s"); $vote->save(); // Increment new option count $optionsTable->update(array('votes' => new Zend_Db_Expr('votes + 1')), array('poll_id = ?' => $this->getIdentity(), 'poll_option_id = ?' => $vote->poll_option_id)); } return $this; }
public function getMembershipsOfSelect(User_Model_User $user, $active = true) { $itemTable = Engine_Api::_()->getItemTable($this->_type); $table = $this->getTable(); $itName = $itemTable->info('name'); $mtName = $table->info('name'); $col = current($itemTable->info('primary')); $select = $itemTable->select()->from($itName)->joinRight($mtName, "`{$mtName}`.`resource_id` = `{$itName}`.`{$col}`", null)->where("`{$mtName}`.`user_id` = ?", $user->getIdentity()); if ($active !== null) { $select->where("`{$mtName}`.`active` = ?", (bool) $active); } return $select; }
/** * Resend invitation emails */ public function resendInvitationEmail(User_Model_User $user, $recipient, $inviting_message, $invitation_code) { $success = 1; $error_message = 'No error happenned'; $settings = Engine_Api::_()->getApi('settings', 'core'); // Get the already invited contacts $invites_table = Engine_Api::_()->getDbTable('invites', 'invite'); $existing_members = $this->getUserByEmail($recipient); // Preprocess recipient email address $recipient = trim($recipient); // Omit recipients who is a current member if (!$this->validateEmail($recipient) || array_key_exists($recipient, $existing_members)) { $success = 0; $error_message = 'Invalid email or already registered email'; $result_message['success'] = $success; $result_message['error_message'] = $error_message; return $result_message; } // Genreate invitation URL $inviteUrl = $link = Zend_Controller_Front::getInstance()->getRouter()->assemble(array('user_id' => $user->getIdentity()), 'contactimporter_ref'); if ($invitation_code) { $inviteUrl = Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'invite', 'controller' => 'signup'), 'default', true) . '?' . http_build_query(array('code' => $invitation_code, 'email' => $recipient)); } // insert the invitation into database $db = Engine_Db_Table::getDefaultAdapter(); $db->beginTransaction(); try { $mail_settings = array('host' => $_SERVER['HTTP_HOST'], 'date' => time(), 'sender_email' => $user->email, 'sender_title' => $user->getTitle(), 'sender_link' => $user->getHref(), 'sender_photo' => $user->getPhotoUrl('thumb.icon'), 'displayname' => $user->getTitle(), 'email' => $recipient, 'message' => $inviting_message, 'object_link' => $inviteUrl); if ($invitation_code) { $mail_settings['code'] = $invitation_code; } // send email $mailType = $settings->getSetting('user.signup.inviteonly'); if ($mailType == 2) { $mail_settings['code'] = $invitation_code; Engine_Api::_()->getApi('mail', 'contactimporter')->sendSystem($recipient, 'invite_code', $mail_settings); } else { $mail_settings['code'] = $invitation_code; Engine_Api::_()->getApi('mail', 'contactimporter')->sendSystem($recipient, 'invite', $mail_settings); } $db->commit(); } catch (Zend_Mail_Transport_Exception $e) { $db->rollBack(); $success = 0; $error_message = 'Fail to create records in database.'; $result_message['success'] = 0; $result_message['error_message'] = $error_message; return $result_message; } $success = 1; $error_message = ''; $result_message['success'] = $success; $result_message['error_message'] = $error_message; return $result_message; }
/** * Get a paginator for request-type notifications * * @param User_Model_User $user * @return Zend_Paginator */ public function getRequestsPaginator(User_Model_User $user) { // Only get enabled types $enabledModuleNames = Engine_Api::_()->getDbtable('modules', 'core')->getEnabledModuleNames(); $typeTable = Engine_Api::_()->getDbtable('notificationTypes', 'activity'); $select = $this->select()->from($this->info('name'))->join($typeTable->info('name'), $typeTable->info('name') . '.type = ' . $this->info('name') . '.type', null)->where('module IN(?)', $enabledModuleNames)->where('user_id = ?', $user->getIdentity())->where('is_request = ?', 1)->where('mitigated = ?', 0)->order('date ASC'); return Zend_Paginator::factory($select); }
public function sendInvites(User_Model_User $user, $recipients, $message) { $settings = Engine_Api::_()->getApi('settings', 'core'); // Check recipients if (is_string($recipients)) { $recipients = preg_split("/[\\s,]+/", $recipients); } if (is_array($recipients)) { $recipients = array_map('strtolower', array_unique(array_filter(array_map('trim', $recipients)))); } if (!is_array($recipients) || empty($recipients)) { return 0; } // Only allow a certain number for now $max = $settings->getSetting('invite.max', 10); if (count($recipients) > $max) { $recipients = array_slice($recipients, 0, $max); } // Check message $message = trim($message); // Get tables $userTable = Engine_Api::_()->getItemTable('user'); $inviteTable = $this; $inviteOnlySetting = $settings->getSetting('user.signup.inviteonly', 0); // Get ones that are already members $alreadyMembers = $userTable->fetchAll(array('email IN(?)' => $recipients)); $alreadyMemberEmails = array(); foreach ($alreadyMembers as $alreadyMember) { if (in_array(strtolower($alreadyMember->email), $recipients)) { $alreadyMemberEmails[] = strtolower($alreadyMember->email); } } // Remove the ones that are already members $recipients = array_diff($recipients, $alreadyMemberEmails); $emailsSent = 0; // Send them invites foreach ($recipients as $recipient) { // start inserting database entry // generate unique invite code and confirm it truly is unique do { $inviteCode = substr(md5(rand(0, 999) . $recipient), 10, 7); } while (null !== $inviteTable->fetchRow(array('code = ?' => $inviteCode))); $row = $inviteTable->createRow(); $row->user_id = $user->getIdentity(); $row->recipient = $recipient; $row->code = $inviteCode; $row->timestamp = new Zend_Db_Expr('NOW()'); $row->message = $message; $row->save(); try { $inviteUrl = (_ENGINE_SSL ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'invite', 'controller' => 'signup'), 'default', true) . '?' . http_build_query(array('code' => $inviteCode, 'email' => $recipient)); $message = str_replace('%invite_url%', $inviteUrl, $message); // Send mail $mailType = $inviteOnlySetting == 2 ? 'invite_code' : 'invite'; $mailParams = array('host' => $_SERVER['HTTP_HOST'], 'email' => $recipient, 'date' => time(), 'sender_email' => $user->email, 'sender_title' => $user->getTitle(), 'sender_link' => $user->getHref(), 'sender_photo' => $user->getPhotoUrl('thumb.icon'), 'message' => $message, 'object_link' => $inviteUrl, 'code' => $inviteCode); Engine_Api::_()->getApi('mail', 'core')->sendSystem($recipient, $mailType, $mailParams); } catch (Exception $e) { // Silence if (APPLICATION_ENV == 'development') { throw $e; } continue; } $emailsSent++; } $user->invites_used += $emailsSent; $user->save(); // @todo Send requests to users that are already members? return $emailsSent; }
public function setAsRead(User_Model_User $user) { Engine_Api::_()->getDbtable('recipients', 'messages')->update(array('inbox_read' => 1), array('user_id = ?' => $user->getIdentity(), 'conversation_id = ?' => $this->getIdentity())); return $this; }
public function getRecipientInfo(User_Model_User $user) { return $this->getRecipientsInfo()->getRowMatching('user_id', $user->getIdentity()); }
public function getUser(User_Model_User $user) { return Engine_Api::_()->getDbtable('RoomUsers', 'chat')->find($this->room_id, $user->getIdentity())->current(); }
public function removeAllUserFriendship(User_Model_User $user) { // first get all cases where user_id == $user->getIdentity $select = $this->getTable()->select()->where('user_id = ?', $user->getIdentity()); $friendships = $this->getTable()->fetchAll($select); foreach ($friendships as $friendship) { // if active == 1 get the user corresponding to resource_id and take away the member_count by 1 if ($friendship->active) { $friend = Engine_Api::_()->getItem('user', $friendship->resource_id); $friend->member_count--; $friend->save(); } $friendship->delete(); } // get all cases where resource_id == $user->getIdentity // remove all $this->getTable()->delete(array('resource_id = ?' => $user->getIdentity())); }