Example #1
0
 function whereClause(&$params, $sortBy = true, $force)
 {
     $values = array();
     $clauses = array();
     $title = $this->get('title');
     if ($title) {
         $clauses[] = "title LIKE %1";
         if (strpos($title, '%') !== false) {
             $params[1] = array(trim($title), 'String', false);
         } else {
             $params[1] = array(trim($title), 'String', true);
         }
     }
     $value = $this->get('event_type_id');
     $val = array();
     if ($value) {
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 if ($v) {
                     $val[$k] = $k;
                 }
             }
             $type = implode(',', $val);
         }
         $clauses[] = "event_type_id IN ({$type})";
     }
     $eventsByDates = $this->get('eventsByDates');
     if ($this->_searchResult) {
         if ($eventsByDates) {
             require_once 'CRM/Utils/Date.php';
             $from = $this->get('start_date');
             if (!CRM_Utils_System::isNull($from)) {
                 $from = CRM_Utils_date::format($from);
                 $from .= '000000';
                 $clauses[] = '( start_date >= %3 OR start_date IS NULL )';
                 $params[3] = array($from, 'String');
             }
             $to = $this->get('end_date');
             if (!CRM_Utils_System::isNull($to)) {
                 $to = CRM_Utils_date::format($to);
                 $to .= '235959';
                 $clauses[] = '( end_date <= %4 OR end_date IS NULL )';
                 $params[4] = array($to, 'String');
             }
         } else {
             $curDate = date('YmdHis');
             $clauses[5] = "(end_date >= {$curDate} OR end_date IS NULL)";
         }
     } else {
         $curDate = date('YmdHis');
         $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
     }
     if ($sortBy && $this->_sortByCharacter) {
         $clauses[] = 'title LIKE %6';
         $params[6] = array($this->_sortByCharacter . '%', 'String');
     }
     // dont do a the below assignment when doing a
     // AtoZ pager clause
     if ($sortBy) {
         if (count($clauses) > 1 || $eventsByDates) {
             $this->assign('isSearch', 1);
         } else {
             $this->assign('isSearch', 0);
         }
     }
     require_once 'CRM/Core/Permission.php';
     $clauses[] = CRM_Core_Permission::eventClause();
     return implode(' AND ', $clauses);
 }