/**
  * Restrict the query to the time frame.
  * @param QUERY $query
  */
 public function prepare_query($query)
 {
     if (!$query) {
         $this->raise("'query' cannot be empty", 'prepare_query', 'TIME_FRAME_SELECTOR');
     }
     switch ($this->period) {
         case Time_frame_recent:
             $query->set_limits(0, $this->num_in_recent);
             break;
         case Time_frame_today:
             $first = new DATE_TIME(mktime(0, 0, 0, date('n'), date('d'), date('Y')));
             $last = new DATE_TIME(time());
             $query->set_days($first->as_iso(), $last->as_iso());
             break;
         case Time_frame_last_week:
             $now = time();
             $last = new DATE_TIME($now);
             $first = new DATE_TIME($now - 86400 * 7);
             $query->set_days($first->as_iso(), $last->as_iso());
             break;
         case Time_frame_last_month:
             $now = time();
             $last = new DATE_TIME($now);
             $first = new DATE_TIME($now - 86400 * 30);
             $query->set_days($first->as_iso(), $last->as_iso());
             break;
         case Time_frame_all:
             break;
     }
     if ($this->period != Time_frame_all) {
         $query->order_by_recent();
     }
 }
Пример #2
0
 /**
  * Compare against 'other' using 'operator'.
  * @param DATE_TIME $other
  * @param int $operator Can be {@link Operator_equal}, {@link Operator_less_than_equal}.
  * @param int $parts Can be {@link Date_time_date_part}, {@link Date_time_time_part} or {@link Date_time_both_parts}.
  * @return boolean
  */
 protected function _compare_to($other, $operator, $parts)
 {
     switch ($parts) {
         case Date_time_both_parts:
             if ($this->_php_time != Date_time_unassigned) {
                 $left = $this->_php_time;
                 $right = $other->as_php();
             } else {
                 $left = $this->_iso_time;
                 $right = $other->as_iso();
             }
             break;
         case Date_time_date_part:
             $left = @date('Ymd', $this->as_php());
             $right = @date('Ymd', $other->as_php());
             //      $left = floor (($this->as_php () + 7200) / 86400);
             //      $right = floor (($other->as_php () + 7200) / 86400);
             break;
         case Date_time_time_part:
             $left = $this->as_php() % 86400;
             $right = $other->as_php() % 86400;
             break;
     }
     switch ($operator) {
         case Operator_equal:
             return $left == $right;
         case Operator_less_than_equal:
             return $left <= $right;
         case Operator_less_than:
             return $left < $right;
         default:
             $this->raise("[{$operator}] is not supported.", '_compare_to', 'DATE_TIME');
     }
     return false;
     // Compiler warning; the call to "raise" should abort execution
 }
Пример #3
0
 /**
  * @param FORM_RENDERER $renderer
  * @access private
  */
 protected function _draw_controls($renderer)
 {
     $renderer->start();
     $renderer->draw_text_line_row('title');
     $renderer->draw_check_box_row('is_visible');
     $this->_draw_kind_controls($renderer);
     $this->_draw_component_controls($renderer);
     // Start the branch section
     $this->_draw_branch_controls($renderer);
     $renderer->draw_submit_button_row();
     $renderer->draw_text_box_row('description');
     $renderer->draw_text_box_row('files');
     $renderer->draw_submit_button_row();
     $renderer->draw_text_box_row('extra_description');
     $branch_id = $this->value_for('main_branch_id');
     /** @var $folder PROJECT */
     $folder = $this->_folder;
     $branch_query = $folder->branch_query();
     /** @var $branch BRANCH */
     $branch = $branch_query->object_at_id($branch_id);
     $release_id = $this->value_for("branch_{$branch_id}_release_id");
     if ($release_id) {
         $release_query = $branch->release_query();
         $release = $release_query->object_at_id($release_id);
         $entry_query = $release->entry_query();
     } else {
         $entry_query = $branch->entry_query();
     }
     $entry_query->set_type('job');
     if ($this->object_exists()) {
         $t = $this->_object->time_created;
     } else {
         $t = new DATE_TIME();
     }
     $job_id = $this->value_for('job_id');
     if (empty($job_id)) {
         $job_id = 0;
     }
     $entry_query->restrict("(entry.id = {$job_id}) OR (closer_id <> 0) <> 0 OR (job.time_closed < '" . $t->as_iso() . "')");
     $this->_jobs = $entry_query->objects();
     $num_jobs = sizeof($this->_jobs);
     if ($num_jobs) {
         $props = $renderer->make_list_properties();
         $props->height = min($num_jobs + 1, 10);
         $props->add_item('[None]', 0);
         /** @var $j JOB */
         foreach ($this->_jobs as $j) {
             $t = $j->title_formatter();
             $t->max_visible_output_chars = 55;
             $props->add_item($j->title_as_plain_text($t), $j->id);
         }
         $job = $this->job_at($this->value_for('job_id'));
         $job_text = 'A change can be attached to the job to which it contributed. Only the jobs for the selected branch and release are shown.';
         if ($job) {
             $renderer->draw_text_row(' ', $job_text . ' The current job is previewed above.', 'notes');
             $renderer->draw_list_box_row('job_id', $props);
         } else {
             $renderer->draw_text_row(' ', $job_text, 'notes');
             $renderer->draw_list_box_row('job_id', $props);
         }
     }
     $renderer->draw_submit_button_row();
     $this->_draw_history_item_controls($renderer);
     $renderer->finish();
 }
Пример #4
0
 /**
  * Adjust first and last days to include the given entry.
  * Only has an effect when the album has a {@link $first_day_mode} or {@link
  * $last_day_mode} of {@link Day_mode_adjust}. Use {@link refresh_dates()} to
  * set the days from already contained content.
  * @param ALBUM_ENTRY $entry
  * @param boolean $update_now Updates the database immediately when
  * <code>True</code>.
  */
 public function include_entry($entry, $update_now = true)
 {
     $first_day = $this->first_day->as_php();
     $last_day = $this->last_day->as_php();
     $day = $entry->date->as_php();
     if ($this->first_day_mode == Day_mode_adjust) {
         if ($day < $first_day) {
             $this->first_day->set_from_php($day);
             if ($update_now) {
                 $this->db->logged_query("UPDATE {$this->app->table_names->folders} SET first_day = '" . $this->first_day->as_iso() . "' WHERE id = {$this->id}");
             }
         }
     }
     if ($this->last_day_mode == Day_mode_adjust) {
         $need_update = $day > $last_day;
         if (!$need_update) {
             $entry_query = $this->entry_query();
             $need_update = $entry_query->size() == 0;
         }
         if ($need_update) {
             $this->last_day->set_from_php($day);
             if ($update_now) {
                 $this->db->logged_query("UPDATE {$this->app->table_names->folders} SET last_day = '" . $this->last_day->as_iso() . "' WHERE id = {$this->id}");
             }
         }
     }
 }
Пример #5
0
 /**
  * Called when the page is set before rendering.
  *
  * This calendar caches the pictures and journals for the new page.
  *
  * @access private
  */
 protected function _page_changed()
 {
     $first_day = new DATE_TIME(mktime(0, 0, 0, $this->_curr_month, 1, $this->_curr_year));
     $last_day = new DATE_TIME(mktime(23, 59, 59, $this->_curr_month, $first_day->last_legal_day(), $this->_curr_year));
     $journal_query = $this->album->entry_query();
     $journal_query->set_type('journal');
     $journal_query->set_days($first_day->as_iso(), $last_day->as_iso());
     $this->_journals = $journal_query->objects();
     $picture_query = $this->album->entry_query();
     $picture_query->set_type('picture');
     $picture_query->set_days($first_day->as_iso(), $last_day->as_iso());
     $this->_pictures = $picture_query->objects();
 }
Пример #6
0
 /**
  * @var FORM $form
  */
 public function validate($form)
 {
     parent::validate($form);
     if ($this->continue_validating($form)) {
         /** @var $value DATE_TIME */
         $value = $this->_value;
         if (!$value->is_valid()) {
             $form->record_error($this->id, "[{$this->_text_value}] is not a valid date/time. Use [d.m.Y] or [m/d/Y] or [Y-m-d]");
         } else {
             $date = $value;
             if (isset($this->max_date)) {
                 if (isset($this->min_date)) {
                     if ($date->less_than_equal($this->min_date) || $this->max_date->less_than_equal($date)) {
                         $form->record_error($this->id, 'Please enter a date between ' . $this->min_date->as_iso() . ' and ' . $this->max_date->as_iso() . " for {$this->caption}");
                     }
                 } else {
                     if ($this->max_date->less_than_equal($date)) {
                         $form->record_error($this->id, 'Please enter a date less than ' . $this->max_date->as_iso() . " for {$this->caption}");
                     }
                 }
             } else {
                 if (isset($this->min_date)) {
                     if ($date->less_than_equal($this->min_date)) {
                         $form->record_error($this->id, 'Please enter a date greater than ' . $this->min_date->as_iso() . " for {$this->caption}");
                     }
                 }
             }
         }
     }
 }