/** * Constructs a query restricted by the given options. * @param [String => Mixed] $opts * @return \Jenssegers\Mongodb\Eloquent\Builder */ protected function where(Options $opts) { $scopes = $opts->getOpt('scopes'); $query = (new $this->model())->where('lrs_id', new \MongoId($opts->getOpt('lrs_id'))); if (in_array('all', $scopes) || in_array('all/read', $scopes) || in_array('statements/read', $scopes)) { // Get all statements. } else { if (in_array('statements/read/mine', $scopes)) { $query = $query->where('client_id', $opts->getOpt('client')->_id); } else { throw new Exceptions\Exception('Unauthorized request.', 401); } } return $query; }
/** * Returns all of the index options set to their default or given value (using the given options). * @param [String => mixed] $opts Index options. * @return [String => mixed] */ protected function mergeDefaults(array $opts) { // Merges with defaults. $opts = parent::mergeDefaults($opts); // Converts types. $opts['active'] = $this->convertToBoolean($opts['active']); $opts['voided'] = $this->convertToBoolean($opts['voided']); $opts['related_agents'] = $this->convertToBoolean($opts['related_agents']); $opts['related_activities'] = $this->convertToBoolean($opts['related_activities']); $opts['attachments'] = $this->convertToBoolean($opts['attachments']); $opts['ascending'] = $this->convertToBoolean($opts['ascending']); $opts['limit'] = $this->convertToInt($opts['limit']); $opts['offset'] = $this->convertToInt($opts['offset']); if ($opts['limit'] === 0) { $opts['limit'] = 100; } return $opts; }
/** * Gets the directory for attachments with the given options. * @param Options $opts * @return String */ private function getDir(Options $opts) { return $opts->getOpt('lrs_id') . '/attachments/'; }
protected function update(array $conditions, $new_object, Options $opts) { $collection = $this->getCollection(); $baseWheres = ['lrs_id' => new \MongoId($opts->getOpt('lrs_id'))]; $scopes = $opts->getOpt('scopes'); if (in_array('all', $scopes) || in_array('all/read', $scopes) || in_array('statements/read', $scopes)) { // Query all statements. } else { if (in_array('statements/read/mine', $scopes)) { $baseWheres['client_id'] = $opts->getOpt('client')->_id; } else { throw new Exceptions\Exception('Unauthorized request.', 401); } } $criteria = array_merge($baseWheres, $conditions); // Use $set as default operator. if (!starts_with(key($new_object), '$')) { $new_object = array('$set' => $new_object); } return $collection->update($criteria, $new_object, ['multiple' => true]); }
/** * Gets the directory for attachments with the given options. * @param Options $opts * @return String */ private function getDir(Options $opts) { return Helpers::getEnvVar('LOCAL_FILESTORE') . '/' . $opts->getOpt('lrs_id') . '/attachments/'; }