Пример #1
0
 public function getUnreadMessageCount(Core_Model_Item_Abstract $user)
 {
     $identity = $user->getIdentity();
     $rName = Engine_Api::_()->getDbtable('recipients', 'messages')->info('name');
     $select = Engine_Api::_()->getDbtable('recipients', 'messages')->select()->setIntegrityCheck(false)->from($rName, new Zend_Db_Expr('COUNT(conversation_id) AS unread'))->where($rName . '.user_id = ?', $identity)->where($rName . '.inbox_deleted = ?', 0)->where($rName . '.inbox_read = ?', 0);
     $data = Engine_Api::_()->getDbtable('recipients', 'messages')->fetchRow($select);
     return (int) $data->unread;
 }
Пример #2
0
 public function createLink(Core_Model_Item_Abstract $owner, $data)
 {
     $table = Engine_Api::_()->getDbtable('links', 'core');
     if (empty($data['parent_type']) || empty($data['parent_id'])) {
         $data['parent_type'] = $owner->getType();
         $data['parent_id'] = $owner->getIdentity();
     }
     $link = $table->createRow();
     $link->setFromArray($data);
     $link->owner_type = $owner->getType();
     $link->owner_id = $owner->getIdentity();
     $link->save();
     // Now try to create thumbnail
     $thumbnail = (string) @$data['thumb'];
     $thumbnail_parsed = @parse_url($thumbnail);
     //$ext = @ltrim(strrchr($thumbnail_parsed['path'], '.'), '.');
     //$link_parsed = @parse_url($link->uri);
     // Make sure to not allow thumbnails from domains other than the link (problems with subdomains, disabled for now)
     //if( $thumbnail && $thumbnail_parsed && $thumbnail_parsed['host'] === $link_parsed['host'] )
     //if( $thumbnail && $ext && $thumbnail_parsed && in_array($ext, array('jpg', 'jpeg', 'gif', 'png')) )
     if ($thumbnail && $thumbnail_parsed) {
         $tmp_path = APPLICATION_PATH . '/temporary/link';
         $tmp_file = $tmp_path . '/' . md5($thumbnail);
         if (!is_dir($tmp_path) && !mkdir($tmp_path, 0777, true)) {
             throw new Core_Model_Exception('Unable to create tmp link folder : ' . $tmp_path);
         }
         $src_fh = fopen($thumbnail, 'r');
         $tmp_fh = fopen($tmp_file, 'w');
         stream_copy_to_stream($src_fh, $tmp_fh, 1024 * 1024 * 2);
         fclose($src_fh);
         fclose($tmp_fh);
         if (($info = getimagesize($tmp_file)) && !empty($info[2])) {
             $ext = image_type_to_extension($info[2]);
             $thumb_file = $tmp_path . '/thumb_' . md5($thumbnail) . '.' . $ext;
             $image = Engine_Image::factory();
             $image->open($tmp_file)->resize(120, 240)->write($thumb_file)->destroy();
             $thumbFileRow = Engine_Api::_()->storage()->create($thumb_file, array('parent_type' => $link->getType(), 'parent_id' => $link->getIdentity()));
             $link->photo_id = $thumbFileRow->file_id;
             $link->save();
             @unlink($thumb_file);
         }
         @unlink($tmp_file);
     }
     return $link;
 }
Пример #3
0
 public function getInvitedMembers(Core_Model_Item_Abstract $resource)
 {
     $rejected_ignored = 1;
     $resource_approved = 1;
     $active = 0;
     $table = $this->getTable();
     $select = $table->select()->where('resource_id = ?', $resource->getIdentity())->where("active = {$active} AND (rejected_ignored = {$rejected_ignored} OR resource_approved = {$resource_approved})");
     return $select;
 }
Пример #4
0
 public function getUnreadMessageCount(Core_Model_Item_Abstract $user)
 {
     $identity = $user->getIdentity();
     $rName = Engine_Api::_()->getDbtable('recipients', 'messages')->info('name');
     $cName = Engine_Api::_()->getDbtable('conversations', 'messages')->info('name');
     $enabledModules = Engine_Api::_()->getDbtable('modules', 'core')->getEnabledModuleNames();
     $select = Engine_Api::_()->getDbtable('recipients', 'messages')->select()->setIntegrityCheck(false)->from($rName, new Zend_Db_Expr("COUNT(`{$rName}`.conversation_id) AS unread"))->joinRight($cName, "`{$cName}`.`conversation_id` = `{$rName}`.`conversation_id`", null)->where($rName . '.user_id = ?', $identity)->where($rName . '.inbox_deleted = ?', 0)->where($rName . '.inbox_read = ?', 0)->where("`{$cName}`.`resource_type` IS NULL or `{$cName}`.`resource_type` ='' or `{$cName}`.`resource_type` IN (?)", $enabledModules);
     $data = Engine_Api::_()->getDbtable('recipients', 'messages')->fetchRow($select);
     return (int) $data->unread;
 }
Пример #5
0
 public function isParentGroupOwner(Core_Model_Item_Abstract $owner)
 {
     if (!$owner->getIdentity()) {
         return false;
     }
     $parent_group = $this->getParentGroup();
     if ($parent_group && $parent_group->isOwner($owner)) {
         return true;
     } else {
         return false;
     }
 }
Пример #6
0
 public function isVoted(Core_Model_Item_Abstract $idea, Core_Model_Item_Abstract $poster = null)
 {
     if (is_null($poster)) {
         $poster = Engine_Api::_()->user()->getViewer();
     }
     if (!$poster->getIdentity()) {
         return false;
     }
     $row = $this->getVote($idea->getIdentity(), $poster->getIdentity());
     if (is_null($row) || $row->value == '0') {
         return false;
     }
     return true;
 }
Пример #7
0
 public function send(Core_Model_Item_Abstract $user, $recipients, $title, $body, $attachment = null)
 {
     // Sanity check recipients
     $recipients = (array) $recipients;
     if (!is_array($recipients) || empty($recipients)) {
         throw new Messages_Model_Exception("A message must have recipients");
     }
     // Create conversation
     $conversation = $this->createRow();
     $conversation->setFromArray(array('user_id' => $user->getIdentity(), 'title' => $title, 'recipients' => count($recipients), 'modified' => date('Y-m-d H:i:s'), 'locked' => 0));
     $conversation->save();
     // Create message
     $message = Engine_Api::_()->getItemTable('messages_message')->createRow();
     $message->setFromArray(array('conversation_id' => $conversation->getIdentity(), 'user_id' => $user->getIdentity(), 'title' => $title, 'body' => $body, 'date' => date('Y-m-d H:i:s'), 'attachment_type' => $attachment ? $attachment->getType() : '', 'attachment_id' => $attachment ? $attachment->getIdentity() : 0));
     $message->save();
     // Create sender outbox
     Engine_Api::_()->getDbtable('recipients', 'messages')->insert(array('user_id' => $user->getIdentity(), 'conversation_id' => $conversation->getIdentity(), 'outbox_message_id' => $message->getIdentity(), 'outbox_updated' => date('Y-m-d H:i:s'), 'outbox_deleted' => 0, 'inbox_deleted' => 1, 'inbox_read' => 1));
     // Create recipients inbox
     foreach ($recipients as $recipient_id) {
         Engine_Api::_()->getDbtable('recipients', 'messages')->insert(array('user_id' => $recipient_id, 'conversation_id' => $conversation->getIdentity(), 'inbox_message_id' => $message->getIdentity(), 'inbox_updated' => date('Y-m-d H:i:s'), 'inbox_deleted' => 0, 'inbox_read' => 0, 'outbox_message_id' => 0, 'outbox_deleted' => 1));
     }
     return $conversation;
 }
Пример #8
0
 public function updateComment(Core_Model_Item_Abstract $resource, Core_Model_Item_Abstract $poster, $body)
 {
     $table = $this->getCommentTable();
     $row = $table->createRow();
     if (isset($row->resource_type)) {
         $row->resource_type = $resource->getType();
     }
     $row->resource_id = $resource->getIdentity();
     $row->poster_type = $poster->getType();
     $row->poster_id = $poster->getIdentity();
     $row->creation_date = date('Y-m-d H:i:s');
     $row->body = $body;
     $row->save();
     return $row;
 }
Пример #9
0
 public function send(Core_Model_Item_Abstract $user, $recipients, $title, $body, $attachment = null)
 {
     $resource = null;
     // Case: single user
     if ($recipients instanceof User_Model_User) {
         $recipients = array($recipients->getIdentity());
     } else {
         if ($recipients instanceof Core_Model_Item_Abstract && method_exists($recipients, 'membership')) {
             $resource = $recipients;
             $recipients = array();
             foreach ($resource->membership()->getMembers() as $member) {
                 if ($member->getIdentity() != $user->getIdentity()) {
                     $recipients[] = $member->getIdentity();
                 }
             }
         } else {
             if (is_numeric($recipients)) {
                 $recipients = array($recipients);
             } else {
                 if (is_array($recipients) && !empty($recipients)) {
                     // Ok
                 } else {
                     throw new Messages_Model_Exception("A message must have recipients");
                 }
             }
         }
     }
     // Create conversation
     $conversation = $this->createRow();
     $conversation->setFromArray(array('user_id' => $user->getIdentity(), 'title' => $title, 'recipients' => count($recipients), 'modified' => date('Y-m-d H:i:s'), 'locked' => $resource ? true : false, 'resource_type' => !$resource ? null : $resource->getType(), 'resource_id' => !$resource ? 0 : $resource->getIdentity()));
     $conversation->save();
     // Create message
     $message = Engine_Api::_()->getItemTable('messages_message')->createRow();
     $message->setFromArray(array('conversation_id' => $conversation->getIdentity(), 'user_id' => $user->getIdentity(), 'title' => $title, 'body' => $body, 'date' => date('Y-m-d H:i:s'), 'attachment_type' => $attachment ? $attachment->getType() : '', 'attachment_id' => $attachment ? $attachment->getIdentity() : 0));
     $message->save();
     // Create sender outbox
     Engine_Api::_()->getDbtable('recipients', 'messages')->insert(array('user_id' => $user->getIdentity(), 'conversation_id' => $conversation->getIdentity(), 'outbox_message_id' => $message->getIdentity(), 'outbox_updated' => date('Y-m-d H:i:s'), 'outbox_deleted' => 0, 'inbox_deleted' => 1, 'inbox_read' => 1));
     // Create recipients inbox
     foreach ($recipients as $recipient_id) {
         Engine_Api::_()->getDbtable('recipients', 'messages')->insert(array('user_id' => $recipient_id, 'conversation_id' => $conversation->getIdentity(), 'inbox_message_id' => $message->getIdentity(), 'inbox_updated' => date('Y-m-d H:i:s'), 'inbox_deleted' => 0, 'inbox_read' => 0, 'outbox_message_id' => 0, 'outbox_deleted' => 1));
     }
     return $conversation;
 }
Пример #10
0
 /**
  * Get a select object for tags on a resource
  *
  * @param Core_Model_Item_Abstract $resource
  * @return Zend_Db_Table_Select
  */
 public function getTagMapSelect(Core_Model_Item_Abstract $resource)
 {
     $table = $this->getMapTable();
     $select = $table->select()->where('resource_type = ?', $resource->getType())->where('resource_id = ?', $resource->getIdentity())->order('tag_id ASC');
     return $select;
 }
Пример #11
0
 public function getStatusSelect(Core_Model_Item_Abstract $resource)
 {
     $select = $this->select();
     if (in_array('resource_type', $this->info('cols'))) {
         $select->where('resource_type = ?', $resource->getType());
     }
     $select->where('resource_id = ?', $resource->getIdentity())->order('status_id DESC');
     return $select;
 }
Пример #12
0
 public function getActionsByAttachment(Core_Model_Item_Abstract $attachment)
 {
     // Get all action ids from attachments
     $attachmentTable = Engine_Api::_()->getDbtable('attachments', 'activity');
     $select = $attachmentTable->select()->where('type = ?', $attachment->getType())->where('id = ?', $attachment->getIdentity());
     $actions = array();
     foreach ($attachmentTable->fetchAll($select) as $attachmentRow) {
         $actions[] = $attachmentRow->action_id;
     }
     // Get all actions
     $select = $this->select()->where('action_id IN(\'' . join("','", $ids) . '\')');
     return $this->fetchAll($select);
 }
Пример #13
0
 public function getMembersObjectSelect(Core_Model_Item_Abstract $resource, $active = true)
 {
     $table = Engine_Api::_()->getDbtable('users', 'user');
     $subtable = $this->getTable();
     $tableName = $table->info('name');
     $subtableName = $subtable->info('name');
     $select = $table->select()->from($tableName)->joinRight($subtableName, '`' . $subtableName . '`.`user_id` = `' . $tableName . '`.`user_id`', null)->where('`' . $subtableName . '`.`resource_id` = ?', $resource->getIdentity());
     if ($active !== null) {
         $select->where('`' . $subtableName . '`.`active` = ?', (bool) $active);
     }
     return $select;
 }
Пример #14
0
 public function getActivityAbout(Core_Model_Item_Abstract $about, User_Model_User $user, array $params = array())
 {
     // Proc args
     extract($this->_getInfo($params));
     // action_id, limit, min_id, max_id, actionFilter, filterValue
     // Prepare main query
     $streamTable = Engine_Api::_()->getDbtable('stream', 'activity');
     $streamName = $streamTable->info('name');
     $actionTableName = $this->info('name');
     $db = $streamTable->getAdapter();
     $union = new Zend_Db_Select($db);
     // Prepare action types
     $masterActionTypes = Engine_Api::_()->getDbtable('actionTypes', 'activity')->getActionTypes();
     $subjectActionTypes = array();
     $objectActionTypes = array();
     // Filter types based on displayable
     foreach ($masterActionTypes as $type) {
         if ($about->getType() == 'event' && Engine_Api::_()->hasItemType('event') || $about->getType() == 'group' && Engine_Api::_()->hasItemType('group') || $about->getType() == 'ynbusinesspages_business' && Engine_Api::_()->hasItemType('ynbusinesspages_business')) {
             if ($actionFilter == 'owner' && isset($type->is_object_thumb) && !$type->is_object_thumb) {
                 continue;
             }
             if ($actionFilter == 'membership' && isset($type->is_object_thumb) && $type->is_object_thumb) {
                 continue;
             }
         }
         if ($type->displayable & 1) {
             $subjectActionTypes[] = $type->type;
         }
         if ($type->displayable & 2) {
             $objectActionTypes[] = $type->type;
         }
     }
     // Filter types based on user request
     if (isset($showTypes) && is_array($showTypes) && !empty($showTypes)) {
         $subjectActionTypes = array_intersect($subjectActionTypes, $showTypes);
         $objectActionTypes = array_intersect($objectActionTypes, $showTypes);
     } else {
         if (isset($hideTypes) && is_array($hideTypes) && !empty($hideTypes)) {
             $subjectActionTypes = array_diff($subjectActionTypes, $hideTypes);
             $objectActionTypes = array_diff($objectActionTypes, $hideTypes);
         }
     }
     // Nothing to show
     if (empty($subjectActionTypes) && empty($objectActionTypes)) {
         return null;
     }
     if (empty($subjectActionTypes)) {
         $subjectActionTypes = null;
     } else {
         if (count($subjectActionTypes) == count($masterActionTypes)) {
             $subjectActionTypes = true;
         } else {
             $subjectActionTypes = "'" . join("', '", $subjectActionTypes) . "'";
         }
     }
     if (empty($objectActionTypes)) {
         $objectActionTypes = null;
     } else {
         if (count($objectActionTypes) == count($masterActionTypes)) {
             $objectActionTypes = true;
         } else {
             $objectActionTypes = "'" . join("', '", $objectActionTypes) . "'";
         }
     }
     // Prepare sub queries
     $event = Engine_Hooks_Dispatcher::getInstance()->callEvent('getActivity', array('for' => $user, 'about' => $about));
     $responses = (array) $event->getResponses();
     if (empty($responses)) {
         return null;
     }
     $friendsFlage = false;
     $action_ids = array();
     // Filter by hashtag
     if ($actionFilter == 'hashtag' && !empty($filterValue)) {
         $action_ids = Engine_Api::_()->getDbtable('hashtags', 'ynfeed')->getHashtagFeeds($filterValue, array(), array('limit' => $limit, 'max_id' => $max_id));
         if (empty($action_ids)) {
             return null;
         }
     }
     // Filter by login as business post
     if ($actionFilter == 'business') {
         $select = $this->select()->where('`subject_type` = ?', 'ynbusinesspages_business')->where('subject_id', $about->getIdentity())->limit($limit);
         if (null !== $max_id) {
             $select->where('action_id <= ?', $max_id);
         }
         $data = $select->query()->fetchAll();
         foreach ($data as $row) {
             $action_ids[] = $row['action_id'];
         }
         if (empty($action_ids)) {
             return null;
         }
     }
     $member_ids = array();
     if ($actionFilter == 'owner') {
         if ($about instanceof User_Model_User) {
             $member_ids[] = $about->getIdentity();
         } elseif ($about instanceof Group_Model_Group || $about instanceof Advgroup_Model_Group) {
             $objectParent = $about->getParent('user');
             if ($objectParent instanceof User_Model_User) {
                 $member_ids[] = $objectParent->getIdentity();
             }
         } else {
             $objectParent = $about->getParent('user');
             if ($objectParent instanceof User_Model_User) {
                 $member_ids[] = $objectParent->getIdentity();
             }
         }
     } elseif ($actionFilter == 'officers') {
         if ($about instanceof Group_Model_Group || $about instanceof Advgroup_Model_Group) {
             $objectParent = $about->getParent('user');
             if ($objectParent instanceof User_Model_User) {
                 $member_ids[] = $objectParent->getIdentity();
             }
             foreach ($about->getOfficerList()->getAll() as $value) {
                 $member_ids[] = $value->child_id;
             }
         }
     } elseif ($actionFilter == 'admins') {
         if ($about instanceof Ynbusinesspages_Model_Business) {
             $objectParent = $about->getParent('user');
             if ($objectParent instanceof User_Model_User) {
                 $member_ids[] = $objectParent->getIdentity();
             }
             foreach ($about->getAdminList()->getAll() as $value) {
                 $member_ids[] = $value->child_id;
             }
         }
     } elseif ($actionFilter == 'membership') {
         if (in_array($about->getType(), array('event', 'group', 'ynbusinesspages_business'))) {
             $members = $about->membership()->getMembers(true);
             foreach ($members as $member) {
                 $member_ids[] = $member->getIdentity();
             }
         } else {
             $member_ids = $user->membership()->getMembershipsOfIds();
         }
         if (empty($member_ids)) {
             return array();
         }
     }
     foreach ($responses as $response) {
         if (empty($response)) {
             continue;
         }
         // Target info
         $select = $streamTable->select()->from($streamTable->info('name'), 'action_id')->where('target_type = ?', $response['type']);
         if (empty($response['data'])) {
             // Simple
             $select->where('target_id = ?', 0);
         } else {
             if (is_scalar($response['data']) || count($response['data']) === 1) {
                 // Single
                 if (is_array($response['data'])) {
                     list($response['data']) = $response['data'];
                 }
                 $select->where('target_id = ?', $response['data']);
             } else {
                 if (is_array($response['data'])) {
                     // Array
                     $select->where('target_id IN(?)', (array) $response['data']);
                 } else {
                     // Unknown
                     continue;
                 }
             }
         }
         // Add action_id/max_id/min_id
         if (null !== $action_id) {
             $select->where('action_id = ?', $action_id);
         } else {
             if (null !== $min_id) {
                 $select->where('action_id >= ?', $min_id);
             } else {
                 if (null !== $max_id) {
                     $select->where('action_id <= ?', $max_id);
                 }
             }
         }
         // Add order/limit
         $select->order('action_id DESC')->limit($limit);
         if (!empty($action_ids)) {
             $select->where($streamName . '.action_id IN(?)', (array) $action_ids);
         }
         // Add subject to main query
         $selectSubject = clone $select;
         if ($subjectActionTypes !== null) {
             if ($subjectActionTypes !== true) {
                 $selectSubject->where('type IN(' . $subjectActionTypes . ')');
             }
             $selectSubject->where('subject_type = ?', $about->getType())->where('subject_id = ?', $about->getIdentity());
             if (!empty($member_ids)) {
                 $selectSubject->where('object_type = ?', 'user')->where('object_id  IN (?)', (array) $member_ids);
             }
             $union->union(array('(' . $selectSubject->__toString() . ')'));
         }
         // Add object to main query
         $selectObject = clone $select;
         if ($objectActionTypes !== null) {
             if ($objectActionTypes !== true) {
                 $selectObject->where('type IN(' . $objectActionTypes . ')');
             }
             $selectObject->where('object_type = ?', $about->getType())->where('object_id = ?', $about->getIdentity());
             if (!empty($member_ids)) {
                 $selectObject->where('subject_type = ?', 'user')->where('subject_id IN (?)', (array) $member_ids);
             }
             $union->union(array('(' . $selectObject->__toString() . ')'));
             // (string) not work before PHP 5.2.0
         }
     }
     // Finish main query
     $union->order('action_id DESC')->limit($limit);
     // Get actions
     $actions = $db->fetchAll($union);
     // Process ids
     $ids = array();
     if (in_array($actionFilter, array('all', 'posts')) && $action_id) {
         $tag_ids = Engine_Api::_()->ynfeed()->getTaggedBaseActionIds($user, array('min' => $min_id, 'max' => $max_id));
         if (in_array($action_id, $tag_ids)) {
             $ids[] = $action_id;
         }
     }
     // No visible actions
     if (empty($actions) && empty($ids)) {
         return null;
     }
     // Process ids
     foreach ($actions as $data) {
         $ids[] = $data['action_id'];
     }
     $ids = array_unique($ids);
     // Finally get activity
     return $this->fetchAll($this->select()->where('action_id IN(' . join(',', $ids) . ')')->order('action_id DESC')->limit($limit));
 }
Пример #15
0
 public function unindex(Core_Model_Item_Abstract $item)
 {
     $table = Engine_Api::_()->getDbtable('search', 'core');
     $table->delete(array('type = ?' => $item->getType(), 'id = ?' => $item->getIdentity()));
     return $this;
 }
Пример #16
0
 /**
  * Remove a notification by subject and type. This is useful for requests, as
  * you can easily delete the request when canceled/ignored etc
  *
  * @param User_Model_User $user The user that received the notification
  * @param Core_Model_Item_Abstract $subject The user the caused the notification
  * @param string $type
  * @return Activity_Api_Notifications
  */
 public function removeNotificationsBySubjectAndType(User_Model_User $user, Core_Model_Item_Abstract $subject, $type)
 {
     $this->delete(array('user_id' => $user->getIdentity(), 'subject_type' => $subject->getType(), 'subject_id' => $subject->getIdentity(), 'type' => $type));
     return $this;
 }
Пример #17
0
 public function get(Core_Model_Item_Abstract $child)
 {
     $table = $this->getListItemTable();
     $select = $table->select()->where('list_id = ?', $this->getIdentity())->where('child_id = ?', $child->getIdentity())->limit(1);
     return $table->fetchRow($select);
 }
Пример #18
0
 public function setActivityObject(Core_Model_Item_Abstract $object)
 {
     $this->subject_type->setValue($object->getType());
     $this->subject_id->setValue($object->getIdentity());
     return $this;
 }
Пример #19
0
 public function getAllCommentsUsers(Core_Model_Item_Abstract $resource)
 {
     $table = $this->getCommentTable();
     $select = new Zend_Db_Select($table->getAdapter());
     $select->from($table->info('name'), array('poster_type', 'poster_id'));
     if (!$this->_custom) {
         $select->where('resource_type = ?', $resource->getType());
     }
     $select->where('resource_id = ?', $resource->getIdentity());
     $users = array();
     foreach ($select->query()->fetchAll() as $data) {
         if ($data['poster_type'] == 'user') {
             $users[] = $data['poster_id'];
         }
     }
     $users = array_values(array_unique($users));
     return Engine_Api::_()->getItemMulti('user', $users);
 }
Пример #20
0
 public function getMemberOfList(Core_Model_Item_Abstract $resource)
 {
     $select = $this->select()->where('owner_id 	 = ?', $resource->getIdentity());
     return $this->fetchAll($select);
 }