protected function execute($arguments = array(), $options = array())
 {
     if (!$this->safeToRun()) {
         print "Process already running!\n";
         die;
     }
     $timer = sfTimerManager::getTimer('execute');
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     //set up index
     $index = EntityTable::getLuceneIndex();
     //delete deleted entities
     $q = LsDoctrineQuery::create()->from('Entity e')->where('e.is_deleted = ?', true)->setHydrationMode(Doctrine::HYDRATE_ARRAY);
     foreach ($q->execute() as $entity) {
         if ($hits = $index->find('key:' . $entity['id'])) {
             if ($options['debug_mode']) {
                 printf("Deleting index for Entity %s\n", $entity['id']);
             }
             foreach ($hits as $hit) {
                 $index->delete($hit->id);
             }
         }
     }
     printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage()));
     printf("Index size: %s\n", $index->count());
     $timer->addTime();
     printf("Run time: %s\n", $timer->getElapsedTime());
     sfTimerManager::clearTimers();
 }
Пример #2
0
 public function getCommentsQuery()
 {
     if (!$this->id) {
         throw new Exception("Can't get comments query for new sfGuardUser");
     }
     return LsDoctrineQuery::create()->from('Comment c')->where('c.user_id = ?', $this->id)->orderBy('c.created_at DESC');
 }
 static function loadModification($field)
 {
     if (!isset($field['Modification']) && !$field['Modification']) {
         $field['Modification'] = LsDoctrineQuery::create()->from('Modification m')->where('m.id = ?', $field['modification_id'])->setHydrationMode(Doctrine::HYDRATE_ARRAY)->fetchOne();
     }
     return $field['Modification'];
 }
Пример #4
0
 public function executeFeatured($request)
 {
     $page = $request->getParameter('page');
     $num = $request->getParameter('num', 10);
     $q = LsDoctrineQuery::create()->from('sfGuardUser u')->leftJoin('u.Profile p')->leftJoin('u.groups g')->where('u.is_super_admin = 0')->orderBy('p.score DESC')->setHydrationMode(Doctrine::HYDRATE_ARRAY);
     $this->user_pager = new LsDoctrinePager($q, $page, $num);
 }
Пример #5
0
 public function executeList($request)
 {
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $q = LsDoctrineQuery::create()->from('UserView v')->leftJoin('v.User u')->orderBy('v.created_at DESC');
     $this->constraints = array();
     if ($userId = $request->getParameter('user_id')) {
         $user = Doctrine::getTable('sfGuardUser')->find($userId);
         $this->constraints[] = 'Limiting to ' . $user->Profile->getFullName();
         $q->addWhere('v.user_id = ?', $userId);
     }
     if (($model = $request->getParameter('object_model')) && ($id = $request->getParameter('object_id'))) {
         if ($object = Objectable::getObjectByModelAndId($model, $id, $includeDeleted = true)) {
             $this->constraints[] = 'Limiting to ' . $object->getName();
         } else {
             $this->constraints[] = 'Limiting to ' . $model . ' ID ' . $id;
         }
         $q->addWhere('v.object_model = ? AND v.object_id = ?', array($model, $id));
     }
     if ($start = $request->getParameter('start')) {
         $start = date('Y-m-d H:i:s', strtotime($start));
         $q->addWhere('v.created_at > ?', $start);
     }
     if ($end = $request->getParameter('end')) {
         $end = date('Y-m-d H:i:s', strtotime($end));
         $q->addWhere('v.created_at < ?', $end);
     }
     $this->view_pager = new LsDoctrinePager($q, $page, $num);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $db = Doctrine_Manager::connection();
     $models = array('Entity', 'Relationship', 'LsList');
     foreach ($models as $model) {
         $modelAlias = strtolower($model);
         $updateAlias = $model == 'LsList' ? 'ls_list' : $modelAlias;
         //get records to update
         $q = LsDoctrineQuery::create()->select('id')->from($model . ' ' . $modelAlias)->where($modelAlias . '.last_user_id IS NULL')->limit($options['limit'])->setHydrationMode(Doctrine::HYDRATE_NONE);
         if (!count($rows = $q->execute())) {
             //nothing to update, go to next model
             continue;
         }
         foreach ($rows as $row) {
             $id = $row[0];
             //get last_user_id
             $result = LsDoctrineQuery::create()->select('m.user_id')->from('Modification m')->where('m.object_model = ? AND m.object_id = ?', array($model, $id))->orderBy('m.id DESC')->setHydrationMode(Doctrine::HYDRATE_NONE)->fetchOne();
             if ($lastUserId = $result[0]) {
                 $query = 'UPDATE ' . $updateAlias . ' SET last_user_id=? WHERE id=?';
                 //use PDO for speed
                 $db->execute($query, array($lastUserId, $id));
             } else {
                 throw new Exception("Couldn't find last_user_id for " . $model . ' #' . $id);
             }
         }
         //only update records of one model at a time
         break;
     }
     //DONE
     LsCli::beep();
 }
Пример #7
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();
 }
Пример #8
0
 public function executeLatest($request)
 {
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 20);
     $q = LsDoctrineQuery::create()->from('Comment c')->leftJoin('c.User u')->orderBy('c.created_at DESC');
     $this->comment_pager = new LsDoctrinePager($q, $page, $num);
 }
Пример #9
0
 public function deleteAllFavorites()
 {
     $object = $this->getInvoker();
     if (!$object->exists()) {
         throw new Exception("Can't remove UserFavorites for new object");
     }
     return LsDoctrineQuery::create()->from('UserFavorite f')->where('f.object_model = ? AND f.object_id = ?', array(get_class($object), $object->id))->delete()->execute();
 }
Пример #10
0
 public function executeAnalysts($request)
 {
     $this->checkNetwork($request);
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 50);
     $q = LsDoctrineQuery::create()->from('sfGuardUser u')->leftJoin('u.Profile p')->where('p.home_network_id = ?', $this->network['id'])->orderBy('p.public_name')->setHydrationMode(Doctrine::HYDRATE_ARRAY);
     $this->user_pager = new LsDoctrinePager($q, $page, $num);
 }
 public static function getTopUsersQuery($limit = 10, $min = 0, $show_all = false)
 {
     $q = LsDoctrineQuery::create()->from('sfGuardUserProfile p')->leftJoin('p.User u')->where('p.score is not NULL and p.score > ? and u.is_super_admin = ?', array(0, 0))->orderBy('p.score DESC');
     if (!$show_all) {
         $q->addWhere('p.ranking_opt_out = ?', 0);
     }
     return $q;
 }
Пример #12
0
 static function getRelationshipIdsBetween($id1, $id2, $categoryIds = null)
 {
     $db = Doctrine_Manager::connection();
     $q = LsDoctrineQuery::create()->select('l.relationship_id')->from('Link l')->where('l.entity1_id = ? AND l.entity2_id = ?', array($id1, $id2));
     if ($categoryIds) {
         $q->andWhereIn('l.category_id', (array) $categoryIds);
     }
     return $db->execute($q->getSqlQuery(), $q->getParams())->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 1);
 }
Пример #13
0
 public function getBoardRelationships($current = 1)
 {
     $q = LsDoctrineQuery::create()->from('Relationship r')->leftJoin('r.Position p')->addWhere('r.entity2_id = ?', $this->entity_id)->addWhere('r.category_id = ?', RelationshipTable::POSITION_CATEGORY)->addWhere('p.is_board = ?', '1');
     if ($current !== null) {
         $q->addWhere('r.is_current = ?', $current);
     }
     $rels = $q->execute();
     return $rels;
 }
Пример #14
0
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $entities = LsDoctrineQuery::create()->from('Entity e')->where('CHAR_LENGTH(e.name) = 100')->groupBy('e.name')->execute();
     foreach ($entities as $e) {
         echo $e->id . ' :: ' . $e->name;
         echo "\n";
         $duplicates = LsDoctrineQuery::create()->from('Entity e')->where('e.id != ? and e.name = ?', array($e->id, $e->name))->execute();
         foreach ($duplicates as $e2) {
             $mergedEntity = EntityTable::mergeAll($e, $e2);
             $e2->setMerge(true);
             $e2->clearRelated();
             $e2->delete();
             echo '  Successfully merged ' . $e2->name . "\n";
         }
     }
     /*$id = 0;
       $industry = LsDoctrineQuery::create()
                                 ->from('Industry i')
                                 ->where('id > ?',$id)
                                 ->fetchOne();
       while ($industry)
       {
         $matches = LsDoctrineQuery::create()
                                     ->from('Industry i')
                                     ->where('i.name = ? and i.id != ?', array($industry->name,$industry->id))
                                     ->execute();
         echo $matches->count() . '...';
         foreach($matches as $match)
         {
           $bis = LsDoctrineQuery::create()
                                     ->from('BusinessIndustry bi')
                                     ->where('bi.industry_id = ?', $match->id)
                                     ->execute();
           foreach($bis as $b)
           {
             $b->industry_id = $industry->id;
             $b->save();
             $match->delete();
           }
           
         }
         $id = $industry->id;
         $industry = LsDoctrineQuery::create()
                                 ->from('Industry i')
                                 ->where('id > ?',$id)
                                 ->fetchOne();
       }
       
       $images = LsQuery::getByModelAndFieldsQuery('Image',array('caption' => 'Array'));
       foreach($images as $image)
       {
         $image->caption = 'From the Biographical Directory of the United States Congress';
         $image->save();
       }*/
 }
Пример #15
0
 public function checkRelationship($request, $includeDeleted = false)
 {
     if ($includeDeleted) {
         $this->relationship = LsDoctrineQuery::create()->from('Relationship r')->leftJoin('r.Entity1 e1')->leftJoin('r.Entity2 e2')->where('r.id = ?', $request->getParameter('id'))->addWhere('r.is_deleted IS NOT NULL')->fetchOne();
     } else {
         $this->relationship = Doctrine::getTable('Relationship')->find($request->getParameter('id'));
     }
     $this->forward404Unless($this->relationship);
 }
 static function getByExtensionsQuery($ext1, $ext2, $orderMatters = false)
 {
     $q = LsDoctrineQuery::create()->from('RelationshipCategory c');
     if ($orderMatters) {
         $q->addWhere('c.entity1_requirements IS NULL OR c.entity1_requirements = ?', $ext1)->addWhere('c.entity2_requirements IS NULL OR c.entity2_requirements = ?', $ext2);
     } else {
         $q->addWhere('( (c.entity1_requirements IS NULL OR c.entity1_requirements = ?) AND (c.entity2_requirements IS NULL OR c.entity2_requirements = ?) ) OR ( (c.entity1_requirements IS NULL OR c.entity1_requirements = ?) AND (c.entity2_requirements IS NULL OR c.entity2_requirements = ?) )', array($ext1, $ext2, $ext2, $ext1));
     }
     return $q;
 }
Пример #17
0
 static function getViewsByUserIdAndModelsQuery($user_id, array $models = null, $groupEntities = false)
 {
     $q = LsDoctrineQuery::create()->from('UserView v')->where('v.user_id = ? AND v.is_visible = ?', array($user_id, true))->orderBy('v.created_at DESC');
     if ($models) {
         $q->andWhereIn('v.object_model', $models);
     }
     if ($groupEntities) {
         $q->groupBy('v.object_model, v.object_id')->orderBy('MAX(v.created_at) DESC');
     }
     return $q;
 }
Пример #18
0
 static function getSimilarQuery(Entity $e, $looseMatch = false)
 {
     if (!$e->hasExtension('Org')) {
         throw new Exception("Entity must have Org extension to get similar Orgs");
     }
     if (!$e->name) {
         return Doctrine_Query::create()->where("1 = 0");
     }
     return LsDoctrineQuery::create()->from('Entity e')->where('e.primary_ext = ?', 'Org')->addWhere('e.name LIKE ?', '%' . self::stripName($e->name) . '%')->addWhere('e.id <> ?', $e->id);
     return EntityTable::getByExtensionQuery('Org')->addWhere('e.id <> ?', $e->id)->addWhere('org.name LIKE ?', '%' . self::stripName($e->name) . '%');
 }
Пример #19
0
 static function getByModelAndFieldsQuery($model, array $fields)
 {
     if (!Doctrine::getTable($model)) {
         throw new Exception("Can't produce query for nonexistent model " . $model);
     }
     $lower = strtolower($model);
     $q = LsDoctrineQuery::create()->from($model . ' ' . $lower);
     foreach ($fields as $name => $value) {
         $q->addWhere($lower . '.' . $name . ' = ?', $value);
     }
     return $q;
 }
Пример #20
0
 public static function create($conn = null)
 {
     $loggedIn = sfContext::hasInstance() && sfContext::getInstance()->getUser()->isAuthenticated();
     if (!$loggedIn && (sfConfig::get('app_cache_query_enabled') || sfConfig::get('app_cache_result_enabled'))) {
         if (sfConfig::get('app_cache_driver') == 'Apc') {
             $driver = new Doctrine_Cache_Apc();
         } else {
             $servers = array('host' => '127.0.0.1', 'port' => 11211, 'persistent' => true);
             $memcacheAry = array('servers' => $servers, 'compression' => false);
             $driver = new Doctrine_Cache_Memcache($memcacheAry);
         }
     }
     $q = new LsDoctrineQuery($conn);
     if (!$loggedIn && sfConfig::get('app_cache_query_enabled')) {
         $q->useQueryCache($driver);
     }
     if (!$loggedIn && sfConfig::get('app_cache_result_enabled')) {
         $q->useResultCache($driver);
     }
     return $q;
 }
Пример #21
0
 public function executeOrgs($request)
 {
     $page = $request->getParameter('page', 1);
     $num = $request->getParameter('num', 50);
     $this->checkCategory($request);
     if ($this->category) {
         $this->sector = $this->category['sector_name'];
         $this->industry = $this->category['industry_name'];
         $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.OsEntityCategory ec')->leftJoin('ec.OsCategory c')->where('e.primary_ext = ?', 'Org')->andWhere('c.category_id = ?', $this->category['category_id'])->orderBy('e.name ASC')->setHydrationMode(Doctrine::HYDRATE_ARRAY);
         $this->org_pager = new LsDoctrinePager($q, $page, $num);
     }
 }
Пример #22
0
 static function getPublicNameSearchQuery($terms)
 {
     $terms = preg_split('#\\s+#', $terms);
     $q = LsDoctrineQuery::create()->from('sfGuardUser u')->leftJoin('u.Profile p')->setHydrationMode(Doctrine::HYDRATE_ARRAY);
     if (!count($terms)) {
         return $q->where('1=0');
     }
     foreach ($terms as $term) {
         $q->andWhere('p.public_name LIKE ?', '%' . $term . '%');
     }
     return $q;
 }
Пример #23
0
 public function checkObject($request)
 {
     $class = $request->getParameter('object_model');
     $lower = strtolower($class);
     $id = $request->getParameter('object_id');
     $q = LsDoctrineQuery::create()->from($class . ' ' . $lower)->where($lower . '.id = ?', $id);
     if (Doctrine::getTable($class)->hasTemplate('Doctrine_Template_SoftDelete')) {
         $q->addWhere($lower . '.is_deleted IS NOT NULL');
     }
     $this->object = $q->fetchOne();
     $this->forward404Unless($this->object);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $q = EntityTable::getByExtensionQuery(array('Person', 'ElectedRepresentative'))->addWhere('summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ?', array('(daughter%', '(son%', '(father%', '(mother%', '(cousin%', '(husband%', '(wife%', '(brother%', '(sister%'))->orderBy('person.name_last');
     $members = $q->execute();
     foreach ($members as $member) {
         if (preg_match('/\\([^\\)]*\\)/isu', $member->summary, $match)) {
             echo $member->name . ":\n";
             if (preg_match_all('/(brother|sister|daughter|mother|father|wife|husband|cousin)\\sof\\s+([^\\;\\)\\,]*)(\\;|\\)|\\,)/isu', $match[0], $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $m) {
                     echo "\t\t" . $m[1] . ' : of : ' . $m[2] . "\n";
                     $m[2] = str_replace('.', '', $m[2]);
                     $parts = LsString::split($m[2]);
                     $q = EntityTable::getByExtensionQuery(array('Person', 'ElectedRepresentative'));
                     foreach ($parts as $part) {
                         $q->addWhere('e.name like ?', '%' . $part . '%');
                     }
                     $people = $q->execute();
                     $family = array();
                     foreach ($people as $person) {
                         echo "\t\t\t\t" . $person->name . "\n";
                         if ($person->id != $member->id) {
                             $family[] = $person;
                         }
                     }
                     if (count($family) == 1) {
                         $q = LsDoctrineQuery::create()->from('Relationship r')->where('(r.entity1_id = ? or r.entity2_id =?) and (r.entity1_id = ? or r.entity2_id = ?)', array($member->id, $member->id, $person->id, $person->id));
                         if (!$q->count()) {
                             if ($description2 = FamilyTable::getDescription2($m[1], $family[0]->Gender->id)) {
                                 $relationship = new Relationship();
                                 $relationship->setCategory('Family');
                                 $relationship->Entity1 = $member;
                                 $relationship->Entity2 = $person;
                                 $relationship->description1 = $m[1];
                                 $relationship->description2 = $description2;
                                 $relationship->save();
                                 $ref = LsQuery::getByModelAndFieldsQuery('Reference', array('object_model' => 'Entity', 'object_id' => $member->id, 'name' => 'Congressional Biographical Directory'))->fetchOne();
                                 if ($ref) {
                                     $relationship->addReference($ref->source, null, null, $ref->name, $ref->source_detail, $ref->publication_date);
                                 }
                                 echo "-------------------------------added relationship\n";
                             }
                         }
                     }
                 }
             }
             echo "\n";
         }
     }
 }
Пример #25
0
 public function getNearbyAddressesQuery($distance = 0.01, $excludeExact = false, $category = null)
 {
     if (!$this->longitude || !$this->latitude) {
         throw new Exception("Can't get nearby addresses query; longitude and latitude must be set");
     }
     $q = LsDoctrineQuery::create()->select('a.*, POWER( POWER(a.longitude - ' . $this->longitude . ', 2) + POWER(a.latitude - ' . $this->latitude . ', 2), 0.5) AS distance')->from('address a')->leftJoin('a.Entity e')->leftJoin('a.Category c')->where('a.longitude IS NOT NULL AND a.latitude IS NOT NULL')->addWhere('a.entity_id <> ?', $this->entity_id)->addWhere('POWER( POWER(a.longitude - ?, 2) + POWER(a.latitude - ?, 2), 0.5) <= ?', array($this->longitude, $this->latitude, $distance))->orderBy('distance ASC');
     if ($excludeExact) {
         $q->addWhere('NOT a.longitude <=> ? AND NOT a.latitude <=> ?', array($this->longitude, $this->latitude));
     }
     if ($category) {
         $q->addWhere('c.name = ?', $category);
     }
     return $q;
 }
Пример #26
0
 protected function execute($arguments = array(), $options = array())
 {
     // add code here
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $minutes = $options['minutes'];
     $time_date_to_check = date('Y-m-d H:i:s', time() - 60 * $minutes);
     $mods = LsDoctrineQuery::create()->select('m.user_id,count(m.id)')->from('Modification m')->where('m.created_at > ? and m.user_id > ?', array($time_date_to_check, 2))->groupBy('m.user_id')->execute();
     $message_arr = array('spikes' => array(), 'new' => array());
     $new_users = array();
     $spike_users = array();
     foreach ($mods as $mod) {
         $previous_mods_count = LsDoctrineQuery::create()->select('m.id')->from('Modification m')->where('m.created_at < ? and m.user_id = ?', array($time_date_to_check, $mod->user_id))->count();
         if ($previous_mods_count == 0) {
             $user = Doctrine::getTable('sfGuardUser')->find($mod->user_id);
             $new_users[] = $user->username . '(' . $mod->count . ')';
             $message_arr['new'][] = $user->Profile->public_name . " / " . $user->username . " / " . 'http://littlesis.org/user/modifications?id=' . $user->id . "\n\t{$mod->count} modifications in last {$minutes}";
         } else {
             if ($mod->count > $previous_mods_count * 0.1) {
                 $user = Doctrine::getTable('sfGuardUser')->find($mod->user_id);
                 $spike_users[] = $user->username . '(' . $mod->count . ')';
                 $message_arr['spikes'][] = $user->Profile->public_name . " / " . $user->username . " / " . 'http://littlesis.org/user/modifications?id=' . $user->id . "\n\t{$mod->count} modifications in last {$minutes} minutes vs. previous count of {$previous_mods_count} modifications";
             }
         }
     }
     $message = '';
     if (count($message_arr['new'])) {
         $message = "New editing:\n\n";
         $message .= implode("\n\n", $message_arr['new']);
     }
     if (count($message_arr['spikes'])) {
         if (strlen($message)) {
             $message .= "\n\n";
         }
         $message .= "Spike in editing:\n\n";
         $message .= implode("\n\n", $message_arr['spikes']);
     }
     $short = "n:" . implode("/", $new_users) . "|s:" . implode("/", $spike_users);
     if (strlen($message)) {
         $subject = count($message_arr['spikes']) . ' spikes & ' . count($message_arr['new']) . ' new -- ' . date('m-d H:i', time());
         $mailer = new Swift(new Swift_Connection_NativeMail());
         $message = new Swift_Message($subject, $message, 'text/plain');
         $short = new Swift_Message('', $short, 'text/plain');
         $address = new Swift_Address(sfConfig::get('app_mail_contact_sender_address'), sfConfig::get('app_mail_contact_sender_name'));
         $mailer->send($message, sfConfig::get('app_mail_contact_recipient_address'), $address);
         $mailer->send($short, '*****@*****.**', $address);
         $mailer->send($short, '*****@*****.**', $address);
         $mailer->disconnect();
     }
 }
Пример #27
0
 public function executeRegister($request)
 {
     $userParams = $request->getParameter('api_user');
     $this->user_form = new ApiUserForm();
     $this->created = false;
     if ($request->isMethod('post')) {
         //bind request params to form
         $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'));
         $userParams = array_merge($userParams, array('captcha' => $captcha));
         $this->user_form->bind($userParams);
         //look for user with duplicate email
         $q = LsDoctrineQuery::create()->from('ApiUser u')->where('u.email = ?', $userParams['email']);
         if ($q->count()) {
             $validator = new sfValidatorString(array(), array('invalid' => 'There is already an API user with that email address.'));
             $this->user_form->getErrorSchema()->addError(new sfValidatorError($validator, 'invalid'), 'email');
             $request->setError('email', 'There is already a user with that email');
         }
         if ($this->user_form->isValid() && !$request->hasErrors()) {
             //create inactive api user
             $user = new ApiUser();
             $user->name_first = $userParams['name_first'];
             $user->name_last = $userParams['name_last'];
             $user->email = $userParams['email'];
             $user->reason = $userParams['reason'];
             $user->api_key = $user->generateKey();
             $user->is_active = 1;
             $user->save();
             //add admin notification email to queue
             $email = new ScheduledEmail();
             $email->from_name = sfConfig::get('app_mail_sender_name');
             $email->from_email = sfConfig::get('app_mail_sender_address');
             $email->to_name = sfConfig::get('app_mail_sender_name');
             $email->to_email = sfConfig::get('app_mail_sender_address');
             $email->subject = sprintf("%s (%s) has requested an API key", $user->getFullName(), $user->email);
             $email->body_text = $this->getPartial('keyrequestnotify', array('user' => $user));
             $email->save();
             $this->created = true;
             //send approval email
             $mailBody = $this->getPartial('keycreatenotify', array('user' => $user));
             $mailer = new Swift(new Swift_Connection_NativeMail());
             $message = new Swift_Message('Your LittleSis API key', $mailBody, 'text/plain');
             $from = new Swift_Address(sfConfig::get('app_mail_sender_address'), sfConfig::get('app_mail_sender_name'));
             $recipients = new Swift_RecipientList();
             $recipients->addTo($user->email, $user->name_first . ' ' . $user->name_last);
             $recipients->addBcc(sfConfig::get('app_mail_sender_address'));
             $mailer->send($message, $recipients, $from);
             $mailer->disconnect();
         }
     }
 }
Пример #28
0
function user_pic($user, $size = 'small', $htmlOptions = array())
{
    //profile object needed to get internal url
    if (!$user['Profile']) {
        $user['Profile'] = LsDoctrineQuery::create()->from('sfGuardUserProfile p')->where('p.user_id = ?', $user['id'])->setHydrationMode(Doctrine::HYDRATE_ARRAY)->fetchOne();
    }
    if ($fn = $user['Profile']['filename']) {
        $str = $size . DIRECTORY_SEPARATOR . $fn;
    } else {
        $str = 'system' . DIRECTORY_SEPARATOR . 'user.png';
    }
    $htmlOptions = array_merge(array('alt' => $user['Profile']['public_name'], 'style' => 'border: 0;'), $htmlOptions);
    $link = link_to(image_tag($str, $htmlOptions), sfGuardUserTable::getInternalUrl($user));
    return $link;
}
 static function getNamesByParent($parent, $havingFields = null)
 {
     $names = array();
     $q = LsDoctrineQuery::create()->from('ExtensionDefinition d')->orderBy('d.id ASC');
     if ($parent) {
         $q->leftJoin('d.Parent p')->addWhere('p.name = ?', $parent);
     }
     if (!is_null($havingFields)) {
         $q->addWhere('d.has_fields = ?', $havingFields);
     }
     $results = $q->fetchArray();
     foreach ($results as $ary) {
         $names[] = $ary['name'];
     }
     return $names;
 }
Пример #30
0
 static function addByListIdAndEntityId($listId, $entityId)
 {
     $le = LsDoctrineQuery::create()->from('LsListEntity le')->where('le.list_id = ?', $listId)->andWhere('le.entity_id = ?', $entityId)->fetchOne();
     if ($le) {
         if ($le['is_deleted']) {
             $le->is_deleted = 0;
             $le->save();
         }
     } else {
         $le = new LsListEntity();
         $le->list_id = $listId;
         $le->entity_id = $entityId;
         $le->save();
     }
     return $le;
 }