public function executeMenu() { $this->items = array(); if ($this->getUser()->isAuthenticated() && $this->getUser()->getGuardUser()) { $name = $this->getUser()->getGuardUser()->getProfile()->public_name; $network_name = LsListTable::getNameById(sfGuardUserTable::getHomeNetworkId()); $network_path = LsListTable::getDisplayNameById(sfGuardUserTable::getHomeNetworkId()); $this->items[$name]['highlighted'] = true; $this->items[$name]['url'] = 'home/notes'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Notes')] = 'home/notes'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Groups')] = 'home/groups'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Edits')] = 'home/modifications'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Maps')] = 'home/maps'; $this->items[$name]['items']['divider1'] = 'divider'; $this->items[$name]['items'][$network_name] = '@localHome?name=' . $network_path; $this->items[$name]['items']['divider2'] = 'divider'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Settings')] = 'home/settings'; $this->items[$name]['items'][$this->getContext()->getI18N()->__('Logout')] = '@sf_guard_signout'; //recent views if ($this->getUser()->getGuardUser()->getProfile()->enable_recent_views && ($entityIds = $this->getUser()->getAttribute('viewed_entity_ids'))) { $this->items[$this->getContext()->getI18N()->__('Recent')] = array('url' => null, 'highlighted' => true, 'items' => array()); //flip entity ids from user session $flippedEntityIds = array_flip($entityIds); $orderedEntities = array(); //get viewed entities from db $entities = LsDoctrineQuery::create()->from('Entity e')->whereIn('e.id', $entityIds)->setHydrationMode(Doctrine::HYDRATE_ARRAY)->execute(); //order entities foreach ($entities as $entity) { $orderedEntities[$flippedEntityIds[$entity['id']]] = $entity; } ksort($orderedEntities); foreach ($orderedEntities as $entity) { $this->items[$this->getContext()->getI18N()->__('Recent')]['items'][$entity['name']] = EntityTable::generateRoute($entity); } } } else { if (sfConfig::get('app_login_enabled')) { $this->items[$this->getContext()->getI18N()->__("Login")] = array('url' => '@sf_guard_signin'); $this->items[$this->getContext()->getI18N()->__("Sign Up")] = array('url' => '@join'); } } $this->items = array_merge($this->items, array($this->getContext()->getI18N()->__('Explore') => array('items' => array($this->getContext()->getI18N()->__('Maps') => '@maps', $this->getContext()->getI18N()->__('Lists') => 'list/list', $this->getContext()->getI18N()->__('Groups') => '@groups', $this->getContext()->getI18N()->__('Notes') => '@notes', $this->getContext()->getI18N()->__('Users') => '@users', $this->getContext()->getI18N()->__('Edits') => '@edits')), $this->getContext()->getI18N()->__('Add') => null, $this->getContext()->getI18N()->__('Help') => array('items' => array($this->getContext()->getI18n()->__('Search Help Pages') => '@help', $this->getContext()->getI18N()->__('Beginner') => '@beginnerhelp', $this->getContext()->getI18N()->__('Advanced') => '@advancedhelp')), $this->getContext()->getI18N()->__('About') => array('items' => array('LittleSis' => '@about', $this->getContext()->getI18N()->__('Features') => '@features', $this->getContext()->getI18N()->__('Our Team') => '@team', $this->getContext()->getI18N()->__('Blog') => 'http://blog.littlesis.org', $this->getContext()->getI18N()->__('Press') => '@press', $this->getContext()->getI18N()->__('Data API') => 'http://api.littlesis.org', $this->getContext()->getI18N()->__('Source Code') => 'https://github.com/littlesis-org/littlesis', $this->getContext()->getI18N()->__('Disclaimer') => '@disclaimer', $this->getContext()->getI18N()->__('Contact Us') => '@contact')))); if (!$this->getUser()->isAuthenticated()) { unset($this->items[$this->getContext()->getI18N()->__('About')]['items'][$this->getContext()->getI18N()->__('Blog')]); $this->items[$this->getContext()->getI18N()->__('Blog')] = array('url' => 'http://blog.littlesis.org'); } if ($this->getUser()->isAuthenticated()) { $this->items[$this->getContext()->getI18N()->__('Add')] = array('items' => array($this->getContext()->getI18N()->__('Person') => 'entity/addPerson', $this->getContext()->getI18N()->__('Organization') => 'entity/addOrg', $this->getContext()->getI18N()->__('List') => 'list/add')); } }
} $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); ?> <?php echo $network['name']; ?> <br /> <?php } ?> <br /> <?php } ?>
<?php include_partial('global/form', array('form' => $entity_form)); ?> <?php if (isset($networks)) { ?> <tr> <td class="form_label">Networks</td> <td class="form_field margin_bottom"> <?php foreach ($networks as $network) { ?> <?php echo checkbox_tag('network_ids[]', $network['id'], $network['id'] == sfGuardUserTable::getHomeNetworkId()); ?> <?php echo $network['name']; ?> <br /> <?php } ?> </td> <tr> <?php } ?>
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(); }
public function executeAddRelationship($request) { $this->checkEntity($request, false, false); //for entity creation form, show network options if user's home network is not the US $homeNetworkId = sfGuardUserTable::getHomeNetworkId(); $networkIds = array_unique(array(LsListTable::US_NETWORK_ID, $homeNetworkId)); if (count($networkIds) > 1) { $this->networks = LsDoctrineQuery::create()->from('LsList l')->whereIn('l.id', $networkIds)->execute(); } if ($request->isMethod('post')) { $primary = $request->getParameter('primary'); $primary = $primary[0]; $name = $request->getParameter('name'); if (!$name) { $request->setError('name', 'You must enter a name'); } if ($primary == 'Person') { $entity = PersonTable::parseFlatName($name); if ($name && !$entity->name_last) { $request->setError('name', 'The name you entered is invalid'); } } elseif ($primary == 'Org') { $entity = new Entity(); $entity->addExtension('Org'); $entity->name = $name; } else { $request->setError('primary', 'You must select a type'); } if (!$request->hasErrors()) { //set blurb $entity->blurb = $request->getParameter('blurb'); //add extensions $extensions = array(); if ($request->getParameter('extensions')) { $extensions = array_keys($request->getParameter('extensions')); } $allowedExtensions = ExtensionDefinitionTable::getNamesByParent($primary); $extensions = array_intersect($extensions, $allowedExtensions); foreach ($extensions as $extension) { $entity->addExtension($extension); } //get networks to add entity to $networkIds = $request->getParameter('network_ids', array(sfGuardUserTable::getHomeNetworkId())); //save and redirect to edit page $entity->save(null, true, $networkIds); $this->redirect($this->entity->getInternalUrl('addRelationshipCategory', array('entity2_id' => $entity->id))); } } //form submission, display matching persons if ($request->hasParameter('q')) { $num = $request->getParameter('num', 10); $page = $request->getParameter('page', 1); if (!($terms = $request->getParameter('q'))) { $this->entity_pager = new LsDoctrinePager(array(), $page, $num); } else { switch (sfConfig::get('app_search_engine')) { case 'sphinx': $this->entity_pager = EntityTable::getSphinxPager($terms, $page, $num); break; case 'lucene': $ary = EntityTable::getLuceneArray($terms, null); $this->entity_pager = new LsDoctrinePager($ary, $page, $num); break; case 'mysql': default: $terms = explode(' ', $terms); $q = EntityTable::getSimpleSearchQuery($terms); $this->entity_pager = new Doctrine_Pager($q, $page, $num); break; } } $this->primary_exts = array('Person', 'Org'); $this->tier2_defs = array(); $this->tier3_defs = array(); foreach ($this->primary_exts as $primaryExt) { $this->tier2_defs[$primaryExt] = ExtensionDefinitionTable::getByTier(2, $primaryExt); $this->tier3_defs[$primaryExt] = ExtensionDefinitionTable::getByTier(3, $primaryExt); } } }