Beispiel #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;
 }
Beispiel #2
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;
 }
 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;
 }
Beispiel #4
0
 public function altUrl(Core_Model_Item_Abstract $item)
 {
     $db = Engine_Db_Table::getDefaultAdapter();
     if (isset($this->_memo[$item->getGuid()])) {
         return $this->_memo[$item->getGuid()];
     }
     $url = $db->select()->from('engine4_seo_pages', 'url')->where('page_id = ?', $item->getGuid())->query()->fetchColumn();
     $this->_memo[$item->getGuid()] = $url;
     return $url;
 }
Beispiel #5
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;
 }
Beispiel #6
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;
 }
 protected function _delete()
 {
     foreach ($this->getAll() as $listitem) {
         $listitem->delete();
     }
     parent::_delete();
 }
 protected function _postUpdate()
 {
     parent::_postUpdate();
     // Update sku
     if (empty($this->sku) || !empty($this->_modifiedFields['product_id'])) {
         $this->_updateSku();
     }
 }
Beispiel #9
0
 protected function _postDelete() {
     parent::_postDelete();
     $playlist = Engine_Api::_()->getItem('ynvideo_playlist', $this->playlist_id);
     if ($playlist) {
         $playlist->video_count = new Zend_Db_Expr('video_count - 1');
         $playlist->save();
     }
 }
Beispiel #10
0
 public function getPhotoUrl($type = null)
 {
     if ($this->photo_id) {
         return parent::getPhotoUrl($type);
     } else {
         return 'application/modules/Ynadvsearch/externals/images/icon-' . $this->type . '.png';
     }
 }
 public function getParent($recurseType = null)
 {
     if ($this->parent_type == 'temporary' || $this->parent_type == 'system') {
         return null;
     } else {
         return parent::getParent($recurseType);
     }
 }
Beispiel #12
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;
 }
Beispiel #13
0
 protected function _postDelete()
 {
     parent::_postDelete();
     $model = new Yntour_Model_DbTable_Touritems();
     $select = $model->select()->where('tour_id=?', $this->getIdentity());
     foreach ($model->fetchAll($select) as $row) {
         $row->delete();
     }
 }
Beispiel #14
0
 public function getPhotoUrl($type = null)
 {
     $imgUrl = parent::getPhotoUrl($type);
     if ($imgUrl) {
         return $imgUrl;
     }
     $type = $type ? str_replace('.', '_', $type) : 'thumb_main';
     $view = Zend_Registry::get("Zend_View");
     return $view->layout()->staticBaseUrl . "application/modules/Ynresponsiveevent/externals/images/nophoto_event_{$type}.png";
 }
Beispiel #15
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;
 }
Beispiel #16
0
 protected function _insert()
 {
     if (!$this->event_id) {
         throw new Exception('Cannot create topic without event_id');
     }
     /*
     $this->getParentEvent()->setFromArray(array(
     
     ))->save();
     */
     parent::_insert();
 }
Beispiel #17
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;
 }
Beispiel #18
0
 protected function _postInsert()
 {
     if ($this->_disableHooks) {
         return;
     }
     // Update topic
     $table = Engine_Api::_()->getDbtable('topics', 'ynevent');
     $select = $table->select()->where('topic_id = ?', $this->topic_id)->limit(1);
     $topic = $table->fetchRow($select);
     $topic->lastpost_id = $this->post_id;
     $topic->lastposter_id = $this->user_id;
     $topic->modified_date = date('Y-m-d H:i:s');
     $topic->post_count++;
     $topic->save();
     parent::_postInsert();
 }
Beispiel #19
0
 protected function _insert()
 {
     if (!$this->event_id) {
         throw new Exception('Cannot create post without event_id');
     }
     if (!$this->topic_id) {
         throw new Exception('Cannot create post without topic_id');
     }
     // Update topic
     $table = Engine_Api::_()->getDbtable('topics', 'event');
     $select = $table->select()->where('topic_id = ?', $this->topic_id)->limit(1);
     $topic = $table->fetchRow($select);
     $topic->lastpost_id = $this->post_id;
     $topic->lastposter_id = $this->user_id;
     $topic->modified_date = date('Y-m-d H:i:s');
     $topic->post_count++;
     $topic->save();
     parent::_insert();
 }
 public function getHref()
 {
     // @todo take directly to the comment
     if (isset($this->resource_type)) {
         $resource = Engine_Api::_()->getItem($this->resource_type, $this->resource_id);
         if ($resource) {
             return $resource->getHref() . '#comment-' . $this->comment_id;
         } else {
             return null;
         }
     } else {
         if (method_exists($this->getTable(), 'getResourceType')) {
             $tmp = Engine_Api::_()->getItem($this->getTable()->getResourceType(), $this->resource_id);
             if ($tmp) {
                 return $tmp->getHref() . '#comment-' . $this->comment_id;
             } else {
                 return null;
             }
         } else {
             return parent::getHref();
             // @todo fix this
         }
     }
 }
Beispiel #21
0
 protected function _readData($spec)
 {
     if (!is_numeric($spec)) {
         $spec = $this->getTable()->fetchRow($this->getTable()->select()->where("name = ?", $spec));
     }
     return parent::_readData($spec);
 }
 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);
 }
Beispiel #23
0
 protected function _delete()
 {
     if ($this->_disableHooks) {
         return;
     }
     // Delete all memberships
     $this->membership()->removeAllMembers();
     // Delete all albums
     $albumTable = Engine_Api::_()->getItemTable('event_album');
     $albumSelect = $albumTable->select()->where('event_id = ?', $this->getIdentity());
     foreach ($albumTable->fetchAll($albumSelect) as $eventAlbum) {
         $eventAlbum->delete();
     }
     // Delete all topics
     $topicTable = Engine_Api::_()->getItemTable('event_topic');
     $topicSelect = $topicTable->select()->where('event_id = ?', $this->getIdentity());
     foreach ($topicTable->fetchAll($topicSelect) as $eventTopic) {
         $eventTopic->delete();
     }
     parent::_delete();
 }
Beispiel #24
0
 protected function _update()
 {
     parent::_update();
 }
 protected function _delete()
 {
     foreach ($this->getCollectibles() as $collectible) {
         $collectible->delete();
     }
     return parent::_delete();
 }
Beispiel #26
0
 protected function _delete()
 {
     // Delete stream stuff
     Engine_Api::_()->getDbtable('stream', 'activity')->delete(array('action_id = ?' => $this->action_id));
     // Delete attachments
     Engine_Api::_()->getDbtable('attachments', 'activity')->delete(array('action_id = ?' => $this->action_id));
     parent::_delete();
 }
Beispiel #27
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;
 }
Beispiel #28
0
 protected function _delete()
 {
     if ($this->_disableHooks) {
         return;
     }
     //Delete Blog Member
     $become_table = Engine_Api::_()->getDbTable('becomes', 'ynblog');
     $become_selected = $become_table->select()->where('blog_id = ?', $this->getIdentity());
     foreach ($become_table->fetchAll($become_selected) as $blog_become) {
         $blog_become->delete();
     }
     parent::_delete();
 }
Beispiel #29
0
 protected function _delete()
 {
     if ($this->_disableHooks) {
         return;
     }
     // Delete all memberships
     $this->membership()->removeAllMembers();
     // Delete officer list
     $this->getOfficerList()->delete();
     // Delete all albums
     $albumTable = Engine_Api::_()->getItemTable('advgroup_album');
     $albumSelect = $albumTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($albumTable->fetchAll($albumSelect) as $groupAlbum) {
         $groupAlbum->delete();
     }
     // Delete all topics
     $topicTable = Engine_Api::_()->getItemTable('advgroup_topic');
     $topicSelect = $topicTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($topicTable->fetchAll($topicSelect) as $groupTopic) {
         $groupTopic->delete();
     }
     //Delete all links
     $linkTable = Engine_Api::_()->getItemTable('advgroup_link');
     $linkSelect = $linkTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($linkTable->fetchAll($linkSelect) as $groupLink) {
         $groupLink->delete();
     }
     //Delete all announcment
     $announcementTable = Engine_Api::_()->getItemTable('advgroup_announcement');
     $announcementSelect = $announcementTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($announcementTable->fetchAll($announcementSelect) as $groupAnnouncement) {
         $groupAnnouncement->delete();
     }
     //Delete invites
     $inviteTable = Engine_Api::_()->getDbTable('invites', 'advgroup');
     $inviteSelect = $inviteTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($inviteTable->fetchAll($inviteSelect) as $groupInvite) {
         $groupInvite->delete();
     }
     //Delete polls
     $pollTable = Engine_Api::_()->getDbTable('polls', 'advgroup');
     $pollSelect = $pollTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($pollTable->fetchAll($pollSelect) as $groupPoll) {
         $groupPoll->delete();
     }
     //Delete reports
     $reportTable = Engine_Api::_()->getDbTable('reports', 'advgroup');
     $reportSelect = $reportTable->select()->where('group_id = ?', $this->getIdentity());
     foreach ($reportTable->fetchAll($reportSelect) as $groupReport) {
         $groupReport->delete();
     }
     //Delete all events
     if (Engine_Api::_()->hasItemType('event')) {
         $eventTable = Engine_Api::_()->getItemTable('event');
         $eventSelect = $eventTable->select()->where("parent_type = 'group' and parent_id = ?", $this->getIdentity());
         foreach ($eventTable->fetchAll($eventSelect) as $groupEvent) {
             $groupEvent->delete();
         }
     }
     if (Engine_Api::_()->hasItemType('video')) {
         $videoTable = Engine_Api::_()->getItemTable('video');
         $videoSelect = $videoTable->select()->where("parent_type = 'group' and parent_id = ?", $this->getIdentity());
         foreach ($videoTable->fetchAll($videoSelect) as $groupVideo) {
             $groupVideo->delete();
         }
     }
     parent::_delete();
 }
Beispiel #30
0
 public function getOwner()
 {
     return parent::getOwner();
     // ?
     //return $this;
 }