예제 #1
0
 /**
  * Time Board.
  */
 public function actionTimeboard($id = null, $day = null, $hour = null, $minute = null)
 {
     if (Yii::app()->user->checkAccess('subject_manage')) {
         $utc_time = SiteLibrary::utc_time();
         //If there are any position changes update the timeboard first
         if ($id and $day and isset($hour) and isset($minute)) {
             //hour and minute can be 0 thats why we use isset instead of simple if
             //if day is less than today then set month as next future month,
             if ($day < (int) date("j", $utc_time)) {
                 $month = date("m", $utc_time) == '12' ? 1 : (int) date("m", $utc_time) + 1;
                 $year = (int) date("Y", $utc_time) + 1;
             } else {
                 $month = date("m", $utc_time);
                 $year = date("Y", $utc_time);
             }
             $position = strtotime($year . "-" . $month . "-" . $day . " " . $hour . ":" . $minute . ":00", $utc_time);
             //$position = strtotime("2012-06-10 14:28");
             //echo $position. $year."-".$month."-".$day." ".$hour.":".$minute.":00";
             //die($position);
             Subject::set_position($id, $position);
         }
         $this->model = new Subject('manage');
         $this->model->unsetAttributes();
         // clear any default values
         $this->model->authorized = 1;
         $this->model->approved = 1;
         $this->model->disabled = 0;
         $this->model->deleted = 0;
         $this->model->position = ">=" . SiteLibrary::utc_time_interval();
         if (isset($_GET['Subject'])) {
             $this->model->attributes = $_GET['Subject'];
         }
         $live_subject = Yii::app()->db->createCommand()->select('*')->from('live_subject')->queryRow();
         //if(! isset($this->model->disabled)) $this->model->disabled = 0;//Set to view only NOT disabled subjects by default(notice isset insted of a simple if)
         $this->render('timeboard', array('model' => $this->model, 'live_subject' => $live_subject));
     } else {
         throw new CHttpException(403, Yii::t('subject', 'You are not allowed to manage subjects.'));
     }
 }
예제 #2
0
 /**
  * This is a cron that sets the next subject to be showed 
  * and the next subject to be cached(subject_id and subject_id_2)
  * 
  */
 public function actionSetNextSubject()
 {
     if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
         die;
     }
     //Only allow to run this locally
     $command = Yii::app()->db->createCommand();
     //If the table its empty by any reason(initial import), insert something to make the UPDATE work
     if (!$command->select('count(*) as num')->from('live_subject')->queryScalar()) {
         $command->insert('live_subject', array('subject_id' => 0, 'subject_id_2' => 0));
     }
     //Position all subs on its time
     Subject::reschedule_positions();
     $round_utc_time = SiteLibrary::utc_time_interval();
     //Remote case: This update is just in case cron didn't run in x times of interva(s)
     //This frees up subs that never were used because they were fixed position but cron failed to run and time passed by
     Subject::model()->updateAll(array('position' => '0', 'user_position' => '0', 'manager_position' => '0'), 'position < ' . $round_utc_time . ' AND user_position < ' . $round_utc_time . ' AND manager_position < ' . $round_utc_time);
     $subject = Subject::model()->find(array('condition' => 'position >= ' . $round_utc_time . ' AND content_type_id <> 2 AND approved=1 AND authorized=1 AND disabled=0 AND deleted=0', 'order' => 'position ASC'));
     $live_subject = Yii::app()->db->createCommand()->select('*')->from('live_subject')->queryRow();
     $command->delete('live_comment');
     $command->update('live_subject', array('comment_id' => 0, 'comment_number' => 0));
     //TEMPORAL:Refill the live_comments table with old comments about this subject if this subject is repeated
     $past_comments = Yii::app()->db->createCommand()->select('t1.id,code,time,comment,comment_number,username,likes,dislikes')->from('comment t1')->where('subject_id =' . $subject->id)->leftJoin('country t2', 'country_id=t2.id')->leftJoin('user t3', 'user_id=t3.id')->order('time ASC')->queryAll();
     echo "<br>gggg";
     print_r($past_comments);
     $i = 0;
     foreach ($past_comments as $past_comment) {
         $i++;
         $country_code = $past_comment['code'] ? $past_comment['code'] : "WW";
         $command->insert('live_comment', array('comment_id' => $past_comment['id'], 'username' => $past_comment['username'], 'subject_id' => $subject->id, 'comment_country' => $country_code, 'comment_time' => $past_comment['time'], 'comment_text' => $past_comment['comment'], 'comment_number' => $i, 'likes' => $past_comment['likes'], 'dislikes' => $past_comment['dislikes']));
         //we neet to use our own sequence because there might be repeated numbers
         $comment_id = $past_comment['id'];
     }
     if ($i > 0) {
         $command->update('live_subject', array('comment_id' => $comment_id, 'comment_number' => $i));
     }
     $command->update('live_subject', array('subject_id' => $subject->id, 'scheduled_time' => SiteLibrary::utc_time_interval(), 'subject_data' => serialize($subject)));
     //Reset position as subject is going to live now
     Subject::model()->updateByPk($subject->id, array('show_time' => SiteLibrary::utc_time(), 'user_position' => 0, 'manager_position' => 0));
     //Notify subject owner via email that his subject its gonna get LIVE
     $user = User::model()->findByPk($subject->user_id);
     if ($user->id != 1 and $user->notify_subject_live == 1) {
         $mail_message = Yii::t('subject', "Hi {username}, \nWe are writing to notify you that your subject got approved and that it is\ngoing to be placed in the live stream(Homepage) in the next 5 minutes.\nDetails\nSubject Title: {title}\nUploaded time: {uploaded_time} UTC\nCurrent time: {current_time} UTC (time of this message)\nEstimated time: {estimated_time} UTC (about 5 minutes)\nIt is even more cool if you chat with your friends about your upcomming subject.\nSo, invite them to go to samesub.com now, you still have 4 minutes.\nIf you do not want to receive this type of notification you can update the settings in\nyour user profile anytime you want.", array('{username}' => $user->username, '{title}' => $subject->title, '{uploaded_time}' => date("Y/m/d H:i", $subject->time_submitted), '{current_time}' => date("Y/m/d H:i", SiteLibrary::utc_time()), '{estimated_time}' => date("Y/m/d H:i", SiteLibrary::utc_time() + 300)));
         $mail_message .= "\n\n";
         $mail_message .= Yii::t('site', "Thanks\nSincerely\nSamesub Team\nwww.samesub.com");
         if (SiteLibrary::send_email($user->email, "Your subject is going LIVE", $mail_message)) {
             echo "An email has been sent.";
         } else {
             echo "Email could not be sent.";
         }
     }
     echo 'Done setting next subject_id_2 : ' . $subject->id;
     //There are some pages that need to be refreshed from the cache such as /subject/index, so that it content reflects the updated data.
     $optional_prefix = "index.php";
     $cmd = Yii::app()->params['cache_refresher'] . ' "' . $optional_prefix . '/subject/index' . '"';
     if (Yii::app()->params['cache_refresher']) {
         exec($cmd);
     }
 }
예제 #3
0
파일: Subject.php 프로젝트: jjsub/samesub
 /**
  * Reschedule positions in the timeboard schedule
  * This function does NOT touch fixed positions(user_position OR manager_position) as those positions are untouchable(Only another fixed position can touch them)
  * @return boolean true on success false on failure 
  */
 public function reschedule_positions()
 {
     //Put position in cero all subs that dont have a fixed position then position them again by priority and arrival order
     //and respect that this new assgnation never overrites Fixed postions(user_position OR manager_position)
     Subject::model()->updateAll(array('position' => '0'), 'position > ' . SiteLibrary::utc_time_interval() . ' AND user_position = 0 AND manager_position = 0');
     //We CAN NOT touch current sub(live), thats why position must be greater than current time
     $timed_subs = Subject::model()->findAll(array('condition' => 'position = 0 AND user_position = 0 AND manager_position = 0 AND approved=1 AND authorized=1 AND disabled=0 AND deleted=0', 'order' => 'show_time ASC, priority_id DESC , time_submitted ASC', 'limit' => 24));
     $position = SiteLibrary::utc_time_interval();
     // + (Yii::app()->params['subject_interval'] * 60);
     foreach ($timed_subs as $timed_sub) {
         do {
             if ($occupied_pos = Subject::model()->find('position = ' . $position)) {
                 $position = $position + Yii::app()->params['subject_interval'] * 60;
                 continue;
             }
             break;
         } while (true);
         Subject::model()->updateByPk($timed_sub->id, array('position' => $position));
     }
 }