Example #1
0
 /**
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = 'tickets.enteredDate desc', $paginated = false, $limit = null)
 {
     $select = new Select('tickets');
     $select->join(['c' => 'categories'], 'tickets.category_id=c.id', [], $select::JOIN_LEFT);
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             if ($value) {
                 switch ($key) {
                     case 'reportedByPerson_id':
                         $select->join(['i' => 'issues'], 'tickets.id=i.ticket_id', [], $select::JOIN_LEFT);
                         $select->where(["i.{$key}" => $value]);
                         break;
                     case 'start_date':
                         $d = date(ActiveRecord::MYSQL_DATE_FORMAT, strtotime($value));
                         $select->where("tickets.enteredDate>='{$d}'");
                         break;
                     case 'end_date':
                         $d = date(ActiveRecord::MYSQL_DATE_FORMAT, strtotime($value));
                         $select->where("tickets.enteredDate<='{$d}'");
                         break;
                     case 'lastModified_before':
                         $d = date(ActiveRecord::MYSQL_DATE_FORMAT, strtotime($value));
                         $select->where("tickets.lastModified<='{$d}'");
                         break;
                     case 'lastModified_after':
                         $d = date(ActiveRecord::MYSQL_DATE_FORMAT, strtotime($value));
                         $select->where("tickets.lastModified>='{$d}'");
                         break;
                     case 'bbox':
                         $bbox = explode(',', $value);
                         if (count($bbox) == 4) {
                             $minLat = (double) $bbox[0];
                             $minLong = (double) $bbox[1];
                             $maxLat = (double) $bbox[2];
                             $maxLong = (double) $bbox[3];
                             $select->where('tickets.latitude is not null and tickets.longitude is not null');
                             $select->where("tickets.latitude  > {$minLat}");
                             $select->where("tickets.longitude > {$minLong}");
                             $select->where("tickets.latitude  < {$maxLat}");
                             $select->where("tickets.longitude < {$maxLong}");
                         }
                         break;
                     default:
                         $select->where(["tickets.{$key}" => $value]);
                 }
             }
         }
     }
     // Only get tickets for categories this user is allowed to see
     if (!isset($_SESSION['USER'])) {
         $select->where("c.displayPermissionLevel='anonymous'");
     } elseif ($_SESSION['USER']->getRole() != 'Staff' && $_SESSION['USER']->getRole() != 'Administrator') {
         $select->where("c.displayPermissionLevel in ('public','anonymous')");
     }
     return parent::performSelect($select, $order, $paginated, $limit);
 }
 /**
  * Populates the collection, using strict matching of the requested fields
  *
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = ['g.ordering', 'g.name', 'categories.name'], $paginated = false, $limit = null)
 {
     $select = new Select('categories');
     $select->join(['g' => 'categoryGroups'], 'categories.categoryGroup_id=g.id', [], $select::JOIN_LEFT);
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             switch ($key) {
                 case 'postableBy':
                     // If they're authenticated, but they are not staff
                     if ($value instanceof Person) {
                         if ($value->getRole() != 'Staff' && $value->getRole() != 'Administrator') {
                             // Limit them to public and anonymous categories
                             $select->where(['categories.postingPermissionLevel' => ['public', 'anonymous']]);
                         }
                     } else {
                         $select->where(['categories.postingPermissionLevel' => 'anonymous']);
                     }
                     break;
                 case 'displayableTo':
                     // If they're authenticated, but they are not staff
                     if ($value instanceof Person) {
                         if ($value->getRole() != 'Staff' && $value->getRole() != 'Administrator') {
                             // Limit them to public and anonymous categories
                             $select->where(['categories.displayPermissionLevel' => ['public', 'anonymous']]);
                         }
                     } else {
                         $select->where(['categories.displayPermissionLevel' => 'anonymous']);
                     }
                     break;
                 case 'department_id':
                     $select->join(['d' => 'department_categories'], 'categories.id=d.category_id', [], $select::JOIN_LEFT);
                     $select->where(['d.department_id' => $value]);
                     break;
                 default:
                     if ($value) {
                         $select->where(["categories.{$key}" => $value]);
                     }
             }
         }
     }
     // Only get categories this user is allowed to see or post to
     if (!isset($_SESSION['USER'])) {
         $select->where("(categories.postingPermissionLevel='anonymous' or categories.displayPermissionLevel='anonymous')");
     } elseif ($_SESSION['USER']->getRole() != 'Staff' && $_SESSION['USER']->getRole() != 'Administrator') {
         $select->where("(categories.postingPermissionLevel in ('public','anonymous') or categories.displayPermissionLevel in ('public','anonymous'))");
     }
     return parent::performSelect($select, $order, $paginated, $limit);
 }
Example #3
0
 /**
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = 'name', $paginated = false, $limit = null)
 {
     $select = new Select('actions');
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             switch ($key) {
                 case 'department_id':
                     $select->join(['d' => 'department_actions'], 'actions.id=d.action_id', [], $select::JOIN_LEFT);
                     $select->where(['d.department_id' => $value]);
                     break;
                 default:
                     $select->where([$key => $value]);
             }
         }
     }
     return parent::performSelect($select, $order, $paginated, $limit);
 }
Example #4
0
 /**
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = 'label', $paginated = false, $limit = null)
 {
     $select = new Select('peopleEmails');
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             if ($value) {
                 switch ($key) {
                     case 'usedForNotifications':
                         $select->where([$key => $value ? 1 : 0]);
                         break;
                     default:
                         $select->where([$key => $value]);
                 }
             }
         }
     }
     return parent::performSelect($select, $order, $paginated, $limit);
 }
Example #5
0
 /**
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = 'labels.name', $paginated = false, $limit = null)
 {
     $select = new Select('labels');
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             if ($value) {
                 switch ($key) {
                     case 'issue_id':
                         $select->join(['i' => 'issue_labels'], 'labels.id=i.label_id', [], Select::JOIN_LEFT);
                         $select->where(['i.issue_id' => $value]);
                         break;
                     default:
                         $this->select->where(["labels.{$key}" => $value]);
                 }
             }
         }
     }
     return parent::performSelect($select, $order, $paginated, $limit);
 }
 /**
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = 'lastname', $paginated = false, $limit = null)
 {
     $select = new Select('people');
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             switch ($key) {
                 case 'user_account':
                     if ($value) {
                         $select->where('username is not null');
                     } else {
                         $select->where('username is null');
                     }
                     break;
                 default:
                     $select->where([$key => $value]);
             }
         }
     }
     return parent::performSelect($select, $order, $paginated, $limit);
 }
 /**
  * @param array $fields Key value pairs to select on
  * @param array $order The default ordering to use for select
  * @param int $itemsPerPage
  * @param int $currentPage
  * @return array|Paginator
  */
 public function find($fields = null, $order = ['lastname'], $itemsPerPage = null, $currentPage = null)
 {
     $select = $this->queryFactory->newSelect();
     $select->cols(['p.*'])->from('people as p');
     if (count($fields)) {
         foreach ($fields as $key => $value) {
             switch ($key) {
                 case 'user_account':
                     if ($value) {
                         $select->where('username is not null');
                     } else {
                         $select->where('username is null');
                     }
                     break;
                 default:
                     $select->where("{$key}=?", $value);
             }
         }
     }
     return parent::performSelect($select, $itemsPerPage, $currentPage);
 }
 /**
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param bool $paginated Whether to return a paginator or a raw resultSet
  * @param int $limit
  */
 public function find($fields = null, $order = 'name', $paginated = false, $limit = null)
 {
     return parent::find($fields, $order, $paginated, $limit);
 }
 public function __construct()
 {
     parent::__construct('bookmarks', __NAMESPACE__ . '\\Bookmark');
 }
Example #10
0
 public function __construct()
 {
     parent::__construct('peoplePhones', __NAMESPACE__ . '\\Phone');
 }
 public function __construct()
 {
     parent::__construct('aggregations', __NAMESPACE__ . '\\Aggregation');
 }
Example #12
0
 /**
  * Populates the collection, using regular expressions for matching
  *
  * @param array $fields
  * @param string|array $order Multi-column sort should be given as an array
  * @param int $limit
  * @param string|array $groupBy Multi-column group by should be given as an array
  */
 public function search($fields = null, $order = "people.lastname, people.firstname", $paginated = false, $limit = null)
 {
     $this->select = new Select('people');
     $search = array();
     if (isset($fields['query'])) {
         $value = trim($fields['query']) . '%';
         $this->select->join(['email' => 'peopleEmails'], 'people.id=email.person_id', [], Select::JOIN_LEFT);
         $this->select->where(function (Where $w) use($value) {
             $w->like('people.firstname', $value);
         })->orWhere(function (Where $w) use($value) {
             $w->like('people.lastname', $value);
         })->orWhere(function (Where $w) use($value) {
             $w->like('email.email', $value);
         })->orWhere(function (Where $w) use($value) {
             $w->like('people.username', $value);
         });
     } elseif (count($fields)) {
         $this->prepareJoins($fields);
         foreach ($fields as $key => $value) {
             switch ($key) {
                 case 'user_account':
                     $value ? $this->select->where('username is not null') : $this->select->where('username is null');
                     break;
                 case 'email':
                     $this->select->where(function (Where $w) use($value) {
                         $w->like('email.email', "{$value}%");
                     });
                     break;
                 case 'phoneNumber':
                     $this->select->where(function (Where $w) use($value) {
                         $w->like('phone.number', "{$value}%");
                     });
                     break;
                 case 'phoneDeviceId':
                     $this->select->where(function (Where $w) use($value) {
                         $w->like('phone.deviceId', "{$value}%");
                     });
                     break;
                 case 'department_id':
                     $this->select->where([$key => $value]);
                     break;
                 case 'address':
                 case 'city':
                 case 'state':
                 case 'zip':
                     $this->select->where(function (Where $w) use($key, $value) {
                         $w->like("address.{$key}", "{$value}%");
                     });
                     break;
                 case 'reportedTicket_id':
                     $this->select->where(['i.reportedByPerson_id' => $value]);
                     break;
                 default:
                     if (in_array($key, self::$fields)) {
                         $this->select->where(function (Where $w) use($key, $value) {
                             $w->like("people.{$key}", "{$value}%");
                         });
                     }
             }
         }
     }
     return parent::performSelect($this->select, $order, $paginated, $limit);
 }
Example #13
0
 public function __construct()
 {
     parent::__construct('peopleAddresses', __NAMESPACE__ . '\\Address');
 }
 public function __construct()
 {
     parent::__construct('maps', __NAMESPACE__ . '\\Map');
 }
 public function __construct()
 {
     parent::__construct('aggregatedCalendars', __NAMESPACE__ . '\\AggregatedCalendar');
 }