repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
czim/laravel-repository
src/Traits/FindsModelsByTranslationTrait.php
FindsModelsByTranslationTrait.findAllByTranslation
public function findAllByTranslation($attribute, $value, $locale = null, $exact = true) { $this->pushCriteriaOnce( new WhereHasTranslation($attribute, $value, $locale, $exact) ); return $this->all(); }
php
public function findAllByTranslation($attribute, $value, $locale = null, $exact = true) { $this->pushCriteriaOnce( new WhereHasTranslation($attribute, $value, $locale, $exact) ); return $this->all(); }
[ "public", "function", "findAllByTranslation", "(", "$", "attribute", ",", "$", "value", ",", "$", "locale", "=", "null", ",", "$", "exact", "=", "true", ")", "{", "$", "this", "->", "pushCriteriaOnce", "(", "new", "WhereHasTranslation", "(", "$", "attribut...
Finds models by a given translated property @param string $attribute must be translated property! @param string $value @param string $locale @param bool $exact = or LIKE match @return \Illuminate\Support\Collection
[ "Finds", "models", "by", "a", "given", "translated", "property" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Traits/FindsModelsByTranslationTrait.php#L33-L38
train
czim/laravel-repository
src/ExtendedRepository.php
ExtendedRepository.addScope
public function addScope($scope, $parameters = []) { if ( ! in_array($scope, $this->scopes)) { $this->scopes[] = $scope; } $this->scopeParameters[ $scope ] = $parameters; $this->refreshSettingDependentCriteria(); return $this; }
php
public function addScope($scope, $parameters = []) { if ( ! in_array($scope, $this->scopes)) { $this->scopes[] = $scope; } $this->scopeParameters[ $scope ] = $parameters; $this->refreshSettingDependentCriteria(); return $this; }
[ "public", "function", "addScope", "(", "$", "scope", ",", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "!", "in_array", "(", "$", "scope", ",", "$", "this", "->", "scopes", ")", ")", "{", "$", "this", "->", "scopes", "[", "]", "=", "$...
Adds a scope to enforce, overwrites with new parameters if it already exists @param string $scope @param array $parameters @return self
[ "Adds", "a", "scope", "to", "enforce", "overwrites", "with", "new", "parameters", "if", "it", "already", "exists" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedRepository.php#L167-L178
train
czim/laravel-repository
src/ExtendedRepository.php
ExtendedRepository.removeScope
public function removeScope($scope) { $this->scopes = array_diff($this->scopes, [ $scope ]); unset($this->scopeParameters[ $scope ]); $this->refreshSettingDependentCriteria(); return $this; }
php
public function removeScope($scope) { $this->scopes = array_diff($this->scopes, [ $scope ]); unset($this->scopeParameters[ $scope ]); $this->refreshSettingDependentCriteria(); return $this; }
[ "public", "function", "removeScope", "(", "$", "scope", ")", "{", "$", "this", "->", "scopes", "=", "array_diff", "(", "$", "this", "->", "scopes", ",", "[", "$", "scope", "]", ")", ";", "unset", "(", "$", "this", "->", "scopeParameters", "[", "$", ...
Adds a scope to enforce @param string $scope @return self
[ "Adds", "a", "scope", "to", "enforce" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedRepository.php#L186-L194
train
czim/laravel-repository
src/ExtendedRepository.php
ExtendedRepository.convertScopesToCriteriaArray
protected function convertScopesToCriteriaArray() { $scopes = []; foreach ($this->scopes as $scope) { if (array_key_exists($scope, $this->scopeParameters) && ! empty($this->scopeParameters[ $scope ])) { $scopes[] = [ $scope, $this->scopeParameters[ $scope ] ]; continue; } $scopes[] = [ $scope, [] ]; } return $scopes; }
php
protected function convertScopesToCriteriaArray() { $scopes = []; foreach ($this->scopes as $scope) { if (array_key_exists($scope, $this->scopeParameters) && ! empty($this->scopeParameters[ $scope ])) { $scopes[] = [ $scope, $this->scopeParameters[ $scope ] ]; continue; } $scopes[] = [ $scope, [] ]; } return $scopes; }
[ "protected", "function", "convertScopesToCriteriaArray", "(", ")", "{", "$", "scopes", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "scopes", "as", "$", "scope", ")", "{", "if", "(", "array_key_exists", "(", "$", "scope", ",", "$", "this", "-...
Converts the tracked scopes to an array that the Scopes Common Criteria will eat. @return array
[ "Converts", "the", "tracked", "scopes", "to", "an", "array", "that", "the", "Scopes", "Common", "Criteria", "will", "eat", "." ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedRepository.php#L215-L231
train
czim/laravel-repository
src/ExtendedRepository.php
ExtendedRepository.enableCache
public function enableCache($enable = true) { $this->enableCache = (bool) $enable; $this->refreshSettingDependentCriteria(); return $this; }
php
public function enableCache($enable = true) { $this->enableCache = (bool) $enable; $this->refreshSettingDependentCriteria(); return $this; }
[ "public", "function", "enableCache", "(", "$", "enable", "=", "true", ")", "{", "$", "this", "->", "enableCache", "=", "(", "bool", ")", "$", "enable", ";", "$", "this", "->", "refreshSettingDependentCriteria", "(", ")", ";", "return", "$", "this", ";", ...
Enables using the cache for retrieval @param bool $enable @return $this
[ "Enables", "using", "the", "cache", "for", "retrieval" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedRepository.php#L293-L300
train
czim/laravel-repository
src/ExtendedRepository.php
ExtendedRepository.activateRecord
public function activateRecord($id, $active = true) { if ( ! $this->hasActive) return false; $model = $this->makeModel(false); if ( ! ($model = $model->find($id))) return false; $model->{$this->activeColumn} = (boolean) $active; return $model->save(); }
php
public function activateRecord($id, $active = true) { if ( ! $this->hasActive) return false; $model = $this->makeModel(false); if ( ! ($model = $model->find($id))) return false; $model->{$this->activeColumn} = (boolean) $active; return $model->save(); }
[ "public", "function", "activateRecord", "(", "$", "id", ",", "$", "active", "=", "true", ")", "{", "if", "(", "!", "$", "this", "->", "hasActive", ")", "return", "false", ";", "$", "model", "=", "$", "this", "->", "makeModel", "(", "false", ")", ";...
Update the active boolean for a record @param int $id @param boolean $active @return boolean
[ "Update", "the", "active", "boolean", "for", "a", "record" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedRepository.php#L334-L345
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.makeModel
public function makeModel($storeModel = true) { $model = $this->app->make($this->model()); if ( ! $model instanceof Model) { throw new RepositoryException("Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model"); } if ($storeModel) $this->model = $model; return $model; }
php
public function makeModel($storeModel = true) { $model = $this->app->make($this->model()); if ( ! $model instanceof Model) { throw new RepositoryException("Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model"); } if ($storeModel) $this->model = $model; return $model; }
[ "public", "function", "makeModel", "(", "$", "storeModel", "=", "true", ")", "{", "$", "model", "=", "$", "this", "->", "app", "->", "make", "(", "$", "this", "->", "model", "(", ")", ")", ";", "if", "(", "!", "$", "model", "instanceof", "Model", ...
Creates instance of model to start building query for @param bool $storeModel if true, this becomes a fresh $this->model property @return Model @throws RepositoryException
[ "Creates", "instance", "of", "model", "to", "start", "building", "query", "for" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L116-L127
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.query
public function query() { $this->applyCriteria(); if ($this->model instanceof Model) { return $this->model->query(); } return clone $this->model; }
php
public function query() { $this->applyCriteria(); if ($this->model instanceof Model) { return $this->model->query(); } return clone $this->model; }
[ "public", "function", "query", "(", ")", "{", "$", "this", "->", "applyCriteria", "(", ")", ";", "if", "(", "$", "this", "->", "model", "instanceof", "Model", ")", "{", "return", "$", "this", "->", "model", "->", "query", "(", ")", ";", "}", "retur...
Give unexecuted query for current criteria @return EloquentBuilder
[ "Give", "unexecuted", "query", "for", "current", "criteria" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L139-L148
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.firstOrFail
public function firstOrFail($columns = ['*']) { $result = $this->query()->first($columns); if ( ! empty($result)) return $result; throw (new ModelNotFoundException)->setModel($this->model()); }
php
public function firstOrFail($columns = ['*']) { $result = $this->query()->first($columns); if ( ! empty($result)) return $result; throw (new ModelNotFoundException)->setModel($this->model()); }
[ "public", "function", "firstOrFail", "(", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "query", "(", ")", "->", "first", "(", "$", "columns", ")", ";", "if", "(", "!", "empty", "(", "$", "result", ")", ...
Returns first match or throws exception if not found @param array $columns @return Model @throws ModelNotFoundException
[ "Returns", "first", "match", "or", "throws", "exception", "if", "not", "found" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L178-L185
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.findWhere
public function findWhere($where, $columns = ['*'], $or = false) { $model = $this->query(); foreach ($where as $field => $value) { if ($value instanceof Closure) { $model = ( ! $or) ? $model->where($value) : $model->orWhere($value); } elseif (is_array($value)) { if (count($value) === 3) { list($field, $operator, $search) = $value; $model = ( ! $or) ? $model->where($field, $operator, $search) : $model->orWhere($field, $operator, $search); } elseif (count($value) === 2) { list($field, $search) = $value; $model = ( ! $or) ? $model->where($field, $search) : $model->orWhere($field, $search); } } else { $model = ( ! $or) ? $model->where($field, $value) : $model->orWhere($field, $value); } } return $model->get($columns); }
php
public function findWhere($where, $columns = ['*'], $or = false) { $model = $this->query(); foreach ($where as $field => $value) { if ($value instanceof Closure) { $model = ( ! $or) ? $model->where($value) : $model->orWhere($value); } elseif (is_array($value)) { if (count($value) === 3) { list($field, $operator, $search) = $value; $model = ( ! $or) ? $model->where($field, $operator, $search) : $model->orWhere($field, $operator, $search); } elseif (count($value) === 2) { list($field, $search) = $value; $model = ( ! $or) ? $model->where($field, $search) : $model->orWhere($field, $search); } } else { $model = ( ! $or) ? $model->where($field, $value) : $model->orWhere($field, $value); } } return $model->get($columns); }
[ "public", "function", "findWhere", "(", "$", "where", ",", "$", "columns", "=", "[", "'*'", "]", ",", "$", "or", "=", "false", ")", "{", "$", "model", "=", "$", "this", "->", "query", "(", ")", ";", "foreach", "(", "$", "where", "as", "$", "fie...
Find a collection of models by the given query conditions. @param array|Arrayable $where @param array $columns @param bool $or @return Collection|null
[ "Find", "a", "collection", "of", "models", "by", "the", "given", "query", "conditions", "." ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L306-L345
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.update
public function update(array $data, $id, $attribute = null) { $model = $this->find($id, ['*'], $attribute); if (empty($model)) return false; return $model->fill($data)->save(); }
php
public function update(array $data, $id, $attribute = null) { $model = $this->find($id, ['*'], $attribute); if (empty($model)) return false; return $model->fill($data)->save(); }
[ "public", "function", "update", "(", "array", "$", "data", ",", "$", "id", ",", "$", "attribute", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "find", "(", "$", "id", ",", "[", "'*'", "]", ",", "$", "attribute", ")", ";", "if", ...
Updates a model by id @param array $data @param mixed $id @param string $attribute @return bool false if could not find model or not succesful in updating
[ "Updates", "a", "model", "by", "id" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L383-L390
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.fill
public function fill(array $data, $id, $attribute = null) { $model = $this->find($id, ['*'], $attribute); if (empty($model)) { throw (new ModelNotFoundException)->setModel($this->model()); } return $model->fill($data); }
php
public function fill(array $data, $id, $attribute = null) { $model = $this->find($id, ['*'], $attribute); if (empty($model)) { throw (new ModelNotFoundException)->setModel($this->model()); } return $model->fill($data); }
[ "public", "function", "fill", "(", "array", "$", "data", ",", "$", "id", ",", "$", "attribute", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "find", "(", "$", "id", ",", "[", "'*'", "]", ",", "$", "attribute", ")", ";", "if", ...
Finds and fills a model by id, without persisting changes @param array $data @param mixed $id @param string $attribute @return Model|false @throws \Illuminate\Database\Eloquent\MassAssignmentException
[ "Finds", "and", "fills", "a", "model", "by", "id", "without", "persisting", "changes" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L401-L410
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.getCriteriaToApply
protected function getCriteriaToApply() { // get the standard criteria $criteriaToApply = $this->getCriteria(); // overrule them with criteria to be applied once if ( ! $this->onceCriteria->isEmpty()) { foreach ($this->onceCriteria as $onceKey => $onceCriteria) { // if there is no key, we can only add the criteria if (is_numeric($onceKey)) { $criteriaToApply->push($onceCriteria); continue; } // if there is a key, override or remove // if Null, remove criteria if (empty($onceCriteria) || is_a($onceCriteria, NullCriteria::class)) { $criteriaToApply->forget($onceKey); continue; } // otherwise, overide the criteria $criteriaToApply->put($onceKey, $onceCriteria); } } return $criteriaToApply; }
php
protected function getCriteriaToApply() { // get the standard criteria $criteriaToApply = $this->getCriteria(); // overrule them with criteria to be applied once if ( ! $this->onceCriteria->isEmpty()) { foreach ($this->onceCriteria as $onceKey => $onceCriteria) { // if there is no key, we can only add the criteria if (is_numeric($onceKey)) { $criteriaToApply->push($onceCriteria); continue; } // if there is a key, override or remove // if Null, remove criteria if (empty($onceCriteria) || is_a($onceCriteria, NullCriteria::class)) { $criteriaToApply->forget($onceKey); continue; } // otherwise, overide the criteria $criteriaToApply->put($onceKey, $onceCriteria); } } return $criteriaToApply; }
[ "protected", "function", "getCriteriaToApply", "(", ")", "{", "// get the standard criteria", "$", "criteriaToApply", "=", "$", "this", "->", "getCriteria", "(", ")", ";", "// overrule them with criteria to be applied once", "if", "(", "!", "$", "this", "->", "onceCri...
Returns the criteria that must be applied for the next query @return Collection
[ "Returns", "the", "criteria", "that", "must", "be", "applied", "for", "the", "next", "query" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L561-L592
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.applyCriteria
public function applyCriteria() { // if we're ignoring criteria, the model must be remade without criteria if ($this->ignoreCriteria === true) { // and make sure that they are re-applied when we stop ignoring if ( ! $this->activeCriteria->isEmpty()) { $this->makeModel(); $this->activeCriteria = new Collection(); } return $this; } if ($this->areActiveCriteriaUnchanged()) return $this; // if the new Criteria are different, clear the model and apply the new Criteria $this->makeModel(); $this->markAppliedCriteriaAsActive(); // apply the collected criteria to the query foreach ($this->getCriteriaToApply() as $criteria) { if ($criteria instanceof CriteriaInterface) { $this->model = $criteria->apply($this->model, $this); } } $this->clearOnceCriteria(); return $this; }
php
public function applyCriteria() { // if we're ignoring criteria, the model must be remade without criteria if ($this->ignoreCriteria === true) { // and make sure that they are re-applied when we stop ignoring if ( ! $this->activeCriteria->isEmpty()) { $this->makeModel(); $this->activeCriteria = new Collection(); } return $this; } if ($this->areActiveCriteriaUnchanged()) return $this; // if the new Criteria are different, clear the model and apply the new Criteria $this->makeModel(); $this->markAppliedCriteriaAsActive(); // apply the collected criteria to the query foreach ($this->getCriteriaToApply() as $criteria) { if ($criteria instanceof CriteriaInterface) { $this->model = $criteria->apply($this->model, $this); } } $this->clearOnceCriteria(); return $this; }
[ "public", "function", "applyCriteria", "(", ")", "{", "// if we're ignoring criteria, the model must be remade without criteria", "if", "(", "$", "this", "->", "ignoreCriteria", "===", "true", ")", "{", "// and make sure that they are re-applied when we stop ignoring", "if", "(...
Applies Criteria to the model for the upcoming query This takes the default/standard Criteria, then overrides them with whatever is found in the onceCriteria list @return $this
[ "Applies", "Criteria", "to", "the", "model", "for", "the", "upcoming", "query" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L602-L635
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.pushCriteria
public function pushCriteria(CriteriaInterface $criteria, $key = null) { // standard bosnadev behavior if (is_null($key)) { $this->criteria->push($criteria); return $this; } // set/override by key $this->criteria->put($key, $criteria); return $this; }
php
public function pushCriteria(CriteriaInterface $criteria, $key = null) { // standard bosnadev behavior if (is_null($key)) { $this->criteria->push($criteria); return $this; } // set/override by key $this->criteria->put($key, $criteria); return $this; }
[ "public", "function", "pushCriteria", "(", "CriteriaInterface", "$", "criteria", ",", "$", "key", "=", "null", ")", "{", "// standard bosnadev behavior", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "$", "this", "->", "criteria", "->", "push", "("...
Pushes Criteria, optionally by identifying key If a criteria already exists for the key, it is overridden Note that this does NOT overrule any onceCriteria, even if set by key! @param CriteriaInterface $criteria @param string $key unique identifier to store criteria as this may be used to remove and overwrite criteria empty for normal automatic numeric key @return $this
[ "Pushes", "Criteria", "optionally", "by", "identifying", "key", "If", "a", "criteria", "already", "exists", "for", "the", "key", "it", "is", "overridden" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L681-L694
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.pushCriteriaOnce
public function pushCriteriaOnce(CriteriaInterface $criteria, $key = null) { if (is_null($key)) { $this->onceCriteria->push($criteria); return $this; } // set/override by key $this->onceCriteria->put($key, $criteria); return $this; }
php
public function pushCriteriaOnce(CriteriaInterface $criteria, $key = null) { if (is_null($key)) { $this->onceCriteria->push($criteria); return $this; } // set/override by key $this->onceCriteria->put($key, $criteria); return $this; }
[ "public", "function", "pushCriteriaOnce", "(", "CriteriaInterface", "$", "criteria", ",", "$", "key", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "$", "this", "->", "onceCriteria", "->", "push", "(", "$", "criteria", ")...
Pushes Criteria, but only for the next call, resets to default afterwards Note that this does NOT work for specific criteria exclusively, it resets to default for ALL Criteria. @param CriteriaInterface $criteria @param string $key @return $this
[ "Pushes", "Criteria", "but", "only", "for", "the", "next", "call", "resets", "to", "default", "afterwards", "Note", "that", "this", "does", "NOT", "work", "for", "specific", "criteria", "exclusively", "it", "resets", "to", "default", "for", "ALL", "Criteria", ...
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L718-L730
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.removeCriteriaOnce
public function removeCriteriaOnce($key) { // if not present in normal list, there is nothing to override if ( ! $this->criteria->has($key)) return $this; // override by key with Null-value $this->onceCriteria->put($key, new NullCriteria); return $this; }
php
public function removeCriteriaOnce($key) { // if not present in normal list, there is nothing to override if ( ! $this->criteria->has($key)) return $this; // override by key with Null-value $this->onceCriteria->put($key, new NullCriteria); return $this; }
[ "public", "function", "removeCriteriaOnce", "(", "$", "key", ")", "{", "// if not present in normal list, there is nothing to override", "if", "(", "!", "$", "this", "->", "criteria", "->", "has", "(", "$", "key", ")", ")", "return", "$", "this", ";", "// overri...
Removes Criteria, but only for the next call, resets to default afterwards Note that this does NOT work for specific criteria exclusively, it resets to default for ALL Criteria. In effect, this adds a NullCriteria to onceCriteria by key, disabling any criteria by that key in the normal criteria list. @param string $key @return $this
[ "Removes", "Criteria", "but", "only", "for", "the", "next", "call", "resets", "to", "default", "afterwards", "Note", "that", "this", "does", "NOT", "work", "for", "specific", "criteria", "exclusively", "it", "resets", "to", "default", "for", "ALL", "Criteria",...
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L744-L753
train
czim/laravel-repository
src/BaseRepository.php
BaseRepository.getDefaultPerPage
protected function getDefaultPerPage() { if (is_numeric($this->perPage) && $this->perPage > 0) { return $this->perPage; } return config('repository.perPage', $this->makeModel(false)->getPerPage()); }
php
protected function getDefaultPerPage() { if (is_numeric($this->perPage) && $this->perPage > 0) { return $this->perPage; } return config('repository.perPage', $this->makeModel(false)->getPerPage()); }
[ "protected", "function", "getDefaultPerPage", "(", ")", "{", "if", "(", "is_numeric", "(", "$", "this", "->", "perPage", ")", "&&", "$", "this", "->", "perPage", ">", "0", ")", "{", "return", "$", "this", "->", "perPage", ";", "}", "return", "config", ...
Returns default per page count. @return int
[ "Returns", "default", "per", "page", "count", "." ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/BaseRepository.php#L765-L772
train
czim/laravel-repository
src/Traits/HandlesEloquentRelationManipulationTrait.php
HandlesEloquentRelationManipulationTrait.sync
public function sync(Model $model, $relation, $ids, $detaching = true) { return $model->{$relation}()->sync($ids, $detaching); }
php
public function sync(Model $model, $relation, $ids, $detaching = true) { return $model->{$relation}()->sync($ids, $detaching); }
[ "public", "function", "sync", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "ids", ",", "$", "detaching", "=", "true", ")", "{", "return", "$", "model", "->", "{", "$", "relation", "}", "(", ")", "->", "sync", "(", "$", "ids", ",", ...
Executes a sync on the model provided @param Model $model @param string $relation name of the relation (method name) @param array $ids list of id's to connect to @param bool $detaching @return
[ "Executes", "a", "sync", "on", "the", "model", "provided" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Traits/HandlesEloquentRelationManipulationTrait.php#L22-L25
train
czim/laravel-repository
src/Traits/HandlesEloquentRelationManipulationTrait.php
HandlesEloquentRelationManipulationTrait.attach
public function attach(Model $model, $relation, $id, array $attributes = array(), $touch = true) { return $model->{$relation}()->attach($id, $attributes, $touch); }
php
public function attach(Model $model, $relation, $id, array $attributes = array(), $touch = true) { return $model->{$relation}()->attach($id, $attributes, $touch); }
[ "public", "function", "attach", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "id", ",", "array", "$", "attributes", "=", "array", "(", ")", ",", "$", "touch", "=", "true", ")", "{", "return", "$", "model", "->", "{", "$", "relation",...
Executes an attach on the model provided @param Model $model @param string $relation name of the relation (method name) @param int $id @param array $attributes @param boolean $touch
[ "Executes", "an", "attach", "on", "the", "model", "provided" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Traits/HandlesEloquentRelationManipulationTrait.php#L36-L39
train
czim/laravel-repository
src/Traits/HandlesEloquentRelationManipulationTrait.php
HandlesEloquentRelationManipulationTrait.detach
public function detach(Model $model, $relation, $ids = array(), $touch = true) { return $model->{$relation}()->detach($ids, $touch); }
php
public function detach(Model $model, $relation, $ids = array(), $touch = true) { return $model->{$relation}()->detach($ids, $touch); }
[ "public", "function", "detach", "(", "Model", "$", "model", ",", "$", "relation", ",", "$", "ids", "=", "array", "(", ")", ",", "$", "touch", "=", "true", ")", "{", "return", "$", "model", "->", "{", "$", "relation", "}", "(", ")", "->", "detach"...
Executes a detach on the model provided @param Model $model @param string $relation name of the relation (method name) @param array $ids @param boolean $touch @return @internal param array $attributes
[ "Executes", "a", "detach", "on", "the", "model", "provided" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Traits/HandlesEloquentRelationManipulationTrait.php#L51-L54
train
czim/laravel-repository
src/Traits/HandlesListifyModelsTrait.php
HandlesListifyModelsTrait.updatePosition
public function updatePosition($id, $newPosition = 1) { $model = $this->makeModel(false); if ( ! ($model = $model->find($id))) { return false; } $this->checkModelHasListify($model); /** @var ListifyInterface $model */ $model->setListPosition( (int) $newPosition ); return $model; }
php
public function updatePosition($id, $newPosition = 1) { $model = $this->makeModel(false); if ( ! ($model = $model->find($id))) { return false; } $this->checkModelHasListify($model); /** @var ListifyInterface $model */ $model->setListPosition( (int) $newPosition ); return $model; }
[ "public", "function", "updatePosition", "(", "$", "id", ",", "$", "newPosition", "=", "1", ")", "{", "$", "model", "=", "$", "this", "->", "makeModel", "(", "false", ")", ";", "if", "(", "!", "(", "$", "model", "=", "$", "model", "->", "find", "(...
Updates the position for a record using Listify @param int $id @param int $newPosition default: top spot @return boolean
[ "Updates", "the", "position", "for", "a", "record", "using", "Listify" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Traits/HandlesListifyModelsTrait.php#L15-L29
train
czim/laravel-repository
src/ExtendedPostProcessingRepository.php
ExtendedPostProcessingRepository.postProcess
public function postProcess($result) { // determine whether there is anything to process if ( is_null($result) || is_a($result, Collection::class) && $result->isEmpty() ) { return $result; } // check if there is anything to do process it through if ($this->postProcessors->isEmpty()) return $result; // for each Model, instantiate and apply the processors if (is_a($result, Collection::class)) { $result->transform(function ($model) { return $this->applyPostProcessorsToModel($model); }); } elseif (is_a($result, AbstractPaginator::class)) { // result is paginate() result // do not apply postprocessing for now (how would we even do it?) return $result; } else { // result is a model $result = $this->applyPostProcessorsToModel($result); } return $result; }
php
public function postProcess($result) { // determine whether there is anything to process if ( is_null($result) || is_a($result, Collection::class) && $result->isEmpty() ) { return $result; } // check if there is anything to do process it through if ($this->postProcessors->isEmpty()) return $result; // for each Model, instantiate and apply the processors if (is_a($result, Collection::class)) { $result->transform(function ($model) { return $this->applyPostProcessorsToModel($model); }); } elseif (is_a($result, AbstractPaginator::class)) { // result is paginate() result // do not apply postprocessing for now (how would we even do it?) return $result; } else { // result is a model $result = $this->applyPostProcessorsToModel($result); } return $result; }
[ "public", "function", "postProcess", "(", "$", "result", ")", "{", "// determine whether there is anything to process", "if", "(", "is_null", "(", "$", "result", ")", "||", "is_a", "(", "$", "result", ",", "Collection", "::", "class", ")", "&&", "$", "result",...
Runs the result for retrieval calls to the repository through postprocessing. @param Collection|Model|null $result the result of the query, ready for postprocessing @return Model|Collection|null
[ "Runs", "the", "result", "for", "retrieval", "calls", "to", "the", "repository", "through", "postprocessing", "." ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedPostProcessingRepository.php#L131-L162
train
czim/laravel-repository
src/ExtendedPostProcessingRepository.php
ExtendedPostProcessingRepository.applyPostProcessorsToModel
protected function applyPostProcessorsToModel(Model $model) { foreach ($this->postProcessors as $processorClass => $parameters) { // if a processor class was added as a value instead of a key, it // does not have parameters if (is_numeric($processorClass)) { $processorClass = $parameters; $parameters = null; } $processor = $this->makePostProcessor($processorClass, $parameters); $model = $processor->process($model); } return $model; }
php
protected function applyPostProcessorsToModel(Model $model) { foreach ($this->postProcessors as $processorClass => $parameters) { // if a processor class was added as a value instead of a key, it // does not have parameters if (is_numeric($processorClass)) { $processorClass = $parameters; $parameters = null; } $processor = $this->makePostProcessor($processorClass, $parameters); $model = $processor->process($model); } return $model; }
[ "protected", "function", "applyPostProcessorsToModel", "(", "Model", "$", "model", ")", "{", "foreach", "(", "$", "this", "->", "postProcessors", "as", "$", "processorClass", "=>", "$", "parameters", ")", "{", "// if a processor class was added as a value instead of a k...
Applies the currently active postprocessors to a model @param Model $model @return Model
[ "Applies", "the", "currently", "active", "postprocessors", "to", "a", "model" ]
5f75a39a1b881f7511d355fe6a5ce07f2101b282
https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/ExtendedPostProcessingRepository.php#L170-L187
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.getBagInfo
function getBagInfo() { $major = $this->bagVersion['major']; $minor = $this->bagVersion['minor']; $info = array( 'version' => "$major.$minor", 'encoding' => $this->tagFileEncoding, 'hash' => $this->getHashEncoding() ); return $info; }
php
function getBagInfo() { $major = $this->bagVersion['major']; $minor = $this->bagVersion['minor']; $info = array( 'version' => "$major.$minor", 'encoding' => $this->tagFileEncoding, 'hash' => $this->getHashEncoding() ); return $info; }
[ "function", "getBagInfo", "(", ")", "{", "$", "major", "=", "$", "this", "->", "bagVersion", "[", "'major'", "]", ";", "$", "minor", "=", "$", "this", "->", "bagVersion", "[", "'minor'", "]", ";", "$", "info", "=", "array", "(", "'version'", "=>", ...
Return the info keys @return array A dictionary array containing these keys: 'version', 'encoding', 'hash'.
[ "Return", "the", "info", "keys" ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L252-L263
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.setHashEncoding
function setHashEncoding($hashAlgorithm) { $hashAlgorithm = strtolower($hashAlgorithm); if ($hashAlgorithm != 'md5' && $hashAlgorithm != 'sha1') { throw new InvalidArgumentException("Invalid hash algorithim: '$hashAlgorithm'."); } $this->manifest->setHashEncoding($hashAlgorithm); if ($this->tagManifest !== null) { $this->tagManifest->setHashEncoding($hashAlgorithm); } }
php
function setHashEncoding($hashAlgorithm) { $hashAlgorithm = strtolower($hashAlgorithm); if ($hashAlgorithm != 'md5' && $hashAlgorithm != 'sha1') { throw new InvalidArgumentException("Invalid hash algorithim: '$hashAlgorithm'."); } $this->manifest->setHashEncoding($hashAlgorithm); if ($this->tagManifest !== null) { $this->tagManifest->setHashEncoding($hashAlgorithm); } }
[ "function", "setHashEncoding", "(", "$", "hashAlgorithm", ")", "{", "$", "hashAlgorithm", "=", "strtolower", "(", "$", "hashAlgorithm", ")", ";", "if", "(", "$", "hashAlgorithm", "!=", "'md5'", "&&", "$", "hashAlgorithm", "!=", "'sha1'", ")", "{", "throw", ...
Sets the bag's checksum hash algorithm. @param string $hashAlgorithm The bag's checksum hash algorithm. Must be either 'sha1' or 'md5'. @return void
[ "Sets", "the", "bag", "s", "checksum", "hash", "algorithm", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L293-L304
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.validate
function validate() { $errors = array(); BagIt_validateExists($this->bagitFile, $errors); BagIt_validateExists($this->getDataDirectory(), $errors); $this->manifest->validate($errors); $this->bagErrors = $errors; return $this->bagErrors; }
php
function validate() { $errors = array(); BagIt_validateExists($this->bagitFile, $errors); BagIt_validateExists($this->getDataDirectory(), $errors); $this->manifest->validate($errors); $this->bagErrors = $errors; return $this->bagErrors; }
[ "function", "validate", "(", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "BagIt_validateExists", "(", "$", "this", "->", "bagitFile", ",", "$", "errors", ")", ";", "BagIt_validateExists", "(", "$", "this", "->", "getDataDirectory", "(", ")", ",...
Runs the bag validator on the contents of the bag. This verifies the presence of required iles and folders and verifies the checksum for each file. For the results of validation, check isValid() and getBagErrors(). @return array The list of bag errors.
[ "Runs", "the", "bag", "validator", "on", "the", "contents", "of", "the", "bag", ".", "This", "verifies", "the", "presence", "of", "required", "iles", "and", "folders", "and", "verifies", "the", "checksum", "for", "each", "file", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L342-L352
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.addFile
function addFile($src, $dest) { $dataPref = 'data' . DIRECTORY_SEPARATOR; $prefLen = strlen($dataPref); if ((strncasecmp($dest, $dataPref, $prefLen) != 0) && (strncasecmp($dest, $dataPref, $prefLen) != 0) ) { $dest = $dataPref . $dest; } $fulldest = "{$this->bagDirectory}/$dest"; $dirname = dirname($fulldest); if (! is_dir($dirname)) { mkdir($dirname, 0777, true); } copy($src, $fulldest); }
php
function addFile($src, $dest) { $dataPref = 'data' . DIRECTORY_SEPARATOR; $prefLen = strlen($dataPref); if ((strncasecmp($dest, $dataPref, $prefLen) != 0) && (strncasecmp($dest, $dataPref, $prefLen) != 0) ) { $dest = $dataPref . $dest; } $fulldest = "{$this->bagDirectory}/$dest"; $dirname = dirname($fulldest); if (! is_dir($dirname)) { mkdir($dirname, 0777, true); } copy($src, $fulldest); }
[ "function", "addFile", "(", "$", "src", ",", "$", "dest", ")", "{", "$", "dataPref", "=", "'data'", ".", "DIRECTORY_SEPARATOR", ";", "$", "prefLen", "=", "strlen", "(", "$", "dataPref", ")", ";", "if", "(", "(", "strncasecmp", "(", "$", "dest", ",", ...
This copies the file specified into the bag at the place given. $dest should begin with "data/", but if it doesn't that will be added. @param string $src The file name for the source file. @param string $dest The file name for the destination file. This should be relative to the bag directory. @return void
[ "This", "copies", "the", "file", "specified", "into", "the", "bag", "at", "the", "place", "given", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L422-L439
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.package
function package($destination, $method='tgz') { $method = strtolower($method); if ($method != 'zip' && $method != 'tgz') { throw new BagItException("Invalid compression method: '$method'."); } if (substr_compare($destination, ".$method", -4, 4, true) != 0) { $destination = "$destination.$method"; } BagIt_compressBag( $this->bagDirectory, $destination, $method ); }
php
function package($destination, $method='tgz') { $method = strtolower($method); if ($method != 'zip' && $method != 'tgz') { throw new BagItException("Invalid compression method: '$method'."); } if (substr_compare($destination, ".$method", -4, 4, true) != 0) { $destination = "$destination.$method"; } BagIt_compressBag( $this->bagDirectory, $destination, $method ); }
[ "function", "package", "(", "$", "destination", ",", "$", "method", "=", "'tgz'", ")", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "if", "(", "$", "method", "!=", "'zip'", "&&", "$", "method", "!=", "'tgz'", ")", "{", "thro...
Compresses the bag into a file. @param string $destination The file to put the bag into. @param string $method Either 'tgz' or 'zip'. Default is 'tgz'. @return void
[ "Compresses", "the", "bag", "into", "a", "file", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L483-L499
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.setBagInfoData
public function setBagInfoData($key, $value) { $this->_ensureBagInfoData(); $this->bagInfoData[$key] = BagIt_getAccumulatedValue( $this->bagInfoData, $key, $value ); }
php
public function setBagInfoData($key, $value) { $this->_ensureBagInfoData(); $this->bagInfoData[$key] = BagIt_getAccumulatedValue( $this->bagInfoData, $key, $value ); }
[ "public", "function", "setBagInfoData", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "_ensureBagInfoData", "(", ")", ";", "$", "this", "->", "bagInfoData", "[", "$", "key", "]", "=", "BagIt_getAccumulatedValue", "(", "$", "this", "->"...
This inserts a value into bagInfoData. @param string $key This is the key to insert into the data. @param string $value This is the value to associate with the key. @return void @author Eric Rochester <erochest@virginia.edu>
[ "This", "inserts", "a", "value", "into", "bagInfoData", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L524-L530
train
scholarslab/BagItPHP
lib/bagit.php
BagIt.getBagInfoData
public function getBagInfoData($key) { $this->_ensureBagInfoData(); return array_key_exists($key, $this->bagInfoData) ? $this->bagInfoData[$key] : null; }
php
public function getBagInfoData($key) { $this->_ensureBagInfoData(); return array_key_exists($key, $this->bagInfoData) ? $this->bagInfoData[$key] : null; }
[ "public", "function", "getBagInfoData", "(", "$", "key", ")", "{", "$", "this", "->", "_ensureBagInfoData", "(", ")", ";", "return", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "bagInfoData", ")", "?", "$", "this", "->", "bagInfoData", "...
This returns the value for a key from bagInfoData. @param string $key This is the key to get the value associated with. @return string|null @author Eric Rochester <erochest@virginia.edu>
[ "This", "returns", "the", "value", "for", "a", "key", "from", "bagInfoData", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L555-L559
train
scholarslab/BagItPHP
lib/bagit.php
BagIt._createExtendedBag
private function _createExtendedBag() { if ($this->extended) { $hashEncoding = $this->getHashEncoding(); $this->tagManifest = new BagItManifest( "{$this->bagDirectory}/tagmanifest-$hashEncoding.txt", $this->bagDirectory . '/', $this->tagFileEncoding ); $fetchFile = $this->bagDirectory . '/fetch.txt'; $this->fetch = new BagItFetch($fetchFile, $this->tagFileEncoding); $this->bagInfoFile = $this->bagDirectory . '/bag-info.txt'; touch($this->bagInfoFile); if (is_null($this->bagInfoData)) { $this->bagInfoData = array(); } } }
php
private function _createExtendedBag() { if ($this->extended) { $hashEncoding = $this->getHashEncoding(); $this->tagManifest = new BagItManifest( "{$this->bagDirectory}/tagmanifest-$hashEncoding.txt", $this->bagDirectory . '/', $this->tagFileEncoding ); $fetchFile = $this->bagDirectory . '/fetch.txt'; $this->fetch = new BagItFetch($fetchFile, $this->tagFileEncoding); $this->bagInfoFile = $this->bagDirectory . '/bag-info.txt'; touch($this->bagInfoFile); if (is_null($this->bagInfoData)) { $this->bagInfoData = array(); } } }
[ "private", "function", "_createExtendedBag", "(", ")", "{", "if", "(", "$", "this", "->", "extended", ")", "{", "$", "hashEncoding", "=", "$", "this", "->", "getHashEncoding", "(", ")", ";", "$", "this", "->", "tagManifest", "=", "new", "BagItManifest", ...
This creates the files for an extended bag. @return void
[ "This", "creates", "the", "files", "for", "an", "extended", "bag", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L675-L694
train
scholarslab/BagItPHP
lib/bagit.php
BagIt._readBagInfo
private function _readBagInfo() { try { $lines = readLines($this->bagInfoFile, $this->tagFileEncoding); $this->bagInfoData = BagIt_parseBagInfo($lines); } catch (Exception $exc) { array_push( $this->bagErrors, array('baginfo', 'Error reading bag info file.') ); } }
php
private function _readBagInfo() { try { $lines = readLines($this->bagInfoFile, $this->tagFileEncoding); $this->bagInfoData = BagIt_parseBagInfo($lines); } catch (Exception $exc) { array_push( $this->bagErrors, array('baginfo', 'Error reading bag info file.') ); } }
[ "private", "function", "_readBagInfo", "(", ")", "{", "try", "{", "$", "lines", "=", "readLines", "(", "$", "this", "->", "bagInfoFile", ",", "$", "this", "->", "tagFileEncoding", ")", ";", "$", "this", "->", "bagInfoData", "=", "BagIt_parseBagInfo", "(", ...
This reads the bag-info.txt file into an array dictionary. @return void
[ "This", "reads", "the", "bag", "-", "info", ".", "txt", "file", "into", "an", "array", "dictionary", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L701-L712
train
scholarslab/BagItPHP
lib/bagit.php
BagIt._writeBagInfo
private function _writeBagInfo() { $lines = array(); if (count($this->bagInfoData)) { foreach ($this->bagInfoData as $label => $value) { if (is_array($value)) { foreach ($value as $v) { $lines[] = "$label: $v\n"; } } else { $lines[] = "$label: $value\n"; } } } writeFileText($this->bagInfoFile, $this->tagFileEncoding, join('', $lines)); }
php
private function _writeBagInfo() { $lines = array(); if (count($this->bagInfoData)) { foreach ($this->bagInfoData as $label => $value) { if (is_array($value)) { foreach ($value as $v) { $lines[] = "$label: $v\n"; } } else { $lines[] = "$label: $value\n"; } } } writeFileText($this->bagInfoFile, $this->tagFileEncoding, join('', $lines)); }
[ "private", "function", "_writeBagInfo", "(", ")", "{", "$", "lines", "=", "array", "(", ")", ";", "if", "(", "count", "(", "$", "this", "->", "bagInfoData", ")", ")", "{", "foreach", "(", "$", "this", "->", "bagInfoData", "as", "$", "label", "=>", ...
This writes the bag-info.txt file with the contents of bagInfoData. @return void @author Eric Rochester <erochest@virginia.edu>
[ "This", "writes", "the", "bag", "-", "info", ".", "txt", "file", "with", "the", "contents", "of", "bagInfoData", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L720-L737
train
scholarslab/BagItPHP
lib/bagit.php
BagIt._isCompressed
private function _isCompressed() { if (is_dir($this->bag)) { return false; } else { $bag = strtolower($this->bag); if (endsWith($bag, '.zip')) { $this->bagCompression = 'zip'; return true; } else if (endsWith($bag, '.tar.gz') || endsWith($bag, '.tgz')) { $this->bagCompression = 'tgz'; return true; } } return false; }
php
private function _isCompressed() { if (is_dir($this->bag)) { return false; } else { $bag = strtolower($this->bag); if (endsWith($bag, '.zip')) { $this->bagCompression = 'zip'; return true; } else if (endsWith($bag, '.tar.gz') || endsWith($bag, '.tgz')) { $this->bagCompression = 'tgz'; return true; } } return false; }
[ "private", "function", "_isCompressed", "(", ")", "{", "if", "(", "is_dir", "(", "$", "this", "->", "bag", ")", ")", "{", "return", "false", ";", "}", "else", "{", "$", "bag", "=", "strtolower", "(", "$", "this", "->", "bag", ")", ";", "if", "(",...
Tests if a bag is compressed @return True if this is a compressed bag.
[ "Tests", "if", "a", "bag", "is", "compressed" ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit.php#L744-L759
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest.read
public function read($fileName=null) { $this->_resetFileName($fileName); $manifest = array(); $hashLen = ($this->hashEncoding == 'sha1') ? 40 : 32; $lines = readLines($this->fileName, $this->fileEncoding); foreach ($lines as $line) { $hash = trim(substr($line, 0, $hashLen)); $payload = trim(substr($line, $hashLen)); if (strlen($payload) > 0) { $manifest[$payload] = $hash; } } $this->data = $manifest; return $manifest; }
php
public function read($fileName=null) { $this->_resetFileName($fileName); $manifest = array(); $hashLen = ($this->hashEncoding == 'sha1') ? 40 : 32; $lines = readLines($this->fileName, $this->fileEncoding); foreach ($lines as $line) { $hash = trim(substr($line, 0, $hashLen)); $payload = trim(substr($line, $hashLen)); if (strlen($payload) > 0) { $manifest[$payload] = $hash; } } $this->data = $manifest; return $manifest; }
[ "public", "function", "read", "(", "$", "fileName", "=", "null", ")", "{", "$", "this", "->", "_resetFileName", "(", "$", "fileName", ")", ";", "$", "manifest", "=", "array", "(", ")", ";", "$", "hashLen", "=", "(", "$", "this", "->", "hashEncoding",...
This reads the data from the file name. @param string $fileName This is the file name to read. It defaults to the current value of the $fileName property. If given, it will set the value of the property also. @return array The data read.
[ "This", "reads", "the", "data", "from", "the", "file", "name", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L126-L145
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest.update
public function update($fileList) { $csums = array(); foreach ($fileList as $file) { if (file_exists($file)) { $hash = $this->calculateHash($file); $csums[$this->_makeRelative($file)] = $hash; } } $this->data = $csums; $this->write(); return $csums; }
php
public function update($fileList) { $csums = array(); foreach ($fileList as $file) { if (file_exists($file)) { $hash = $this->calculateHash($file); $csums[$this->_makeRelative($file)] = $hash; } } $this->data = $csums; $this->write(); return $csums; }
[ "public", "function", "update", "(", "$", "fileList", ")", "{", "$", "csums", "=", "array", "(", ")", ";", "foreach", "(", "$", "fileList", "as", "$", "file", ")", "{", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "hash", "=", ...
This updates the data in the manifest from the files passed in. @param array $fileList A list of files to include in the manifest. @return array The new hash mapping from those files.
[ "This", "updates", "the", "data", "in", "the", "manifest", "from", "the", "files", "passed", "in", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L165-L181
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest.write
public function write($fileName=null) { $this->_resetFileName($fileName); ksort($this->data); $output = array(); foreach ($this->data as $path => $hash) { array_push($output, "$hash $path\n"); } writeFileText( $this->fileName, $this->fileEncoding, implode('', $output) ); }
php
public function write($fileName=null) { $this->_resetFileName($fileName); ksort($this->data); $output = array(); foreach ($this->data as $path => $hash) { array_push($output, "$hash $path\n"); } writeFileText( $this->fileName, $this->fileEncoding, implode('', $output) ); }
[ "public", "function", "write", "(", "$", "fileName", "=", "null", ")", "{", "$", "this", "->", "_resetFileName", "(", "$", "fileName", ")", ";", "ksort", "(", "$", "this", "->", "data", ")", ";", "$", "output", "=", "array", "(", ")", ";", "foreach...
This writes the data to the manifest file. @param string $fileName This is the file name to write to. It defaults to the current value of the $fileName property. If given, it will set the value of the property also. @return void
[ "This", "writes", "the", "data", "to", "the", "manifest", "file", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L204-L220
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest.getHash
public function getHash($fileName) { if (array_key_exists($fileName, $this->data)) { return $this->data[$fileName]; } else if (array_key_exists($this->_makeRelative($fileName), $this->data)) { return $this->data[$this->_makeRelative($fileName)]; } else { return null; } }
php
public function getHash($fileName) { if (array_key_exists($fileName, $this->data)) { return $this->data[$fileName]; } else if (array_key_exists($this->_makeRelative($fileName), $this->data)) { return $this->data[$this->_makeRelative($fileName)]; } else { return null; } }
[ "public", "function", "getHash", "(", "$", "fileName", ")", "{", "if", "(", "array_key_exists", "(", "$", "fileName", ",", "$", "this", "->", "data", ")", ")", "{", "return", "$", "this", "->", "data", "[", "$", "fileName", "]", ";", "}", "else", "...
This returns the hash for a file. @param string $fileName This can be either the absolute file name or the file name without the path prefix. @return string The file's hash.
[ "This", "returns", "the", "hash", "for", "a", "file", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L230-L239
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest.setHashEncoding
public function setHashEncoding($hashEncoding) { $this->hashEncoding = $hashEncoding; $fileName = preg_replace( '/-\w+\.txt$/', "-$hashEncoding.txt", $this->fileName ); if ($fileName != $this->fileName) { rename($this->fileName, $fileName); $this->fileName = $fileName; } }
php
public function setHashEncoding($hashEncoding) { $this->hashEncoding = $hashEncoding; $fileName = preg_replace( '/-\w+\.txt$/', "-$hashEncoding.txt", $this->fileName ); if ($fileName != $this->fileName) { rename($this->fileName, $fileName); $this->fileName = $fileName; } }
[ "public", "function", "setHashEncoding", "(", "$", "hashEncoding", ")", "{", "$", "this", "->", "hashEncoding", "=", "$", "hashEncoding", ";", "$", "fileName", "=", "preg_replace", "(", "'/-\\w+\\.txt$/'", ",", "\"-$hashEncoding.txt\"", ",", "$", "this", "->", ...
This sets the hash encoding. @param string $hashEncoding This sets the encoding to use when creating the manifest hash data. This must be either 'md5' or 'sha1'; however, it does not test for this. @return void
[ "This", "sets", "the", "hash", "encoding", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L309-L323
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest.validate
public function validate(&$errors) { $errLen = count($errors); // That the manifest file does exist; if (! file_exists($this->fileName)) { $basename = basename($this->fileName); array_push( $errors, array($basename, "$basename does not exist.") ); // There's no manifest file, so we might as well bail now. return false; } // That the files in the hash mapping do exist; and // That the hashes in the mapping are correct. foreach ($this->data as $fileName => $hash) { $fullPath = $this->pathPrefix . $fileName; if (! file_exists($fullPath)) { array_push( $errors, array($fileName, 'Missing data file.') ); } else if ($this->calculateHash($fullPath) != $hash) { array_push( $errors, array($fileName, 'Checksum mismatch.') ); } } return ($errLen == count($errors)); }
php
public function validate(&$errors) { $errLen = count($errors); // That the manifest file does exist; if (! file_exists($this->fileName)) { $basename = basename($this->fileName); array_push( $errors, array($basename, "$basename does not exist.") ); // There's no manifest file, so we might as well bail now. return false; } // That the files in the hash mapping do exist; and // That the hashes in the mapping are correct. foreach ($this->data as $fileName => $hash) { $fullPath = $this->pathPrefix . $fileName; if (! file_exists($fullPath)) { array_push( $errors, array($fileName, 'Missing data file.') ); } else if ($this->calculateHash($fullPath) != $hash) { array_push( $errors, array($fileName, 'Checksum mismatch.') ); } } return ($errLen == count($errors)); }
[ "public", "function", "validate", "(", "&", "$", "errors", ")", "{", "$", "errLen", "=", "count", "(", "$", "errors", ")", ";", "// That the manifest file does exist;", "if", "(", "!", "file_exists", "(", "$", "this", "->", "fileName", ")", ")", "{", "$"...
This validates the data in the manifest. This tests three things: <ol> <li>That the manifest file does exist;</li> <li>That the files in the hash mapping do exist; and</li> <li>That the hashes in the mapping are correct.</li> </ol> Problems will be added to the errors. @param array &$errors A list of error messages. Messages about any errors in validation will be appended to this. @return boolean Does this validate or not?
[ "This", "validates", "the", "data", "in", "the", "manifest", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L342-L375
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest._resetFileName
private function _resetFileName($fileName=null) { if ($fileName === null) { return $this->fileName; } else { $this->hashEncoding = $this->_parseHashEncoding($fileName); $this->fileName = $fileName; return $fileName; } }
php
private function _resetFileName($fileName=null) { if ($fileName === null) { return $this->fileName; } else { $this->hashEncoding = $this->_parseHashEncoding($fileName); $this->fileName = $fileName; return $fileName; } }
[ "private", "function", "_resetFileName", "(", "$", "fileName", "=", "null", ")", "{", "if", "(", "$", "fileName", "===", "null", ")", "{", "return", "$", "this", "->", "fileName", ";", "}", "else", "{", "$", "this", "->", "hashEncoding", "=", "$", "t...
This returns the file name to use. If a file name is passed into this function, that will be used. Otherwise, the current value of the $fileName property will be used. @param string $fileName If given, then this file name will be used; otherwise, the $fileName property will be used. @return string The file name to use for the $fileName property.
[ "This", "returns", "the", "file", "name", "to", "use", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L411-L420
train
scholarslab/BagItPHP
lib/bagit_manifest.php
BagItManifest._makeRelative
private function _makeRelative($filename) { $rel = substr($filename, strlen($this->pathPrefix)); if (! $rel) { return ''; } else { return $rel; } }
php
private function _makeRelative($filename) { $rel = substr($filename, strlen($this->pathPrefix)); if (! $rel) { return ''; } else { return $rel; } }
[ "private", "function", "_makeRelative", "(", "$", "filename", ")", "{", "$", "rel", "=", "substr", "(", "$", "filename", ",", "strlen", "(", "$", "this", "->", "pathPrefix", ")", ")", ";", "if", "(", "!", "$", "rel", ")", "{", "return", "''", ";", ...
This takes a file name and strips the prefix path from it. This is unsafe, strictly speaking, because it doesn't check that the file name passed in actually begins with the prefix. @param string $filename An absolute file name under the bag directory. @return string The file name with the $pathPrefix.
[ "This", "takes", "a", "file", "name", "and", "strips", "the", "prefix", "path", "from", "it", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_manifest.php#L432-L440
train
scholarslab/BagItPHP
lib/bagit_fetch.php
BagItFetch.read
public function read() { $lines = readLines($this->fileName, $this->fileEncoding); $fetch = array(); foreach ($lines as $line) { $fields = preg_split('/\s+/', $line); if (count($fields) == 3) { array_push( $fetch, array('url' => $fields[0], 'length' => $fields[1], 'filename' => $fields[2]) ); } } $this->data = $fetch; }
php
public function read() { $lines = readLines($this->fileName, $this->fileEncoding); $fetch = array(); foreach ($lines as $line) { $fields = preg_split('/\s+/', $line); if (count($fields) == 3) { array_push( $fetch, array('url' => $fields[0], 'length' => $fields[1], 'filename' => $fields[2]) ); } } $this->data = $fetch; }
[ "public", "function", "read", "(", ")", "{", "$", "lines", "=", "readLines", "(", "$", "this", "->", "fileName", ",", "$", "this", "->", "fileEncoding", ")", ";", "$", "fetch", "=", "array", "(", ")", ";", "foreach", "(", "$", "lines", "as", "$", ...
This reads the data from the fetch file and populates the data array. @return array The data from the file.
[ "This", "reads", "the", "data", "from", "the", "fetch", "file", "and", "populates", "the", "data", "array", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_fetch.php#L111-L128
train
scholarslab/BagItPHP
lib/bagit_fetch.php
BagItFetch.write
public function write() { $lines = array(); foreach ($this->data as $fetch) { $data = array($fetch['url'], $fetch['length'], $fetch['filename']); array_push($lines, join(' ', $data) . "\n"); } if (count($lines) == 0) { if (file_exists($this->fileName)) { unlink($this->fileName); } } else { writeFileText($this->fileName, $this->fileEncoding, join('', $lines)); } }
php
public function write() { $lines = array(); foreach ($this->data as $fetch) { $data = array($fetch['url'], $fetch['length'], $fetch['filename']); array_push($lines, join(' ', $data) . "\n"); } if (count($lines) == 0) { if (file_exists($this->fileName)) { unlink($this->fileName); } } else { writeFileText($this->fileName, $this->fileEncoding, join('', $lines)); } }
[ "public", "function", "write", "(", ")", "{", "$", "lines", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "fetch", ")", "{", "$", "data", "=", "array", "(", "$", "fetch", "[", "'url'", "]", ",", "$", "fetch"...
This writes the data to the fetch file. @return void
[ "This", "writes", "the", "data", "to", "the", "fetch", "file", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_fetch.php#L135-L151
train
scholarslab/BagItPHP
lib/bagit_fetch.php
BagItFetch.add
public function add($url, $filename) { array_push( $this->data, array('url' => $url, 'length' => '-', 'filename' => $filename) ); $this->write(); }
php
public function add($url, $filename) { array_push( $this->data, array('url' => $url, 'length' => '-', 'filename' => $filename) ); $this->write(); }
[ "public", "function", "add", "(", "$", "url", ",", "$", "filename", ")", "{", "array_push", "(", "$", "this", "->", "data", ",", "array", "(", "'url'", "=>", "$", "url", ",", "'length'", "=>", "'-'", ",", "'filename'", "=>", "$", "filename", ")", "...
This adds an entry to the fetch data. @param string $url This is the URL to load the file from. @param string $filename This is the file name, relative to the fetch file's directory, to save the data to. @return void
[ "This", "adds", "an", "entry", "to", "the", "fetch", "data", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_fetch.php#L173-L180
train
scholarslab/BagItPHP
lib/bagit_fetch.php
BagItFetch.download
public function download() { $basedir = dirname($this->fileName); foreach ($this->data as $fetch) { $filename = $basedir . '/' . $fetch['filename']; if (! file_exists($filename)) { $this->_downloadFile($fetch['url'], $filename); } } }
php
public function download() { $basedir = dirname($this->fileName); foreach ($this->data as $fetch) { $filename = $basedir . '/' . $fetch['filename']; if (! file_exists($filename)) { $this->_downloadFile($fetch['url'], $filename); } } }
[ "public", "function", "download", "(", ")", "{", "$", "basedir", "=", "dirname", "(", "$", "this", "->", "fileName", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "fetch", ")", "{", "$", "filename", "=", "$", "basedir", ".", "'/'"...
This downloads the files in the fetch information that aren't on the file system. @return void
[ "This", "downloads", "the", "files", "in", "the", "fetch", "information", "that", "aren", "t", "on", "the", "file", "system", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_fetch.php#L188-L197
train
scholarslab/BagItPHP
lib/bagit_fetch.php
BagItFetch._downloadFile
private function _downloadFile($url, $filename) { $dirname = dirname($filename); if (! is_dir($dirname)) { mkdir($dirname, 0777, true); } saveUrl($url, $filename); }
php
private function _downloadFile($url, $filename) { $dirname = dirname($filename); if (! is_dir($dirname)) { mkdir($dirname, 0777, true); } saveUrl($url, $filename); }
[ "private", "function", "_downloadFile", "(", "$", "url", ",", "$", "filename", ")", "{", "$", "dirname", "=", "dirname", "(", "$", "filename", ")", ";", "if", "(", "!", "is_dir", "(", "$", "dirname", ")", ")", "{", "mkdir", "(", "$", "dirname", ","...
This downloads a single file. @param string $url The URL to fetch. @param string $filename The absolute file name to save to. @return void
[ "This", "downloads", "a", "single", "file", "." ]
8d197da6d18c06a7aa880d853eb50820f408c4bb
https://github.com/scholarslab/BagItPHP/blob/8d197da6d18c06a7aa880d853eb50820f408c4bb/lib/bagit_fetch.php#L211-L218
train
novosga/attendance-bundle
Controller/DefaultController.php
DefaultController.naoCompareceu
public function naoCompareceu( Request $request, AtendimentoService $atendimentoService, TranslatorInterface $translator ) { $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); $atual = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade); if (!$atual) { throw new Exception( $translator->trans('error.attendance.empty', [], self::DOMAIN) ); } $atendimentoService->naoCompareceu($atual, $usuario); $data = $atual->jsonSerialize(); $envelope = new Envelope(); $envelope->setData($data); return $this->json($envelope); }
php
public function naoCompareceu( Request $request, AtendimentoService $atendimentoService, TranslatorInterface $translator ) { $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); $atual = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade); if (!$atual) { throw new Exception( $translator->trans('error.attendance.empty', [], self::DOMAIN) ); } $atendimentoService->naoCompareceu($atual, $usuario); $data = $atual->jsonSerialize(); $envelope = new Envelope(); $envelope->setData($data); return $this->json($envelope); }
[ "public", "function", "naoCompareceu", "(", "Request", "$", "request", ",", "AtendimentoService", "$", "atendimentoService", ",", "TranslatorInterface", "$", "translator", ")", "{", "$", "usuario", "=", "$", "this", "->", "getUser", "(", ")", ";", "$", "unidad...
Marca o atendimento como nao compareceu. @param Novosga\Request $request @Route("/nao_compareceu", name="novosga_attendance_naocompareceu", methods={"POST"})
[ "Marca", "o", "atendimento", "como", "nao", "compareceu", "." ]
598ea735822ed7da0ef2cf1fb2b2575358e62859
https://github.com/novosga/attendance-bundle/blob/598ea735822ed7da0ef2cf1fb2b2575358e62859/Controller/DefaultController.php#L310-L332
train
novosga/attendance-bundle
Controller/DefaultController.php
DefaultController.encerrar
public function encerrar( Request $request, AtendimentoService $atendimentoService, TranslatorInterface $translator ) { $envelope = new Envelope(); $data = json_decode($request->getContent()); $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); $atual = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade); if (!$atual) { throw new Exception( $translator->trans('error.attendance.not_in_process', [], self::DOMAIN) ); } $servicos = explode(',', $data->servicos); $resolucao = $data->resolucao; $observacao = $data->observacao; if (empty($servicos)) { throw new Exception( $translator->trans('error.attendance.no_service', [], self::DOMAIN) ); } $em = $this->getDoctrine()->getManager(); $novoUsuario = null; $servicoRedirecionado = null; if ($data->redirecionar) { $servicoRedirecionado = $em ->getRepository(Servico::class) ->find($data->novoServico); if (isset($data->novoUsuario)) { $novoUsuario = $em ->getRepository(Usuario::class) ->find($data->novoServico); } } if (in_array($resolucao, [ AtendimentoService::RESOLVIDO, AtendimentoService::PENDENTE ])) { $atual->setResolucao($resolucao); } if ($observacao) { $atual->setObservacao($observacao); } $atendimentoService->encerrar($atual, $unidade, $servicos, $servicoRedirecionado, $novoUsuario); return $this->json($envelope); }
php
public function encerrar( Request $request, AtendimentoService $atendimentoService, TranslatorInterface $translator ) { $envelope = new Envelope(); $data = json_decode($request->getContent()); $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); $atual = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade); if (!$atual) { throw new Exception( $translator->trans('error.attendance.not_in_process', [], self::DOMAIN) ); } $servicos = explode(',', $data->servicos); $resolucao = $data->resolucao; $observacao = $data->observacao; if (empty($servicos)) { throw new Exception( $translator->trans('error.attendance.no_service', [], self::DOMAIN) ); } $em = $this->getDoctrine()->getManager(); $novoUsuario = null; $servicoRedirecionado = null; if ($data->redirecionar) { $servicoRedirecionado = $em ->getRepository(Servico::class) ->find($data->novoServico); if (isset($data->novoUsuario)) { $novoUsuario = $em ->getRepository(Usuario::class) ->find($data->novoServico); } } if (in_array($resolucao, [ AtendimentoService::RESOLVIDO, AtendimentoService::PENDENTE ])) { $atual->setResolucao($resolucao); } if ($observacao) { $atual->setObservacao($observacao); } $atendimentoService->encerrar($atual, $unidade, $servicos, $servicoRedirecionado, $novoUsuario); return $this->json($envelope); }
[ "public", "function", "encerrar", "(", "Request", "$", "request", ",", "AtendimentoService", "$", "atendimentoService", ",", "TranslatorInterface", "$", "translator", ")", "{", "$", "envelope", "=", "new", "Envelope", "(", ")", ";", "$", "data", "=", "json_dec...
Marca o atendimento como encerrado. @param Novosga\Request $request @Route("/encerrar", name="novosga_attendance_encerrar", methods={"POST"})
[ "Marca", "o", "atendimento", "como", "encerrado", "." ]
598ea735822ed7da0ef2cf1fb2b2575358e62859
https://github.com/novosga/attendance-bundle/blob/598ea735822ed7da0ef2cf1fb2b2575358e62859/Controller/DefaultController.php#L341-L397
train
novosga/attendance-bundle
Controller/DefaultController.php
DefaultController.redirecionar
public function redirecionar( Request $request, AtendimentoService $atendimentoService, TranslatorInterface $translator ) { $envelope = new Envelope(); $data = json_decode($request->getContent()); $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); $servico = (int) $data->servico; $novoUsuario = null; $atual = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade); if (!$atual) { throw new Exception( $translator->trans('error.attendance.not_in_process', [], self::DOMAIN) ); } if (isset($data->usuario)) { $novoUsuario = $this ->getDoctrine() ->getManager() ->getRepository(Usuario::class) ->find($data->usuario); } $redirecionado = $atendimentoService->redirecionar($atual, $unidade, $servico, $novoUsuario); if (!$redirecionado->getId()) { throw new Exception( $translator->trans( 'error.attendance.redirect', [ '%atendimento%' => $atual->getId(), '%servico%' => $servico, ], self::DOMAIN ) ); } return $this->json($envelope); }
php
public function redirecionar( Request $request, AtendimentoService $atendimentoService, TranslatorInterface $translator ) { $envelope = new Envelope(); $data = json_decode($request->getContent()); $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); $servico = (int) $data->servico; $novoUsuario = null; $atual = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade); if (!$atual) { throw new Exception( $translator->trans('error.attendance.not_in_process', [], self::DOMAIN) ); } if (isset($data->usuario)) { $novoUsuario = $this ->getDoctrine() ->getManager() ->getRepository(Usuario::class) ->find($data->usuario); } $redirecionado = $atendimentoService->redirecionar($atual, $unidade, $servico, $novoUsuario); if (!$redirecionado->getId()) { throw new Exception( $translator->trans( 'error.attendance.redirect', [ '%atendimento%' => $atual->getId(), '%servico%' => $servico, ], self::DOMAIN ) ); } return $this->json($envelope); }
[ "public", "function", "redirecionar", "(", "Request", "$", "request", ",", "AtendimentoService", "$", "atendimentoService", ",", "TranslatorInterface", "$", "translator", ")", "{", "$", "envelope", "=", "new", "Envelope", "(", ")", ";", "$", "data", "=", "json...
Marca o atendimento como erro de triagem. E gera um novo atendimento para o servico informado. @param Novosga\Request $request @Route("/redirecionar", name="novosga_attendance_redirecionar", methods={"POST"})
[ "Marca", "o", "atendimento", "como", "erro", "de", "triagem", ".", "E", "gera", "um", "novo", "atendimento", "para", "o", "servico", "informado", "." ]
598ea735822ed7da0ef2cf1fb2b2575358e62859
https://github.com/novosga/attendance-bundle/blob/598ea735822ed7da0ef2cf1fb2b2575358e62859/Controller/DefaultController.php#L407-L450
train
markroland/converge-api-php
src/ConvergeApi.php
ConvergeApi.sendRequest
private function sendRequest($api_method, $data, $multisplit = NULL, $multikey = NULL) { $responseBody = $this->httpRequest($api_method, $data); // Parse and return return $this->parseAsciiResponse($responseBody, $multisplit, $multikey); }
php
private function sendRequest($api_method, $data, $multisplit = NULL, $multikey = NULL) { $responseBody = $this->httpRequest($api_method, $data); // Parse and return return $this->parseAsciiResponse($responseBody, $multisplit, $multikey); }
[ "private", "function", "sendRequest", "(", "$", "api_method", ",", "$", "data", ",", "$", "multisplit", "=", "NULL", ",", "$", "multikey", "=", "NULL", ")", "{", "$", "responseBody", "=", "$", "this", "->", "httpRequest", "(", "$", "api_method", ",", "...
Send a HTTP request to the API @param string $api_method The API method to be called @param array $data Any data to be sent to the API @param string $multisplit The key in the response body to use to break multiple records on @param string $multikey The key in the response array to put the multiple results @return array
[ "Send", "a", "HTTP", "request", "to", "the", "API" ]
ba0f30d1a3a0ed00a2c36bb7d242287ec565e14c
https://github.com/markroland/converge-api-php/blob/ba0f30d1a3a0ed00a2c36bb7d242287ec565e14c/src/ConvergeApi.php#L151-L157
train
arendjantetteroo/guzzle-toggl
src/AJT/Toggl/TogglClient.php
TogglClient.factory
public static function factory($config = []) { $clientConfig = self::getClientConfig($config); $guzzleClient = new Client($clientConfig); if (isset($config['apiVersion']) && $config['apiVersion'] !== 'v8') { throw new \Exception('Only v8 is supported at this time'); } $description = self::getAPIDescriptionByJsonFile('services_v8.json'); $client = new GuzzleClient($guzzleClient, $description); return $client; }
php
public static function factory($config = []) { $clientConfig = self::getClientConfig($config); $guzzleClient = new Client($clientConfig); if (isset($config['apiVersion']) && $config['apiVersion'] !== 'v8') { throw new \Exception('Only v8 is supported at this time'); } $description = self::getAPIDescriptionByJsonFile('services_v8.json'); $client = new GuzzleClient($guzzleClient, $description); return $client; }
[ "public", "static", "function", "factory", "(", "$", "config", "=", "[", "]", ")", "{", "$", "clientConfig", "=", "self", "::", "getClientConfig", "(", "$", "config", ")", ";", "$", "guzzleClient", "=", "new", "Client", "(", "$", "clientConfig", ")", "...
Factory method to create a new TogglClient The following array keys and values are available options: - username: username or API key - password: password (if empty, then username is a API key) See https://www.toggl.com/public/api#api_token for more information on the api token @param array $config Configuration data @return TogglClient @throws \Exception
[ "Factory", "method", "to", "create", "a", "new", "TogglClient" ]
8b5b571ce3b2282de7e8a6865fa5457a962a2d78
https://github.com/arendjantetteroo/guzzle-toggl/blob/8b5b571ce3b2282de7e8a6865fa5457a962a2d78/src/AJT/Toggl/TogglClient.php#L30-L46
train
Ontraport/SDK-PHP
src/Models/FieldEditor/ObjectSection.php
ObjectSection.updateField
public function updateField($field) { if (!$field instanceof ObjectField) { throw new FieldEditorException(print_r($field, true) . " is not of type ObjectField"); } foreach ($this->_fields as $column => $fields) { foreach ($fields as $index => $f) { $existing_field = $f->getField(); if ($existing_field !== null && $field->getField() === $existing_field) { // If the field name (f1234) exists merge replace on that. $this->_fields[$column][$index] = $field; return; } } } throw new FieldEditorException("Could not find an existing field: {$field->getField()} in this Section"); }
php
public function updateField($field) { if (!$field instanceof ObjectField) { throw new FieldEditorException(print_r($field, true) . " is not of type ObjectField"); } foreach ($this->_fields as $column => $fields) { foreach ($fields as $index => $f) { $existing_field = $f->getField(); if ($existing_field !== null && $field->getField() === $existing_field) { // If the field name (f1234) exists merge replace on that. $this->_fields[$column][$index] = $field; return; } } } throw new FieldEditorException("Could not find an existing field: {$field->getField()} in this Section"); }
[ "public", "function", "updateField", "(", "$", "field", ")", "{", "if", "(", "!", "$", "field", "instanceof", "ObjectField", ")", "{", "throw", "new", "FieldEditorException", "(", "print_r", "(", "$", "field", ",", "true", ")", ".", "\" is not of type Object...
Given an ObjectField, find a matching one in this section to update @param ObjectField $field @throws FieldEditorException
[ "Given", "an", "ObjectField", "find", "a", "matching", "one", "in", "this", "section", "to", "update" ]
6752a9de17d1b2129215339a2966e3a6f1020628
https://github.com/Ontraport/SDK-PHP/blob/6752a9de17d1b2129215339a2966e3a6f1020628/src/Models/FieldEditor/ObjectSection.php#L170-L190
train
ezsystems/EzSystemsRecommendationBundle
Command/ExportCommand.php
ExportCommand.prepare
private function prepare() { $session = new Session(); $session->start(); $request = Request::createFromGlobals(); $request->setSession($session); $this->requestStack->push($request); $this->tokenStorage->setToken( new AnonymousToken('anonymous', 'anonymous', ['ROLE_ADMINISTRATOR']) ); }
php
private function prepare() { $session = new Session(); $session->start(); $request = Request::createFromGlobals(); $request->setSession($session); $this->requestStack->push($request); $this->tokenStorage->setToken( new AnonymousToken('anonymous', 'anonymous', ['ROLE_ADMINISTRATOR']) ); }
[ "private", "function", "prepare", "(", ")", "{", "$", "session", "=", "new", "Session", "(", ")", ";", "$", "session", "->", "start", "(", ")", ";", "$", "request", "=", "Request", "::", "createFromGlobals", "(", ")", ";", "$", "request", "->", "setS...
Prepares Request and Token for CLI environment, required by RichTextConverter to render embeded content. Avoid 'The token storage contains no authentication token' and 'Rendering a fragment can only be done when handling a Request' exceptions.
[ "Prepares", "Request", "and", "Token", "for", "CLI", "environment", "required", "by", "RichTextConverter", "to", "render", "embeded", "content", ".", "Avoid", "The", "token", "storage", "contains", "no", "authentication", "token", "and", "Rendering", "a", "fragmen...
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Command/ExportCommand.php#L105-L117
train
ezsystems/EzSystemsRecommendationBundle
EventListener/Login.php
Login.getUser
private function getUser(TokenInterface $authenticationToken) { $user = $authenticationToken->getUser(); if (is_string($user)) { return $user; } elseif (method_exists($user, 'getAPIUser')) { return $user->getAPIUser()->id; } return $authenticationToken->getUsername(); }
php
private function getUser(TokenInterface $authenticationToken) { $user = $authenticationToken->getUser(); if (is_string($user)) { return $user; } elseif (method_exists($user, 'getAPIUser')) { return $user->getAPIUser()->id; } return $authenticationToken->getUsername(); }
[ "private", "function", "getUser", "(", "TokenInterface", "$", "authenticationToken", ")", "{", "$", "user", "=", "$", "authenticationToken", "->", "getUser", "(", ")", ";", "if", "(", "is_string", "(", "$", "user", ")", ")", "{", "return", "$", "user", "...
Returns current username or ApiUser id. @param TokenInterface $authenticationToken @return int|string
[ "Returns", "current", "username", "or", "ApiUser", "id", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/EventListener/Login.php#L136-L147
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.validate
private function validate(array $options) { if (array_key_exists('mandatorId', $options)) { $options['mandatorId'] = (int) $options['mandatorId']; } list($customerId, $licenseKey) = $this->siteAccessHelper->getRecommendationServiceCredentials($options['mandatorId'], $options['siteaccess']); $options = array_filter($options, function ($val) { return $val !== null; }); $resolver = new OptionsResolver(); $resolver->setRequired(['contentTypeIdList', 'host', 'webHook', 'transaction']); $resolver->setDefined(array_keys($options)); $resolver->setDefaults([ 'transaction' => (new \DateTime())->format('YmdHis') . rand(111, 999), 'customerId' => $customerId, 'licenseKey' => $licenseKey, 'mandatorId' => null, 'siteaccess' => null, 'lang' => null, ]); return $resolver->resolve($options); }
php
private function validate(array $options) { if (array_key_exists('mandatorId', $options)) { $options['mandatorId'] = (int) $options['mandatorId']; } list($customerId, $licenseKey) = $this->siteAccessHelper->getRecommendationServiceCredentials($options['mandatorId'], $options['siteaccess']); $options = array_filter($options, function ($val) { return $val !== null; }); $resolver = new OptionsResolver(); $resolver->setRequired(['contentTypeIdList', 'host', 'webHook', 'transaction']); $resolver->setDefined(array_keys($options)); $resolver->setDefaults([ 'transaction' => (new \DateTime())->format('YmdHis') . rand(111, 999), 'customerId' => $customerId, 'licenseKey' => $licenseKey, 'mandatorId' => null, 'siteaccess' => null, 'lang' => null, ]); return $resolver->resolve($options); }
[ "private", "function", "validate", "(", "array", "$", "options", ")", "{", "if", "(", "array_key_exists", "(", "'mandatorId'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'mandatorId'", "]", "=", "(", "int", ")", "$", "options", "[", "'ma...
Validates required options. @param array $options @return array
[ "Validates", "required", "options", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L151-L177
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.getLanguages
private function getLanguages($options) { if (!empty($options['lang'])) { return Text::getArrayFromString($options['lang']); } return $this->siteAccessHelper->getLanguages($options['mandatorId'], $options['siteaccess']); }
php
private function getLanguages($options) { if (!empty($options['lang'])) { return Text::getArrayFromString($options['lang']); } return $this->siteAccessHelper->getLanguages($options['mandatorId'], $options['siteaccess']); }
[ "private", "function", "getLanguages", "(", "$", "options", ")", "{", "if", "(", "!", "empty", "(", "$", "options", "[", "'lang'", "]", ")", ")", "{", "return", "Text", "::", "getArrayFromString", "(", "$", "options", "[", "'lang'", "]", ")", ";", "}...
Returns languages list. @param array $options @return array
[ "Returns", "languages", "list", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L186-L193
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.generateFiles
private function generateFiles($languages, $chunkDir, array $options, OutputInterface $output) { $urls = array(); $output->writeln(sprintf('Exporting %s content types', count($options['contentTypeIds']))); foreach ($options['contentTypeIds'] as $contentTypeId) { $contentTypeCurrentName = null; foreach ($languages as $lang) { $options['lang'] = $lang; $count = $this->countContentItemsByContentTypeId($contentTypeId, $options); $info = sprintf('Fetching %s items of contentTypeId %s (language: %s)', $count, $contentTypeId, $lang); $output->writeln($info); $this->logger->info($info); $contentTypeName = $this->contentTypeService->loadContentType($contentTypeId)->getName($lang); if ($contentTypeName !== null) { $contentTypeCurrentName = $contentTypeName; } for ($i = 1; $i <= ceil($count / $options['pageSize']); ++$i) { $filename = sprintf('%d_%s_%d', $contentTypeId, $lang, $i); $chunkPath = $chunkDir . $filename; $options['page'] = $i; $output->writeln(sprintf( 'Fetching content from database for contentTypeId: %s, language: %s, chunk: #%s', $contentTypeId, $lang, $i )); $contentItems = $this->getContentItems($contentTypeId, $options); $parameters = new ParameterBag($options); $output->writeln(sprintf( 'Preparing content for contentTypeId: %s, language: %s, amount: %s, chunk: #%s', $contentTypeId, $lang, count($contentItems), $i )); $content = $this->content->prepareContent(array($contentTypeId => $contentItems), $parameters, $output); unset($contentItems); $output->writeln(sprintf( 'Generating file for contentTypeId: %s, language: %s, chunk: #%s', $contentTypeId, $lang, $i )); $this->generateFile($content, $chunkPath, $options); unset($content); $url = sprintf( '%s/api/ezp/v2/ez_recommendation/v1/exportDownload/%s%s', $options['host'], $chunkDir, $filename ); $info = sprintf('Generating url: %s', $url); $output->writeln($info); $this->logger->info($info); $urls[$contentTypeId][$lang]['urlList'][] = $url; $urls[$contentTypeId][$lang]['contentTypeName'] = $contentTypeCurrentName; } } } return $urls; }
php
private function generateFiles($languages, $chunkDir, array $options, OutputInterface $output) { $urls = array(); $output->writeln(sprintf('Exporting %s content types', count($options['contentTypeIds']))); foreach ($options['contentTypeIds'] as $contentTypeId) { $contentTypeCurrentName = null; foreach ($languages as $lang) { $options['lang'] = $lang; $count = $this->countContentItemsByContentTypeId($contentTypeId, $options); $info = sprintf('Fetching %s items of contentTypeId %s (language: %s)', $count, $contentTypeId, $lang); $output->writeln($info); $this->logger->info($info); $contentTypeName = $this->contentTypeService->loadContentType($contentTypeId)->getName($lang); if ($contentTypeName !== null) { $contentTypeCurrentName = $contentTypeName; } for ($i = 1; $i <= ceil($count / $options['pageSize']); ++$i) { $filename = sprintf('%d_%s_%d', $contentTypeId, $lang, $i); $chunkPath = $chunkDir . $filename; $options['page'] = $i; $output->writeln(sprintf( 'Fetching content from database for contentTypeId: %s, language: %s, chunk: #%s', $contentTypeId, $lang, $i )); $contentItems = $this->getContentItems($contentTypeId, $options); $parameters = new ParameterBag($options); $output->writeln(sprintf( 'Preparing content for contentTypeId: %s, language: %s, amount: %s, chunk: #%s', $contentTypeId, $lang, count($contentItems), $i )); $content = $this->content->prepareContent(array($contentTypeId => $contentItems), $parameters, $output); unset($contentItems); $output->writeln(sprintf( 'Generating file for contentTypeId: %s, language: %s, chunk: #%s', $contentTypeId, $lang, $i )); $this->generateFile($content, $chunkPath, $options); unset($content); $url = sprintf( '%s/api/ezp/v2/ez_recommendation/v1/exportDownload/%s%s', $options['host'], $chunkDir, $filename ); $info = sprintf('Generating url: %s', $url); $output->writeln($info); $this->logger->info($info); $urls[$contentTypeId][$lang]['urlList'][] = $url; $urls[$contentTypeId][$lang]['contentTypeName'] = $contentTypeCurrentName; } } } return $urls; }
[ "private", "function", "generateFiles", "(", "$", "languages", ",", "$", "chunkDir", ",", "array", "$", "options", ",", "OutputInterface", "$", "output", ")", "{", "$", "urls", "=", "array", "(", ")", ";", "$", "output", "->", "writeln", "(", "sprintf", ...
Generate export files. @param array $languages @param string $chunkDir @param array $options @param OutputInterface $output @return array
[ "Generate", "export", "files", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L205-L283
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.countContentItemsByContentTypeId
private function countContentItemsByContentTypeId($contentTypeId, $options) { $criteria = $this->generateCriteria($contentTypeId, $options); $query = new Query(); $query->query = new Criterion\LogicalAnd($criteria); $query->limit = 0; return $this->searchService->findContent( $query, (!empty($options['lang']) ? array('languages' => array($options['lang'])) : array()) )->totalCount; }
php
private function countContentItemsByContentTypeId($contentTypeId, $options) { $criteria = $this->generateCriteria($contentTypeId, $options); $query = new Query(); $query->query = new Criterion\LogicalAnd($criteria); $query->limit = 0; return $this->searchService->findContent( $query, (!empty($options['lang']) ? array('languages' => array($options['lang'])) : array()) )->totalCount; }
[ "private", "function", "countContentItemsByContentTypeId", "(", "$", "contentTypeId", ",", "$", "options", ")", "{", "$", "criteria", "=", "$", "this", "->", "generateCriteria", "(", "$", "contentTypeId", ",", "$", "options", ")", ";", "$", "query", "=", "ne...
Returns total amount of content based on ContentType ids. @param int $contentTypeId @param array $options @return int
[ "Returns", "total", "amount", "of", "content", "based", "on", "ContentType", "ids", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L293-L305
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.generateCriteria
private function generateCriteria($contentTypeId, array $options) { $criteria = array( new Criterion\ContentTypeId($contentTypeId), ); if ($options['path']) { $criteria[] = new Criterion\Subtree($options['path']); } if (!$options['hidden']) { $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); } $criteria[] = $this->generateSubtreeCriteria($options['mandatorId'], $options['siteaccess']); return $criteria; }
php
private function generateCriteria($contentTypeId, array $options) { $criteria = array( new Criterion\ContentTypeId($contentTypeId), ); if ($options['path']) { $criteria[] = new Criterion\Subtree($options['path']); } if (!$options['hidden']) { $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); } $criteria[] = $this->generateSubtreeCriteria($options['mandatorId'], $options['siteaccess']); return $criteria; }
[ "private", "function", "generateCriteria", "(", "$", "contentTypeId", ",", "array", "$", "options", ")", "{", "$", "criteria", "=", "array", "(", "new", "Criterion", "\\", "ContentTypeId", "(", "$", "contentTypeId", ")", ",", ")", ";", "if", "(", "$", "o...
Generates criteria for search query. @param int $contentTypeId @param array $options @return array
[ "Generates", "criteria", "for", "search", "query", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L337-L354
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.generateSubtreeCriteria
private function generateSubtreeCriteria($mandatorId = null, $siteAccess = null) { $siteAccesses = $this->siteAccessHelper->getSiteAccesses($mandatorId, $siteAccess); $subtreeCriteria = []; $rootLocations = $this->siteAccessHelper->getRootLocationsBySiteAccesses($siteAccesses); foreach ($rootLocations as $rootLocationId) { $subtreeCriteria[] = new Criterion\Subtree($this->locationService->loadLocation($rootLocationId)->pathString); } return new Criterion\LogicalOr($subtreeCriteria); }
php
private function generateSubtreeCriteria($mandatorId = null, $siteAccess = null) { $siteAccesses = $this->siteAccessHelper->getSiteAccesses($mandatorId, $siteAccess); $subtreeCriteria = []; $rootLocations = $this->siteAccessHelper->getRootLocationsBySiteAccesses($siteAccesses); foreach ($rootLocations as $rootLocationId) { $subtreeCriteria[] = new Criterion\Subtree($this->locationService->loadLocation($rootLocationId)->pathString); } return new Criterion\LogicalOr($subtreeCriteria); }
[ "private", "function", "generateSubtreeCriteria", "(", "$", "mandatorId", "=", "null", ",", "$", "siteAccess", "=", "null", ")", "{", "$", "siteAccesses", "=", "$", "this", "->", "siteAccessHelper", "->", "getSiteAccesses", "(", "$", "mandatorId", ",", "$", ...
Generates Criterions based on mandatorId or requested siteAccess. @param null|int $mandatorId @param null|string $siteAccess @return Criterion\LogicalOr
[ "Generates", "Criterions", "based", "on", "mandatorId", "or", "requested", "siteAccess", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L364-L375
train
ezsystems/EzSystemsRecommendationBundle
Export/Exporter.php
Exporter.generateFile
private function generateFile($content, $chunkPath, array $options) { $data = new ContentData($content, $options); $this->outputGenerator->reset(); $this->outputGenerator->startDocument($data); $contents = array(); foreach ($data->contents as $contentTypes) { foreach ($contentTypes as $contentType) { $contents[] = $contentType; } } $this->contentListElementGenerator->generateElement($this->outputGenerator, $contents); unset($contents); $filePath = $this->fileSystemHelper->getDir() . $chunkPath; $this->fileSystemHelper->save($filePath, $this->outputGenerator->endDocument($data)); unset($data); $this->logger->info(sprintf('Generating file: %s', $filePath)); }
php
private function generateFile($content, $chunkPath, array $options) { $data = new ContentData($content, $options); $this->outputGenerator->reset(); $this->outputGenerator->startDocument($data); $contents = array(); foreach ($data->contents as $contentTypes) { foreach ($contentTypes as $contentType) { $contents[] = $contentType; } } $this->contentListElementGenerator->generateElement($this->outputGenerator, $contents); unset($contents); $filePath = $this->fileSystemHelper->getDir() . $chunkPath; $this->fileSystemHelper->save($filePath, $this->outputGenerator->endDocument($data)); unset($data); $this->logger->info(sprintf('Generating file: %s', $filePath)); }
[ "private", "function", "generateFile", "(", "$", "content", ",", "$", "chunkPath", ",", "array", "$", "options", ")", "{", "$", "data", "=", "new", "ContentData", "(", "$", "content", ",", "$", "options", ")", ";", "$", "this", "->", "outputGenerator", ...
Generating export file. @param array $content @param string $chunkPath @param array $options
[ "Generating", "export", "file", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Export/Exporter.php#L384-L408
train
ezsystems/EzSystemsRecommendationBundle
Client/YooChooseNotifier.php
YooChooseNotifier.isContentTypeExcluded
private function isContentTypeExcluded(Content $content) { $contentType = $this->repository->sudo(function () use ($content) { $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); return $contentType; }); return !in_array($contentType->identifier, $this->options['included-content-types']); }
php
private function isContentTypeExcluded(Content $content) { $contentType = $this->repository->sudo(function () use ($content) { $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); return $contentType; }); return !in_array($contentType->identifier, $this->options['included-content-types']); }
[ "private", "function", "isContentTypeExcluded", "(", "Content", "$", "content", ")", "{", "$", "contentType", "=", "$", "this", "->", "repository", "->", "sudo", "(", "function", "(", ")", "use", "(", "$", "content", ")", "{", "$", "contentType", "=", "$...
Checks if content is excluded from supported content types. @param \eZ\Publish\API\Repository\Values\Content\Content $content @return bool
[ "Checks", "if", "content", "is", "excluded", "from", "supported", "content", "types", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Client/YooChooseNotifier.php#L296-L305
train
ezsystems/EzSystemsRecommendationBundle
Client/YooChooseNotifier.php
YooChooseNotifier.notify
protected function notify(array $events) { $this->logger->debug(sprintf('POST notification to Recommendation Service: %s', json_encode($events, true))); $data = array( 'json' => array( 'transaction' => null, 'events' => $events, ), 'auth' => array( $this->options['customer-id'], $this->options['license-key'], ), ); if (method_exists($this->guzzle, 'post')) { $this->notifyGuzzle5($data); } else { $this->notifyGuzzle6($data); } }
php
protected function notify(array $events) { $this->logger->debug(sprintf('POST notification to Recommendation Service: %s', json_encode($events, true))); $data = array( 'json' => array( 'transaction' => null, 'events' => $events, ), 'auth' => array( $this->options['customer-id'], $this->options['license-key'], ), ); if (method_exists($this->guzzle, 'post')) { $this->notifyGuzzle5($data); } else { $this->notifyGuzzle6($data); } }
[ "protected", "function", "notify", "(", "array", "$", "events", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "sprintf", "(", "'POST notification to Recommendation Service: %s'", ",", "json_encode", "(", "$", "events", ",", "true", ")", ")", ")", ...
Notifies the Recommendation Service API of one or more repository events. A repository event is defined as an array with three keys: - action: the event name (update, delete) - uri: the event's target, as an absolute HTTP URI to the REST resource - contentTypeId: currently processed ContentType ID @param array $events @throws \InvalidArgumentException If provided $events seems to be of wrong type @throws \GuzzleHttp\Exception\RequestException if a request error occurs
[ "Notifies", "the", "Recommendation", "Service", "API", "of", "one", "or", "more", "repository", "events", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Client/YooChooseNotifier.php#L368-L388
train
ezsystems/EzSystemsRecommendationBundle
Client/YooChooseNotifier.php
YooChooseNotifier.notifyGuzzle6
private function notifyGuzzle6(array $data) { $response = $this->guzzle->request('POST', $this->getNotificationEndpoint(), $data); $this->logger->debug(sprintf('Got %s from Recommendation Service notification POST (guzzle v6)', $response->getStatusCode())); }
php
private function notifyGuzzle6(array $data) { $response = $this->guzzle->request('POST', $this->getNotificationEndpoint(), $data); $this->logger->debug(sprintf('Got %s from Recommendation Service notification POST (guzzle v6)', $response->getStatusCode())); }
[ "private", "function", "notifyGuzzle6", "(", "array", "$", "data", ")", "{", "$", "response", "=", "$", "this", "->", "guzzle", "->", "request", "(", "'POST'", ",", "$", "this", "->", "getNotificationEndpoint", "(", ")", ",", "$", "data", ")", ";", "$"...
Notifies the Recommendation Service API using Guzzle 6 synchronously. @param array $data
[ "Notifies", "the", "Recommendation", "Service", "API", "using", "Guzzle", "6", "synchronously", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Client/YooChooseNotifier.php#L407-L412
train
ezsystems/EzSystemsRecommendationBundle
Rest/Controller/ExportController.php
ExportController.parseRequest
private function parseRequest(Request $request) { $query = $request->query; $path = $query->get('path'); $hidden = (int)$query->get('hidden', 0); $image = $query->get('image'); $siteAccess = $query->get('siteaccess'); $webHook = $query->get('webHook'); $transaction = $query->get('transaction'); $fields = $query->get('fields'); $customerId = $query->get('customerId'); $licenseKey = $query->get('licenseKey'); if (preg_match('/^\/\d+(?:\/\d+)*\/$/', $path) !== 1) { $path = null; } if (preg_match('/^[a-zA-Z0-9\-\_]+$/', $image) !== 1) { $image = null; } if (preg_match('/^[a-zA-Z0-9_-]+$/', $siteAccess) !== 1) { $siteAccess = null; } if (preg_match('/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $webHook) !== 1) { $webHook = null; } if (preg_match('/^[0-9]+$/', $transaction) !== 1) { $transaction = (new \DateTime())->format('YmdHisv'); } if (preg_match('/^[a-zA-Z0-9\-\_\,]+$/', $fields) !== 1) { $fields = null; } if (preg_match('/^[a-zA-Z0-9_-]+$/', $customerId) !== 1) { $customerId = null; } if (preg_match('/^[a-zA-Z0-9_-]+$/', $licenseKey) !== 1) { $licenseKey = null; } return array( 'pageSize' => (int)$query->get('pageSize', null), 'page' => (int)$query->get('page', 1), 'path' => $path, 'hidden' => $hidden, 'image' => $image, 'siteaccess' => $siteAccess, 'documentRoot' => $request->server->get('DOCUMENT_ROOT'), 'host' => $request->getSchemeAndHttpHost(), 'webHook' => $webHook, 'transaction' => $transaction, 'lang' => preg_replace('/[^a-zA-Z0-9_-]+/', '', $query->get('lang')), 'fields' => $fields, 'mandatorId' => (int)$query->get('mandatorId', 0), 'customerId' => $customerId, 'licenseKey' => $licenseKey, ); }
php
private function parseRequest(Request $request) { $query = $request->query; $path = $query->get('path'); $hidden = (int)$query->get('hidden', 0); $image = $query->get('image'); $siteAccess = $query->get('siteaccess'); $webHook = $query->get('webHook'); $transaction = $query->get('transaction'); $fields = $query->get('fields'); $customerId = $query->get('customerId'); $licenseKey = $query->get('licenseKey'); if (preg_match('/^\/\d+(?:\/\d+)*\/$/', $path) !== 1) { $path = null; } if (preg_match('/^[a-zA-Z0-9\-\_]+$/', $image) !== 1) { $image = null; } if (preg_match('/^[a-zA-Z0-9_-]+$/', $siteAccess) !== 1) { $siteAccess = null; } if (preg_match('/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $webHook) !== 1) { $webHook = null; } if (preg_match('/^[0-9]+$/', $transaction) !== 1) { $transaction = (new \DateTime())->format('YmdHisv'); } if (preg_match('/^[a-zA-Z0-9\-\_\,]+$/', $fields) !== 1) { $fields = null; } if (preg_match('/^[a-zA-Z0-9_-]+$/', $customerId) !== 1) { $customerId = null; } if (preg_match('/^[a-zA-Z0-9_-]+$/', $licenseKey) !== 1) { $licenseKey = null; } return array( 'pageSize' => (int)$query->get('pageSize', null), 'page' => (int)$query->get('page', 1), 'path' => $path, 'hidden' => $hidden, 'image' => $image, 'siteaccess' => $siteAccess, 'documentRoot' => $request->server->get('DOCUMENT_ROOT'), 'host' => $request->getSchemeAndHttpHost(), 'webHook' => $webHook, 'transaction' => $transaction, 'lang' => preg_replace('/[^a-zA-Z0-9_-]+/', '', $query->get('lang')), 'fields' => $fields, 'mandatorId' => (int)$query->get('mandatorId', 0), 'customerId' => $customerId, 'licenseKey' => $licenseKey, ); }
[ "private", "function", "parseRequest", "(", "Request", "$", "request", ")", "{", "$", "query", "=", "$", "request", "->", "query", ";", "$", "path", "=", "$", "query", "->", "get", "(", "'path'", ")", ";", "$", "hidden", "=", "(", "int", ")", "$", ...
Parses the request values. @param Request $request @return array
[ "Parses", "the", "request", "values", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Controller/ExportController.php#L131-L194
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.getRootLocationBySiteAccessName
public function getRootLocationBySiteAccessName($siteAccessName = null) { return $this->configResolver->getParameter( 'content.tree_root.location_id', null, $siteAccessName ?: $this->siteAccess->name ); }
php
public function getRootLocationBySiteAccessName($siteAccessName = null) { return $this->configResolver->getParameter( 'content.tree_root.location_id', null, $siteAccessName ?: $this->siteAccess->name ); }
[ "public", "function", "getRootLocationBySiteAccessName", "(", "$", "siteAccessName", "=", "null", ")", "{", "return", "$", "this", "->", "configResolver", "->", "getParameter", "(", "'content.tree_root.location_id'", ",", "null", ",", "$", "siteAccessName", "?", ":"...
Returns rootLocation by siteAccess name or by default siteAccess. @param string|null $siteAccessName @return int
[ "Returns", "rootLocation", "by", "siteAccess", "name", "or", "by", "default", "siteAccess", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L52-L59
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.getRootLocationsBySiteAccesses
public function getRootLocationsBySiteAccesses(array $siteAccesses) { $rootLocations = []; foreach ($siteAccesses as $siteAccess) { $rootLocationId = $this->getRootLocationBySiteAccessName($siteAccess); $rootLocations[$rootLocationId] = $rootLocationId; } return array_keys($rootLocations); }
php
public function getRootLocationsBySiteAccesses(array $siteAccesses) { $rootLocations = []; foreach ($siteAccesses as $siteAccess) { $rootLocationId = $this->getRootLocationBySiteAccessName($siteAccess); $rootLocations[$rootLocationId] = $rootLocationId; } return array_keys($rootLocations); }
[ "public", "function", "getRootLocationsBySiteAccesses", "(", "array", "$", "siteAccesses", ")", "{", "$", "rootLocations", "=", "[", "]", ";", "foreach", "(", "$", "siteAccesses", "as", "$", "siteAccess", ")", "{", "$", "rootLocationId", "=", "$", "this", "-...
Returns list of rootLocations from siteAccess list. @param array $siteAccesses @return array
[ "Returns", "list", "of", "rootLocations", "from", "siteAccess", "list", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L68-L79
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.getLanguages
public function getLanguages($mandatorId = null, $siteAccess = null) { if ($mandatorId) { $languages = $this->getMainLanguagesBySiteAccesses( $this->getSiteAccessesByMandatorId($mandatorId) ); } elseif ($siteAccess) { $languages = $this->configResolver->getParameter('languages', '', $siteAccess); } else { $languages = $this->configResolver->getParameter('languages'); } if (empty($languages)) { throw new LogicException(sprintf('No languages found using SiteAccess or mandatorId')); } return $languages; }
php
public function getLanguages($mandatorId = null, $siteAccess = null) { if ($mandatorId) { $languages = $this->getMainLanguagesBySiteAccesses( $this->getSiteAccessesByMandatorId($mandatorId) ); } elseif ($siteAccess) { $languages = $this->configResolver->getParameter('languages', '', $siteAccess); } else { $languages = $this->configResolver->getParameter('languages'); } if (empty($languages)) { throw new LogicException(sprintf('No languages found using SiteAccess or mandatorId')); } return $languages; }
[ "public", "function", "getLanguages", "(", "$", "mandatorId", "=", "null", ",", "$", "siteAccess", "=", "null", ")", "{", "if", "(", "$", "mandatorId", ")", "{", "$", "languages", "=", "$", "this", "->", "getMainLanguagesBySiteAccesses", "(", "$", "this", ...
Returns languages based on mandatorId or siteaccess. @param null|int $mandatorId @param null|string $siteAccess @return array
[ "Returns", "languages", "based", "on", "mandatorId", "or", "siteaccess", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L89-L106
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.isMandatorIdConfigured
private function isMandatorIdConfigured($mandatorId) { return in_array($this->defaultSiteAccessName, $this->siteAccessConfig) && $this->siteAccessConfig[$this->defaultSiteAccessName]['yoochoose']['customer_id'] == $mandatorId; }
php
private function isMandatorIdConfigured($mandatorId) { return in_array($this->defaultSiteAccessName, $this->siteAccessConfig) && $this->siteAccessConfig[$this->defaultSiteAccessName]['yoochoose']['customer_id'] == $mandatorId; }
[ "private", "function", "isMandatorIdConfigured", "(", "$", "mandatorId", ")", "{", "return", "in_array", "(", "$", "this", "->", "defaultSiteAccessName", ",", "$", "this", "->", "siteAccessConfig", ")", "&&", "$", "this", "->", "siteAccessConfig", "[", "$", "t...
Checks if mandatorId is configured with default siteAccess. @param int $mandatorId @return bool
[ "Checks", "if", "mandatorId", "is", "configured", "with", "default", "siteAccess", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L175-L179
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.getSiteAccesses
public function getSiteAccesses($mandatorId = null, $siteAccess = null) { if ($mandatorId) { $siteAccesses = $this->getSiteaccessesByMandatorId($mandatorId); } elseif ($siteAccess) { $siteAccesses = array($siteAccess); } else { $siteAccesses = array($this->siteAccess->name); } return $siteAccesses; }
php
public function getSiteAccesses($mandatorId = null, $siteAccess = null) { if ($mandatorId) { $siteAccesses = $this->getSiteaccessesByMandatorId($mandatorId); } elseif ($siteAccess) { $siteAccesses = array($siteAccess); } else { $siteAccesses = array($this->siteAccess->name); } return $siteAccesses; }
[ "public", "function", "getSiteAccesses", "(", "$", "mandatorId", "=", "null", ",", "$", "siteAccess", "=", "null", ")", "{", "if", "(", "$", "mandatorId", ")", "{", "$", "siteAccesses", "=", "$", "this", "->", "getSiteaccessesByMandatorId", "(", "$", "mand...
Returns siteAccesses based on mandatorId, requested siteAccess or default SiteAccess. @param null|int $mandatorId @param null|string $siteAccess @return array
[ "Returns", "siteAccesses", "based", "on", "mandatorId", "requested", "siteAccess", "or", "default", "SiteAccess", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L189-L200
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.getRecommendationServiceCredentials
public function getRecommendationServiceCredentials($mandatorId = null, $siteAccess = null) { $siteAccesses = $this->getSiteAccesses($mandatorId, $siteAccess); $siteAccess = end($siteAccesses); if ($siteAccess === self::SYSTEM_DEFAULT_SITEACCESS_NAME) { $siteAccess = null; } $customerId = $this->configResolver->getParameter('yoochoose.customer_id', 'ez_recommendation', $siteAccess); $licenceKey = $this->configResolver->getParameter('yoochoose.license_key', 'ez_recommendation', $siteAccess); return [$customerId, $licenceKey]; }
php
public function getRecommendationServiceCredentials($mandatorId = null, $siteAccess = null) { $siteAccesses = $this->getSiteAccesses($mandatorId, $siteAccess); $siteAccess = end($siteAccesses); if ($siteAccess === self::SYSTEM_DEFAULT_SITEACCESS_NAME) { $siteAccess = null; } $customerId = $this->configResolver->getParameter('yoochoose.customer_id', 'ez_recommendation', $siteAccess); $licenceKey = $this->configResolver->getParameter('yoochoose.license_key', 'ez_recommendation', $siteAccess); return [$customerId, $licenceKey]; }
[ "public", "function", "getRecommendationServiceCredentials", "(", "$", "mandatorId", "=", "null", ",", "$", "siteAccess", "=", "null", ")", "{", "$", "siteAccesses", "=", "$", "this", "->", "getSiteAccesses", "(", "$", "mandatorId", ",", "$", "siteAccess", ")"...
Returns Recommendation Service credentials based on current siteAccess or mandatorId. @param null|int $mandatorId @param null|string $siteAccess @return array
[ "Returns", "Recommendation", "Service", "credentials", "based", "on", "current", "siteAccess", "or", "mandatorId", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L210-L223
train
ezsystems/EzSystemsRecommendationBundle
Helper/SiteAccess.php
SiteAccess.getMainLanguagesBySiteAccesses
private function getMainLanguagesBySiteAccesses(array $siteAccesses) { $languages = array(); foreach ($siteAccesses as $siteAccess) { $languageList = $this->configResolver->getParameter( 'languages', '', $siteAccess !== 'default' ? $siteAccess : null ); $mainLanguage = reset($languageList); if ($mainLanguage) { $languages[$mainLanguage] = $mainLanguage; } } return array_keys($languages); }
php
private function getMainLanguagesBySiteAccesses(array $siteAccesses) { $languages = array(); foreach ($siteAccesses as $siteAccess) { $languageList = $this->configResolver->getParameter( 'languages', '', $siteAccess !== 'default' ? $siteAccess : null ); $mainLanguage = reset($languageList); if ($mainLanguage) { $languages[$mainLanguage] = $mainLanguage; } } return array_keys($languages); }
[ "private", "function", "getMainLanguagesBySiteAccesses", "(", "array", "$", "siteAccesses", ")", "{", "$", "languages", "=", "array", "(", ")", ";", "foreach", "(", "$", "siteAccesses", "as", "$", "siteAccess", ")", "{", "$", "languageList", "=", "$", "this"...
Returns main languages from siteAccess list. @param array $siteAccesses @return array
[ "Returns", "main", "languages", "from", "siteAccess", "list", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/SiteAccess.php#L232-L250
train
ezsystems/EzSystemsRecommendationBundle
EventListener/SessionBackup.php
SessionBackup.onKernelRequest
public function onKernelRequest(GetResponseEvent $event) { $session = $event->getRequest()->getSession(); if ($session === null || !$session->isStarted()) { return; } if (!$event->getRequest()->cookies->has('yc-session-id')) { $event->getRequest()->cookies->set('yc-session-id', $session->getId()); } }
php
public function onKernelRequest(GetResponseEvent $event) { $session = $event->getRequest()->getSession(); if ($session === null || !$session->isStarted()) { return; } if (!$event->getRequest()->cookies->has('yc-session-id')) { $event->getRequest()->cookies->set('yc-session-id', $session->getId()); } }
[ "public", "function", "onKernelRequest", "(", "GetResponseEvent", "$", "event", ")", "{", "$", "session", "=", "$", "event", "->", "getRequest", "(", ")", "->", "getSession", "(", ")", ";", "if", "(", "$", "session", "===", "null", "||", "!", "$", "ses...
Creates a backup of current sessionId in case of sessionId change, we need this value to identify user on YooChoose side. Be aware that session is automatically destroyed when user logs off, in this case the new sessionId will be set. This issue can be treated as a later improvement as it's not required by YooChoose to work correctly. @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
[ "Creates", "a", "backup", "of", "current", "sessionId", "in", "case", "of", "sessionId", "change", "we", "need", "this", "value", "to", "identify", "user", "on", "YooChoose", "side", ".", "Be", "aware", "that", "session", "is", "automatically", "destroyed", ...
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/EventListener/SessionBackup.php#L24-L35
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/RelationMapper.php
RelationMapper.getMapping
public function getMapping($contentTypeIdentifier, $fieldIdentifier) { $key = $contentTypeIdentifier . '.' . $fieldIdentifier; if (!isset($this->fieldMappings[$key])) { return false; } $identifier = explode('.', $this->fieldMappings[$key]); return array( 'content' => $identifier[0], 'field' => $identifier[1], ); }
php
public function getMapping($contentTypeIdentifier, $fieldIdentifier) { $key = $contentTypeIdentifier . '.' . $fieldIdentifier; if (!isset($this->fieldMappings[$key])) { return false; } $identifier = explode('.', $this->fieldMappings[$key]); return array( 'content' => $identifier[0], 'field' => $identifier[1], ); }
[ "public", "function", "getMapping", "(", "$", "contentTypeIdentifier", ",", "$", "fieldIdentifier", ")", "{", "$", "key", "=", "$", "contentTypeIdentifier", ".", "'.'", ".", "$", "fieldIdentifier", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "fie...
Get related mapping for specified content and field. @param string $contentTypeIdentifier @param string $fieldIdentifier @return mixed Returns mathing mapping array or false if no matching mapping found
[ "Get", "related", "mapping", "for", "specified", "content", "and", "field", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/RelationMapper.php#L29-L43
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/Value.php
Value.getImageFieldIdentifier
private function getImageFieldIdentifier($contentId, $language, $related = false) { $content = $this->contentService->loadContent($contentId); $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); $fieldDefinitions = $this->getFieldDefinitionList(); $fieldNames = array_flip($fieldDefinitions); if (in_array('ezimage', $fieldDefinitions)) { return $fieldNames['ezimage']; } elseif (in_array('ezobjectrelation', $fieldDefinitions) && !$related) { $field = $content->getFieldValue($fieldNames['ezobjectrelation'], $language); if (!empty($field->destinationContentId)) { return $this->getImageFieldIdentifier($field->destinationContentId, $language, true); } } else { return $this->getConfiguredFieldIdentifier('image', $contentType); } }
php
private function getImageFieldIdentifier($contentId, $language, $related = false) { $content = $this->contentService->loadContent($contentId); $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); $fieldDefinitions = $this->getFieldDefinitionList(); $fieldNames = array_flip($fieldDefinitions); if (in_array('ezimage', $fieldDefinitions)) { return $fieldNames['ezimage']; } elseif (in_array('ezobjectrelation', $fieldDefinitions) && !$related) { $field = $content->getFieldValue($fieldNames['ezobjectrelation'], $language); if (!empty($field->destinationContentId)) { return $this->getImageFieldIdentifier($field->destinationContentId, $language, true); } } else { return $this->getConfiguredFieldIdentifier('image', $contentType); } }
[ "private", "function", "getImageFieldIdentifier", "(", "$", "contentId", ",", "$", "language", ",", "$", "related", "=", "false", ")", "{", "$", "content", "=", "$", "this", "->", "contentService", "->", "loadContent", "(", "$", "contentId", ")", ";", "$",...
Return identifier of a field of ezimage type. @param mixed $contentId @param string $language @param bool $related @return string
[ "Return", "identifier", "of", "a", "field", "of", "ezimage", "type", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/Value.php#L136-L155
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/Value.php
Value.getRelation
private function getRelation(Content $content, $field, $language) { $fieldDefinitions = $this->getFieldDefinitionList(); $fieldNames = array_flip($fieldDefinitions); $isRelation = (in_array('ezobjectrelation', $fieldDefinitions) && $field == $fieldNames['ezobjectrelation']); if ($isRelation && $field == $fieldNames['ezobjectrelation']) { $fieldValue = $content->getFieldValue($fieldNames['ezobjectrelation'], $language); if (isset($fieldValue->destinationContentId)) { return $fieldValue->destinationContentId; } } return null; }
php
private function getRelation(Content $content, $field, $language) { $fieldDefinitions = $this->getFieldDefinitionList(); $fieldNames = array_flip($fieldDefinitions); $isRelation = (in_array('ezobjectrelation', $fieldDefinitions) && $field == $fieldNames['ezobjectrelation']); if ($isRelation && $field == $fieldNames['ezobjectrelation']) { $fieldValue = $content->getFieldValue($fieldNames['ezobjectrelation'], $language); if (isset($fieldValue->destinationContentId)) { return $fieldValue->destinationContentId; } } return null; }
[ "private", "function", "getRelation", "(", "Content", "$", "content", ",", "$", "field", ",", "$", "language", ")", "{", "$", "fieldDefinitions", "=", "$", "this", "->", "getFieldDefinitionList", "(", ")", ";", "$", "fieldNames", "=", "array_flip", "(", "$...
Checks if content has image relation field, returns its ID if true. @param \eZ\Publish\API\Repository\Values\Content\Content $content @param string $field @param string $language @return int|null
[ "Checks", "if", "content", "has", "image", "relation", "field", "returns", "its", "ID", "if", "true", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/Value.php#L166-L181
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/Value.php
Value.getConfiguredFieldIdentifier
public function getConfiguredFieldIdentifier($fieldName, ContentType $contentType) { $contentTypeName = $contentType->identifier; if (isset($this->parameters['fieldIdentifiers'])) { $fieldIdentifiers = $this->parameters['fieldIdentifiers']; if (isset($fieldIdentifiers[$fieldName]) && !empty($fieldIdentifiers[$fieldName][$contentTypeName])) { return $fieldIdentifiers[$fieldName][$contentTypeName]; } } return $fieldName; }
php
public function getConfiguredFieldIdentifier($fieldName, ContentType $contentType) { $contentTypeName = $contentType->identifier; if (isset($this->parameters['fieldIdentifiers'])) { $fieldIdentifiers = $this->parameters['fieldIdentifiers']; if (isset($fieldIdentifiers[$fieldName]) && !empty($fieldIdentifiers[$fieldName][$contentTypeName])) { return $fieldIdentifiers[$fieldName][$contentTypeName]; } } return $fieldName; }
[ "public", "function", "getConfiguredFieldIdentifier", "(", "$", "fieldName", ",", "ContentType", "$", "contentType", ")", "{", "$", "contentTypeName", "=", "$", "contentType", "->", "identifier", ";", "if", "(", "isset", "(", "$", "this", "->", "parameters", "...
Returns field name. To define another field name for specific value (e. g. author) add it to parameters.yml For example: ez_recommendation.field_identifiers: author: blog_post: authors image: blog_post: thumbnail @param string $fieldName @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType @return string
[ "Returns", "field", "name", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/Value.php#L201-L214
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/Value.php
Value.setFieldDefinitionsList
public function setFieldDefinitionsList(ContentType $contentType) { foreach ($contentType->fieldDefinitions as $fieldDef) { $this->fieldDefIdentifiers[$fieldDef->identifier] = $fieldDef->fieldTypeIdentifier; } }
php
public function setFieldDefinitionsList(ContentType $contentType) { foreach ($contentType->fieldDefinitions as $fieldDef) { $this->fieldDefIdentifiers[$fieldDef->identifier] = $fieldDef->fieldTypeIdentifier; } }
[ "public", "function", "setFieldDefinitionsList", "(", "ContentType", "$", "contentType", ")", "{", "foreach", "(", "$", "contentType", "->", "fieldDefinitions", "as", "$", "fieldDef", ")", "{", "$", "this", "->", "fieldDefIdentifiers", "[", "$", "fieldDef", "->"...
Prepares an array with field type identifiers. @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
[ "Prepares", "an", "array", "with", "field", "type", "identifiers", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/Value.php#L221-L226
train
ezsystems/EzSystemsRecommendationBundle
Rest/Content/Content.php
Content.prepareContent
public function prepareContent($data, ParameterBag $options, OutputInterface $output = null) { if ($output === null) { $output = new NullOutput(); } $content = array(); foreach ($data as $contentTypeId => $items) { $progress = new ProgressBar($output, count($items)); $progress->start(); foreach ($items as $contentValue) { $contentValue = $contentValue->valueObject; $contentType = $this->contentTypeService->loadContentType($contentValue->contentInfo->contentTypeId); $location = $this->locationService->loadLocation($contentValue->contentInfo->mainLocationId); $language = $options->get('lang', $location->contentInfo->mainLanguageCode); $this->value->setFieldDefinitionsList($contentType); $content[$contentTypeId][$contentValue->id] = array( 'contentId' => $contentValue->id, 'contentTypeId' => $contentType->id, 'identifier' => $contentType->identifier, 'language' => $language, 'publishedDate' => $contentValue->contentInfo->publishedDate->format('c'), 'author' => $this->getAuthor($contentValue, $contentType), 'uri' => $this->generator->generate($location, array(), false), 'mainLocation' => array( 'href' => '/api/ezp/v2/content/locations' . $location->pathString, ), 'locations' => array( 'href' => '/api/ezp/v2/content/objects/' . $contentValue->id . '/locations', ), 'categoryPath' => $location->pathString, 'fields' => array(), ); $fields = $this->prepareFields($contentType, $options->get('fields')); if (!empty($fields)) { foreach ($fields as $field) { $field = $this->value->getConfiguredFieldIdentifier($field, $contentType); $content[$contentTypeId][$contentValue->id]['fields'][$field] = $this->value->getFieldValue($contentValue, $field, $language, $options->all()); } } $progress->advance(); } $progress->finish(); $output->writeln(''); } return $content; }
php
public function prepareContent($data, ParameterBag $options, OutputInterface $output = null) { if ($output === null) { $output = new NullOutput(); } $content = array(); foreach ($data as $contentTypeId => $items) { $progress = new ProgressBar($output, count($items)); $progress->start(); foreach ($items as $contentValue) { $contentValue = $contentValue->valueObject; $contentType = $this->contentTypeService->loadContentType($contentValue->contentInfo->contentTypeId); $location = $this->locationService->loadLocation($contentValue->contentInfo->mainLocationId); $language = $options->get('lang', $location->contentInfo->mainLanguageCode); $this->value->setFieldDefinitionsList($contentType); $content[$contentTypeId][$contentValue->id] = array( 'contentId' => $contentValue->id, 'contentTypeId' => $contentType->id, 'identifier' => $contentType->identifier, 'language' => $language, 'publishedDate' => $contentValue->contentInfo->publishedDate->format('c'), 'author' => $this->getAuthor($contentValue, $contentType), 'uri' => $this->generator->generate($location, array(), false), 'mainLocation' => array( 'href' => '/api/ezp/v2/content/locations' . $location->pathString, ), 'locations' => array( 'href' => '/api/ezp/v2/content/objects/' . $contentValue->id . '/locations', ), 'categoryPath' => $location->pathString, 'fields' => array(), ); $fields = $this->prepareFields($contentType, $options->get('fields')); if (!empty($fields)) { foreach ($fields as $field) { $field = $this->value->getConfiguredFieldIdentifier($field, $contentType); $content[$contentTypeId][$contentValue->id]['fields'][$field] = $this->value->getFieldValue($contentValue, $field, $language, $options->all()); } } $progress->advance(); } $progress->finish(); $output->writeln(''); } return $content; }
[ "public", "function", "prepareContent", "(", "$", "data", ",", "ParameterBag", "$", "options", ",", "OutputInterface", "$", "output", "=", "null", ")", "{", "if", "(", "$", "output", "===", "null", ")", "{", "$", "output", "=", "new", "NullOutput", "(", ...
Prepare content array. @param array $data @param ParameterBag $options @param OutputInterface|null $output @return array
[ "Prepare", "content", "array", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Content/Content.php#L75-L129
train
ezsystems/EzSystemsRecommendationBundle
Rest/Content/Content.php
Content.getAuthor
private function getAuthor(ApiContent $contentValue, ApiContentType $contentType) { $author = $contentValue->getFieldValue( $this->value->getConfiguredFieldIdentifier('author', $contentType) ); if (null === $author) { try { $ownerId = empty($contentValue->contentInfo->ownerId) ? $this->defaultAuthorId : $contentValue->contentInfo->ownerId; $userContentInfo = $this->contentService->loadContentInfo($ownerId); $author = $userContentInfo->name; } catch (UnauthorizedException $e) { $author = ''; } } return (string) $author; }
php
private function getAuthor(ApiContent $contentValue, ApiContentType $contentType) { $author = $contentValue->getFieldValue( $this->value->getConfiguredFieldIdentifier('author', $contentType) ); if (null === $author) { try { $ownerId = empty($contentValue->contentInfo->ownerId) ? $this->defaultAuthorId : $contentValue->contentInfo->ownerId; $userContentInfo = $this->contentService->loadContentInfo($ownerId); $author = $userContentInfo->name; } catch (UnauthorizedException $e) { $author = ''; } } return (string) $author; }
[ "private", "function", "getAuthor", "(", "ApiContent", "$", "contentValue", ",", "ApiContentType", "$", "contentType", ")", "{", "$", "author", "=", "$", "contentValue", "->", "getFieldValue", "(", "$", "this", "->", "value", "->", "getConfiguredFieldIdentifier", ...
Returns author of the content. @param \eZ\Publish\API\Repository\Values\Content\Content $contentValue @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType @return string
[ "Returns", "author", "of", "the", "content", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Content/Content.php#L139-L156
train
ezsystems/EzSystemsRecommendationBundle
Rest/Content/Content.php
Content.prepareFields
private function prepareFields(ApiContentType $contentType, $fields = null) { if ($fields !== null) { if (strpos($fields, ',') !== false) { return explode(',', $fields); } return array($fields); } $fields = array(); $contentFields = $contentType->getFieldDefinitions(); foreach ($contentFields as $field) { $fields[] = $field->identifier; } return $fields; }
php
private function prepareFields(ApiContentType $contentType, $fields = null) { if ($fields !== null) { if (strpos($fields, ',') !== false) { return explode(',', $fields); } return array($fields); } $fields = array(); $contentFields = $contentType->getFieldDefinitions(); foreach ($contentFields as $field) { $fields[] = $field->identifier; } return $fields; }
[ "private", "function", "prepareFields", "(", "ApiContentType", "$", "contentType", ",", "$", "fields", "=", "null", ")", "{", "if", "(", "$", "fields", "!==", "null", ")", "{", "if", "(", "strpos", "(", "$", "fields", ",", "','", ")", "!==", "false", ...
Checks if fields are given, if not - returns all of them. @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType @param string $fields @return array|null
[ "Checks", "if", "fields", "are", "given", "if", "not", "-", "returns", "all", "of", "them", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Content/Content.php#L166-L184
train
ezsystems/EzSystemsRecommendationBundle
Twig/RecommendationTwigExtension.php
RecommendationTwigExtension.trackUser
public function trackUser(Twig_Environment $twigEnvironment, $contentId) { if (!in_array($this->getContentIdentifier($contentId), $this->options['includedContentTypes'])) { return ''; } return $twigEnvironment->render( 'EzSystemsRecommendationBundle::track_user.html.twig', array( 'contentId' => $contentId, 'contentTypeId' => $this->getContentTypeId($this->getContentIdentifier($contentId)), 'language' => $this->getCurrentLanguage(), 'userId' => $this->getCurrentUserId(), 'customerId' => $this->options['customerId'], 'consumeTimeout' => ($this->options['consumeTimeout'] * 1000), 'trackingScriptUrl' => $this->options['trackingScriptUrl'], ) ); }
php
public function trackUser(Twig_Environment $twigEnvironment, $contentId) { if (!in_array($this->getContentIdentifier($contentId), $this->options['includedContentTypes'])) { return ''; } return $twigEnvironment->render( 'EzSystemsRecommendationBundle::track_user.html.twig', array( 'contentId' => $contentId, 'contentTypeId' => $this->getContentTypeId($this->getContentIdentifier($contentId)), 'language' => $this->getCurrentLanguage(), 'userId' => $this->getCurrentUserId(), 'customerId' => $this->options['customerId'], 'consumeTimeout' => ($this->options['consumeTimeout'] * 1000), 'trackingScriptUrl' => $this->options['trackingScriptUrl'], ) ); }
[ "public", "function", "trackUser", "(", "Twig_Environment", "$", "twigEnvironment", ",", "$", "contentId", ")", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "getContentIdentifier", "(", "$", "contentId", ")", ",", "$", "this", "->", "options", ...
Renders simple tracking snippet code. @param \Twig_Environment $twigEnvironment @param int|mixed $contentId @return string
[ "Renders", "simple", "tracking", "snippet", "code", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Twig/RecommendationTwigExtension.php#L170-L188
train
ezsystems/EzSystemsRecommendationBundle
Twig/RecommendationTwigExtension.php
RecommendationTwigExtension.showRecommendations
public function showRecommendations( Twig_Environment $twigEnvironment, $contentId, $scenario, $limit, $contentType, $template, array $fields, array $params = array() ) { if (empty($fields)) { throw new InvalidArgumentException('Missing recommendation fields, at least one field is required'); } $filters = ''; if (isset($params['filters'])) { foreach ($params['filters'] as $key => $filter) { $filter = is_array($filter) ? implode(',', $filter) : $filter; $filters .= sprintf('&%s=%s', $key, $filter); } } return $twigEnvironment->render( sprintf('EzSystemsRecommendationBundle::%s.html.twig', $template), array( 'contentId' => $contentId, 'language' => $this->getCurrentLanguage(), 'scenario' => $scenario, 'limit' => $limit, 'templateId' => uniqid(), 'fields' => $fields, 'filters' => $filters, 'endpointUrl' => $this->getEndPointUrl(), 'feedbackUrl' => $this->getFeedbackUrl($this->getContentTypeId($contentType)), 'contentType' => $this->getContentTypeId($this->getContentIdentifier($contentId)), 'outputTypeId' => $this->getContentTypeId($contentType), 'categoryPath' => $this->getLocationPathString($contentId), ) ); }
php
public function showRecommendations( Twig_Environment $twigEnvironment, $contentId, $scenario, $limit, $contentType, $template, array $fields, array $params = array() ) { if (empty($fields)) { throw new InvalidArgumentException('Missing recommendation fields, at least one field is required'); } $filters = ''; if (isset($params['filters'])) { foreach ($params['filters'] as $key => $filter) { $filter = is_array($filter) ? implode(',', $filter) : $filter; $filters .= sprintf('&%s=%s', $key, $filter); } } return $twigEnvironment->render( sprintf('EzSystemsRecommendationBundle::%s.html.twig', $template), array( 'contentId' => $contentId, 'language' => $this->getCurrentLanguage(), 'scenario' => $scenario, 'limit' => $limit, 'templateId' => uniqid(), 'fields' => $fields, 'filters' => $filters, 'endpointUrl' => $this->getEndPointUrl(), 'feedbackUrl' => $this->getFeedbackUrl($this->getContentTypeId($contentType)), 'contentType' => $this->getContentTypeId($this->getContentIdentifier($contentId)), 'outputTypeId' => $this->getContentTypeId($contentType), 'categoryPath' => $this->getLocationPathString($contentId), ) ); }
[ "public", "function", "showRecommendations", "(", "Twig_Environment", "$", "twigEnvironment", ",", "$", "contentId", ",", "$", "scenario", ",", "$", "limit", ",", "$", "contentType", ",", "$", "template", ",", "array", "$", "fields", ",", "array", "$", "para...
Renders recommendations snippet code. @param \Twig_Environment $twigEnvironment @param int|mixed $contentId @param string $scenario @param int $limit @param string $contentType @param string $template @param array $fields @param array $params @return string @throws \EzSystems\RecommendationBundle\Exception\InvalidArgumentException when attributes are missing
[ "Renders", "recommendations", "snippet", "code", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Twig/RecommendationTwigExtension.php#L237-L276
train
ezsystems/EzSystemsRecommendationBundle
Twig/RecommendationTwigExtension.php
RecommendationTwigExtension.getFeedbackUrl
protected function getFeedbackUrl($outputContentTypeId) { return sprintf('%s/api/%d/rendered/%s/%d/', $this->options['trackingEndPoint'], $this->options['customerId'], $this->getCurrentUserId(), $outputContentTypeId ); }
php
protected function getFeedbackUrl($outputContentTypeId) { return sprintf('%s/api/%d/rendered/%s/%d/', $this->options['trackingEndPoint'], $this->options['customerId'], $this->getCurrentUserId(), $outputContentTypeId ); }
[ "protected", "function", "getFeedbackUrl", "(", "$", "outputContentTypeId", ")", "{", "return", "sprintf", "(", "'%s/api/%d/rendered/%s/%d/'", ",", "$", "this", "->", "options", "[", "'trackingEndPoint'", "]", ",", "$", "this", "->", "options", "[", "'customerId'"...
Returns YooChoose feedback end-point address used to report that recommendations were successfully fetched and displayed. @param int $outputContentTypeId ContentType ID for which recommendations should be delivered @return string
[ "Returns", "YooChoose", "feedback", "end", "-", "point", "address", "used", "to", "report", "that", "recommendations", "were", "successfully", "fetched", "and", "displayed", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Twig/RecommendationTwigExtension.php#L327-L335
train
ezsystems/EzSystemsRecommendationBundle
Twig/RecommendationTwigExtension.php
RecommendationTwigExtension.getCurrentUserId
private function getCurrentUserId() { if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY') // user has just logged in || $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') // user has logged in using remember_me cookie ) { $authenticationToken = $this->tokenStorage->getToken(); $user = $authenticationToken->getUser(); if (is_string($user)) { return $user; } elseif (method_exists($user, 'getAPIUser')) { return $user->getAPIUser()->id; } return $authenticationToken->getUsername(); } if (!$this->session->isStarted()) { $this->session->start(); } $request = $this->requestStack->getMasterRequest(); if (!$request->cookies->has('yc-session-id')) { $request->cookies->set('yc-session-id', $this->session->getId()); } return $request->cookies->get('yc-session-id'); }
php
private function getCurrentUserId() { if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY') // user has just logged in || $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') // user has logged in using remember_me cookie ) { $authenticationToken = $this->tokenStorage->getToken(); $user = $authenticationToken->getUser(); if (is_string($user)) { return $user; } elseif (method_exists($user, 'getAPIUser')) { return $user->getAPIUser()->id; } return $authenticationToken->getUsername(); } if (!$this->session->isStarted()) { $this->session->start(); } $request = $this->requestStack->getMasterRequest(); if (!$request->cookies->has('yc-session-id')) { $request->cookies->set('yc-session-id', $this->session->getId()); } return $request->cookies->get('yc-session-id'); }
[ "private", "function", "getCurrentUserId", "(", ")", "{", "if", "(", "$", "this", "->", "authorizationChecker", "->", "isGranted", "(", "'IS_AUTHENTICATED_FULLY'", ")", "// user has just logged in", "||", "$", "this", "->", "authorizationChecker", "->", "isGranted", ...
Returns logged-in userId or anonymous sessionId. @return int|string
[ "Returns", "logged", "-", "in", "userId", "or", "anonymous", "sessionId", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Twig/RecommendationTwigExtension.php#L342-L370
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/TypeValue.php
TypeValue.ezxmltext
public function ezxmltext(Field $field) { try { $xml = $this->xmlHtml5Converter->convert($field->value->xml); } catch (LogicException $e) { $xml = $field->value->xml->saveHTML(); } return '<![CDATA[' . $xml . ']]>'; }
php
public function ezxmltext(Field $field) { try { $xml = $this->xmlHtml5Converter->convert($field->value->xml); } catch (LogicException $e) { $xml = $field->value->xml->saveHTML(); } return '<![CDATA[' . $xml . ']]>'; }
[ "public", "function", "ezxmltext", "(", "Field", "$", "field", ")", "{", "try", "{", "$", "xml", "=", "$", "this", "->", "xmlHtml5Converter", "->", "convert", "(", "$", "field", "->", "value", "->", "xml", ")", ";", "}", "catch", "(", "LogicException",...
Method for parsing ezxmltext field. @param \eZ\Publish\API\Repository\Values\Content\Field $field @return string
[ "Method", "for", "parsing", "ezxmltext", "field", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/TypeValue.php#L71-L80
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/TypeValue.php
TypeValue.ezrichtext
public function ezrichtext(Field $field) { return '<![CDATA[' . $this->richHtml5Converter->convert($field->value->xml)->saveHTML() . ']]>'; }
php
public function ezrichtext(Field $field) { return '<![CDATA[' . $this->richHtml5Converter->convert($field->value->xml)->saveHTML() . ']]>'; }
[ "public", "function", "ezrichtext", "(", "Field", "$", "field", ")", "{", "return", "'<![CDATA['", ".", "$", "this", "->", "richHtml5Converter", "->", "convert", "(", "$", "field", "->", "value", "->", "xml", ")", "->", "saveHTML", "(", ")", ".", "']]>'"...
Method for parsing ezrichtext field. @param \eZ\Publish\API\Repository\Values\Content\Field $field @return string
[ "Method", "for", "parsing", "ezrichtext", "field", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/TypeValue.php#L89-L92
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/TypeValue.php
TypeValue.ezimage
public function ezimage(Field $field, Content $content, $language, $imageFieldIdentifier, $options = []) { if (!isset($field->value->id)) { return ''; } $variations = $this->configResolver->getParameter('image_variations'); $variation = 'original'; if ((!empty($options['image'])) && in_array($options['image'], array_keys($variations))) { $variation = $options['image']; } try { $uri = $this ->imageVariationService ->getVariation($field, $content->versionInfo, $variation) ->uri; if (strpos($uri, 'http://:0') !== false) { $uri = str_replace('http://:0', 'http://0', $uri); } return parse_url($uri, PHP_URL_PATH); } catch (SourceImageNotFoundException $exception) { return ''; } }
php
public function ezimage(Field $field, Content $content, $language, $imageFieldIdentifier, $options = []) { if (!isset($field->value->id)) { return ''; } $variations = $this->configResolver->getParameter('image_variations'); $variation = 'original'; if ((!empty($options['image'])) && in_array($options['image'], array_keys($variations))) { $variation = $options['image']; } try { $uri = $this ->imageVariationService ->getVariation($field, $content->versionInfo, $variation) ->uri; if (strpos($uri, 'http://:0') !== false) { $uri = str_replace('http://:0', 'http://0', $uri); } return parse_url($uri, PHP_URL_PATH); } catch (SourceImageNotFoundException $exception) { return ''; } }
[ "public", "function", "ezimage", "(", "Field", "$", "field", ",", "Content", "$", "content", ",", "$", "language", ",", "$", "imageFieldIdentifier", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "field", "->", "valu...
Method for parsing ezimage field. @param \eZ\Publish\API\Repository\Values\Content\Field $field @param \eZ\Publish\API\Repository\Values\Content\Content $content @param string $language @param string $imageFieldIdentifier @param array $options @return string @throws \eZ\Publish\API\Repository\Exceptions\InvalidVariationException @throws \eZ\Publish\Core\MVC\Exception\SourceImageNotFoundException
[ "Method", "for", "parsing", "ezimage", "field", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/TypeValue.php#L108-L135
train
ezsystems/EzSystemsRecommendationBundle
Rest/Field/TypeValue.php
TypeValue.ezobjectrelation
public function ezobjectrelation(Field $field, Content $content, $language, $imageFieldIdentifier, $options = []) { $fields = $content->getFieldsByLanguage($language); foreach ($fields as $type => $field) { if ($type == $imageFieldIdentifier) { return $this->ezimage($field, $content, $language, $imageFieldIdentifier, $options); } } return ''; }
php
public function ezobjectrelation(Field $field, Content $content, $language, $imageFieldIdentifier, $options = []) { $fields = $content->getFieldsByLanguage($language); foreach ($fields as $type => $field) { if ($type == $imageFieldIdentifier) { return $this->ezimage($field, $content, $language, $imageFieldIdentifier, $options); } } return ''; }
[ "public", "function", "ezobjectrelation", "(", "Field", "$", "field", ",", "Content", "$", "content", ",", "$", "language", ",", "$", "imageFieldIdentifier", ",", "$", "options", "=", "[", "]", ")", "{", "$", "fields", "=", "$", "content", "->", "getFiel...
Method for parsing ezobjectrelation field. For now related fields refer to images. @param \eZ\Publish\API\Repository\Values\Content\Field $field @param \eZ\Publish\API\Repository\Values\Content\Content $content @param string $language @param string $imageFieldIdentifier @param array $options @return string
[ "Method", "for", "parsing", "ezobjectrelation", "field", ".", "For", "now", "related", "fields", "refer", "to", "images", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Field/TypeValue.php#L149-L159
train
ezsystems/EzSystemsRecommendationBundle
Rest/Controller/ContentTypeController.php
ContentTypeController.prepareContentByContentTypeIds
protected function prepareContentByContentTypeIds($contentTypeIds, Request $request) { $options = $this->parseParameters($request->query, ['page_size', 'page', 'path', 'hidden', 'lang', 'sa', 'image']); $pageSize = (int)$options->get('page_size', self::PAGE_SIZE); $page = (int)$options->get('page', 1); $offset = $page * $pageSize - $pageSize; $path = $options->get('path'); $hidden = $options->get('hidden'); $lang = $options->get('lang'); $siteAccess = $options->get('sa'); $rootLocationPathString = $this->locationService->loadLocation( $this->siteAccessHelper->getRootLocationBySiteAccessName($siteAccess) )->pathString; $contentItems = array(); foreach ($contentTypeIds as $contentTypeId) { $criteria = array(new Criterion\ContentTypeId($contentTypeId)); if ($path) { $criteria[] = new Criterion\Subtree($path); } if (!$hidden) { $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); } $criteria[] = new Criterion\Subtree($rootLocationPathString); $query = new Query(); $query->query = new Criterion\LogicalAnd($criteria); $query->limit = $pageSize; $query->offset = $offset; $contentItems[$contentTypeId] = $this->searchService->findContent( $query, (!empty($lang) ? array('languages' => array($lang)) : array()) )->searchHits; } $contentOptions = $this->parseParameters($request->query, ['lang', 'fields', 'image']); return $this->content->prepareContent($contentItems, $contentOptions); }
php
protected function prepareContentByContentTypeIds($contentTypeIds, Request $request) { $options = $this->parseParameters($request->query, ['page_size', 'page', 'path', 'hidden', 'lang', 'sa', 'image']); $pageSize = (int)$options->get('page_size', self::PAGE_SIZE); $page = (int)$options->get('page', 1); $offset = $page * $pageSize - $pageSize; $path = $options->get('path'); $hidden = $options->get('hidden'); $lang = $options->get('lang'); $siteAccess = $options->get('sa'); $rootLocationPathString = $this->locationService->loadLocation( $this->siteAccessHelper->getRootLocationBySiteAccessName($siteAccess) )->pathString; $contentItems = array(); foreach ($contentTypeIds as $contentTypeId) { $criteria = array(new Criterion\ContentTypeId($contentTypeId)); if ($path) { $criteria[] = new Criterion\Subtree($path); } if (!$hidden) { $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); } $criteria[] = new Criterion\Subtree($rootLocationPathString); $query = new Query(); $query->query = new Criterion\LogicalAnd($criteria); $query->limit = $pageSize; $query->offset = $offset; $contentItems[$contentTypeId] = $this->searchService->findContent( $query, (!empty($lang) ? array('languages' => array($lang)) : array()) )->searchHits; } $contentOptions = $this->parseParameters($request->query, ['lang', 'fields', 'image']); return $this->content->prepareContent($contentItems, $contentOptions); }
[ "protected", "function", "prepareContentByContentTypeIds", "(", "$", "contentTypeIds", ",", "Request", "$", "request", ")", "{", "$", "options", "=", "$", "this", "->", "parseParameters", "(", "$", "request", "->", "query", ",", "[", "'page_size'", ",", "'page...
Returns paged content based on ContentType ids. @param array $contentTypeIds @param \Symfony\Component\HttpFoundation\Request $request @return array
[ "Returns", "paged", "content", "based", "on", "ContentType", "ids", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Rest/Controller/ContentTypeController.php#L64-L109
train
ezsystems/EzSystemsRecommendationBundle
Helper/FileSystem.php
FileSystem.load
public function load($file) { $dir = $this->getDir(); if (!$this->filesystem->exists($dir . $file)) { throw new NotFoundException('File not found.'); } return file_get_contents($dir . $file); }
php
public function load($file) { $dir = $this->getDir(); if (!$this->filesystem->exists($dir . $file)) { throw new NotFoundException('File not found.'); } return file_get_contents($dir . $file); }
[ "public", "function", "load", "(", "$", "file", ")", "{", "$", "dir", "=", "$", "this", "->", "getDir", "(", ")", ";", "if", "(", "!", "$", "this", "->", "filesystem", "->", "exists", "(", "$", "dir", ".", "$", "file", ")", ")", "{", "throw", ...
Load the content from file. @param string $file @return bool|string @throws NotFoundException when file not found.
[ "Load", "the", "content", "from", "file", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/FileSystem.php#L44-L53
train
ezsystems/EzSystemsRecommendationBundle
Helper/FileSystem.php
FileSystem.createChunkDir
public function createChunkDir() { $directoryName = date('Y/m/d/H/i/', time()); $dir = $this->getDir() . $directoryName; if (!$this->filesystem->exists($dir)) { $this->filesystem->mkdir($dir, 0755); } return $directoryName; }
php
public function createChunkDir() { $directoryName = date('Y/m/d/H/i/', time()); $dir = $this->getDir() . $directoryName; if (!$this->filesystem->exists($dir)) { $this->filesystem->mkdir($dir, 0755); } return $directoryName; }
[ "public", "function", "createChunkDir", "(", ")", "{", "$", "directoryName", "=", "date", "(", "'Y/m/d/H/i/'", ",", "time", "(", ")", ")", ";", "$", "dir", "=", "$", "this", "->", "getDir", "(", ")", ".", "$", "directoryName", ";", "if", "(", "!", ...
Generates directory for export files. @return string
[ "Generates", "directory", "for", "export", "files", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/FileSystem.php#L81-L91
train
ezsystems/EzSystemsRecommendationBundle
Helper/FileSystem.php
FileSystem.unlock
public function unlock() { $dir = $this->getDir(); if ($this->filesystem->exists($dir . '.lock')) { $this->filesystem->remove($dir . '.lock'); } }
php
public function unlock() { $dir = $this->getDir(); if ($this->filesystem->exists($dir . '.lock')) { $this->filesystem->remove($dir . '.lock'); } }
[ "public", "function", "unlock", "(", ")", "{", "$", "dir", "=", "$", "this", "->", "getDir", "(", ")", ";", "if", "(", "$", "this", "->", "filesystem", "->", "exists", "(", "$", "dir", ".", "'.lock'", ")", ")", "{", "$", "this", "->", "filesystem...
Unlock directory by deleting lock file.
[ "Unlock", "directory", "by", "deleting", "lock", "file", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/FileSystem.php#L106-L113
train
ezsystems/EzSystemsRecommendationBundle
Helper/FileSystem.php
FileSystem.secureDir
public function secureDir($chunkDir, $credentials) { $dir = $this->getDir() . $chunkDir; if ($credentials['method'] == 'none') { return array(); } elseif ($credentials['method'] == 'user') { return array( 'login' => $credentials['login'], 'password' => $credentials['password'], ); } $user = 'yc'; $password = substr(md5(microtime()), 0, 10); $this->filesystem->dumpFile( $dir . '.htpasswd', sprintf('%s:%s', $user, crypt($password, md5($password))) ); return array( 'login' => $user, 'password' => $password, ); }
php
public function secureDir($chunkDir, $credentials) { $dir = $this->getDir() . $chunkDir; if ($credentials['method'] == 'none') { return array(); } elseif ($credentials['method'] == 'user') { return array( 'login' => $credentials['login'], 'password' => $credentials['password'], ); } $user = 'yc'; $password = substr(md5(microtime()), 0, 10); $this->filesystem->dumpFile( $dir . '.htpasswd', sprintf('%s:%s', $user, crypt($password, md5($password))) ); return array( 'login' => $user, 'password' => $password, ); }
[ "public", "function", "secureDir", "(", "$", "chunkDir", ",", "$", "credentials", ")", "{", "$", "dir", "=", "$", "this", "->", "getDir", "(", ")", ".", "$", "chunkDir", ";", "if", "(", "$", "credentials", "[", "'method'", "]", "==", "'none'", ")", ...
Securing the directory regarding the authentication method. @param string $chunkDir @param array $credentials @return array
[ "Securing", "the", "directory", "regarding", "the", "authentication", "method", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/FileSystem.php#L133-L158
train
ezsystems/EzSystemsRecommendationBundle
Helper/Text.php
Text.getIdListFromString
public static function getIdListFromString($string) { if (filter_var($string, FILTER_VALIDATE_INT) !== false) { return array($string); } return array_map( function ($id) { if (false === filter_var($id, FILTER_VALIDATE_INT)) { throw new InvalidArgumentException('String should be a list of Integers'); } return (int) $id; }, explode(',', $string) ); }
php
public static function getIdListFromString($string) { if (filter_var($string, FILTER_VALIDATE_INT) !== false) { return array($string); } return array_map( function ($id) { if (false === filter_var($id, FILTER_VALIDATE_INT)) { throw new InvalidArgumentException('String should be a list of Integers'); } return (int) $id; }, explode(',', $string) ); }
[ "public", "static", "function", "getIdListFromString", "(", "$", "string", ")", "{", "if", "(", "filter_var", "(", "$", "string", ",", "FILTER_VALIDATE_INT", ")", "!==", "false", ")", "{", "return", "array", "(", "$", "string", ")", ";", "}", "return", "...
Preparing array of integers based on comma separated integers in string or single integer in string. @param string $string list of integers separated by comma character @return array @throws InvalidArgumentException If incorrect $list value is given
[ "Preparing", "array", "of", "integers", "based", "on", "comma", "separated", "integers", "in", "string", "or", "single", "integer", "in", "string", "." ]
ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a
https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/ecacbe8fcca9e4e0eb06e2fc8b548c8dde00352a/Helper/Text.php#L25-L41
train
rfussien/leboncoin-crawler
src/GetFrom.php
GetFrom.search
public function search($url, $detailedAd = false) { $searchData = new SearchResultCrawler( new Crawler((string) $this->client->get($url)->getBody()), $url ); $url = new SearchResultUrlParser($url, $searchData->getNbPages()); $ads = ($detailedAd) ? $searchData->getAds() : $searchData->getAdsId(); $sumarize = [ 'total_ads' => $searchData->getNbAds(), 'total_page' => $searchData->getNbPages(), 'ads_per_page' => $searchData->getNbAdsPerPage(), 'category' => $searchData->getUrlParser()->getCategory(), 'location' => $searchData->getUrlParser()->getLocation(), 'search_area' => $searchData->getUrlParser()->getSearchArea(), 'sort_by' => $searchData->getUrlParser()->getSortType(), 'type' => $searchData->getUrlParser()->getType(), 'ads' => $ads, ]; return array_merge($url->getNav(), $sumarize); }
php
public function search($url, $detailedAd = false) { $searchData = new SearchResultCrawler( new Crawler((string) $this->client->get($url)->getBody()), $url ); $url = new SearchResultUrlParser($url, $searchData->getNbPages()); $ads = ($detailedAd) ? $searchData->getAds() : $searchData->getAdsId(); $sumarize = [ 'total_ads' => $searchData->getNbAds(), 'total_page' => $searchData->getNbPages(), 'ads_per_page' => $searchData->getNbAdsPerPage(), 'category' => $searchData->getUrlParser()->getCategory(), 'location' => $searchData->getUrlParser()->getLocation(), 'search_area' => $searchData->getUrlParser()->getSearchArea(), 'sort_by' => $searchData->getUrlParser()->getSortType(), 'type' => $searchData->getUrlParser()->getType(), 'ads' => $ads, ]; return array_merge($url->getNav(), $sumarize); }
[ "public", "function", "search", "(", "$", "url", ",", "$", "detailedAd", "=", "false", ")", "{", "$", "searchData", "=", "new", "SearchResultCrawler", "(", "new", "Crawler", "(", "(", "string", ")", "$", "this", "->", "client", "->", "get", "(", "$", ...
retrieve the search result data from the given url @param $url @param bool $detailedAd @return array
[ "retrieve", "the", "search", "result", "data", "from", "the", "given", "url" ]
1ff5abced9392d24a759f6c8b5170e90d2e1ddb2
https://github.com/rfussien/leboncoin-crawler/blob/1ff5abced9392d24a759f6c8b5170e90d2e1ddb2/src/GetFrom.php#L50-L74
train
rfussien/leboncoin-crawler
src/GetFrom.php
GetFrom.adByUrl
private function adByUrl($url) { $content = $this->client->get($url)->getBody()->getContents(); $adData = new AdCrawler(new Crawler(utf8_encode($content)), $url); return $adData->getAll(); }
php
private function adByUrl($url) { $content = $this->client->get($url)->getBody()->getContents(); $adData = new AdCrawler(new Crawler(utf8_encode($content)), $url); return $adData->getAll(); }
[ "private", "function", "adByUrl", "(", "$", "url", ")", "{", "$", "content", "=", "$", "this", "->", "client", "->", "get", "(", "$", "url", ")", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ";", "$", "adData", "=", "new", "AdCrawler",...
Retrieve the ad's data from the given url @param $url @return array
[ "Retrieve", "the", "ad", "s", "data", "from", "the", "given", "url" ]
1ff5abced9392d24a759f6c8b5170e90d2e1ddb2
https://github.com/rfussien/leboncoin-crawler/blob/1ff5abced9392d24a759f6c8b5170e90d2e1ddb2/src/GetFrom.php#L95-L102
train
rfussien/leboncoin-crawler
src/GetFrom.php
GetFrom.ad
public function ad() { if (func_num_args() === 1) { return call_user_func_array([$this, 'adByUrl'], func_get_args()); } if (func_num_args() === 2) { return call_user_func_array([$this, 'adById'], func_get_args()); } throw new \InvalidArgumentException('Bad number of argument'); }
php
public function ad() { if (func_num_args() === 1) { return call_user_func_array([$this, 'adByUrl'], func_get_args()); } if (func_num_args() === 2) { return call_user_func_array([$this, 'adById'], func_get_args()); } throw new \InvalidArgumentException('Bad number of argument'); }
[ "public", "function", "ad", "(", ")", "{", "if", "(", "func_num_args", "(", ")", "===", "1", ")", "{", "return", "call_user_func_array", "(", "[", "$", "this", ",", "'adByUrl'", "]", ",", "func_get_args", "(", ")", ")", ";", "}", "if", "(", "func_num...
Dynamique method to retrive the data by url OR id and category @return bool|mixed
[ "Dynamique", "method", "to", "retrive", "the", "data", "by", "url", "OR", "id", "and", "category" ]
1ff5abced9392d24a759f6c8b5170e90d2e1ddb2
https://github.com/rfussien/leboncoin-crawler/blob/1ff5abced9392d24a759f6c8b5170e90d2e1ddb2/src/GetFrom.php#L109-L120
train