示例#1
0
 public function action_home()
 {
     $ads = Model_Ad::search(array('search_string' => arr::get($_GET, 's'), 'limit' => $this->config['feed']['limit'], 'telecommute' => arr::get($_GET, 'telecommute'), 'jobtype_id' => arr::get($_GET, 'jobtype_id'), 'category_id' => arr::get($_GET, 'category_id'), 'fields' => array('id', 'title', 'telecommute', 'jobtype_id', 'company_name', 'highlight', 'location', 'created_at', 'description', 'jobboard_id')));
     // Formats some field for better viewing
     foreach ($ads['rows'] as $key => $ad) {
         $ads['rows'][$key]['link'] = $ads['rows'][$key]['url'];
         $ads['rows'][$key]['title'] = HTML::chars($ads['rows'][$key]['title'], true);
         $ads['rows'][$key]['description'] = HTML::chars($ads['rows'][$key]['description'], true);
         unset($ads['rows'][$key]['url']);
     }
     // Sets thje info text for the RSS feed
     $info = array('title' => arr::get($_GET, 's') . 'Gowork@: IT Jobs board', 'link' => arr::get($_SERVER, 'SCRIPT_NAME'), 'description' => 'Recent Jobs posted', 'language' => 'en-US', 'generator' => '', 'ttl' => 60);
     $content = Kohana_Feed::create($info, $ads['rows']);
     header('Content-Type: text/xml');
     echo $content;
     die;
 }
示例#2
0
 /**
  * It will send notifications to users if their search params match
  * 1000 emails at a time.
  */
 public function action_send_notifications()
 {
     // Get CLI params
     $options = CLI::options('frequency');
     // Die if no --frequency= param is not found or not a number
     if (!isset($options['frequency']) || !is_numeric($options['frequency'])) {
         die("Insuficient params.\n");
     }
     // Get all users with the correct frequency number
     if ($options['frequency'] == 0) {
         $time_interval = strtotime("-1 day");
         $title = 'Daily';
         $frequency_type = 'day';
     } else {
         $time_interval = strtotime("-1 week");
         $title = 'Weekly';
         $frequency_type = 'week';
     }
     // Execute query
     $rows = ORM::factory('mailinglist')->where('frequency', '=', $options['frequency'])->where(DB::expr('UNIX_TIMESTAMP(last_checked)'), '<=', $time_interval)->limit(1000)->find_all();
     // If no rows found die
     if (!count($rows) > 0) {
         die("No rows to process.\n");
     }
     // Updates all rows tothe current date, to avoid sending duplication
     // from other cron workers
     foreach ($rows as $row) {
         $current_row = ORM::factory('mailinglist', $row->id);
         $current_row->last_checked = date("Y-m-d h:i:s", strtotime("now"));
         $current_row->save();
     }
     // Start fetching data and send to users
     foreach ($rows as $row) {
         // Tries to unserialize search string, if something's wrong
         // the row will be deleted
         try {
             // Conver string into an array
             $search_array = unserialize($row->saved_search);
         } catch (Exception $e) {
             echo 'Invalid search_array: ' . $e->getMessage() . "\n";
             $row->delete();
             continue;
         }
         // Tries to fetch ads from search engine
         try {
             // Fetch data from database
             $ads = Model_Ad::search(array('search_string' => arr::get($search_array, 'search_string'), 'offset' => 0, 'created_after' => $time_interval, 'telecommute' => arr::get($search_array, 'telecommute'), 'jobboard_id' => arr::get($search_array, 'jobtype_id'), 'category_id' => arr::get($search_array, 'category_id'), 'jobtype_id' => arr::get($search_array, 'jobtype_id'), 'fields' => array('id', 'title', 'telecommute', 'jobtype_id', 'description', 'company_name', 'company_logo', 'highlight', 'location', 'created_at', 'jobboard_id')));
         } catch (Exception $e) {
             echo 'Could not get any data from search server: ' . $e->getMessage() . "\n";
         }
         // Prepares the email
         if ($ads['total'] > 0) {
             foreach ($ads['rows'] as $key => $ad) {
                 $ads['rows'][$key]['link'] = $ads['rows'][$key]['url'];
                 $ads['rows'][$key]['description'] = $ads['rows'][$key]['description'];
                 unset($ads['rows'][$key]['url']);
             }
             $filter = arr::get($search_array, 'search_string');
             if (arr::get($search_array, 'telecommute')) {
                 $filter .= ", Telecommute";
             }
             if (arr::get($search_array, 'jobtype_id')) {
                 $jobtype = ORM::factory('jobtype', arr::get($search_array, 'jobtype_id'));
                 $filter .= ", " . $jobtype->name;
             }
             if (arr::get($search_array, 'category_id')) {
                 $category = ORM::factory('category', arr::get($search_array, 'category_id'));
                 $filter .= ", " . $category->name;
             }
             $template = View::factory('emails/mailing', array('ads' => $ads, 'title' => $title . " Report", 'frequency_type' => $frequency_type, 'filter' => $filter, 'unsubscribe_link' => "http://" . Helper_Utils::get_server_domain() . "/mailinglist/remove/?email=" . $row->email . "&id=" . $row->id))->render();
             // Send it to user
             $this->config = Kohana::$config->load('application');
             $this->config['global']['email_feed'];
             Email::send($row->email, $this->config['global']['email_feed'], $title . " Report", $template, TRUE);
         }
     }
     exit(0);
 }
示例#3
0
文件: ads.php 项目: hbarroso/Goworkat
 /**
  * Perfoms a search on the ad Model
  *
  * @param Array $params
  * @return Array
  */
 private function search($params)
 {
     // $page will start from 0 if none is supplied
     $page = arr::get($params, 'page');
     if (!is_numeric($page) || $page <= 0) {
         $page = 1;
     }
     // Sets the limit per page
     $limit = arr::get($params, 'limit', $this->config['search']['limit']);
     // Sets the offset
     $offset = ($page - 1) * $limit;
     // Fetch data from database
     $ads = Model_Ad::search(array('search_string' => arr::get($params, 'search_string'), 'limit' => $limit, 'random_order' => arr::get($params, 'random_order'), 'offset' => $offset, 'telecommute' => arr::get($params, 'telecommute'), 'jobboard_id' => arr::get($params, 'jobboard_id'), 'jobtype_id' => arr::get($params, 'jobtype_id'), 'fields' => array('id', 'title', 'telecommute', 'jobtype_id', 'company_name', 'company_logo', 'highlight', 'location', 'created_at', 'jobboard_id', 'contact', 'description')));
     // Prepares the response
     $response_data = array('ads' => $ads['rows'], 'words' => $ads['words'], 'pagination' => array('total' => intval($ads['total']), 'per_page' => $limit, 'next_page' => $page + 1, 'remaining' => $ads['total'] - (count($ads['rows']) + $offset)));
     return $response_data;
 }