Пример #1
0
 public function getNetworks($hydrationMode = Doctrine::HYDRATE_ARRAY)
 {
     if (count($networkIds = NoteTable::unserialize($this->network_ids))) {
         return LsDoctrineQuery::create()->from('LsList l')->whereIn('l.id', $networkIds)->setHydrationMode($hydrationMode)->execute();
     }
     return array();
 }
Пример #2
0
 public function executeNotes($request)
 {
     $this->checkNetwork($request);
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $this->query = $request->getParameter('query');
     $s = new LsSphinxClient($page, $num);
     $s->setFilter('network_ids', array($this->network['id']));
     $s->setFilter('visible_to_user_ids', array_unique(array(0, sfGuardUserTable::getCurrentUserId())));
     $this->note_pager = NoteTable::getSphinxPager($s, $this->query, Doctrine::HYDRATE_ARRAY);
 }
Пример #3
0
 public function executeRecordSample()
 {
     $model = isset($this->model) ? $this->model : get_class($this->record);
     $this->actions = array(array('text' => 'see all', 'url' => $this->more_uri ? $this->more_uri : $this->record->getInternalUrl('notes')));
     if ($this->getUser()->isAuthenticated()) {
         $class = $model == 'LsList' ? 'List' : $model;
         $this->actions[] = array('text' => 'write a note', 'url' => 'home/notes?compose=1&' . strtolower($class) . '_id=' . $this->record['id']);
         $this->actions[] = array('text' => 'note all', 'credential' => 'editor', 'url' => 'home/notes?compose=1&analysts=1&' . strtolower($class) . '_id=' . $this->record['id']);
     }
     $attribute = strtolower($model) . '_ids';
     $s = new LsSphinxClient(1, 5);
     $s->setFilter($attribute, array($this->record['id']));
     if (!($currentUserId = sfGuardUserTable::getCurrentUserId())) {
         $currentUserId = 0;
     }
     $s->setFilter('visible_to_user_ids', array_unique(array(0, $currentUserId)));
     $this->notes = NoteTable::getSphinxRecords($s, null, Doctrine::HYDRATE_ARRAY);
 }
Пример #4
0
 public function executeNotes($request)
 {
     $this->checkUser($request);
     if ($this->user->isCurrentUser()) {
         $this->redirect('home/notes');
     }
     $this->note_form = new NoteForm();
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $withReplies = $request->getParameter('replies', 1);
     $s = new LsSphinxClient($page, $num);
     if ($withReplies) {
         $s->setFilter('visible_to_user_ids', array($this->user->id));
     } else {
         $s->setFilter('user_id', array($this->user->id));
     }
     $s->setFilter('visible_to_user_ids', array_unique(array(0, sfGuardUserTable::getCurrentUserId())));
     $this->note_pager = NoteTable::getSphinxPager($s, null, Doctrine::HYDRATE_ARRAY);
 }
Пример #5
0
 public function executeNameSearch($request)
 {
     $this->results = array();
     if ($terms = $request->getParameter('name')) {
         $entities = array();
         $page = $request->getParameter('page', 1);
         $num = $request->getParameter('num', 20);
         $result = EntityTable::getSphinxHits($terms, $page, $num);
         if ($result['total_found'] > 0 && isset($result['matches'])) {
             $ids = array_keys($result['matches']);
             $db = Doctrine_Manager::connection();
             $sql = 'SELECT e.*, FIELD(e.id, ' . implode(',', $ids) . ') AS field ' . 'FROM entity e WHERE e.id IN (' . implode(',', $ids) . ') AND e.is_deleted = 0 ' . 'ORDER BY field';
             $stmt = $db->execute($sql);
             $entities = $stmt->fetchAll(PDO::FETCH_ASSOC);
         }
         foreach ($entities as $entity) {
             $this->results[] = array('name' => $entity['name'], 'markup' => NoteTable::getRecordMarkup($entity, $entity['name'], 'entity'));
         }
     }
 }
Пример #6
0
?>
  
      &nbsp;<?php 
echo NoteTable::prepareBodyForDisplay($note['body']);
?>

      <div class="note_full_date">
        <?php 
echo link_to(time_ago_in_words(strtotime($note['created_at'])) . ' ago', NoteTable::getInternalUrl($note));
?>
      
        <?php 
if (NoteTable::hasNonUsNetworks($note)) {
    ?>
          <?php 
    $networks = NoteTable::getNetworksArray($note);
    ?>
          <?php 
    $networkLinks = array();
    ?>
          <?php 
    foreach ($networks as $network) {
        ?>
            <?php 
        $networkLinks[] = network_link($network);
        ?>
          <?php 
    }
    ?>
    
          in <?php 
Пример #7
0
    }
    ?>

<?php 
    $initialValue = '';
    if (isset($user)) {
        $initialValue = NoteTable::getUserMarkup($user);
    } elseif (isset($record)) {
        if (isset($analysts)) {
            $handles = array();
            foreach ($analysts as $analyst) {
                $handles[] = NoteTable::getUserMarkup($analyst);
            }
            $initialValue = "To all " . NoteTable::getRecordMarkup($record, $record->getName()) . " analysts (" . implode(", ", $handles) . "): \n";
        } else {
            $initialValue = NoteTable::getRecordMarkup($record, $record->getName());
        }
    }
    ?>

<?php 
    if (isset($networks)) {
        ?>
  <?php 
        foreach ($networks as $network) {
            ?>
    <?php 
            $isChecked = isset($network_ids) ? in_array($network['id'], $network_ids) : $network['id'] == sfGuardUserTable::getHomeNetworkId();
            ?>
    <?php 
            echo checkbox_tag('network_ids[]', $network['id'], $isChecked);
Пример #8
0
?>
  
  &nbsp;<?php 
echo NoteTable::prepareBodyForDisplay($note['body']);
?>

  <div class="note_short_date">
    <?php 
echo link_to(time_ago_in_words(strtotime($note['created_at'])) . ' ago', NoteTable::getInternalUrl($note));
?>

    <?php 
if (NoteTable::hasNonUsNetworks($note)) {
    ?>
      <?php 
    $networks = NoteTable::getNetworks($note);
    ?>
      <?php 
    $networkLinks = array();
    ?>
      <?php 
    foreach ($networks as $network) {
        ?>
        <?php 
        $networkLinks[] = network_link($network);
        ?>
      <?php 
    }
    ?>
    
      in <?php 
Пример #9
0
 public function executeNotes($request)
 {
     $this->checkGroup($request);
     $this->checkUser($request);
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $s = new LsSphinxClient($page, $num);
     $s->setFilter('sfguardgroup_ids', array($this->group['id']));
     $s->setFilter('visible_to_user_ids', array_unique(array(0, sfGuardUserTable::getCurrentUserId())));
     if ($userId = $request->getParameter('user_id')) {
         $s->setFilter('user_id', array($userId));
     }
     $this->note_pager = NoteTable::getSphinxPager($s);
 }
Пример #10
0
    $networks = NoteTable::getNetworksArray($note);
    ?>
  <?php 
    $networkLinks = array();
    ?>
  <?php 
    foreach ($networks as $network) {
        ?>
    <?php 
        $networkLinks[] = network_link($network);
        ?>
  <?php 
    }
    ?>
    
  in <?php 
    echo implode(', ', $networkLinks);
}
?>
      

</em></span>

<br />
<br />

<div class="note_big">
  <?php 
echo NoteTable::prepareBodyForDisplay($note['body']);
?>
</div>
Пример #11
0
 public function executeNotes($request)
 {
     $this->checkList($request);
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $s = new LsSphinxClient($page, $num);
     $s->setFilter('lslist_ids', array($this->list['id']));
     $s->setFilter('visible_to_user_ids', array_unique(array(0, sfGuardUserTable::getCurrentUserId())));
     if ($userId = $request->getParameter('user_id')) {
         $s->setFilter('user_id', array($userId));
     }
     $this->note_pager = NoteTable::getSphinxPager($s, null, Doctrine::HYDRATE_ARRAY);
 }
Пример #12
0
 public function executeNotes($request)
 {
     $this->checkUser();
     $this->profile = $this->getUser()->getProfile();
     $this->note_form = new NoteForm();
     $this->unread_notes = $this->profile->unread_notes;
     $this->profile->unread_notes = 0;
     $this->profile->save();
     //get network options
     $networkIds = array_unique(array(sfGuardUserTable::getHomeNetworkId(), LsListTable::US_NETWORK_ID));
     $networkIds = array_unique(array_merge($networkIds, $request->getParameter('network_ids', array())));
     if (count($networkIds) > 1) {
         $this->networks = LsDoctrineQuery::create()->from('LsList l')->whereIn('l.id', $networkIds)->fetchArray();
     }
     if ($request->isMethod('post')) {
         $params = $request->getParameter('note');
         $this->note_form->bind($params);
         if ($this->note_form->isValid()) {
             $db = Doctrine_Manager::connection();
             try {
                 $db->beginTransaction();
                 //associate note with specified networks, or else the user's home network
                 $networkIds = $request->getParameter('network_ids', array(sfGuardUserTable::getHomeNetworkId()));
                 $note = new Note();
                 $note->user_id = $this->getUser()->getGuardUser()->id;
                 $note->encodeBody($params['body']);
                 $note->is_private = isset($params['is_private']) ? true : false;
                 $note->network_ids = NoteTable::serialize($networkIds);
                 $note->save();
                 //if there are alerted users, add notification emails to email queue
                 foreach (NoteTable::unserialize($note->alerted_user_names) as $public_name) {
                     if ($profile = Doctrine::getTable('sfGuardUserProfile')->findOneByPublicName($public_name)) {
                         $public_name = $this->getUser()->getGuardUser()->getProfile()->public_name;
                         $profile->unread_notes++;
                         $profile->save();
                         $email = new ScheduledEmail();
                         $email->from_name = sfConfig::get('app_mail_notes_sender_name');
                         $email->from_email = sfConfig::get('app_mail_notes_sender_address');
                         $email->to_name = $profile->getName();
                         $email->to_email = $profile->email;
                         $email->subject = $public_name . ' has written you a note on LittleSis';
                         $email->body_text = $this->getPartial('notenotify', array('note_author' => $public_name, 'note_author_id' => $note->user_id, 'note_body' => NoteTable::prepareBodyForEmail($note->body), 'note_is_private' => $note->is_private));
                         $email->body_html = nl2br($this->getPartial('notenotify', array('note_author' => $public_name, 'note_author_id' => $note->user_id, 'note_body' => NoteTable::prepareBodyForEmail($note->body, true), 'note_is_private' => $note->is_private)));
                         $email->save();
                     }
                 }
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollback();
                 throw $e;
             }
             $this->redirect('home/notes');
         }
     }
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $withReplies = $request->getParameter('replies', 1);
     //get notes to/from the current user using sphinx
     $s = new LsSphinxClient($page, $num);
     $currentUserId = sfGuardUserTable::getCurrentUserId();
     if ($withReplies) {
         $s->setFilter('visible_to_user_ids', array($currentUserId));
     } else {
         $s->setFilter('user_id', array($currentUserId));
     }
     $this->note_pager = NoteTable::getSphinxPager($s, null, Doctrine::HYDRATE_ARRAY);
     //execute pager to get most recently indexed note
     $notes = $this->note_pager->execute();
     $lastNoteId = count($notes) ? $notes[0]['id'] : 1;
     //get new notes that may not yet be indexed
     $this->new_notes = LsDoctrineQuery::create()->from('Note n')->leftJoin('n.User u')->leftJoin('u.Profile p')->where('n.user_id = ?', $this->getUser()->getGuardUser()->id)->andWhere('n.id > ?', $lastNoteId)->orderBy('n.id DESC')->setHydrationMode(Doctrine::HYDRATE_ARRAY)->execute();
 }
Пример #13
0
 static function getNetworksArray($note)
 {
     if ($count = count($networkIds = NoteTable::unserialize($note['network_ids']))) {
         $db = Doctrine_Manager::connection();
         $sql = 'SELECT * FROM ls_list WHERE id IN (' . implode(',', array_fill(0, $count, '?')) . ') ' . 'AND is_network = 1';
         $stmt = $db->execute($sql, $networkIds);
         return $stmt->fetchAll(PDO::FETCH_ASSOC);
     }
     return array();
 }
Пример #14
0
<?php

use_helper('Date');
?>

<?php 
$actions = array(array('text' => 'see all', 'url' => $more_uri ? $more_uri : $record->getInternalUrl('notes')));
?>

<?php 
$model = isset($model) ? $model : get_class($record);
if ($sf_user->isAuthenticated()) {
    $class = $model == 'LsList' ? 'List' : $model;
    $actions[] = array('text' => 'write a note', 'url' => 'home/notes?compose=1&' . strtolower($class) . '_id=' . $record['id']);
    $actions[] = array('text' => 'note all', 'credential' => 'editor', 'url' => 'home/notes?compose=1&analysts=1&' . strtolower($class) . '_id=' . $record['id']);
}
?>

<?php 
include_partial('global/section', array('title' => 'Notes', 'pointer' => 'Analyst notes about ' . (isset($name) ? $name : $record['name']), 'actions' => $actions));
?>

<?php 
foreach (NoteTable::getNotesByModelAndIdQuery($model, $record['id'])->limit(5)->execute() as $note) {
    ?>
  <?php 
    include_partial('note/short', array('note' => $note, 'record' => $record));
}
Пример #15
0
 public function executeRecentNotes()
 {
     $s = new LsSphinxClient($page = 1, $num = 10);
     if (isset($this->network_ids)) {
         $s->setFilter('network_ids', $this->network_ids);
     }
     $userIds = array_filter(array_unique(array(0, sfGuardUserTable::getCurrentUserId())), 'strlen');
     $s->setFilter('visible_to_user_ids', $userIds);
     $this->notes = NoteTable::getSphinxRecords($s, null, Doctrine::HYDRATE_ARRAY);
 }