Example #1
0
 public function actionNotificationAdmin()
 {
     $results = null;
     $results1 = null;
     $username = Yii::app()->user->name;
     $user = User::model()->find("username=:username", array(':username' => $username));
     $notification = Notification::model()->getNotificationId($user->id);
     // pass the notifications
     $matchnotification = MatchNotification::model()->findBySql("SELECT * FROM match_notification ORDER BY date_modified DESC limit 1");
     $status = array('status' => $matchnotification['status'], 'date_modified' => $matchnotification['date_modified'], 'userid' => $matchnotification['userid']);
     $user = User::model()->find("id=:id", array(':id' => $matchnotification['userid']));
     $status['username'] = $user['username'];
     $this->render('notificationadmin', array('results' => $results, 'results1' => $results1, 'notification' => $notification, 'matchnotification' => $status));
 }
Example #2
0
 public function run($args)
 {
     date_default_timezone_set('America/New_York');
     $new_active_user = false;
     $nau_info = array();
     $interval = 0;
     $send_empl = false;
     $switches = array("-u", "-e", "-i", "-h", "-m", "--help");
     if (count($args) > 0) {
         for ($j = 0; $j < count($args); $j++) {
             if (in_array($args[$j], $args)) {
                 switch ($args[$j]) {
                     case "-u":
                         $new_active_user = true;
                         $nau_info['username'] = $args[$j + 1];
                         break;
                     case "-m":
                         $send_empl = true;
                         break;
                     case "-e":
                         $new_active_user = true;
                         $nau_info['email'] = $args[$j + 1];
                         break;
                     case "-i":
                         $interval = intval($args[$j + 1]);
                         if (!in_array($interval, array(1, 7, 30))) {
                             echo "[INVALID] Invalid interval value.\n";
                             $this->getHelp();
                         }
                         break;
                     case "-h":
                     case "--help":
                         $this->getHelp();
                 }
             }
         }
     } else {
         $this->getHelp();
     }
     $now = date('Y-m-d H:i:s');
     $date = date('Y-m-d');
     $time = date('H:i:s');
     $pasttime = $date . " " . date('H:i:s', strtotime("-30 min"));
     $matchnotification = MatchNotification::model()->findBySql("SELECT * FROM match_notification ORDER BY date_modified DESC limit 1");
     $notfication_status = intval($matchnotification['status']);
     if ($notfication_status) {
         if ($new_active_user) {
             if (isset($nau_info['email']) && $nau_info['email'] != '' && isset($nau_info['username']) && $nau_info['username'] != '') {
                 $jobs = Job::model()->findAll("active = 1");
                 $student = User::model()->find("username=:username", array(':username' => $nau_info['username']));
                 if ($student['username'] != null && $student['looking_for_job'] == 1 && $student['job_notification'] == 1) {
                     $message = "";
                     $results = Yii::app()->jobmatch->getStudentMatchJobs(intval($student['id']), $jobs);
                     if (count($results) > 0) {
                         $message .= $this->buildTable('student', $results, $interval);
                         User::sendEmail($student->email, "Virtual Job Fair | Job Matches", "Your Job Matches", $message);
                     }
                     return;
                 }
                 return;
             }
             return;
         }
         echo "[*] Job Matching Notification is ON\n";
         $jobs = Job::model()->findAll("post_date > '{$pasttime}' AND active = 1");
         #Add fecthing for user not active or validated
         $students = User::model()->findAll("FK_usertype = 1 AND job_notification = 1 AND looking_for_job = 1 AND activated = 1 AND disable = 0");
         echo "\n::::::::::::::::::::\n[*] Matching jobs for students.\n";
         foreach ($students as $st) {
             $message = "";
             $results = array();
             $saved_queries = SavedQuery::model()->findAll("FK_userid=:id AND active = 1", array(':id' => $st->id));
             if (count($saved_queries) > 0 && $interval == intval($st->job_int_date) && $interval > 0) {
                 $word = "query";
                 if (count($saved_queries) > 1) {
                     $word = "queries";
                 }
                 $message .= "Jobs matching your custom {$word}:<br/>";
                 foreach ($saved_queries as $query) {
                     $results = Yii::app()->jobmatch->customJobSearch(html_entity_decode($query->query), $query->location);
                     $message .= "Matches for query [{$query->query}]<br/>";
                     $message .= $this->buildTable('student_custom', $results, $interval);
                     $message .= "<br/>";
                 }
                 echo "[*] Sending custom search job results email to: {$st->email}\n";
                 User::sendEmail($st->email, "Virtual Job Fair | Job Matches", "Your Job Matches", $message);
             } else {
                 if ($interval == intval($st->job_int_date) && $interval > 0) {
                     $results = Yii::app()->jobmatch->getStudentMatchJobs($st->id, $jobs);
                     if (count($results) > 0) {
                         $message .= "The following jobs matched with your skills:<br/>";
                         $message .= $this->buildTable('student', $results, $interval);
                         echo "[*] Sending skill matches results email to: {$st->email}\n";
                         User::sendEmail($st->email, "Virtual Job Fair | Job Matches", "Your Job Matches", $message);
                     }
                 }
             }
         }
         if ($send_empl) {
             $count = 1;
             foreach ($jobs as $job) {
                 $message = "";
                 $job_poster_info = User::model()->findByPk($job->FK_poster);
                 if (!$job_poster_info->job_notification) {
                     echo "[*] Employer {$job_poster_info->username} has notifications OFF\n";
                     continue;
                 }
                 $job_poster_email = $job_poster_info->email;
                 echo "\n[*] Working on jobid {$job->id} : {$job->title}\n";
                 $results = Yii::app()->jobmatch->getJobStudentsMatch($job->id);
                 if (!isset($results['students']) || count($results) == 0 || $results['students'] == NULL) {
                     echo "[*] No student matches found for: " . $job->title . "\n";
                     continue;
                 }
                 $message .= "The following students matched this job posting:<br/>";
                 $table = $this->buildTable('', $results, $interval);
                 $message .= $table;
                 echo $this->replaceTags($message);
                 echo "[*] Sending email to {$job_poster_email}\n";
                 User::sendEmail($job_poster_email, "Virtual Job Fair | Job Matches", "Job Matches for {$job->title}", $message);
             }
         }
         return 0;
     } else {
         echo "[*] Job Matching Notification is OFF\n";
     }
 }
Example #3
0
 public function actionCheckNotificationState()
 {
     if (User::isCurrentUserAdmin()) {
         $matchnotification = MatchNotification::model()->findBySql("SELECT * FROM match_notification ORDER BY date_modified DESC limit 1");
         $status = array('status' => $matchnotification['status'], 'date_modified' => $matchnotification['date_modified'], 'userid' => $matchnotification['userid']);
         $user = User::model()->find("id=:id", array(':id' => $matchnotification['userid']));
         $status['username'] = $user['username'];
         echo CJSON::encode($status);
     }
 }