<commit_before><?php

/**
 * 
 */
class CRM_Timetrack_Form_Search_TimetrackPunches implements CRM_Contact_Form_Search_Interface {
  protected $_formValues;
  protected $_tableName;
  protected $_tables;
  protected $_whereTables;
  protected $_permissionWhereClause;

  function __construct(&$formValues) {
    $this->_formValues = $formValues;
    $this->_tables = array();
    $this->_whereTables = array();

    /**
     * Define the columns for search result rows
     */
    $this->_columns = array(
      "#" => 'case_id',
      ts('Project') => 'case_subject',
      ts('Task') => 'task',
      ts('Punch') => 'pid',
      ts('Worker') => 'uid',
      ts('Begin') => 'begin',
      ts('Duration') => 'duration',
      ts('Rounded') => 'duration_rounded',
      ts('Comment') => 'comment',
      ts('Billing') => 'invoice_id',
    );

    if (empty($this->_formValues['case_id'])) {
      $this->_formValues = array_merge($this->_formValues, $this->setDefaultValues());
    }

    // Needs to be set in form for the export tasks?
    if (! empty($formValues['case_id'])) {
      $this->case_id = $formValues['case_id'];
    }
    else {
      $this->case_id = CRM_Utils_Request::retrieve('case_id', 'Integer', $this, FALSE, NULL);
    }
  }

  function get($name) {
    return $this->$name;
  }

  function set($name, $value) {
    $this->$name = $value;
  }

  function buildForm(&$form) {
    // Needs to be set in the $form, so that we don't loose it after filter/task submit.
    $this->case_id = CRM_Utils_Request::retrieve('case_id', 'Integer', $form, FALSE, NULL);

    $elements = array();

    // Get the case subject
    $result = civicrm_api3('Case', 'getsingle', array(
      'id' => $this->case_id,
    ));

    $this->setTitle(ts('List of punches for %1', array(1 => $result['subject'])));

    // Punch filters
    // NB: ktask select must not be named 'task' or it will conflict with the 'task' select in the results.
    $form->addElement('hidden', 'case_id', $this->case_id);

    $form->addDate('start_date', ts('Punch start date'), FALSE, array('formatType' => 'custom', 'id' => 'date_start'));
    $form->addDate('end_date', ts('Punch end date'), FALSE, array('formatType' => 'custom', 'id' => 'date_end'));

    $tasks = CRM_Timetrack_Utils::getActivitiesForCase($this->case_id);
    $tasks[''] = ts('- select -');

    $form->add('select', 'ktask', ts('Task'), $tasks);
    $form->add('text', 'comment', ts('Comment'), FALSE);
    $form->add('select', 'state', ts('Invoice status'), array_merge(array('' => ts('- select -')), CRM_Timetrack_PseudoConstant::getInvoiceStatuses()));

    array_push($elements, 'case_id');
    array_push($elements, 'start_date');
    array_push($elements, 'end_date');
    array_push($elements, 'ktask');
    array_push($elements, 'comment');
    array_push($elements, 'state');

    $form->assign('elements', $elements);
  }

  function setDefaultValues() {
    $defaults = array();

    if (empty($this->_formValues['case_id'])) {
      $this->case_id = CRM_Utils_Request::retrieve('case_id', 'Integer', $this, FALSE, NULL);
      if ($this->case_id) {
        $defaults['case_id'] = $this->case_id;
      }
    }

    // New punches by default
    $defaults['state'] = 0;

    return $defaults;
  }

  function templateFile() {
    return 'CRM/Timetrack/Form/Search/TimetrackPunches.tpl';<commit_msg>Punch search: for CiviCRM 4.5, disable crm-ajax-selection-form, which causes issues in this report, because we are not using contacts.<commit_after><?php

/**
 * 
 */
class CRM_Timetrack_Form_Search_TimetrackPunches implements CRM_Contact_Form_Search_Interface {
  protected $_formValues;
  protected $_tableName;
  protected $_tables;
  protected $_whereTables;
  protected $_permissionWhereClause;

  function __construct(&$formValues) {
    $this->_formValues = $formValues;
    $this->_tables = array();
    $this->_whereTables = array();

    /**
     * Define the columns for search result rows
     */
    $this->_columns = array(
      "#" => 'case_id',
      ts('Project') => 'case_subject',
      ts('Task') => 'task',
      ts('Punch') => 'pid',
      ts('Worker') => 'uid',
      ts('Begin') => 'begin',
      ts('Duration') => 'duration',
      ts('Rounded') => 'duration_rounded',
      ts('Comment') => 'comment',
      ts('Billing') => 'invoice_id',
    );

    if (empty($this->_formValues['case_id'])) {
      $this->_formValues = array_merge($this->_formValues, $this->setDefaultValues());
    }

    // Needs to be set in form for the export tasks?
    if (! empty($formValues['case_id'])) {
      $this->case_id = $formValues['case_id'];
    }
    else {
      $this->case_id = CRM_Utils_Request::retrieve('case_id', 'Integer', $this, FALSE, NULL);
    }
  }

  function get($name) {
    return $this->$name;
  }

  function set($name, $value) {
    $this->$name = $value;
  }

  function buildForm(&$form) {
    // Needs to be set in the $form, so that we don't loose it after filter/task submit.
    $this->case_id = CRM_Utils_Request::retrieve('case_id', 'Integer', $form, FALSE, NULL);

    $elements = array();

    // Get the case subject
    $result = civicrm_api3('Case', 'getsingle', array(
      'id' => $this->case_id,
    ));

    $this->setTitle(ts('List of punches for %1', array(1 => $result['subject'])));

    // Punch filters
    // NB: ktask select must not be named 'task' or it will conflict with the 'task' select in the results.
    $form->addElement('hidden', 'case_id', $this->case_id);

    $form->addDate('start_date', ts('Punch start date'), FALSE, array('formatType' => 'custom', 'id' => 'date_start'));
    $form->addDate('end_date', ts('Punch end date'), FALSE, array('formatType' => 'custom', 'id' => 'date_end'));

    $tasks = CRM_Timetrack_Utils::getActivitiesForCase($this->case_id);
    $tasks[''] = ts('- select -');

    $form->add('select', 'ktask', ts('Task'), $tasks);
    $form->add('text', 'comment', ts('Comment'), FALSE);
    $form->add('select', 'state', ts('Invoice status'), array_merge(array('' => ts('- select -')), CRM_Timetrack_PseudoConstant::getInvoiceStatuses()));

    array_push($elements, 'case_id');
    array_push($elements, 'start_date');
    array_push($elements, 'end_date');
    array_push($elements, 'ktask');
    array_push($elements, 'comment');
    array_push($elements, 'state');

    $form->assign('elements', $elements);

    // FIXME: this disables ./Contact/Form/Search.php from doing: $this->addClass('crm-ajax-selection-form');
    // because the ajax selection doesn't work on non-contacts (always returns 0 items).
    $form->set('component_mode', 999);
  }

  function setDefaultValues() {
    $defaults = array();

    if (empty($this->_formValues['case_id'])) {
      $this->case_id = CRM_Utils_Request::retrieve('case_id', 'Integer', $this, FALSE, NULL);
      if ($this->case_id) {
        $defaults['case_id'] = $this->case_id;
      }
    }

    // New punches by default
    $defaults['state'] = 0;

    return $defaults;
  }

  function templateFile() {
    return 'CRM/Timetrack/Form/Search/TimetrackPunches.tpl';
{'fraction_non_alphanumeric': 0.18647656691134953, 'fraction_numerical': 0.001976284584980237, 'mean_word_length': 3.6489501312335957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1361122', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2281, 'n_words': 506}