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
grrr-amsterdam/garp3
library/Garp/Service/Google/Chart.php
Garp_Service_Google_Chart.fetchQRCodeUrl
public function fetchQRCodeUrl($refUrl) { $size = 150; $EC_level = 'L'; $margin = 0; $trail = '?qr=1'; return self::CHART_API_URL .'chs='.$size.'x'.$size.'&cht=qr' .'&chld='.$EC_level.'|'.$margin .'&chl=' .urlencode($refUrl.$trail); }
php
public function fetchQRCodeUrl($refUrl) { $size = 150; $EC_level = 'L'; $margin = 0; $trail = '?qr=1'; return self::CHART_API_URL .'chs='.$size.'x'.$size.'&cht=qr' .'&chld='.$EC_level.'|'.$margin .'&chl=' .urlencode($refUrl.$trail); }
[ "public", "function", "fetchQRCodeUrl", "(", "$", "refUrl", ")", "{", "$", "size", "=", "150", ";", "$", "EC_level", "=", "'L'", ";", "$", "margin", "=", "0", ";", "$", "trail", "=", "'?qr=1'", ";", "return", "self", "::", "CHART_API_URL", ".", "'chs...
Fetches the URL to the QR code image for a specific reference URL. @param String $refUrl The unencoded URL this QR code should point to. A QR code identifier is automatically attached at the end @return String URL to the QR code image
[ "Fetches", "the", "URL", "to", "the", "QR", "code", "image", "for", "a", "specific", "reference", "URL", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Google/Chart.php#L28-L39
train
grrr-amsterdam/garp3
library/Garp/Spawn/Js/ModelsIncluder.php
Garp_Spawn_Js_ModelsIncluder._save
protected function _save($content) { if (!file_put_contents($this->_getIncludesFilename(), $content)) { throw new Exception(sprintf(self::EXCEPTION_WRITE_ERROR)); } return true; }
php
protected function _save($content) { if (!file_put_contents($this->_getIncludesFilename(), $content)) { throw new Exception(sprintf(self::EXCEPTION_WRITE_ERROR)); } return true; }
[ "protected", "function", "_save", "(", "$", "content", ")", "{", "if", "(", "!", "file_put_contents", "(", "$", "this", "->", "_getIncludesFilename", "(", ")", ",", "$", "content", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "self", ...
Write the file @param String $content The full content to write to the includes file. @return bool
[ "Write", "the", "file" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Js/ModelsIncluder.php#L78-L83
train
grrr-amsterdam/garp3
library/Garp/Cli/Command/Composer.php
Garp_Cli_Command_Composer.migrate
public function migrate() { $this->_requireGarpComposerPackage(); $this->_updateSymlinks(); $this->_updateIndexPhp(); $this->_updateLocaleFiles(); $this->_updateRoutesInclude(); $this->_updateCapFile(); Garp_Cli::lineOut('Done!'); Garp_Cli::lineOut( 'I\'m leaving the original garp folder in case you ' . 'still have to push something from the subtree.', Garp_Cli::BLUE ); return true; }
php
public function migrate() { $this->_requireGarpComposerPackage(); $this->_updateSymlinks(); $this->_updateIndexPhp(); $this->_updateLocaleFiles(); $this->_updateRoutesInclude(); $this->_updateCapFile(); Garp_Cli::lineOut('Done!'); Garp_Cli::lineOut( 'I\'m leaving the original garp folder in case you ' . 'still have to push something from the subtree.', Garp_Cli::BLUE ); return true; }
[ "public", "function", "migrate", "(", ")", "{", "$", "this", "->", "_requireGarpComposerPackage", "(", ")", ";", "$", "this", "->", "_updateSymlinks", "(", ")", ";", "$", "this", "->", "_updateIndexPhp", "(", ")", ";", "$", "this", "->", "_updateLocaleFile...
Migrate garp to the composer version. @return bool
[ "Migrate", "garp", "to", "the", "composer", "version", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Composer.php#L25-L40
train
grrr-amsterdam/garp3
library/Garp/Spawn/Behavior/Type/Sluggable.php
Garp_Spawn_Behavior_Type_Sluggable._baseFieldIsMultilingual
protected function _baseFieldIsMultilingual() { $modelBaseFields = $this->_getModelBaseFields(); foreach ($modelBaseFields as $field) { if ($field->isMultilingual()) { return true; } } return false; }
php
protected function _baseFieldIsMultilingual() { $modelBaseFields = $this->_getModelBaseFields(); foreach ($modelBaseFields as $field) { if ($field->isMultilingual()) { return true; } } return false; }
[ "protected", "function", "_baseFieldIsMultilingual", "(", ")", "{", "$", "modelBaseFields", "=", "$", "this", "->", "_getModelBaseFields", "(", ")", ";", "foreach", "(", "$", "modelBaseFields", "as", "$", "field", ")", "{", "if", "(", "$", "field", "->", "...
Whether one or more base fields are multilingual
[ "Whether", "one", "or", "more", "base", "fields", "are", "multilingual" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Behavior/Type/Sluggable.php#L98-L108
train
grrr-amsterdam/garp3
library/Garp/Content/Export/Txt.php
Garp_Content_Export_Txt._formatRow
protected function _formatRow(array $row) { $out = ''; foreach ($row as $key => $value) { if (is_array($value)) { // This is the case with hasMany and hasAndBelongsToMany related // rowsets. $value = $this->_formatRelatedRowset($value); } $out .= "$key: $value\n"; } return $out; }
php
protected function _formatRow(array $row) { $out = ''; foreach ($row as $key => $value) { if (is_array($value)) { // This is the case with hasMany and hasAndBelongsToMany related // rowsets. $value = $this->_formatRelatedRowset($value); } $out .= "$key: $value\n"; } return $out; }
[ "protected", "function", "_formatRow", "(", "array", "$", "row", ")", "{", "$", "out", "=", "''", ";", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "// This i...
Format a single row @param array $row @return string
[ "Format", "a", "single", "row" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Export/Txt.php#L43-L54
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/FileRelatable.php
Garp_Model_Behavior_FileRelatable.beforeUpdate
public function beforeUpdate(array &$args) { $data = &$args[1]; foreach ($data as $key => $value) { /** * Save the current file value. * If it differs from the given value, it will be cleared * by afterUpdate. */ if (in_array($key, $this->_fields)) { $this->_newValues[$key] = $value; if (!$this->_affectedRows) { $model = $args[0]; $where = $args[2]; $affectedRows = $model->fetchAll($where); $this->_affectedRows = $affectedRows; } } } }
php
public function beforeUpdate(array &$args) { $data = &$args[1]; foreach ($data as $key => $value) { /** * Save the current file value. * If it differs from the given value, it will be cleared * by afterUpdate. */ if (in_array($key, $this->_fields)) { $this->_newValues[$key] = $value; if (!$this->_affectedRows) { $model = $args[0]; $where = $args[2]; $affectedRows = $model->fetchAll($where); $this->_affectedRows = $affectedRows; } } } }
[ "public", "function", "beforeUpdate", "(", "array", "&", "$", "args", ")", "{", "$", "data", "=", "&", "$", "args", "[", "1", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "/**\n * Save the current f...
Before update callback. Save the original file values here. If they have changed afterUpdate, clear them. @param Array $options The new data is in $args[0] @return Array Or throw Exception if you wish to stop the insert
[ "Before", "update", "callback", ".", "Save", "the", "original", "file", "values", "here", ".", "If", "they", "have", "changed", "afterUpdate", "clear", "them", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/FileRelatable.php#L70-L88
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/FileRelatable.php
Garp_Model_Behavior_FileRelatable.afterUpdate
public function afterUpdate(array &$args) { foreach ($this->_affectedRows as $row) { foreach ($this->_newValues as $key => $value) { // compare the old and new values if ($row->$key != $value) { $this->_deleteFile($row->$key); } } } }
php
public function afterUpdate(array &$args) { foreach ($this->_affectedRows as $row) { foreach ($this->_newValues as $key => $value) { // compare the old and new values if ($row->$key != $value) { $this->_deleteFile($row->$key); } } } }
[ "public", "function", "afterUpdate", "(", "array", "&", "$", "args", ")", "{", "foreach", "(", "$", "this", "->", "_affectedRows", "as", "$", "row", ")", "{", "foreach", "(", "$", "this", "->", "_newValues", "as", "$", "key", "=>", "$", "value", ")",...
After update callback. Clear the files if the columns are modified. We do this afterUpdate to make sure the update succeeded. @param Array $args The new data is in $args[1] @return Void
[ "After", "update", "callback", ".", "Clear", "the", "files", "if", "the", "columns", "are", "modified", ".", "We", "do", "this", "afterUpdate", "to", "make", "sure", "the", "update", "succeeded", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/FileRelatable.php#L97-L106
train
grrr-amsterdam/garp3
library/Garp/Form/Element/File.php
Garp_Form_Element_File._getUploadInfoString
protected function _getUploadInfoString() { $maxFileSize = $this->getUploadMaxFilesize(); $allowedExtensions = $this->getAllowedExtensions(); $lastExtension = array_pop($allowedExtensions); $translator = $this->getTranslator(); $uploadInfoStr = $translator->translate('Only %1$s and %2$s files with a maximum of %3$s MB are allowed'); $uploadInfoStr = sprintf($uploadInfoStr, implode(', ', $allowedExtensions), $lastExtension, $maxFileSize); return $uploadInfoStr; }
php
protected function _getUploadInfoString() { $maxFileSize = $this->getUploadMaxFilesize(); $allowedExtensions = $this->getAllowedExtensions(); $lastExtension = array_pop($allowedExtensions); $translator = $this->getTranslator(); $uploadInfoStr = $translator->translate('Only %1$s and %2$s files with a maximum of %3$s MB are allowed'); $uploadInfoStr = sprintf($uploadInfoStr, implode(', ', $allowedExtensions), $lastExtension, $maxFileSize); return $uploadInfoStr; }
[ "protected", "function", "_getUploadInfoString", "(", ")", "{", "$", "maxFileSize", "=", "$", "this", "->", "getUploadMaxFilesize", "(", ")", ";", "$", "allowedExtensions", "=", "$", "this", "->", "getAllowedExtensions", "(", ")", ";", "$", "lastExtension", "=...
Retrieve an informative string describing upload restrictions. @return String
[ "Retrieve", "an", "informative", "string", "describing", "upload", "restrictions", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/Element/File.php#L62-L72
train
grrr-amsterdam/garp3
library/Garp/Form/Element/File.php
Garp_Form_Element_File.getFileObject
public function getFileObject() { if ($this->getAttrib('data-type') === Garp_File::TYPE_IMAGES) { $file = new Garp_Image_File(); } else { $file = new Garp_File(); } return $file; }
php
public function getFileObject() { if ($this->getAttrib('data-type') === Garp_File::TYPE_IMAGES) { $file = new Garp_Image_File(); } else { $file = new Garp_File(); } return $file; }
[ "public", "function", "getFileObject", "(", ")", "{", "if", "(", "$", "this", "->", "getAttrib", "(", "'data-type'", ")", "===", "Garp_File", "::", "TYPE_IMAGES", ")", "{", "$", "file", "=", "new", "Garp_Image_File", "(", ")", ";", "}", "else", "{", "$...
Get file object based on attribute data-type @return Garp_File
[ "Get", "file", "object", "based", "on", "attribute", "data", "-", "type" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/Element/File.php#L101-L108
train
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._areRulesEgocentricallySorted
protected function _areRulesEgocentricallySorted(array $ruleNames) { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); return $ruleNames[0] === $localModel->id; }
php
protected function _areRulesEgocentricallySorted(array $ruleNames) { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); return $ruleNames[0] === $localModel->id; }
[ "protected", "function", "_areRulesEgocentricallySorted", "(", "array", "$", "ruleNames", ")", "{", "$", "relation", "=", "$", "this", "->", "getRelation", "(", ")", ";", "$", "localModel", "=", "$", "relation", "->", "getLocalModel", "(", ")", ";", "return"...
Order in such a way that the reference to the referring model comes before the referred model.
[ "Order", "in", "such", "a", "way", "that", "the", "reference", "to", "the", "referring", "model", "comes", "before", "the", "referred", "model", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L69-L73
train
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._getRules
protected function _getRules() { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); $hasNameConflict = $relation->name === $localModel->id; if ($hasNameConflict) { return array($relation->name . '1', $relation->name . '2'); } $modelIds = $this->_getModelIdsAlphabetically(); $rules = array($relation->name, $this->_getSecondRule()); $rules = $this->_sortRulesEgocentrically($rules); return $rules; }
php
protected function _getRules() { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); $hasNameConflict = $relation->name === $localModel->id; if ($hasNameConflict) { return array($relation->name . '1', $relation->name . '2'); } $modelIds = $this->_getModelIdsAlphabetically(); $rules = array($relation->name, $this->_getSecondRule()); $rules = $this->_sortRulesEgocentrically($rules); return $rules; }
[ "protected", "function", "_getRules", "(", ")", "{", "$", "relation", "=", "$", "this", "->", "getRelation", "(", ")", ";", "$", "localModel", "=", "$", "relation", "->", "getLocalModel", "(", ")", ";", "$", "hasNameConflict", "=", "$", "relation", "->",...
Returns relation rules, sorted egocentrically. @return Array First rule refers to the model itself, second to the related model referenced in the $relation object.
[ "Returns", "relation", "rules", "sorted", "egocentrically", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L87-L102
train
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._getSecondRule
protected function _getSecondRule() { $relation = $this->getRelation(); $firstRule = $relation->name; $hasCustomRelName = $this->_hasCustomRelName(); $modelIds = $this->_getModelIdsAlphabetically(); if ($hasCustomRelName) { return $modelIds[0]; } return $modelIds[0] !== $firstRule ? $modelIds[0] : $modelIds[1] ; }
php
protected function _getSecondRule() { $relation = $this->getRelation(); $firstRule = $relation->name; $hasCustomRelName = $this->_hasCustomRelName(); $modelIds = $this->_getModelIdsAlphabetically(); if ($hasCustomRelName) { return $modelIds[0]; } return $modelIds[0] !== $firstRule ? $modelIds[0] : $modelIds[1] ; }
[ "protected", "function", "_getSecondRule", "(", ")", "{", "$", "relation", "=", "$", "this", "->", "getRelation", "(", ")", ";", "$", "firstRule", "=", "$", "relation", "->", "name", ";", "$", "hasCustomRelName", "=", "$", "this", "->", "_hasCustomRelName"...
Displays second HABTM rule. The first rule is always the name of the direct relation to the end model.
[ "Displays", "second", "HABTM", "rule", ".", "The", "first", "rule", "is", "always", "the", "name", "of", "the", "direct", "relation", "to", "the", "end", "model", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L107-L121
train
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._areModelIdsSortedByRule
protected function _areModelIdsSortedByRule(array $modelIds) { $rules = $this->_getRules(); foreach ($modelIds as $modelId) { $ruleNumber = array_search($modelId, $rules); if ($ruleNumber !== false) { return $rules[$ruleNumber] === $modelIds[$ruleNumber]; } } }
php
protected function _areModelIdsSortedByRule(array $modelIds) { $rules = $this->_getRules(); foreach ($modelIds as $modelId) { $ruleNumber = array_search($modelId, $rules); if ($ruleNumber !== false) { return $rules[$ruleNumber] === $modelIds[$ruleNumber]; } } }
[ "protected", "function", "_areModelIdsSortedByRule", "(", "array", "$", "modelIds", ")", "{", "$", "rules", "=", "$", "this", "->", "_getRules", "(", ")", ";", "foreach", "(", "$", "modelIds", "as", "$", "modelId", ")", "{", "$", "ruleNumber", "=", "arra...
Whether modelId sorting is coherent with the egocentric sorting of rules. @return Boolean
[ "Whether", "modelId", "sorting", "is", "coherent", "with", "the", "egocentric", "sorting", "of", "rules", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L161-L170
train
grrr-amsterdam/garp3
library/Garp/Model/Db/Location.php
Garp_Model_Db_Location.normalizeZip
public function normalizeZip($zip) { if (strlen($zip) === 6) { $zip = substr($zip, 0, 4) . ' ' . strtoupper(substr($zip, 4, 2)); } return $zip; }
php
public function normalizeZip($zip) { if (strlen($zip) === 6) { $zip = substr($zip, 0, 4) . ' ' . strtoupper(substr($zip, 4, 2)); } return $zip; }
[ "public", "function", "normalizeZip", "(", "$", "zip", ")", "{", "if", "(", "strlen", "(", "$", "zip", ")", "===", "6", ")", "{", "$", "zip", "=", "substr", "(", "$", "zip", ",", "0", ",", "4", ")", ".", "' '", ".", "strtoupper", "(", "substr",...
Normalize the input so that it matches the stored format.
[ "Normalize", "the", "input", "so", "that", "it", "matches", "the", "stored", "format", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Location.php#L45-L51
train
grrr-amsterdam/garp3
library/Garp/Model/IniFile.php
Garp_Model_IniFile.init
public function init($file, $namespace = null) { $ini = Garp_Config_Ini::getCached($file); if ($namespace) { $namespaces = explode('.', $namespace); do { $namespace = array_shift($namespaces); $ini = $ini->{$namespace}; } while ($namespaces); } $this->_ini = $ini; }
php
public function init($file, $namespace = null) { $ini = Garp_Config_Ini::getCached($file); if ($namespace) { $namespaces = explode('.', $namespace); do { $namespace = array_shift($namespaces); $ini = $ini->{$namespace}; } while ($namespaces); } $this->_ini = $ini; }
[ "public", "function", "init", "(", "$", "file", ",", "$", "namespace", "=", "null", ")", "{", "$", "ini", "=", "Garp_Config_Ini", "::", "getCached", "(", "$", "file", ")", ";", "if", "(", "$", "namespace", ")", "{", "$", "namespaces", "=", "explode",...
Initialize the ini file. @param string $file The path to the ini file @param string $namespace What namespace to use in the ini file @return void
[ "Initialize", "the", "ini", "file", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/IniFile.php#L60-L70
train
grrr-amsterdam/garp3
library/Garp/Model/IniFile.php
Garp_Model_IniFile.registerObserver
public function registerObserver(Garp_Util_Observer $observer, $name = false) { $name = $name ?: $observer->getName(); $this->_observers[$name] = $observer; return $this; }
php
public function registerObserver(Garp_Util_Observer $observer, $name = false) { $name = $name ?: $observer->getName(); $this->_observers[$name] = $observer; return $this; }
[ "public", "function", "registerObserver", "(", "Garp_Util_Observer", "$", "observer", ",", "$", "name", "=", "false", ")", "{", "$", "name", "=", "$", "name", "?", ":", "$", "observer", "->", "getName", "(", ")", ";", "$", "this", "->", "_observers", "...
Register observer. The observer will then listen to events broadcasted from this class. @param Garp_Util_Observer $observer The observer @param string $name Optional custom name @return Garp_Util_Observable $this
[ "Register", "observer", ".", "The", "observer", "will", "then", "listen", "to", "events", "broadcasted", "from", "this", "class", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/IniFile.php#L126-L130
train
grrr-amsterdam/garp3
library/Garp/Content/Manager/Proxy.php
Garp_Content_Manager_Proxy.pass
public function pass($model, $method, $args = array()) { $manager = new Garp_Content_Manager( Garp_Content_Api::modelAliasToClass($model)); if (!method_exists($manager, $method)) { throw new Garp_Content_Exception('Unknown method requested.'); } $params = !empty($args) ? $args[0] : array(); $result = $this->_produceResult($manager, $method, $params); if ($result instanceof Zend_Db_Table_Rowset_Abstract || $result instanceof Zend_Db_Table_Row_Abstract) { $result = $result->toArray(); } return $result; }
php
public function pass($model, $method, $args = array()) { $manager = new Garp_Content_Manager( Garp_Content_Api::modelAliasToClass($model)); if (!method_exists($manager, $method)) { throw new Garp_Content_Exception('Unknown method requested.'); } $params = !empty($args) ? $args[0] : array(); $result = $this->_produceResult($manager, $method, $params); if ($result instanceof Zend_Db_Table_Rowset_Abstract || $result instanceof Zend_Db_Table_Row_Abstract) { $result = $result->toArray(); } return $result; }
[ "public", "function", "pass", "(", "$", "model", ",", "$", "method", ",", "$", "args", "=", "array", "(", ")", ")", "{", "$", "manager", "=", "new", "Garp_Content_Manager", "(", "Garp_Content_Api", "::", "modelAliasToClass", "(", "$", "model", ")", ")", ...
Pass methods along to Garp_Content_Manager. @param String $model The desired model to manipulate @param String $method The desired method to execute @param Array $args Arguments @return Mixed Whatever the Garp_Content_Manager returns, optionally converted to array.
[ "Pass", "methods", "along", "to", "Garp_Content_Manager", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager/Proxy.php#L19-L34
train
grrr-amsterdam/garp3
library/Garp/Content/Manager/Proxy.php
Garp_Content_Manager_Proxy._handleDatabaseException
protected function _handleDatabaseException(Zend_Db_Statement_Exception $e) { if (strpos($e->getMessage(), 'Duplicate entry') === false) { throw $e; } // Note the double spaces in the template string are required since quotes would be // added greedily to the parsed values. list($value, $index) = sscanf($e->getMessage(), 'SQLSTATE[23000]: Integrity constraint violation: ' . '1062 Duplicate entry %s for key %s '); // Throw an exception with a human-friendly error throw new Exception( sprintf(__('%s is already in use, please provide a unique value.'), $value)); }
php
protected function _handleDatabaseException(Zend_Db_Statement_Exception $e) { if (strpos($e->getMessage(), 'Duplicate entry') === false) { throw $e; } // Note the double spaces in the template string are required since quotes would be // added greedily to the parsed values. list($value, $index) = sscanf($e->getMessage(), 'SQLSTATE[23000]: Integrity constraint violation: ' . '1062 Duplicate entry %s for key %s '); // Throw an exception with a human-friendly error throw new Exception( sprintf(__('%s is already in use, please provide a unique value.'), $value)); }
[ "protected", "function", "_handleDatabaseException", "(", "Zend_Db_Statement_Exception", "$", "e", ")", "{", "if", "(", "strpos", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'Duplicate entry'", ")", "===", "false", ")", "{", "throw", "$", "e", ";", ...
Look for 'Duplicate entry' exceptions, and convert to a human-friendly message.
[ "Look", "for", "Duplicate", "entry", "exceptions", "and", "convert", "to", "a", "human", "-", "friendly", "message", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager/Proxy.php#L48-L61
train
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless.requestToken
public function requestToken(array $userData) { if (empty($userData['email'])) { $this->_addError( sprintf( __('%s is a required field'), __('Email') ) ); return false; } $validator = new Zend_Validate_EmailAddress(); if (!$validator->isValid($userData['email'])) { $this->_addError( sprintf( __('%s is not a valid email address'), __('Email') ) ); return false; } $userId = $this->_createOrFetchUserRecord($userData); $token = $this->createOrUpdateAuthRecord($userId); $this->_sendTokenEmail($userData['email'], $userId, $token); $this->setRedirect($this->_getRedirectUrl()); }
php
public function requestToken(array $userData) { if (empty($userData['email'])) { $this->_addError( sprintf( __('%s is a required field'), __('Email') ) ); return false; } $validator = new Zend_Validate_EmailAddress(); if (!$validator->isValid($userData['email'])) { $this->_addError( sprintf( __('%s is not a valid email address'), __('Email') ) ); return false; } $userId = $this->_createOrFetchUserRecord($userData); $token = $this->createOrUpdateAuthRecord($userId); $this->_sendTokenEmail($userData['email'], $userId, $token); $this->setRedirect($this->_getRedirectUrl()); }
[ "public", "function", "requestToken", "(", "array", "$", "userData", ")", "{", "if", "(", "empty", "(", "$", "userData", "[", "'email'", "]", ")", ")", "{", "$", "this", "->", "_addError", "(", "sprintf", "(", "__", "(", "'%s is a required field'", ")", ...
Request a new token @param array $userData @return void @todo Allow different delivery-methods, such as SMS?
[ "Request", "a", "new", "token" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L54-L81
train
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless.acceptToken
public function acceptToken($token, $uid) { if (!$token || !$uid) { $this->_addError(__('Insufficient data received')); return false; } $authPwlessModel = $this->_getPasswordlessModel(); $select = $authPwlessModel->select() ->where('`token` = ?', $token) ->where('user_id = ?', $uid); $row = $authPwlessModel->fetchRow($select); if (!$row || !$row->Model_User) { $this->_addError(__('passwordless token not found')); return false; } // Check wether the user is already logged in. Let's not inconvenience them // with security when it's not that important if ($this->_userIsAlreadyLoggedIn($row)) { return $row->Model_User; } if (!$this->_tokenIsValid($row)) { return false; } $authPwlessModel->getObserver('Authenticatable')->updateLoginStats( $row->Model_User->id, array( 'claimed' => 1 ) ); return $row->Model_User; }
php
public function acceptToken($token, $uid) { if (!$token || !$uid) { $this->_addError(__('Insufficient data received')); return false; } $authPwlessModel = $this->_getPasswordlessModel(); $select = $authPwlessModel->select() ->where('`token` = ?', $token) ->where('user_id = ?', $uid); $row = $authPwlessModel->fetchRow($select); if (!$row || !$row->Model_User) { $this->_addError(__('passwordless token not found')); return false; } // Check wether the user is already logged in. Let's not inconvenience them // with security when it's not that important if ($this->_userIsAlreadyLoggedIn($row)) { return $row->Model_User; } if (!$this->_tokenIsValid($row)) { return false; } $authPwlessModel->getObserver('Authenticatable')->updateLoginStats( $row->Model_User->id, array( 'claimed' => 1 ) ); return $row->Model_User; }
[ "public", "function", "acceptToken", "(", "$", "token", ",", "$", "uid", ")", "{", "if", "(", "!", "$", "token", "||", "!", "$", "uid", ")", "{", "$", "this", "->", "_addError", "(", "__", "(", "'Insufficient data received'", ")", ")", ";", "return",...
Accept a user token @param string $token @param int $uid User id @return Garp_Model_Db Logged in user
[ "Accept", "a", "user", "token" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L90-L123
train
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless.createOrUpdateAuthRecord
public function createOrUpdateAuthRecord($userId) { $token = $this->_getToken($userId); $authPwlessModel = new Model_AuthPasswordless(); $select = $authPwlessModel->select()->where('user_id = ?', $userId); if ($authRecord = $authPwlessModel->fetchRow($select)) { $authPwlessModel->update( array( 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate(), 'claimed' => 0 ), 'id = ' . $authRecord->id ); return $token; } $authPwlessModel->insert( array( 'user_id' => $userId, 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate() ) ); return $token; }
php
public function createOrUpdateAuthRecord($userId) { $token = $this->_getToken($userId); $authPwlessModel = new Model_AuthPasswordless(); $select = $authPwlessModel->select()->where('user_id = ?', $userId); if ($authRecord = $authPwlessModel->fetchRow($select)) { $authPwlessModel->update( array( 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate(), 'claimed' => 0 ), 'id = ' . $authRecord->id ); return $token; } $authPwlessModel->insert( array( 'user_id' => $userId, 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate() ) ); return $token; }
[ "public", "function", "createOrUpdateAuthRecord", "(", "$", "userId", ")", "{", "$", "token", "=", "$", "this", "->", "_getToken", "(", "$", "userId", ")", ";", "$", "authPwlessModel", "=", "new", "Model_AuthPasswordless", "(", ")", ";", "$", "select", "="...
Create auth record containing the token a user can log in with @param int $userId @return string The token
[ "Create", "auth", "record", "containing", "the", "token", "a", "user", "can", "log", "in", "with" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L131-L153
train
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless._getToken
protected function _getToken($userId = null) { if ($userId && $this->_getAuthVars() && array_get($this->_getAuthVars()->toArray(), 'reuse_existing_token') ) { return $this->_fetchExistingToken($userId) ?: $this->_getToken(); } if (function_exists('openssl_random_pseudo_bytes')) { return bin2hex(openssl_random_pseudo_bytes(32)); } return mt_rand(); }
php
protected function _getToken($userId = null) { if ($userId && $this->_getAuthVars() && array_get($this->_getAuthVars()->toArray(), 'reuse_existing_token') ) { return $this->_fetchExistingToken($userId) ?: $this->_getToken(); } if (function_exists('openssl_random_pseudo_bytes')) { return bin2hex(openssl_random_pseudo_bytes(32)); } return mt_rand(); }
[ "protected", "function", "_getToken", "(", "$", "userId", "=", "null", ")", "{", "if", "(", "$", "userId", "&&", "$", "this", "->", "_getAuthVars", "(", ")", "&&", "array_get", "(", "$", "this", "->", "_getAuthVars", "(", ")", "->", "toArray", "(", "...
Generate a unique token. If `reuse_existing_token` is configured thus, we will check if a token is known already for the given userid. @param int $userId @return string
[ "Generate", "a", "unique", "token", ".", "If", "reuse_existing_token", "is", "configured", "thus", "we", "will", "check", "if", "a", "token", "is", "known", "already", "for", "the", "given", "userid", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L193-L204
train
grrr-amsterdam/garp3
library/Garp/Spawn/Relation/Set.php
Garp_Spawn_Relation_Set._addSingularRelation
protected function _addSingularRelation( array $relationSet, $relName, Garp_Spawn_Relation $relation ) { if ($relation->isSingular()) { $relationSet[$relName] = $relation; } return $relationSet; }
php
protected function _addSingularRelation( array $relationSet, $relName, Garp_Spawn_Relation $relation ) { if ($relation->isSingular()) { $relationSet[$relName] = $relation; } return $relationSet; }
[ "protected", "function", "_addSingularRelation", "(", "array", "$", "relationSet", ",", "$", "relName", ",", "Garp_Spawn_Relation", "$", "relation", ")", "{", "if", "(", "$", "relation", "->", "isSingular", "(", ")", ")", "{", "$", "relationSet", "[", "$", ...
Adds the relation to the relation set, if it's singular. @param array $relationSet The set to add the relation to @param string $relName The relation name @param Garp_Spawn_Relation $relation The relation instance, plural or singular @return array The relation set with the added singular relation
[ "Adds", "the", "relation", "to", "the", "relation", "set", "if", "it", "s", "singular", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Relation/Set.php#L262-L270
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Timestampable.php
Garp_Model_Behavior_Timestampable._setup
protected function _setup($config) { if (empty($config['createdField'])) { $config['createdField'] = 'created'; } if (empty($config['modifiedField'])) { $config['modifiedField'] = 'modified'; } $this->_fields = $config; }
php
protected function _setup($config) { if (empty($config['createdField'])) { $config['createdField'] = 'created'; } if (empty($config['modifiedField'])) { $config['modifiedField'] = 'modified'; } $this->_fields = $config; }
[ "protected", "function", "_setup", "(", "$", "config", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'createdField'", "]", ")", ")", "{", "$", "config", "[", "'createdField'", "]", "=", "'created'", ";", "}", "if", "(", "empty", "(", "$", ...
Make sure the config array is at least filled with some default values to work with. @param Array $config Configuration values @return Void
[ "Make", "sure", "the", "config", "array", "is", "at", "least", "filled", "with", "some", "default", "values", "to", "work", "with", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Timestampable.php#L32-L40
train
grrr-amsterdam/garp3
library/Garp/Model/Validator/Email.php
Garp_Model_Validator_Email.validate
public function validate(array $data, Garp_Model_Db $model, $onlyIfAvailable = true) { $theColumns = $this->_fields; $regexp = self::EMAIL_REGEXP; $validate = function($c) use ($data, $onlyIfAvailable, $regexp) { if ( $onlyIfAvailable && ( !array_key_exists($c, $data) || empty($data[$c]) ) ) { return; } if (empty($data[$c]) || !preg_match($regexp, $data[$c])) { $value = !empty($data[$c]) ? $data[$c] : ''; $error = sprintf(__("'%value%' is not a valid email address in the basic format local-part@hostname"), $value); throw new Garp_Model_Validator_Email_Exception($error); } }; array_walk($theColumns, $validate); }
php
public function validate(array $data, Garp_Model_Db $model, $onlyIfAvailable = true) { $theColumns = $this->_fields; $regexp = self::EMAIL_REGEXP; $validate = function($c) use ($data, $onlyIfAvailable, $regexp) { if ( $onlyIfAvailable && ( !array_key_exists($c, $data) || empty($data[$c]) ) ) { return; } if (empty($data[$c]) || !preg_match($regexp, $data[$c])) { $value = !empty($data[$c]) ? $data[$c] : ''; $error = sprintf(__("'%value%' is not a valid email address in the basic format local-part@hostname"), $value); throw new Garp_Model_Validator_Email_Exception($error); } }; array_walk($theColumns, $validate); }
[ "public", "function", "validate", "(", "array", "$", "data", ",", "Garp_Model_Db", "$", "model", ",", "$", "onlyIfAvailable", "=", "true", ")", "{", "$", "theColumns", "=", "$", "this", "->", "_fields", ";", "$", "regexp", "=", "self", "::", "EMAIL_REGEX...
Validate wether the given columns are not empty @param Array $data The data to validate @param Boolean $onlyIfAvailable Wether to skip validation on fields that are not in the array @return Void @throws Garp_Model_Validator_Exception
[ "Validate", "wether", "the", "given", "columns", "are", "not", "empty" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Validator/Email.php#L44-L64
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable.getI18nModel
public function getI18nModel(Garp_Model_Db $model) { $modelName = get_class($model); $modelName .= self::I18N_MODEL_SUFFIX; $model = new $modelName; // Do not block unpublished items, we might not get the right record from the fetchRow() // call in self::_saveI18nRecord() if ($draftable = $model->getObserver('Draftable')) { $draftable->setBlockOfflineItems(false); } return $model; }
php
public function getI18nModel(Garp_Model_Db $model) { $modelName = get_class($model); $modelName .= self::I18N_MODEL_SUFFIX; $model = new $modelName; // Do not block unpublished items, we might not get the right record from the fetchRow() // call in self::_saveI18nRecord() if ($draftable = $model->getObserver('Draftable')) { $draftable->setBlockOfflineItems(false); } return $model; }
[ "public", "function", "getI18nModel", "(", "Garp_Model_Db", "$", "model", ")", "{", "$", "modelName", "=", "get_class", "(", "$", "model", ")", ";", "$", "modelName", ".=", "self", "::", "I18N_MODEL_SUFFIX", ";", "$", "model", "=", "new", "$", "modelName",...
Retrieve i18n model @param Garp_Model_Db $model @return Garp_Model_Db
[ "Retrieve", "i18n", "model" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L87-L98
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable.bindWithI18nModel
public function bindWithI18nModel(Garp_Model_Db $model) { $i18nModel = $this->getI18nModel($model); $model->bindModel( self::I18N_MODEL_BINDING_ALIAS, array( 'modelClass' => $i18nModel, 'conditions' => $i18nModel->select()->from( $i18nModel->getName(), array_merge($this->_translatableFields, array(self::LANG_COLUMN)) ) ) ); }
php
public function bindWithI18nModel(Garp_Model_Db $model) { $i18nModel = $this->getI18nModel($model); $model->bindModel( self::I18N_MODEL_BINDING_ALIAS, array( 'modelClass' => $i18nModel, 'conditions' => $i18nModel->select()->from( $i18nModel->getName(), array_merge($this->_translatableFields, array(self::LANG_COLUMN)) ) ) ); }
[ "public", "function", "bindWithI18nModel", "(", "Garp_Model_Db", "$", "model", ")", "{", "$", "i18nModel", "=", "$", "this", "->", "getI18nModel", "(", "$", "model", ")", ";", "$", "model", "->", "bindModel", "(", "self", "::", "I18N_MODEL_BINDING_ALIAS", ",...
Bind with i18n model @param Garp_Model_Db $model @return Void
[ "Bind", "with", "i18n", "model" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L106-L117
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable.mergeTranslatedFields
public function mergeTranslatedFields($result) { if (!isset($result->{self::I18N_MODEL_BINDING_ALIAS})) { return; } $translationRecordList = $result->{self::I18N_MODEL_BINDING_ALIAS}; if ($translationRecordList instanceof Zend_Db_Table_Rowset_Abstract) { $translationRecordList = $translationRecordList->toArray(); } $translatedFields = array(); $allLocales = Garp_I18n::getLocales(); foreach ($this->_translatableFields as $translatableField) { // provide default values foreach ($allLocales as $locale) { $translatedFields[$translatableField][$locale] = null; } foreach ($translationRecordList as $translationRecord) { $lang = $translationRecord[self::LANG_COLUMN]; $translatedFields[$translatableField][$lang] = $translationRecord[$translatableField]; } $result->setVirtual($translatableField, $translatedFields[$translatableField]); //$lang] = $translationRecord[$translatableField]; } // We now have a $translatedFields array like this: // array( // "name" => array( // "nl" => "Schaap", // "en" => "Sheep" // ) // ) //$result->setFromArray($translatedFields); unset($result->{self::I18N_MODEL_BINDING_ALIAS}); }
php
public function mergeTranslatedFields($result) { if (!isset($result->{self::I18N_MODEL_BINDING_ALIAS})) { return; } $translationRecordList = $result->{self::I18N_MODEL_BINDING_ALIAS}; if ($translationRecordList instanceof Zend_Db_Table_Rowset_Abstract) { $translationRecordList = $translationRecordList->toArray(); } $translatedFields = array(); $allLocales = Garp_I18n::getLocales(); foreach ($this->_translatableFields as $translatableField) { // provide default values foreach ($allLocales as $locale) { $translatedFields[$translatableField][$locale] = null; } foreach ($translationRecordList as $translationRecord) { $lang = $translationRecord[self::LANG_COLUMN]; $translatedFields[$translatableField][$lang] = $translationRecord[$translatableField]; } $result->setVirtual($translatableField, $translatedFields[$translatableField]); //$lang] = $translationRecord[$translatableField]; } // We now have a $translatedFields array like this: // array( // "name" => array( // "nl" => "Schaap", // "en" => "Sheep" // ) // ) //$result->setFromArray($translatedFields); unset($result->{self::I18N_MODEL_BINDING_ALIAS}); }
[ "public", "function", "mergeTranslatedFields", "(", "$", "result", ")", "{", "if", "(", "!", "isset", "(", "$", "result", "->", "{", "self", "::", "I18N_MODEL_BINDING_ALIAS", "}", ")", ")", "{", "return", ";", "}", "$", "translationRecordList", "=", "$", ...
Merge translated fields into the main records @param Garp_Db_Table_Row $result @return void
[ "Merge", "translated", "fields", "into", "the", "main", "records" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L167-L199
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._beforeSave
protected function _beforeSave($model, &$data, $where = null) { $localizedData = array(); foreach ($this->_translatableFields as $field) { if (array_key_exists($field, $data)) { $localizedData[$field] = $data[$field]; unset($data[$field]); } } // Can't use values that are not arrays $localizedData = array_filter($localizedData, 'is_array'); // We now have an array containing all values that are provided in one or more languages $languages = Garp_I18n::getLocales(); $existingRows = array_fill_keys($languages, array()); if (!is_null($where)) { $pKeys = $this->_getPrimaryKeysOfAffectedRows($model, $where); if (!count($pKeys)) { // No primary keys found in update? // That means there aren't any affected rows and there's nothing for us to do. return; } $existingRows = $this->_fetchLocalizedRows($languages, $model, $pKeys); } $defaultLanguage = Garp_I18n::getDefaultLocale(); $languages = array_diff($languages, array($defaultLanguage)); foreach ($localizedData as $column => $val) { foreach ($languages as $language) { if (!empty($val[$language])) { // If value provided in language: good! continue; } if (empty($val[$defaultLanguage])) { // No default? Nothing to fall back to continue; } if (!$where) { // If insert, just use default value $localizedData[$column][$language] = $val[$defaultLanguage]; continue; } // Else if update, make sure existing row isn't different from default language row if (!$this->_translatedVersionHasBeenChanged( $existingRows[$defaultLanguage], $existingRows[$language], $column ) ) { $localizedData[$column][$language] = $val[$defaultLanguage]; } } } $this->_queue = $localizedData; }
php
protected function _beforeSave($model, &$data, $where = null) { $localizedData = array(); foreach ($this->_translatableFields as $field) { if (array_key_exists($field, $data)) { $localizedData[$field] = $data[$field]; unset($data[$field]); } } // Can't use values that are not arrays $localizedData = array_filter($localizedData, 'is_array'); // We now have an array containing all values that are provided in one or more languages $languages = Garp_I18n::getLocales(); $existingRows = array_fill_keys($languages, array()); if (!is_null($where)) { $pKeys = $this->_getPrimaryKeysOfAffectedRows($model, $where); if (!count($pKeys)) { // No primary keys found in update? // That means there aren't any affected rows and there's nothing for us to do. return; } $existingRows = $this->_fetchLocalizedRows($languages, $model, $pKeys); } $defaultLanguage = Garp_I18n::getDefaultLocale(); $languages = array_diff($languages, array($defaultLanguage)); foreach ($localizedData as $column => $val) { foreach ($languages as $language) { if (!empty($val[$language])) { // If value provided in language: good! continue; } if (empty($val[$defaultLanguage])) { // No default? Nothing to fall back to continue; } if (!$where) { // If insert, just use default value $localizedData[$column][$language] = $val[$defaultLanguage]; continue; } // Else if update, make sure existing row isn't different from default language row if (!$this->_translatedVersionHasBeenChanged( $existingRows[$defaultLanguage], $existingRows[$language], $column ) ) { $localizedData[$column][$language] = $val[$defaultLanguage]; } } } $this->_queue = $localizedData; }
[ "protected", "function", "_beforeSave", "(", "$", "model", ",", "&", "$", "data", ",", "$", "where", "=", "null", ")", "{", "$", "localizedData", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_translatableFields", "as", "$", "field",...
Callback before inserting or updating. Extracts translatable fields. @param Garp_Model_Db $model @param Array $data The submitted data @param String $where WHERE clause (in case of update) @return Void
[ "Callback", "before", "inserting", "or", "updating", ".", "Extracts", "translatable", "fields", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L270-L322
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._afterSave
protected function _afterSave(Garp_Model_Db $model, $pKeys) { if (!$this->_queue) { return; } $locales = Garp_I18n::getLocales(); foreach ($pKeys as $primaryKey) { foreach ($locales as $locale) { $this->_saveI18nRecord($locale, $model, $primaryKey); } } // Reset queue $this->_queue = array(); }
php
protected function _afterSave(Garp_Model_Db $model, $pKeys) { if (!$this->_queue) { return; } $locales = Garp_I18n::getLocales(); foreach ($pKeys as $primaryKey) { foreach ($locales as $locale) { $this->_saveI18nRecord($locale, $model, $primaryKey); } } // Reset queue $this->_queue = array(); }
[ "protected", "function", "_afterSave", "(", "Garp_Model_Db", "$", "model", ",", "$", "pKeys", ")", "{", "if", "(", "!", "$", "this", "->", "_queue", ")", "{", "return", ";", "}", "$", "locales", "=", "Garp_I18n", "::", "getLocales", "(", ")", ";", "f...
Callback after inserting or updating. @param Garp_Model_Db $model @param array $pKeys @return void
[ "Callback", "after", "inserting", "or", "updating", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L370-L382
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._saveI18nRecord
protected function _saveI18nRecord($language, Garp_Model_Db $model, array $pKeys) { $data = $this->_extractDataForLanguage($language, $model); // If no data was given in the specified language, we don't save anything if (empty($data)) { return; } // Add the language... $data[self::LANG_COLUMN] = $language; // ...and foreign keys $data = $this->_mergeDataWithForeignKeyColumns($data, $model, $pKeys); $i18nModel = $this->getI18nModel($model); $row = $this->_fetchLocalizedRow($language, $model, $pKeys) ?: $i18nModel->createRow(); if (!$row->isConnected()) { $row->setTable($i18nModel); } $row->setFromArray($data); if (!$row->save()) { throw new Garp_Model_Behavior_Exception( sprintf(self::SAVE_IN_LANG_EXCEPTION, $language) ); } return true; }
php
protected function _saveI18nRecord($language, Garp_Model_Db $model, array $pKeys) { $data = $this->_extractDataForLanguage($language, $model); // If no data was given in the specified language, we don't save anything if (empty($data)) { return; } // Add the language... $data[self::LANG_COLUMN] = $language; // ...and foreign keys $data = $this->_mergeDataWithForeignKeyColumns($data, $model, $pKeys); $i18nModel = $this->getI18nModel($model); $row = $this->_fetchLocalizedRow($language, $model, $pKeys) ?: $i18nModel->createRow(); if (!$row->isConnected()) { $row->setTable($i18nModel); } $row->setFromArray($data); if (!$row->save()) { throw new Garp_Model_Behavior_Exception( sprintf(self::SAVE_IN_LANG_EXCEPTION, $language) ); } return true; }
[ "protected", "function", "_saveI18nRecord", "(", "$", "language", ",", "Garp_Model_Db", "$", "model", ",", "array", "$", "pKeys", ")", "{", "$", "data", "=", "$", "this", "->", "_extractDataForLanguage", "(", "$", "language", ",", "$", "model", ")", ";", ...
Save a new i18n record in the given language @param String $language @param Garp_Model_Db $model @param Array $pKeys @return Boolean
[ "Save", "a", "new", "i18n", "record", "in", "the", "given", "language" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L392-L416
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._extractDataForLanguage
protected function _extractDataForLanguage($language, Garp_Model_Db $model) { $localizedData = array_filter($this->_queue, 'is_array'); $out = array(); foreach ($localizedData as $key => $value) { if (array_key_exists($language, $value)) { $out[$key] = $value[$language]; } } return $out; }
php
protected function _extractDataForLanguage($language, Garp_Model_Db $model) { $localizedData = array_filter($this->_queue, 'is_array'); $out = array(); foreach ($localizedData as $key => $value) { if (array_key_exists($language, $value)) { $out[$key] = $value[$language]; } } return $out; }
[ "protected", "function", "_extractDataForLanguage", "(", "$", "language", ",", "Garp_Model_Db", "$", "model", ")", "{", "$", "localizedData", "=", "array_filter", "(", "$", "this", "->", "_queue", ",", "'is_array'", ")", ";", "$", "out", "=", "array", "(", ...
Make a regular insertable data array from the localized version we saved. @param string $language @param Garp_Model_Db $model @return array
[ "Make", "a", "regular", "insertable", "data", "array", "from", "the", "localized", "version", "we", "saved", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L431-L440
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._getPrimaryKeysOfAffectedRows
protected function _getPrimaryKeysOfAffectedRows(Garp_Model_Db $model, $where) { if ($draftableObserver = $model->getObserver('Draftable')) { // Unregister so it doesn't screw up the upcoming fetch call $model->unregisterObserver($draftableObserver); } $pkExtractor = new Garp_Db_PrimaryKeyExtractor($model, $where); $pks = $pkExtractor->extract(); if (count($pks)) { return array($pks); } $rows = $model->fetchAll($where); $pks = array(); foreach ($rows as $row) { if (!$row->isConnected()) { $row->setTable($model); } $pks[] = (array)$row->getPrimaryKey(); } if ($draftableObserver) { $model->registerObserver($draftableObserver); } return $pks; }
php
protected function _getPrimaryKeysOfAffectedRows(Garp_Model_Db $model, $where) { if ($draftableObserver = $model->getObserver('Draftable')) { // Unregister so it doesn't screw up the upcoming fetch call $model->unregisterObserver($draftableObserver); } $pkExtractor = new Garp_Db_PrimaryKeyExtractor($model, $where); $pks = $pkExtractor->extract(); if (count($pks)) { return array($pks); } $rows = $model->fetchAll($where); $pks = array(); foreach ($rows as $row) { if (!$row->isConnected()) { $row->setTable($model); } $pks[] = (array)$row->getPrimaryKey(); } if ($draftableObserver) { $model->registerObserver($draftableObserver); } return $pks; }
[ "protected", "function", "_getPrimaryKeysOfAffectedRows", "(", "Garp_Model_Db", "$", "model", ",", "$", "where", ")", "{", "if", "(", "$", "draftableObserver", "=", "$", "model", "->", "getObserver", "(", "'Draftable'", ")", ")", "{", "// Unregister so it doesn't ...
Retrieve primary keys of affected records @param Garp_Model_Db $model @param String $where @return Array
[ "Retrieve", "primary", "keys", "of", "affected", "records" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L449-L472
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._getForeignKeyData
protected function _getForeignKeyData(array $referenceMap, array $pKeys) { $data = array(); $foreignKeyColumns = $referenceMap['columns']; if (count($foreignKeyColumns) !== count($pKeys)) { throw new Garp_Model_Behavior_Exception( sprintf( self::SAVE_FOREIGN_KEY_EXCEPTION, count($pKeys), count($foreignKeyColumns) ) ); } $data = array_combine($foreignKeyColumns, $pKeys); return $data; }
php
protected function _getForeignKeyData(array $referenceMap, array $pKeys) { $data = array(); $foreignKeyColumns = $referenceMap['columns']; if (count($foreignKeyColumns) !== count($pKeys)) { throw new Garp_Model_Behavior_Exception( sprintf( self::SAVE_FOREIGN_KEY_EXCEPTION, count($pKeys), count($foreignKeyColumns) ) ); } $data = array_combine($foreignKeyColumns, $pKeys); return $data; }
[ "protected", "function", "_getForeignKeyData", "(", "array", "$", "referenceMap", ",", "array", "$", "pKeys", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "foreignKeyColumns", "=", "$", "referenceMap", "[", "'columns'", "]", ";", "if", "(", "...
Create array containing the foreign keys in the relationship mapped to the primary keys from the save. @param Array $referenceMap The referenceMap describing the relationship @param Arary $pKeys The given primary keys @return Array
[ "Create", "array", "containing", "the", "foreign", "keys", "in", "the", "relationship", "mapped", "to", "the", "primary", "keys", "from", "the", "save", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L482-L495
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._cleanClause
protected function _cleanClause($clause) { $clause = trim($clause); while ($clause[0] === '(' && $clause[strlen($clause)-1] === ')') { $clause = substr($clause, 1, -1); } return $clause; }
php
protected function _cleanClause($clause) { $clause = trim($clause); while ($clause[0] === '(' && $clause[strlen($clause)-1] === ')') { $clause = substr($clause, 1, -1); } return $clause; }
[ "protected", "function", "_cleanClause", "(", "$", "clause", ")", "{", "$", "clause", "=", "trim", "(", "$", "clause", ")", ";", "while", "(", "$", "clause", "[", "0", "]", "===", "'('", "&&", "$", "clause", "[", "strlen", "(", "$", "clause", ")", ...
Remove parentheses and whitespace around the clause @param string $clause @return string
[ "Remove", "parentheses", "and", "whitespace", "around", "the", "clause" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L540-L546
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._joinCmsSearchQuery
protected function _joinCmsSearchQuery( Garp_Model_Db $model, Zend_Db_Select &$select, $likeValue ) { $languages = Garp_I18n::getLocales(); $default_language = array(Garp_I18n::getDefaultLocale()); $langColumn = self::LANG_COLUMN; // Exclude default language, since that's already joined in the joint view $languages = array_diff($languages, $default_language); $adapter = $model->getAdapter(); $where = array(); foreach ($languages as $language) { $i18nModel = $this->getI18nModel($model); $i18nAlias = $model->getName() . '_i18n_' . $language; $onClause = $i18nModel->refMapToOnClause( get_class($model), $i18nAlias, $model->getJointView() ); // join i18n model $select->joinLeft( array($i18nAlias => $i18nModel->getName()), "$onClause AND {$i18nAlias}.{$langColumn} = '{$language}'", array() ); // add WHERE clauses that search in the i18n model $translatedFields = $this->_translatableFields; foreach ($translatedFields as $i18nField) { $where[] = "{$i18nAlias}.{$i18nField} LIKE " . $adapter->quote($likeValue); } } return implode(' OR ', $where); }
php
protected function _joinCmsSearchQuery( Garp_Model_Db $model, Zend_Db_Select &$select, $likeValue ) { $languages = Garp_I18n::getLocales(); $default_language = array(Garp_I18n::getDefaultLocale()); $langColumn = self::LANG_COLUMN; // Exclude default language, since that's already joined in the joint view $languages = array_diff($languages, $default_language); $adapter = $model->getAdapter(); $where = array(); foreach ($languages as $language) { $i18nModel = $this->getI18nModel($model); $i18nAlias = $model->getName() . '_i18n_' . $language; $onClause = $i18nModel->refMapToOnClause( get_class($model), $i18nAlias, $model->getJointView() ); // join i18n model $select->joinLeft( array($i18nAlias => $i18nModel->getName()), "$onClause AND {$i18nAlias}.{$langColumn} = '{$language}'", array() ); // add WHERE clauses that search in the i18n model $translatedFields = $this->_translatableFields; foreach ($translatedFields as $i18nField) { $where[] = "{$i18nAlias}.{$i18nField} LIKE " . $adapter->quote($likeValue); } } return implode(' OR ', $where); }
[ "protected", "function", "_joinCmsSearchQuery", "(", "Garp_Model_Db", "$", "model", ",", "Zend_Db_Select", "&", "$", "select", ",", "$", "likeValue", ")", "{", "$", "languages", "=", "Garp_I18n", "::", "getLocales", "(", ")", ";", "$", "default_language", "=",...
A real hacky solution to enable admins to search for translated content in the CMS @param Garp_Model_Db $model @param Zend_Db_Select $select @param string $likeValue @return string A search clause
[ "A", "real", "hacky", "solution", "to", "enable", "admins", "to", "search", "for", "translated", "content", "in", "the", "CMS" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L556-L589
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._setup
protected function _setup($config) { if (empty($config['columns'])) { throw new Garp_Model_Behavior_Exception(self::MISSING_COLUMNS_EXCEPTION); } $this->_translatableFields = $config['columns']; }
php
protected function _setup($config) { if (empty($config['columns'])) { throw new Garp_Model_Behavior_Exception(self::MISSING_COLUMNS_EXCEPTION); } $this->_translatableFields = $config['columns']; }
[ "protected", "function", "_setup", "(", "$", "config", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'columns'", "]", ")", ")", "{", "throw", "new", "Garp_Model_Behavior_Exception", "(", "self", "::", "MISSING_COLUMNS_EXCEPTION", ")", ";", "}", "...
Configure this behavior @param Array $config @return Void
[ "Configure", "this", "behavior" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L597-L602
train
grrr-amsterdam/garp3
library/Garp/Cli/Command/S3.php
Garp_Cli_Command_S3.makeBucket
public function makeBucket(array $args = array()) { $bucket = isset($args[0]) ? $args[0] : null; if (is_null($bucket)) { $config = Zend_Registry::get('config'); $bucket = isset($config->cdn->s3->bucket) ? $config->cdn->s3->bucket : null; } if (is_null($bucket)) { Garp_Cli::errorOut('No bucket configured'); return false; } return $this->s3( 'mb', array( 's3://' . $bucket ) ); }
php
public function makeBucket(array $args = array()) { $bucket = isset($args[0]) ? $args[0] : null; if (is_null($bucket)) { $config = Zend_Registry::get('config'); $bucket = isset($config->cdn->s3->bucket) ? $config->cdn->s3->bucket : null; } if (is_null($bucket)) { Garp_Cli::errorOut('No bucket configured'); return false; } return $this->s3( 'mb', array( 's3://' . $bucket ) ); }
[ "public", "function", "makeBucket", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "$", "bucket", "=", "isset", "(", "$", "args", "[", "0", "]", ")", "?", "$", "args", "[", "0", "]", ":", "null", ";", "if", "(", "is_null", "(", ...
Create a new bucket on S3. This defaults to the configured bucket. @param array $args @return bool
[ "Create", "a", "new", "bucket", "on", "S3", ".", "This", "defaults", "to", "the", "configured", "bucket", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/S3.php#L18-L33
train
grrr-amsterdam/garp3
library/Garp/Cli/Command/S3.php
Garp_Cli_Command_S3.setCors
public function setCors() { $corsConfig = array( 'CORSRules' => array(array( 'AllowedHeaders' => array('*'), 'AllowedMethods' => array('GET'), 'AllowedOrigins' => array('*'), )) ); $args = array( 'bucket' => Zend_Registry::get('config')->cdn->s3->bucket, 'cors-configuration' => "'" . json_encode($corsConfig) . "'" ); return $this->s3api('put-bucket-cors', $args); }
php
public function setCors() { $corsConfig = array( 'CORSRules' => array(array( 'AllowedHeaders' => array('*'), 'AllowedMethods' => array('GET'), 'AllowedOrigins' => array('*'), )) ); $args = array( 'bucket' => Zend_Registry::get('config')->cdn->s3->bucket, 'cors-configuration' => "'" . json_encode($corsConfig) . "'" ); return $this->s3api('put-bucket-cors', $args); }
[ "public", "function", "setCors", "(", ")", "{", "$", "corsConfig", "=", "array", "(", "'CORSRules'", "=>", "array", "(", "array", "(", "'AllowedHeaders'", "=>", "array", "(", "'*'", ")", ",", "'AllowedMethods'", "=>", "array", "(", "'GET'", ")", ",", "'A...
Set CORS settings on bucket @return bool @todo Make CORS options configurable? Do you ever want full-fletched control over these?
[ "Set", "CORS", "settings", "on", "bucket" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/S3.php#L102-L115
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._setup
protected function _setup($config) { $config = new Garp_Util_Configuration($config); $config->obligate('contentTypes'); $this->_config = $config; }
php
protected function _setup($config) { $config = new Garp_Util_Configuration($config); $config->obligate('contentTypes'); $this->_config = $config; }
[ "protected", "function", "_setup", "(", "$", "config", ")", "{", "$", "config", "=", "new", "Garp_Util_Configuration", "(", "$", "config", ")", ";", "$", "config", "->", "obligate", "(", "'contentTypes'", ")", ";", "$", "this", "->", "_config", "=", "$",...
Configure the behavior @param array $config @return void
[ "Configure", "the", "behavior" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L31-L35
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article.bindWithChapters
public function bindWithChapters(Garp_Model_Db &$model) { $chapterModel = new Model_Chapter(); $contentNodeModel = new Model_ContentNode(); $contentNodeModel->setCmsContext($model->isCmsContext()); $chapterModel->bindModel( 'content', array('modelClass' => $contentNodeModel) ); foreach ($this->_config['contentTypes'] as $chapterType) { $chapterAlias = $this->_extractContentTypeAlias($chapterType); $options = $this->_extractContentTypeBindOptions($chapterType, $contentNodeModel); $contentNodeModel->bindModel($chapterAlias, $options); } $model->bindModel( 'chapters', array('modelClass' => $chapterModel) ); }
php
public function bindWithChapters(Garp_Model_Db &$model) { $chapterModel = new Model_Chapter(); $contentNodeModel = new Model_ContentNode(); $contentNodeModel->setCmsContext($model->isCmsContext()); $chapterModel->bindModel( 'content', array('modelClass' => $contentNodeModel) ); foreach ($this->_config['contentTypes'] as $chapterType) { $chapterAlias = $this->_extractContentTypeAlias($chapterType); $options = $this->_extractContentTypeBindOptions($chapterType, $contentNodeModel); $contentNodeModel->bindModel($chapterAlias, $options); } $model->bindModel( 'chapters', array('modelClass' => $chapterModel) ); }
[ "public", "function", "bindWithChapters", "(", "Garp_Model_Db", "&", "$", "model", ")", "{", "$", "chapterModel", "=", "new", "Model_Chapter", "(", ")", ";", "$", "contentNodeModel", "=", "new", "Model_ContentNode", "(", ")", ";", "$", "contentNodeModel", "->"...
Bind all the Chapters and ContentNodes to fetch the complete Article. @param Garp_Model_Db $model @return void
[ "Bind", "all", "the", "Chapters", "and", "ContentNodes", "to", "fetch", "the", "complete", "Article", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L44-L61
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article.afterFetch
public function afterFetch(&$args) { $results = &$args[1]; $iterator = new Garp_Db_Table_Rowset_Iterator( $results, array($this, 'convertArticleLayout') ); $iterator->walk(); return true; }
php
public function afterFetch(&$args) { $results = &$args[1]; $iterator = new Garp_Db_Table_Rowset_Iterator( $results, array($this, 'convertArticleLayout') ); $iterator->walk(); return true; }
[ "public", "function", "afterFetch", "(", "&", "$", "args", ")", "{", "$", "results", "=", "&", "$", "args", "[", "1", "]", ";", "$", "iterator", "=", "new", "Garp_Db_Table_Rowset_Iterator", "(", "$", "results", ",", "array", "(", "$", "this", ",", "'...
AfterFetch callback, reforms the bound Chapters into a more concise collection. @param array $args Event listener parameters @return void
[ "AfterFetch", "callback", "reforms", "the", "bound", "Chapters", "into", "a", "more", "concise", "collection", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L86-L94
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._convertChapterLayout
protected function _convertChapterLayout(array $chapterRow) { $chapter = array(); $chapter['type'] = $chapterRow['type']; if (!isset($chapterRow['content'])) { return $chapter; } $chapter['content'] = array_map( array($this, '_convertContentNodeLayout'), $chapterRow['content'] ); return $chapter; }
php
protected function _convertChapterLayout(array $chapterRow) { $chapter = array(); $chapter['type'] = $chapterRow['type']; if (!isset($chapterRow['content'])) { return $chapter; } $chapter['content'] = array_map( array($this, '_convertContentNodeLayout'), $chapterRow['content'] ); return $chapter; }
[ "protected", "function", "_convertChapterLayout", "(", "array", "$", "chapterRow", ")", "{", "$", "chapter", "=", "array", "(", ")", ";", "$", "chapter", "[", "'type'", "]", "=", "$", "chapterRow", "[", "'type'", "]", ";", "if", "(", "!", "isset", "(",...
Convert bound Chapters to a more concise format. @param array $chapterRow @return array
[ "Convert", "bound", "Chapters", "to", "a", "more", "concise", "format", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L200-L211
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._convertContentNodeLayout
protected function _convertContentNodeLayout(array $contentNodeRow) { $contentTypes = $this->_config['contentTypes']; $contentNode = array(); foreach ($contentTypes as $contentType) { $contentType = $this->_extractContentTypeAlias($contentType); if ($contentNodeRow[$contentType]) { $modelName = explode('_', $contentType); $modelName = array_pop($modelName); $contentNode['model'] = $modelName; $contentNode['type'] = $contentNodeRow['type']; $contentNode['data'] = $contentNodeRow[$contentType]; $contentNode['columns'] = $contentNodeRow['columns']; $contentNode['classes'] = $contentNodeRow['classes']; break; } } return $contentNode; }
php
protected function _convertContentNodeLayout(array $contentNodeRow) { $contentTypes = $this->_config['contentTypes']; $contentNode = array(); foreach ($contentTypes as $contentType) { $contentType = $this->_extractContentTypeAlias($contentType); if ($contentNodeRow[$contentType]) { $modelName = explode('_', $contentType); $modelName = array_pop($modelName); $contentNode['model'] = $modelName; $contentNode['type'] = $contentNodeRow['type']; $contentNode['data'] = $contentNodeRow[$contentType]; $contentNode['columns'] = $contentNodeRow['columns']; $contentNode['classes'] = $contentNodeRow['classes']; break; } } return $contentNode; }
[ "protected", "function", "_convertContentNodeLayout", "(", "array", "$", "contentNodeRow", ")", "{", "$", "contentTypes", "=", "$", "this", "->", "_config", "[", "'contentTypes'", "]", ";", "$", "contentNode", "=", "array", "(", ")", ";", "foreach", "(", "$"...
Convert bound ContentNodes to a more concise format. @param array $contentNodeRow @return array
[ "Convert", "bound", "ContentNodes", "to", "a", "more", "concise", "format", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L219-L236
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article.relateChapters
public function relateChapters(array $chapters, Garp_Model_Db $model, $articleId) { // Start by unrelating all chapters Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, ) ); // Reverse order since the Weighable behavior sorts chapter by weight DESC, // giving each new chapter the highest weight. $chapters = array_reverse($chapters); foreach ($chapters as $chapterData) { $chapterData = $this->_getValidChapterData($chapterData); /** * Insert a new chapter. * The chapter will take care of storing and relating the * content nodes. */ $chapterModel = new Model_Chapter(); $chapterId = $chapterModel->insert( array( 'type' => $chapterData['type'], 'content' => $chapterData['content'], ) ); Garp_Content_Relation_Manager::relate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, 'keyB' => $chapterId, ) ); } }
php
public function relateChapters(array $chapters, Garp_Model_Db $model, $articleId) { // Start by unrelating all chapters Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, ) ); // Reverse order since the Weighable behavior sorts chapter by weight DESC, // giving each new chapter the highest weight. $chapters = array_reverse($chapters); foreach ($chapters as $chapterData) { $chapterData = $this->_getValidChapterData($chapterData); /** * Insert a new chapter. * The chapter will take care of storing and relating the * content nodes. */ $chapterModel = new Model_Chapter(); $chapterId = $chapterModel->insert( array( 'type' => $chapterData['type'], 'content' => $chapterData['content'], ) ); Garp_Content_Relation_Manager::relate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, 'keyB' => $chapterId, ) ); } }
[ "public", "function", "relateChapters", "(", "array", "$", "chapters", ",", "Garp_Model_Db", "$", "model", ",", "$", "articleId", ")", "{", "// Start by unrelating all chapters", "Garp_Content_Relation_Manager", "::", "unrelate", "(", "array", "(", "'modelA'", "=>", ...
Relate Chapters. Called after insert and after update. @param array $chapters @param Garp_Model_Db $model The subject model @param int $articleId The id of the involved article @return void
[ "Relate", "Chapters", ".", "Called", "after", "insert", "and", "after", "update", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L248-L285
train
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._getValidChapterData
protected function _getValidChapterData($chapterData) { $chapterData = $chapterData instanceof Garp_Util_Configuration ? $chapterData : new Garp_Util_Configuration($chapterData); $chapterData ->obligate('content') ->setDefault('type', ''); return $chapterData; }
php
protected function _getValidChapterData($chapterData) { $chapterData = $chapterData instanceof Garp_Util_Configuration ? $chapterData : new Garp_Util_Configuration($chapterData); $chapterData ->obligate('content') ->setDefault('type', ''); return $chapterData; }
[ "protected", "function", "_getValidChapterData", "(", "$", "chapterData", ")", "{", "$", "chapterData", "=", "$", "chapterData", "instanceof", "Garp_Util_Configuration", "?", "$", "chapterData", ":", "new", "Garp_Util_Configuration", "(", "$", "chapterData", ")", ";...
Convert chapter to Garp_Util_Configuration and validate its keys. @param array|Garp_Util_Configuration $chapterData @return Garp_Util_Configuration
[ "Convert", "chapter", "to", "Garp_Util_Configuration", "and", "validate", "its", "keys", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L293-L300
train
grrr-amsterdam/garp3
library/Garp/Cli/Command/Email.php
Garp_Cli_Command_Email._validateArgs
protected function _validateArgs(array $args): bool { foreach (self::REQUIRED_FLAGS as $flag) { if (!array_key_exists($flag, $args)) { Garp_Cli::errorOut("No {$flag} flag provided."); return false; } } return true; }
php
protected function _validateArgs(array $args): bool { foreach (self::REQUIRED_FLAGS as $flag) { if (!array_key_exists($flag, $args)) { Garp_Cli::errorOut("No {$flag} flag provided."); return false; } } return true; }
[ "protected", "function", "_validateArgs", "(", "array", "$", "args", ")", ":", "bool", "{", "foreach", "(", "self", "::", "REQUIRED_FLAGS", "as", "$", "flag", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "flag", ",", "$", "args", ")", ")", ...
Validates given arguments @param array $args @return boolean
[ "Validates", "given", "arguments" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Email.php#L50-L58
train
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Facebook.php
Garp_Auth_Adapter_Facebook._getFacebookClient
protected function _getFacebookClient() { $authVars = $this->_getAuthVars(); $facebook = Garp_Social_Facebook::getInstance(array( 'appId' => $authVars->appId, 'secret' => $authVars->secret, 'cookie' => false, )); return $facebook; }
php
protected function _getFacebookClient() { $authVars = $this->_getAuthVars(); $facebook = Garp_Social_Facebook::getInstance(array( 'appId' => $authVars->appId, 'secret' => $authVars->secret, 'cookie' => false, )); return $facebook; }
[ "protected", "function", "_getFacebookClient", "(", ")", "{", "$", "authVars", "=", "$", "this", "->", "_getAuthVars", "(", ")", ";", "$", "facebook", "=", "Garp_Social_Facebook", "::", "getInstance", "(", "array", "(", "'appId'", "=>", "$", "authVars", "->"...
Load Facebook's own client @return Facebook
[ "Load", "Facebook", "s", "own", "client" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Facebook.php#L132-L140
train
grrr-amsterdam/garp3
application/modules/g/views/helpers/FullUrl.php
G_View_Helper_FullUrl.fullUrl
public function fullUrl($url = false, $omitProtocol = false, $omitBaseUrl = false) { if (!$url) { $url = $this->view->url(); } $fullUrl = new Garp_Util_FullUrl($url, $omitProtocol, $omitBaseUrl); return $fullUrl->__toString(); }
php
public function fullUrl($url = false, $omitProtocol = false, $omitBaseUrl = false) { if (!$url) { $url = $this->view->url(); } $fullUrl = new Garp_Util_FullUrl($url, $omitProtocol, $omitBaseUrl); return $fullUrl->__toString(); }
[ "public", "function", "fullUrl", "(", "$", "url", "=", "false", ",", "$", "omitProtocol", "=", "false", ",", "$", "omitBaseUrl", "=", "false", ")", "{", "if", "(", "!", "$", "url", ")", "{", "$", "url", "=", "$", "this", "->", "view", "->", "url"...
Create full URL from relative URL. @param string|bool $url Relative URL (will be passed thru baseUrl() if $omitBaseUrl = false) @param bool $omitProtocol @param bool $omitBaseUrl @return string Full URL
[ "Create", "full", "URL", "from", "relative", "URL", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/FullUrl.php#L18-L24
train
grrr-amsterdam/garp3
library/Garp/Controller/Helper/Upload.php
Garp_Controller_Helper_Upload.uploadRaw
public function uploadRaw($uploadType, $filename, $bytes) { $uploadType = $uploadType ?: Garp_File::TYPE_IMAGES; return array( $filename => $this->_store($uploadType, $filename, $bytes) ); }
php
public function uploadRaw($uploadType, $filename, $bytes) { $uploadType = $uploadType ?: Garp_File::TYPE_IMAGES; return array( $filename => $this->_store($uploadType, $filename, $bytes) ); }
[ "public", "function", "uploadRaw", "(", "$", "uploadType", ",", "$", "filename", ",", "$", "bytes", ")", "{", "$", "uploadType", "=", "$", "uploadType", "?", ":", "Garp_File", "::", "TYPE_IMAGES", ";", "return", "array", "(", "$", "filename", "=>", "$", ...
Upload raw POST data. @param string $uploadType The type of file being uploaded, either 'images' or 'documents' @param string $filename The filename @param string $bytes @return array Response is consistent with self::uploadFromFiles.
[ "Upload", "raw", "POST", "data", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/Upload.php#L122-L127
train
grrr-amsterdam/garp3
library/Garp/Controller/Helper/Upload.php
Garp_Controller_Helper_Upload._store
protected function _store($uploadType, $name, $bytes, $overwrite = false) { if (!array_key_exists($uploadType, $this->_fileHandlers)) { $this->_fileHandlers[$uploadType] = $uploadType === Garp_File::TYPE_IMAGES ? new Garp_Image_File() : new Garp_File($uploadType); } return $this->_fileHandlers[$uploadType]->store($name, $bytes, $overwrite); }
php
protected function _store($uploadType, $name, $bytes, $overwrite = false) { if (!array_key_exists($uploadType, $this->_fileHandlers)) { $this->_fileHandlers[$uploadType] = $uploadType === Garp_File::TYPE_IMAGES ? new Garp_Image_File() : new Garp_File($uploadType); } return $this->_fileHandlers[$uploadType]->store($name, $bytes, $overwrite); }
[ "protected", "function", "_store", "(", "$", "uploadType", ",", "$", "name", ",", "$", "bytes", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "uploadType", ",", "$", "this", "->", "_fileHandlers", ")", ")"...
Store the uploaded bytes in a file. @param string $uploadType The type of file being uploaded, either 'images' or 'documents' @param string $name The filename @param string $bytes @param bool $overwrite @return string The new filename
[ "Store", "the", "uploaded", "bytes", "in", "a", "file", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/Upload.php#L138-L145
train
grrr-amsterdam/garp3
application/modules/g/views/helpers/Browsebox.php
G_View_Helper_Browsebox.browsebox
public function browsebox(Garp_Browsebox $browsebox = null, $params = array()) { if (is_null($browsebox)) { return $this; } static::$_store[$browsebox->getId()] = $browsebox; $params = array_merge( $params, array( 'results' => $browsebox->getResults(), 'next' => $browsebox->getNextUrl(), 'prev' => $browsebox->getPrevUrl() ) ); return $this->view->partial( $browsebox->getViewPath(), 'default', $params ); }
php
public function browsebox(Garp_Browsebox $browsebox = null, $params = array()) { if (is_null($browsebox)) { return $this; } static::$_store[$browsebox->getId()] = $browsebox; $params = array_merge( $params, array( 'results' => $browsebox->getResults(), 'next' => $browsebox->getNextUrl(), 'prev' => $browsebox->getPrevUrl() ) ); return $this->view->partial( $browsebox->getViewPath(), 'default', $params ); }
[ "public", "function", "browsebox", "(", "Garp_Browsebox", "$", "browsebox", "=", "null", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "is_null", "(", "$", "browsebox", ")", ")", "{", "return", "$", "this", ";", "}", "static", "::"...
Render a browsebox object @param Garp_Browsebox $browsebox @param array $params Extra parameters sent to the partial @return string
[ "Render", "a", "browsebox", "object" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Browsebox.php#L24-L42
train
grrr-amsterdam/garp3
application/modules/g/views/helpers/Browsebox.php
G_View_Helper_Browsebox.config
public function config($id = false) { $boxes = $this->_getAllBrowseboxes(); if (count($boxes)) { $script = "Garp.browseboxes = [];\n"; foreach ($boxes as $boxId => $box) { $jsConfig = $this->_getJavascriptOptions($box); $boxScript = ''; $boxScript .= "new Garp.Browsebox({\n"; $boxScript .= "\t\"id\": \"$boxId\",\n"; $i = 0; $total = count($jsConfig); foreach ($jsConfig as $confKey => $confVal) { $boxScript .= "\t\"$confKey\": \"$confVal\""; if ($i < ($total-1)) { $boxScript .= ','; } $boxScript .= "\n"; $i++; } $boxScript .= "})"; if ($id && $boxId === $id) { return $this->_wrapInTags($boxScript); } $script .= "Garp.browseboxes.push($boxScript);\n"; } return $this->_wrapInTags($script); } return ''; }
php
public function config($id = false) { $boxes = $this->_getAllBrowseboxes(); if (count($boxes)) { $script = "Garp.browseboxes = [];\n"; foreach ($boxes as $boxId => $box) { $jsConfig = $this->_getJavascriptOptions($box); $boxScript = ''; $boxScript .= "new Garp.Browsebox({\n"; $boxScript .= "\t\"id\": \"$boxId\",\n"; $i = 0; $total = count($jsConfig); foreach ($jsConfig as $confKey => $confVal) { $boxScript .= "\t\"$confKey\": \"$confVal\""; if ($i < ($total-1)) { $boxScript .= ','; } $boxScript .= "\n"; $i++; } $boxScript .= "})"; if ($id && $boxId === $id) { return $this->_wrapInTags($boxScript); } $script .= "Garp.browseboxes.push($boxScript);\n"; } return $this->_wrapInTags($script); } return ''; }
[ "public", "function", "config", "(", "$", "id", "=", "false", ")", "{", "$", "boxes", "=", "$", "this", "->", "_getAllBrowseboxes", "(", ")", ";", "if", "(", "count", "(", "$", "boxes", ")", ")", "{", "$", "script", "=", "\"Garp.browseboxes = [];\\n\""...
Create Javascript configuration for browsebox objects. @param string $id The browsebox id. If given, only config for this browsebox is returned. @return string
[ "Create", "Javascript", "configuration", "for", "browsebox", "objects", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Browsebox.php#L51-L80
train
grrr-amsterdam/garp3
application/modules/g/views/helpers/Browsebox.php
G_View_Helper_Browsebox._getJavascriptOptions
protected function _getJavascriptOptions(Garp_Browsebox $box) { $options = $box->getJavascriptOptions(); $options = $options instanceof Garp_Util_Configuration ? $options : new Garp_Util_Configuration($options); return $options->setDefault('rememberState', false) ->setDefault('transition', 'crossFade'); }
php
protected function _getJavascriptOptions(Garp_Browsebox $box) { $options = $box->getJavascriptOptions(); $options = $options instanceof Garp_Util_Configuration ? $options : new Garp_Util_Configuration($options); return $options->setDefault('rememberState', false) ->setDefault('transition', 'crossFade'); }
[ "protected", "function", "_getJavascriptOptions", "(", "Garp_Browsebox", "$", "box", ")", "{", "$", "options", "=", "$", "box", "->", "getJavascriptOptions", "(", ")", ";", "$", "options", "=", "$", "options", "instanceof", "Garp_Util_Configuration", "?", "$", ...
Get JS options @param Garp_Browsebox $box @return Garp_Util_Configuration
[ "Get", "JS", "options" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Browsebox.php#L108-L115
train
grrr-amsterdam/garp3
application/modules/g/views/helpers/Chapter.php
G_View_Helper_Chapter.render
public function render(array $chapter, array $params = array()) { $partial = 'partials/chapters/' . ($chapter['type'] ?: 'default') . '.phtml'; $params['content'] = $chapter['content']; return $this->view->partial($partial, 'default', $params); }
php
public function render(array $chapter, array $params = array()) { $partial = 'partials/chapters/' . ($chapter['type'] ?: 'default') . '.phtml'; $params['content'] = $chapter['content']; return $this->view->partial($partial, 'default', $params); }
[ "public", "function", "render", "(", "array", "$", "chapter", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "$", "partial", "=", "'partials/chapters/'", ".", "(", "$", "chapter", "[", "'type'", "]", "?", ":", "'default'", ")", ".", "...
Render the chapter @param array $chapter @param array $params Additional parameters for the partial. @return string
[ "Render", "the", "chapter" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Chapter.php#L26-L30
train
grrr-amsterdam/garp3
application/modules/g/views/helpers/Chapter.php
G_View_Helper_Chapter.renderContentNode
public function renderContentNode(array $contentNode, array $params = array()) { if (empty($contentNode)) { return ''; } $model = strtolower($contentNode['model']); $type = $contentNode['type'] ?: 'default'; $partial = "partials/chapters/$model/$type.phtml"; $params['contentNode'] = $contentNode; return $this->view->partial($partial, 'default', $params); }
php
public function renderContentNode(array $contentNode, array $params = array()) { if (empty($contentNode)) { return ''; } $model = strtolower($contentNode['model']); $type = $contentNode['type'] ?: 'default'; $partial = "partials/chapters/$model/$type.phtml"; $params['contentNode'] = $contentNode; return $this->view->partial($partial, 'default', $params); }
[ "public", "function", "renderContentNode", "(", "array", "$", "contentNode", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "contentNode", ")", ")", "{", "return", "''", ";", "}", "$", "model", "=", "strt...
Render a content node @param array $contentNode @param array $params Additional parameters for the partial @return string
[ "Render", "a", "content", "node" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Chapter.php#L39-L48
train
grrr-amsterdam/garp3
library/Garp/Cli/Command/Figlet.php
Garp_Cli_Command_Figlet.display
public function display(array $args = array()) { if (empty($args)) { Garp_Cli::errorOut('The least you can do is provide a text...'); } else { $text = implode(' ', $args); $figlet = new Zend_Text_Figlet(); Garp_Cli::lineOut($figlet->render($text)); } return true; }
php
public function display(array $args = array()) { if (empty($args)) { Garp_Cli::errorOut('The least you can do is provide a text...'); } else { $text = implode(' ', $args); $figlet = new Zend_Text_Figlet(); Garp_Cli::lineOut($figlet->render($text)); } return true; }
[ "public", "function", "display", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "args", ")", ")", "{", "Garp_Cli", "::", "errorOut", "(", "'The least you can do is provide a text...'", ")", ";", "}", "else", "{...
Display a figlet @param array $args @return bool
[ "Display", "a", "figlet" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Figlet.php#L16-L25
train
grrr-amsterdam/garp3
library/Garp/Model/Db/CropTemplate.php
Garp_Model_Db_CropTemplate.fetchAll
public function fetchAll() { $templates = parent::fetchAll(); $out = array(); $id = 1; foreach ($templates as $key => $value) { if (!array_key_exists('richtextable', $value) || !$value['richtextable']) { continue; } $out[] = array( 'id' => $id++, 'name' => $key, 'w' => !empty($value['w']) ? $value['w'] : null, 'h' => !empty($value['h']) ? $value['h'] : null, 'crop' => !empty($value['crop']) ? $value['crop'] : null, 'grow' => !empty($value['grow']) ? $value['grow'] : null ); } return $out; }
php
public function fetchAll() { $templates = parent::fetchAll(); $out = array(); $id = 1; foreach ($templates as $key => $value) { if (!array_key_exists('richtextable', $value) || !$value['richtextable']) { continue; } $out[] = array( 'id' => $id++, 'name' => $key, 'w' => !empty($value['w']) ? $value['w'] : null, 'h' => !empty($value['h']) ? $value['h'] : null, 'crop' => !empty($value['crop']) ? $value['crop'] : null, 'grow' => !empty($value['grow']) ? $value['grow'] : null ); } return $out; }
[ "public", "function", "fetchAll", "(", ")", "{", "$", "templates", "=", "parent", "::", "fetchAll", "(", ")", ";", "$", "out", "=", "array", "(", ")", ";", "$", "id", "=", "1", ";", "foreach", "(", "$", "templates", "as", "$", "key", "=>", "$", ...
Fetch all entries @return array
[ "Fetch", "all", "entries" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/CropTemplate.php#L29-L47
train
grrr-amsterdam/garp3
library/Garp/Model/Db/Chapter.php
Garp_Model_Db_Chapter.relateContentNodes
public function relateContentNodes($contentNodeList, $chapterId) { // Reverse node list because the Weighable behavior sorts different from the way // the CMS sends us the nodes. $contentNodeList = array_reverse($contentNodeList); foreach ($contentNodeList as $contentNode) { $node = $this->_getValidContentNodeData($contentNode); // Save ContentNode $node['chapter_id'] = $chapterId; $contentNodeId = $this->_insertContentNode($node); // @todo Move everything below here to Model_ContentNode::afterInsert() // Determine content type $contentTypeModelName = 'Model_'.$node['model']; $contentTypeModel = new $contentTypeModelName(); // Check for existing id $data = $node['data']; if (empty($data['id'])) { // If no id is present, create a new subtype record $contentTypeId = $contentTypeModel->insert($data); } else { // Update the chapter subtype's content $contentTypeModel->update($data, 'id = '.$contentTypeModel->getAdapter()->quote($data['id'])); $contentTypeId = $data['id']; } // Relate the ContentNode to the subtype record Garp_Content_Relation_Manager::relate(array( 'modelA' => 'Model_ContentNode', 'modelB' => $contentTypeModel, 'keyA' => $contentNodeId, 'keyB' => $contentTypeId, )); } }
php
public function relateContentNodes($contentNodeList, $chapterId) { // Reverse node list because the Weighable behavior sorts different from the way // the CMS sends us the nodes. $contentNodeList = array_reverse($contentNodeList); foreach ($contentNodeList as $contentNode) { $node = $this->_getValidContentNodeData($contentNode); // Save ContentNode $node['chapter_id'] = $chapterId; $contentNodeId = $this->_insertContentNode($node); // @todo Move everything below here to Model_ContentNode::afterInsert() // Determine content type $contentTypeModelName = 'Model_'.$node['model']; $contentTypeModel = new $contentTypeModelName(); // Check for existing id $data = $node['data']; if (empty($data['id'])) { // If no id is present, create a new subtype record $contentTypeId = $contentTypeModel->insert($data); } else { // Update the chapter subtype's content $contentTypeModel->update($data, 'id = '.$contentTypeModel->getAdapter()->quote($data['id'])); $contentTypeId = $data['id']; } // Relate the ContentNode to the subtype record Garp_Content_Relation_Manager::relate(array( 'modelA' => 'Model_ContentNode', 'modelB' => $contentTypeModel, 'keyA' => $contentNodeId, 'keyB' => $contentTypeId, )); } }
[ "public", "function", "relateContentNodes", "(", "$", "contentNodeList", ",", "$", "chapterId", ")", "{", "// Reverse node list because the Weighable behavior sorts different from the way", "// the CMS sends us the nodes.", "$", "contentNodeList", "=", "array_reverse", "(", "$", ...
Relate ContentNodes to a chapter. @param Array $contentNodeList @param Int $chapterId @return Void
[ "Relate", "ContentNodes", "to", "a", "chapter", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Chapter.php#L103-L139
train
grrr-amsterdam/garp3
library/Garp/Model/Db/Chapter.php
Garp_Model_Db_Chapter._insertContentNode
protected function _insertContentNode(Garp_Util_Configuration $contentNodeData) { $contentNodeModel = new Model_ContentNode(); $contentNodeId = $contentNodeModel->insert(array( 'columns' => $contentNodeData['columns'], 'classes' => $contentNodeData['classes'], 'type' => $contentNodeData['type'], 'chapter_id' => $contentNodeData['chapter_id'], )); return $contentNodeId; }
php
protected function _insertContentNode(Garp_Util_Configuration $contentNodeData) { $contentNodeModel = new Model_ContentNode(); $contentNodeId = $contentNodeModel->insert(array( 'columns' => $contentNodeData['columns'], 'classes' => $contentNodeData['classes'], 'type' => $contentNodeData['type'], 'chapter_id' => $contentNodeData['chapter_id'], )); return $contentNodeId; }
[ "protected", "function", "_insertContentNode", "(", "Garp_Util_Configuration", "$", "contentNodeData", ")", "{", "$", "contentNodeModel", "=", "new", "Model_ContentNode", "(", ")", ";", "$", "contentNodeId", "=", "$", "contentNodeModel", "->", "insert", "(", "array"...
Insert new ContentNode record @param Garp_Util_Configuration $contentNodeData @return Int The primary key
[ "Insert", "new", "ContentNode", "record" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Chapter.php#L147-L156
train
grrr-amsterdam/garp3
library/Garp/Model/Db/Chapter.php
Garp_Model_Db_Chapter._getValidContentNodeData
protected function _getValidContentNodeData($contentNode) { $contentNode = $contentNode instanceof Garp_Util_Configuration ? $contentNode : new Garp_Util_Configuration($contentNode); $contentNode ->obligate('model') ->obligate('data') ->obligate('columns') ->setDefault('type', '') ->setDefault('classes', '') ; return $contentNode; }
php
protected function _getValidContentNodeData($contentNode) { $contentNode = $contentNode instanceof Garp_Util_Configuration ? $contentNode : new Garp_Util_Configuration($contentNode); $contentNode ->obligate('model') ->obligate('data') ->obligate('columns') ->setDefault('type', '') ->setDefault('classes', '') ; return $contentNode; }
[ "protected", "function", "_getValidContentNodeData", "(", "$", "contentNode", ")", "{", "$", "contentNode", "=", "$", "contentNode", "instanceof", "Garp_Util_Configuration", "?", "$", "contentNode", ":", "new", "Garp_Util_Configuration", "(", "$", "contentNode", ")", ...
Validate content node @param Array $contentNode @return Array
[ "Validate", "content", "node" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Chapter.php#L164-L174
train
grrr-amsterdam/garp3
library/Garp/Content/Db/Server/Remote.php
Garp_Content_Db_Server_Remote.store
public function store($path, &$data) { $ssh = $this->getSshSession(); $sftp = ssh2_sftp($ssh); $sftpStream = @fopen('ssh2.sftp://' . $sftp . $path, 'wb'); if (!$sftpStream) { throw new Exception("Could not open remote file: $path"); } if (@fwrite($sftpStream, $data) === false) { throw new Exception("Could not store {$path} by SFTP on " . $this->getEnvironment()); } fclose($sftpStream); return true; }
php
public function store($path, &$data) { $ssh = $this->getSshSession(); $sftp = ssh2_sftp($ssh); $sftpStream = @fopen('ssh2.sftp://' . $sftp . $path, 'wb'); if (!$sftpStream) { throw new Exception("Could not open remote file: $path"); } if (@fwrite($sftpStream, $data) === false) { throw new Exception("Could not store {$path} by SFTP on " . $this->getEnvironment()); } fclose($sftpStream); return true; }
[ "public", "function", "store", "(", "$", "path", ",", "&", "$", "data", ")", "{", "$", "ssh", "=", "$", "this", "->", "getSshSession", "(", ")", ";", "$", "sftp", "=", "ssh2_sftp", "(", "$", "ssh", ")", ";", "$", "sftpStream", "=", "@", "fopen", ...
Stores data in a file. @param String $path Absolute path within the server to a file where the data should be stored. @param String &$data The data to store. @return Boolean Success status of the storage process.
[ "Stores", "data", "in", "a", "file", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Db/Server/Remote.php#L124-L140
train
grrr-amsterdam/garp3
library/Garp/Controller/Helper/CanonicalUrl.php
Garp_Controller_Helper_CanonicalUrl.validateOrRedirect
public function validateOrRedirect($canonical) { if (!$this->validate($canonical)) { $this->redirect($canonical); return false; } return true; }
php
public function validateOrRedirect($canonical) { if (!$this->validate($canonical)) { $this->redirect($canonical); return false; } return true; }
[ "public", "function", "validateOrRedirect", "(", "$", "canonical", ")", "{", "if", "(", "!", "$", "this", "->", "validate", "(", "$", "canonical", ")", ")", "{", "$", "this", "->", "redirect", "(", "$", "canonical", ")", ";", "return", "false", ";", ...
Helper method that combines validating and redirecting @param String $canonical @return Boolean
[ "Helper", "method", "that", "combines", "validating", "and", "redirecting" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/CanonicalUrl.php#L16-L22
train
grrr-amsterdam/garp3
library/Garp/Controller/Helper/CanonicalUrl.php
Garp_Controller_Helper_CanonicalUrl.validate
public function validate($canonical) { $currUrl = $this->getRequest()->getRequestUri(); // match using a full url if the canonical starts with a protocol if (preg_match('~^[a-z]+://~', $canonical)) { $isObj = $canonical instanceof Garp_Util_FullUrl; $omitProtocol = $isObj ? $canonical->getOmitProtocol() : false; $omitBaseUrl = $isObj ? $canonical->getOmitBaseUrl() : false; $currUrl = new Garp_Util_FullUrl($currUrl, $omitProtocol, $omitBaseUrl); } return (string)$currUrl == (string)$canonical; }
php
public function validate($canonical) { $currUrl = $this->getRequest()->getRequestUri(); // match using a full url if the canonical starts with a protocol if (preg_match('~^[a-z]+://~', $canonical)) { $isObj = $canonical instanceof Garp_Util_FullUrl; $omitProtocol = $isObj ? $canonical->getOmitProtocol() : false; $omitBaseUrl = $isObj ? $canonical->getOmitBaseUrl() : false; $currUrl = new Garp_Util_FullUrl($currUrl, $omitProtocol, $omitBaseUrl); } return (string)$currUrl == (string)$canonical; }
[ "public", "function", "validate", "(", "$", "canonical", ")", "{", "$", "currUrl", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getRequestUri", "(", ")", ";", "// match using a full url if the canonical starts with a protocol", "if", "(", "preg_match", "...
Validate wether the supposed canonical url is actually the current request url @param String $canonical @return Boolean
[ "Validate", "wether", "the", "supposed", "canonical", "url", "is", "actually", "the", "current", "request", "url" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/CanonicalUrl.php#L29-L39
train
grrr-amsterdam/garp3
library/Garp/Controller/Helper/CanonicalUrl.php
Garp_Controller_Helper_CanonicalUrl.redirect
public function redirect($canonical) { if (!preg_match('~^[a-z]+://~', $canonical)) { $canonical = new Garp_Util_FullUrl($canonical); } $controller = $this->getActionController(); $controller->getHelper('cache')->disable(); $controller->getHelper('viewRenderer')->setNoRender(true); $controller->getHelper('layout')->disableLayout(); $controller->getHelper('redirector')->gotoUrl((string)$canonical, array('code' => 301)); }
php
public function redirect($canonical) { if (!preg_match('~^[a-z]+://~', $canonical)) { $canonical = new Garp_Util_FullUrl($canonical); } $controller = $this->getActionController(); $controller->getHelper('cache')->disable(); $controller->getHelper('viewRenderer')->setNoRender(true); $controller->getHelper('layout')->disableLayout(); $controller->getHelper('redirector')->gotoUrl((string)$canonical, array('code' => 301)); }
[ "public", "function", "redirect", "(", "$", "canonical", ")", "{", "if", "(", "!", "preg_match", "(", "'~^[a-z]+://~'", ",", "$", "canonical", ")", ")", "{", "$", "canonical", "=", "new", "Garp_Util_FullUrl", "(", "$", "canonical", ")", ";", "}", "$", ...
Redirect to the canonical URL @param String $canonical @return Void
[ "Redirect", "to", "the", "canonical", "URL" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/CanonicalUrl.php#L46-L55
train
grrr-amsterdam/garp3
library/Garp/Spawn/Relation.php
Garp_Spawn_Relation.getRules
public function getRules($subjectModel) { if ($this->type === 'hasMany') { return array($this->oppositeRule); } if ($this->type === 'hasAndBelongsToMany') { $bindingModel = $this->getBindingModel(); $relations = $bindingModel->relations->getRelations(); $rules = array_keys($relations); /* Now sort egocentrically, because current sorting is alphabetical (since $relations is an associative array) */ $firstRel = current($relations); if ($firstRel->model !== $subjectModel) { $rules = array_reverse($rules); } if ($this->isHomo() && ($rules[0] !== $subjectModel && $rules[1] === $subjectModel) ) { // Make sure that the custom named relation always comes second. // This is part of egocentrism. $rules = array_reverse($rules); } return $rules; } return array($this->name); }
php
public function getRules($subjectModel) { if ($this->type === 'hasMany') { return array($this->oppositeRule); } if ($this->type === 'hasAndBelongsToMany') { $bindingModel = $this->getBindingModel(); $relations = $bindingModel->relations->getRelations(); $rules = array_keys($relations); /* Now sort egocentrically, because current sorting is alphabetical (since $relations is an associative array) */ $firstRel = current($relations); if ($firstRel->model !== $subjectModel) { $rules = array_reverse($rules); } if ($this->isHomo() && ($rules[0] !== $subjectModel && $rules[1] === $subjectModel) ) { // Make sure that the custom named relation always comes second. // This is part of egocentrism. $rules = array_reverse($rules); } return $rules; } return array($this->name); }
[ "public", "function", "getRules", "(", "$", "subjectModel", ")", "{", "if", "(", "$", "this", "->", "type", "===", "'hasMany'", ")", "{", "return", "array", "(", "$", "this", "->", "oppositeRule", ")", ";", "}", "if", "(", "$", "this", "->", "type", ...
Return the rules that make up this relation, as used in the referenceMap. @param string $subjectModel Name of the model you're viewing from. Determines the direction in some cases. @return array In case of 'hasMany', an array containing a single rule, in case of 'hasAndBelongsToMany', an array containing two rules referencing two models.
[ "Return", "the", "rules", "that", "make", "up", "this", "relation", "as", "used", "in", "the", "referenceMap", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Relation.php#L281-L307
train
grrr-amsterdam/garp3
library/Garp/Spawn/Relation.php
Garp_Spawn_Relation._addRelationFieldInLocalModel
protected function _addRelationFieldInLocalModel() { if (!$this->isSingular()) { return; } $column = Garp_Spawn_Relation_Set::getRelationColumn($this->name); $fieldParams = array( 'model' => $this->model, 'type' => 'numeric', 'editable' => true, 'visible' => true, 'primary' => $this->primary, 'required' => $this->required, 'relationAlias' => $this->name, 'relationType' => $this->type ); if ($this->multilingual && $this->_localModel->isMultilingual()) { // The relation is added to the i18n model by Garp_Spawn_Config_Model_I18n return; } $this->_localModel->fields->add('relation', $column, $fieldParams); }
php
protected function _addRelationFieldInLocalModel() { if (!$this->isSingular()) { return; } $column = Garp_Spawn_Relation_Set::getRelationColumn($this->name); $fieldParams = array( 'model' => $this->model, 'type' => 'numeric', 'editable' => true, 'visible' => true, 'primary' => $this->primary, 'required' => $this->required, 'relationAlias' => $this->name, 'relationType' => $this->type ); if ($this->multilingual && $this->_localModel->isMultilingual()) { // The relation is added to the i18n model by Garp_Spawn_Config_Model_I18n return; } $this->_localModel->fields->add('relation', $column, $fieldParams); }
[ "protected", "function", "_addRelationFieldInLocalModel", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isSingular", "(", ")", ")", "{", "return", ";", "}", "$", "column", "=", "Garp_Spawn_Relation_Set", "::", "getRelationColumn", "(", "$", "this", "->"...
Registers this relation as a Field in the Model. @return void
[ "Registers", "this", "relation", "as", "a", "Field", "in", "the", "Model", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Relation.php#L477-L498
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager.count
public function count(array $options = null) { if ($this->_model instanceof Garp_Model_Db) { unset($options['sort']); $options['fields'] = 'COUNT(*)'; try { $result = $this->fetch($options); return !empty($result[0]['COUNT(*)']) ? $result[0]['COUNT(*)'] : 0; } catch (Zend_Db_Statement_Exception $e) { /** * @todo When fetching results * filtered using a HABTM relationship, extra * meta field are returned from the binding table. * This results in an SQL error; when using COUNT() * and returning results from multiple tables a * GROUP BY clause is mandatory. This must be fixed in * the future. */ return 1000; } } else { return $this->_model->count(); } }
php
public function count(array $options = null) { if ($this->_model instanceof Garp_Model_Db) { unset($options['sort']); $options['fields'] = 'COUNT(*)'; try { $result = $this->fetch($options); return !empty($result[0]['COUNT(*)']) ? $result[0]['COUNT(*)'] : 0; } catch (Zend_Db_Statement_Exception $e) { /** * @todo When fetching results * filtered using a HABTM relationship, extra * meta field are returned from the binding table. * This results in an SQL error; when using COUNT() * and returning results from multiple tables a * GROUP BY clause is mandatory. This must be fixed in * the future. */ return 1000; } } else { return $this->_model->count(); } }
[ "public", "function", "count", "(", "array", "$", "options", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_model", "instanceof", "Garp_Model_Db", ")", "{", "unset", "(", "$", "options", "[", "'sort'", "]", ")", ";", "$", "options", "[", "'fi...
Count records according to given criteria @param Array $options Options @return Int
[ "Count", "records", "according", "to", "given", "criteria" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L249-L271
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager.relate
public function relate(array $options) { $this->_checkAcl('relate'); extract($options); if (!isset($primaryKey) || !isset($model) || !isset($foreignKeys)) { throw new Garp_Content_Exception( 'Not enough options. "primaryKey", "model" and "foreignKeys" are required.' ); } $model = Garp_Content_Api::modelAliasToClass($model); $primaryKey = (array)$primaryKey; $foreignKeys = (array)$foreignKeys; $rule = isset($rule) ? $rule : null; $rule2 = isset($rule2) ? $rule2 : null; $bindingModel = isset($bindingModel) ? 'Model_' . $bindingModel : null; $bidirectional = isset($bidirectional) ? $bidirectional : null; if (isset($bindingModel)) { $bindingModel = new $bindingModel(); $bindingModel->setCmsContext(true); } if (array_key_exists('unrelateExisting', $options) && $options['unrelateExisting']) { Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $this->_model, 'modelB' => $model, 'keyA' => $primaryKey, 'rule' => $rule, 'ruleB' => $rule2, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional, ) ); } $success = $attempts = 0; foreach ($foreignKeys as $i => $relationData) { if (!array_key_exists('key', $relationData)) { throw new Garp_Content_Exception('Foreign key is a required key.'); } $foreignKey = $relationData['key']; $extraFields = array_key_exists('relationMetadata', $relationData) ? $relationData['relationMetadata'] : array(); if (Garp_Content_Relation_Manager::relate( array( 'modelA' => $this->_model, 'modelB' => $model, 'keyA' => $primaryKey, 'keyB' => $foreignKey, 'extraFields' => $extraFields, 'rule' => $rule, 'ruleB' => $rule2, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional, ) ) ) { $success++; } $attempts++; } return $success == $attempts; }
php
public function relate(array $options) { $this->_checkAcl('relate'); extract($options); if (!isset($primaryKey) || !isset($model) || !isset($foreignKeys)) { throw new Garp_Content_Exception( 'Not enough options. "primaryKey", "model" and "foreignKeys" are required.' ); } $model = Garp_Content_Api::modelAliasToClass($model); $primaryKey = (array)$primaryKey; $foreignKeys = (array)$foreignKeys; $rule = isset($rule) ? $rule : null; $rule2 = isset($rule2) ? $rule2 : null; $bindingModel = isset($bindingModel) ? 'Model_' . $bindingModel : null; $bidirectional = isset($bidirectional) ? $bidirectional : null; if (isset($bindingModel)) { $bindingModel = new $bindingModel(); $bindingModel->setCmsContext(true); } if (array_key_exists('unrelateExisting', $options) && $options['unrelateExisting']) { Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $this->_model, 'modelB' => $model, 'keyA' => $primaryKey, 'rule' => $rule, 'ruleB' => $rule2, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional, ) ); } $success = $attempts = 0; foreach ($foreignKeys as $i => $relationData) { if (!array_key_exists('key', $relationData)) { throw new Garp_Content_Exception('Foreign key is a required key.'); } $foreignKey = $relationData['key']; $extraFields = array_key_exists('relationMetadata', $relationData) ? $relationData['relationMetadata'] : array(); if (Garp_Content_Relation_Manager::relate( array( 'modelA' => $this->_model, 'modelB' => $model, 'keyA' => $primaryKey, 'keyB' => $foreignKey, 'extraFields' => $extraFields, 'rule' => $rule, 'ruleB' => $rule2, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional, ) ) ) { $success++; } $attempts++; } return $success == $attempts; }
[ "public", "function", "relate", "(", "array", "$", "options", ")", "{", "$", "this", "->", "_checkAcl", "(", "'relate'", ")", ";", "extract", "(", "$", "options", ")", ";", "if", "(", "!", "isset", "(", "$", "primaryKey", ")", "||", "!", "isset", "...
Relate entities to each other, optionally removing previous existing relations. @param array $options @return bool
[ "Relate", "entities", "to", "each", "other", "optionally", "removing", "previous", "existing", "relations", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L374-L441
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager.unrelate
public function unrelate(array $options) { $this->_checkAcl('relate'); extract($options); if (!isset($primaryKey) || !isset($model) || !isset($foreignKeys)) { throw new Garp_Content_Exception( 'Not enough options. "primaryKey", "model" and "foreignKeys" are required.' ); } $model = Garp_Content_Api::modelAliasToClass($model); $primaryKey = (array)$primaryKey; $foreignKeys = (array)$foreignKeys; $rule = isset($rule) ? $rule : null; $rule2 = isset($rule2) ? $rule2 : null; $bindingModel = isset($bindingModel) ? 'Model_' . $bindingModel : null; $bidirectional = isset($bidirectional) ? $bidirectional : null; Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $this->_model, 'modelB' => $model, 'keyA' => $primaryKey, 'keyB' => $foreignKeys, 'rule' => $rule, 'ruleB' => $rule2, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional, ) ); }
php
public function unrelate(array $options) { $this->_checkAcl('relate'); extract($options); if (!isset($primaryKey) || !isset($model) || !isset($foreignKeys)) { throw new Garp_Content_Exception( 'Not enough options. "primaryKey", "model" and "foreignKeys" are required.' ); } $model = Garp_Content_Api::modelAliasToClass($model); $primaryKey = (array)$primaryKey; $foreignKeys = (array)$foreignKeys; $rule = isset($rule) ? $rule : null; $rule2 = isset($rule2) ? $rule2 : null; $bindingModel = isset($bindingModel) ? 'Model_' . $bindingModel : null; $bidirectional = isset($bidirectional) ? $bidirectional : null; Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $this->_model, 'modelB' => $model, 'keyA' => $primaryKey, 'keyB' => $foreignKeys, 'rule' => $rule, 'ruleB' => $rule2, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional, ) ); }
[ "public", "function", "unrelate", "(", "array", "$", "options", ")", "{", "$", "this", "->", "_checkAcl", "(", "'relate'", ")", ";", "extract", "(", "$", "options", ")", ";", "if", "(", "!", "isset", "(", "$", "primaryKey", ")", "||", "!", "isset", ...
Unrelate entities from each other @param array $options @return bool
[ "Unrelate", "entities", "from", "each", "other" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L449-L478
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._createWhereClause
protected function _createWhereClause(array $query, $separator = 'AND', $useJointView = true) { $where = array(); $adapter = $this->_model->getAdapter(); $nativeColumns = $this->_model->info(Zend_Db_Table_Abstract::COLS); if ($useJointView) { $tableName = $this->_getTableName($this->_model); $mockTable = new Zend_Db_Table( array( Zend_Db_Table_Abstract::NAME => $tableName, Zend_Db_Table_Abstract::PRIMARY => $this->_model->info( Zend_Db_Table_Abstract::PRIMARY )) ); $nativeColumns = $mockTable->info(Zend_Db_Table_Abstract::COLS); } else { $tableName = $this->_model->getName(); } // change native columns to lowercase // because when columnName is configured in camelcase in the model config // it causes problems when checking if refColumn is a native column $nativeColumns = array_map( function ($column) { return strtolower($column); }, $nativeColumns ); foreach ($query as $column => $value) { if (strtoupper($column) === 'OR' && is_array($value)) { $where[] = $this->_createWhereClause($value, 'OR'); } elseif (is_array($value)) { $where[] = $adapter->quoteInto( $adapter->quoteIdentifier($tableName) . '.' . $column . ' IN(?)', $value ); } elseif (is_null($value)) { if (substr($column, -2) == '<>') { $column = preg_replace('/<>$/', '', $column); $where[] = $column . ' IS NOT NULL'; } else { $where[] = $column . ' IS NULL'; } } elseif (is_scalar($value)) { // Use $refColumn to see if this column is native to the current // model. $refColumn = null; if (!preg_match('/(>=?|<=?|like|<>)/i', $column, $matches)) { $refColumn = $column; $column = $adapter->quoteIdentifier($column) . ' ='; } else { // explode column so the actual column name can be quoted $parts = explode(' ', $column); $refColumn = $parts[0]; $column = $adapter->quoteIdentifier($parts[0]) . ' ' . $parts[1]; } if (strpos($refColumn, '.') === false && in_array($refColumn, $nativeColumns)) { $column = $adapter->quoteIdentifier($tableName) . '.' . $column; } $where[] = $adapter->quoteInto($column . ' ?', $value); } } return '(' . implode(" $separator ", $where) . ')'; }
php
protected function _createWhereClause(array $query, $separator = 'AND', $useJointView = true) { $where = array(); $adapter = $this->_model->getAdapter(); $nativeColumns = $this->_model->info(Zend_Db_Table_Abstract::COLS); if ($useJointView) { $tableName = $this->_getTableName($this->_model); $mockTable = new Zend_Db_Table( array( Zend_Db_Table_Abstract::NAME => $tableName, Zend_Db_Table_Abstract::PRIMARY => $this->_model->info( Zend_Db_Table_Abstract::PRIMARY )) ); $nativeColumns = $mockTable->info(Zend_Db_Table_Abstract::COLS); } else { $tableName = $this->_model->getName(); } // change native columns to lowercase // because when columnName is configured in camelcase in the model config // it causes problems when checking if refColumn is a native column $nativeColumns = array_map( function ($column) { return strtolower($column); }, $nativeColumns ); foreach ($query as $column => $value) { if (strtoupper($column) === 'OR' && is_array($value)) { $where[] = $this->_createWhereClause($value, 'OR'); } elseif (is_array($value)) { $where[] = $adapter->quoteInto( $adapter->quoteIdentifier($tableName) . '.' . $column . ' IN(?)', $value ); } elseif (is_null($value)) { if (substr($column, -2) == '<>') { $column = preg_replace('/<>$/', '', $column); $where[] = $column . ' IS NOT NULL'; } else { $where[] = $column . ' IS NULL'; } } elseif (is_scalar($value)) { // Use $refColumn to see if this column is native to the current // model. $refColumn = null; if (!preg_match('/(>=?|<=?|like|<>)/i', $column, $matches)) { $refColumn = $column; $column = $adapter->quoteIdentifier($column) . ' ='; } else { // explode column so the actual column name can be quoted $parts = explode(' ', $column); $refColumn = $parts[0]; $column = $adapter->quoteIdentifier($parts[0]) . ' ' . $parts[1]; } if (strpos($refColumn, '.') === false && in_array($refColumn, $nativeColumns)) { $column = $adapter->quoteIdentifier($tableName) . '.' . $column; } $where[] = $adapter->quoteInto($column . ' ?', $value); } } return '(' . implode(" $separator ", $where) . ')'; }
[ "protected", "function", "_createWhereClause", "(", "array", "$", "query", ",", "$", "separator", "=", "'AND'", ",", "$", "useJointView", "=", "true", ")", "{", "$", "where", "=", "array", "(", ")", ";", "$", "adapter", "=", "$", "this", "->", "_model"...
Create a WHERE clause for use with Zend_Db_Select @param array $query WHERE options @param string $separator AND/OR @param bool $useJointView Wether to use the *_joint view or the table. @return string WHERE clause
[ "Create", "a", "WHERE", "clause", "for", "use", "with", "Zend_Db_Select" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L508-L571
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._addJoinClause
protected function _addJoinClause(Zend_Db_Select $select, array $related, $rule = null, $bindingModel = null, $bidirectional = true ) { foreach ($related as $filterModelName => $filterValue) { $fieldInfo = explode('.', $filterModelName, 2); $filterModelName = Garp_Content_Api::modelAliasToClass($fieldInfo[0]); $filterColumn = $fieldInfo[1]; $filterModel = new $filterModelName(); /** * Determine wether a negation clause (e.g. !=) is requested * and normalize the filterColumn. */ $negation = strpos($filterColumn, '<>') !== false; $filterColumn = str_replace(' <>', '', $filterColumn); if ($filterModelName === get_class($this->_model)) { /* This is a homophile relation and the current condition touches the homophile model. The following condition prevents a 'relatable' list to include the current record, because a record cannot be related to itself. */ $select->where( $this->_getTableName($filterModel) . '.' . $filterColumn . ' != ?', $filterValue ); } try { // the other model is a child $reference = $filterModel->getReference(get_class($this->_model), $rule); $this->_addHasManyClause( array( 'select' => $select, 'filterModel' => $filterModel, 'reference' => $reference, 'filterColumn' => $filterColumn, 'filterValue' => $filterValue, 'negation' => $negation ) ); } catch (Zend_Db_Table_Exception $e) { try { // the other model is the parent $reference = $this->_model->getReference(get_class($filterModel), $rule); $this->_addBelongsToClause( array( 'select' => $select, 'reference' => $reference, 'filterColumn' => $filterColumn, 'filterValue' => $filterValue, 'negation' => $negation ) ); } catch (Zend_Db_Table_Exception $e) { try { // the models are equal; a binding model is needed $this->_addHasAndBelongsToManyClause( array( 'select' => $select, 'filterModel' => $filterModel, 'filterColumn' => $filterColumn, 'filterValue' => $filterValue, 'negation' => $negation, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional ) ); } catch (Zend_Db_Table_Exception $e) { throw $e; } } } } }
php
protected function _addJoinClause(Zend_Db_Select $select, array $related, $rule = null, $bindingModel = null, $bidirectional = true ) { foreach ($related as $filterModelName => $filterValue) { $fieldInfo = explode('.', $filterModelName, 2); $filterModelName = Garp_Content_Api::modelAliasToClass($fieldInfo[0]); $filterColumn = $fieldInfo[1]; $filterModel = new $filterModelName(); /** * Determine wether a negation clause (e.g. !=) is requested * and normalize the filterColumn. */ $negation = strpos($filterColumn, '<>') !== false; $filterColumn = str_replace(' <>', '', $filterColumn); if ($filterModelName === get_class($this->_model)) { /* This is a homophile relation and the current condition touches the homophile model. The following condition prevents a 'relatable' list to include the current record, because a record cannot be related to itself. */ $select->where( $this->_getTableName($filterModel) . '.' . $filterColumn . ' != ?', $filterValue ); } try { // the other model is a child $reference = $filterModel->getReference(get_class($this->_model), $rule); $this->_addHasManyClause( array( 'select' => $select, 'filterModel' => $filterModel, 'reference' => $reference, 'filterColumn' => $filterColumn, 'filterValue' => $filterValue, 'negation' => $negation ) ); } catch (Zend_Db_Table_Exception $e) { try { // the other model is the parent $reference = $this->_model->getReference(get_class($filterModel), $rule); $this->_addBelongsToClause( array( 'select' => $select, 'reference' => $reference, 'filterColumn' => $filterColumn, 'filterValue' => $filterValue, 'negation' => $negation ) ); } catch (Zend_Db_Table_Exception $e) { try { // the models are equal; a binding model is needed $this->_addHasAndBelongsToManyClause( array( 'select' => $select, 'filterModel' => $filterModel, 'filterColumn' => $filterColumn, 'filterValue' => $filterValue, 'negation' => $negation, 'bindingModel' => $bindingModel, 'bidirectional' => $bidirectional ) ); } catch (Zend_Db_Table_Exception $e) { throw $e; } } } } }
[ "protected", "function", "_addJoinClause", "(", "Zend_Db_Select", "$", "select", ",", "array", "$", "related", ",", "$", "rule", "=", "null", ",", "$", "bindingModel", "=", "null", ",", "$", "bidirectional", "=", "true", ")", "{", "foreach", "(", "$", "r...
Add a JOIN clause to a Zend_Db_Select object @param Zend_Db_Select $select The select object @param array $related Collection of related models @param string $rule Used to figure out the relationship metadata from the referencemap @param string $bindingModel Binding model used in HABTM relations @param bool $bidirectional @return void
[ "Add", "a", "JOIN", "clause", "to", "a", "Zend_Db_Select", "object" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L583-L657
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._filterForeignKeyColumns
protected function _filterForeignKeyColumns($fields, $referenceMap) { $out = array(); $foreignKeys = array(); // create an array of foreign keys... foreach ($referenceMap as $relName => $relConfig) { $foreignKeys = array_merge($foreignKeys, (array)$relConfig['columns']); } // ...and return the values that are not in that array. return array_diff($fields, $foreignKeys); }
php
protected function _filterForeignKeyColumns($fields, $referenceMap) { $out = array(); $foreignKeys = array(); // create an array of foreign keys... foreach ($referenceMap as $relName => $relConfig) { $foreignKeys = array_merge($foreignKeys, (array)$relConfig['columns']); } // ...and return the values that are not in that array. return array_diff($fields, $foreignKeys); }
[ "protected", "function", "_filterForeignKeyColumns", "(", "$", "fields", ",", "$", "referenceMap", ")", "{", "$", "out", "=", "array", "(", ")", ";", "$", "foreignKeys", "=", "array", "(", ")", ";", "// create an array of foreign keys...", "foreach", "(", "$",...
Filter columns that are foreign keys. @param array $fields All columns @param array $referenceMap The model's referenceMap @return array
[ "Filter", "columns", "that", "are", "foreign", "keys", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L892-L901
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._findSecondRuleKeyForHomophiles
protected function _findSecondRuleKeyForHomophiles($filterModel, $bindingModel) { $homophileSecondRuleKey = null; if ($this->_isHomophile($filterModel)) { $bindingReferenceMap = $bindingModel->info(Zend_Db_Table_Abstract::REFERENCE_MAP); $foundRelevantRule = false; foreach ($bindingReferenceMap as $ruleKey => $rule) { if ($rule['refTableClass'] === get_class($this->_model)) { if ($foundRelevantRule) { $homophileSecondRuleKey = $ruleKey; } $foundRelevantRule = !$foundRelevantRule; } } } return $homophileSecondRuleKey; }
php
protected function _findSecondRuleKeyForHomophiles($filterModel, $bindingModel) { $homophileSecondRuleKey = null; if ($this->_isHomophile($filterModel)) { $bindingReferenceMap = $bindingModel->info(Zend_Db_Table_Abstract::REFERENCE_MAP); $foundRelevantRule = false; foreach ($bindingReferenceMap as $ruleKey => $rule) { if ($rule['refTableClass'] === get_class($this->_model)) { if ($foundRelevantRule) { $homophileSecondRuleKey = $ruleKey; } $foundRelevantRule = !$foundRelevantRule; } } } return $homophileSecondRuleKey; }
[ "protected", "function", "_findSecondRuleKeyForHomophiles", "(", "$", "filterModel", ",", "$", "bindingModel", ")", "{", "$", "homophileSecondRuleKey", "=", "null", ";", "if", "(", "$", "this", "->", "_isHomophile", "(", "$", "filterModel", ")", ")", "{", "$",...
In case of a homophile relation, this function returns the key to the second rule, to prevent the same rule being returned twice, because both rules in a homophile binding model point to the same related model. @param Garp_Model_Db $filterModel @param string $bindingModel @return string|null Returns the name of the second rule key in the reference map, if this is a homophile relation. Otherwise, null is returned.
[ "In", "case", "of", "a", "homophile", "relation", "this", "function", "returns", "the", "key", "to", "the", "second", "rule", "to", "prevent", "the", "same", "rule", "being", "returned", "twice", "because", "both", "rules", "in", "a", "homophile", "binding",...
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L923-L941
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._checkAcl
protected function _checkAcl($method) { if (!Garp_Auth::getInstance()->isAllowed(get_class($this->_model), $method)) { throw new Garp_Auth_Exception('You are not allowed to execute the requested action.'); } }
php
protected function _checkAcl($method) { if (!Garp_Auth::getInstance()->isAllowed(get_class($this->_model), $method)) { throw new Garp_Auth_Exception('You are not allowed to execute the requested action.'); } }
[ "protected", "function", "_checkAcl", "(", "$", "method", ")", "{", "if", "(", "!", "Garp_Auth", "::", "getInstance", "(", ")", "->", "isAllowed", "(", "get_class", "(", "$", "this", "->", "_model", ")", ",", "$", "method", ")", ")", "{", "throw", "n...
Check to see if the current model supports the requested method @param string $method The method @return bool @throws Garp_Content_Exception If the method is not supported
[ "Check", "to", "see", "if", "the", "current", "model", "supports", "the", "requested", "method" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L950-L954
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._itemBelongsToUser
protected function _itemBelongsToUser($data, $where = false) { $userData = Garp_Auth::getInstance()->getUserData(); $userId = $userData['id']; if (!array_key_exists('author_id', $data)) { if (!$where) { return false; } // fetch the record based on the given WHERE clause $row = $this->_model->fetchRow($where); if (!$row || !$row->author_id) { return false; } $data = $row->toArray(); } return $userId == $data['author_id']; }
php
protected function _itemBelongsToUser($data, $where = false) { $userData = Garp_Auth::getInstance()->getUserData(); $userId = $userData['id']; if (!array_key_exists('author_id', $data)) { if (!$where) { return false; } // fetch the record based on the given WHERE clause $row = $this->_model->fetchRow($where); if (!$row || !$row->author_id) { return false; } $data = $row->toArray(); } return $userId == $data['author_id']; }
[ "protected", "function", "_itemBelongsToUser", "(", "$", "data", ",", "$", "where", "=", "false", ")", "{", "$", "userData", "=", "Garp_Auth", "::", "getInstance", "(", ")", "->", "getUserData", "(", ")", ";", "$", "userId", "=", "$", "userData", "[", ...
Check a record belongs to the currently logged in user. This check is based on the author_id column. @param array $data The record data. Primary key must be present here. @param string $where A WHERE clause to find the record @return bool
[ "Check", "a", "record", "belongs", "to", "the", "currently", "logged", "in", "user", ".", "This", "check", "is", "based", "on", "the", "author_id", "column", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L964-L979
train
grrr-amsterdam/garp3
library/Garp/Content/Manager.php
Garp_Content_Manager._getTableName
protected function _getTableName($model) { if (!$this->usesJointView()) { return $model->getName(); } return $model->getJointView() ?: $model->getName(); }
php
protected function _getTableName($model) { if (!$this->usesJointView()) { return $model->getName(); } return $model->getJointView() ?: $model->getName(); }
[ "protected", "function", "_getTableName", "(", "$", "model", ")", "{", "if", "(", "!", "$", "this", "->", "usesJointView", "(", ")", ")", "{", "return", "$", "model", "->", "getName", "(", ")", ";", "}", "return", "$", "model", "->", "getJointView", ...
Negotiate between joint view and actual table name. @param Garp_Model_Db $model @return string
[ "Negotiate", "between", "joint", "view", "and", "actual", "table", "name", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager.php#L1000-L1005
train
grrr-amsterdam/garp3
library/Garp/I18n/Translate/Adapter/Snippet.php
Garp_I18n_Translate_Adapter_Snippet._loadTranslationData
protected function _loadTranslationData($data, $locale, array $options = array()) { $data = array(); try { $i18nModelFactory = new Garp_I18n_ModelFactory($locale); $snippetModel = $i18nModelFactory->getModel('Snippet'); $out = array(); $data = $snippetModel->fetchAll( $snippetModel->select() ->from($snippetModel->getName(), array( 'identifier', 'text' => new Zend_Db_Expr('IF(text IS NULL, IF(name IS NULL, identifier, name), text)'), )) ->where('has_text = ?', 1) ->orWhere('has_name = ?', 1) ->order('identifier ASC') ); $data = $this->_reformatData($data); } catch (Zend_Db_Adapter_Exception $e) { Garp_ErrorHandler::handlePrematureException($e); } $out[$locale] = $data; return $out; }
php
protected function _loadTranslationData($data, $locale, array $options = array()) { $data = array(); try { $i18nModelFactory = new Garp_I18n_ModelFactory($locale); $snippetModel = $i18nModelFactory->getModel('Snippet'); $out = array(); $data = $snippetModel->fetchAll( $snippetModel->select() ->from($snippetModel->getName(), array( 'identifier', 'text' => new Zend_Db_Expr('IF(text IS NULL, IF(name IS NULL, identifier, name), text)'), )) ->where('has_text = ?', 1) ->orWhere('has_name = ?', 1) ->order('identifier ASC') ); $data = $this->_reformatData($data); } catch (Zend_Db_Adapter_Exception $e) { Garp_ErrorHandler::handlePrematureException($e); } $out[$locale] = $data; return $out; }
[ "protected", "function", "_loadTranslationData", "(", "$", "data", ",", "$", "locale", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "data", "=", "array", "(", ")", ";", "try", "{", "$", "i18nModelFactory", "=", "new", "Garp_I18n...
Load translation data @param string|array $data @param string $locale Locale/Language to add data for, identical with locale identifier, see Zend_Locale for more information @param array $options OPTIONAL Options to use @return array
[ "Load", "translation", "data" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/I18n/Translate/Adapter/Snippet.php#L20-L44
train
grrr-amsterdam/garp3
library/Garp/I18n/Translate/Adapter/Snippet.php
Garp_I18n_Translate_Adapter_Snippet._reformatData
protected function _reformatData(Garp_Db_Table_Rowset $data) { $out = array(); foreach ($data as $datum) { $out[$datum->identifier] = $datum->text; } return $out; }
php
protected function _reformatData(Garp_Db_Table_Rowset $data) { $out = array(); foreach ($data as $datum) { $out[$datum->identifier] = $datum->text; } return $out; }
[ "protected", "function", "_reformatData", "(", "Garp_Db_Table_Rowset", "$", "data", ")", "{", "$", "out", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "datum", ")", "{", "$", "out", "[", "$", "datum", "->", "identifier", "]", ...
Reformat rowset into a usable array. @param Garp_Db_Table_Rowset $data @return Array
[ "Reformat", "rowset", "into", "a", "usable", "array", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/I18n/Translate/Adapter/Snippet.php#L51-L57
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.camelcasedToUnderscored
static public function camelcasedToUnderscored($str) { $str = lcfirst($str); return preg_replace_callback( '/([A-Z])/', function ($str) { return "_" . strtolower($str[1]); }, $str ); }
php
static public function camelcasedToUnderscored($str) { $str = lcfirst($str); return preg_replace_callback( '/([A-Z])/', function ($str) { return "_" . strtolower($str[1]); }, $str ); }
[ "static", "public", "function", "camelcasedToUnderscored", "(", "$", "str", ")", "{", "$", "str", "=", "lcfirst", "(", "$", "str", ")", ";", "return", "preg_replace_callback", "(", "'/([A-Z])/'", ",", "function", "(", "$", "str", ")", "{", "return", "\"_\"...
Converts 'SnoopDoggyDog' to 'snoop_doggy_dog' @param string $str @return string
[ "Converts", "SnoopDoggyDog", "to", "snoop_doggy_dog" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L20-L29
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.camelcasedToDashed
static public function camelcasedToDashed($str) { $str = lcfirst($str); return preg_replace_callback( '/([A-Z])/', function ($str) { return "-" . strtolower($str[1]); }, $str ); }
php
static public function camelcasedToDashed($str) { $str = lcfirst($str); return preg_replace_callback( '/([A-Z])/', function ($str) { return "-" . strtolower($str[1]); }, $str ); }
[ "static", "public", "function", "camelcasedToDashed", "(", "$", "str", ")", "{", "$", "str", "=", "lcfirst", "(", "$", "str", ")", ";", "return", "preg_replace_callback", "(", "'/([A-Z])/'", ",", "function", "(", "$", "str", ")", "{", "return", "\"-\"", ...
Converts 'SnoopDoggyDog' to 'snoop-doggy-dog' @param string $str @return string
[ "Converts", "SnoopDoggyDog", "to", "snoop", "-", "doggy", "-", "dog" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L37-L46
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.underscoredToReadable
static public function underscoredToReadable($str, $ucfirst = true) { if ($ucfirst) { $str = ucfirst($str); } $str = str_replace("_", " ", $str); return $str; }
php
static public function underscoredToReadable($str, $ucfirst = true) { if ($ucfirst) { $str = ucfirst($str); } $str = str_replace("_", " ", $str); return $str; }
[ "static", "public", "function", "underscoredToReadable", "(", "$", "str", ",", "$", "ucfirst", "=", "true", ")", "{", "if", "(", "$", "ucfirst", ")", "{", "$", "str", "=", "ucfirst", "(", "$", "str", ")", ";", "}", "$", "str", "=", "str_replace", "...
Converts 'doggy_dog_world_id' to 'Doggy dog world id' @param string $str @param bool $ucfirst Wether to uppercase the fist character @return string
[ "Converts", "doggy_dog_world_id", "to", "Doggy", "dog", "world", "id" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L99-L105
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.underscoredToCamelcased
static public function underscoredToCamelcased($str, $ucfirst = false) { if ($ucfirst) { $str = ucfirst($str); } $func = f\compose('strtoupper', f\prop(1)); return preg_replace_callback('/_([a-z])/', $func, $str); }
php
static public function underscoredToCamelcased($str, $ucfirst = false) { if ($ucfirst) { $str = ucfirst($str); } $func = f\compose('strtoupper', f\prop(1)); return preg_replace_callback('/_([a-z])/', $func, $str); }
[ "static", "public", "function", "underscoredToCamelcased", "(", "$", "str", ",", "$", "ucfirst", "=", "false", ")", "{", "if", "(", "$", "ucfirst", ")", "{", "$", "str", "=", "ucfirst", "(", "$", "str", ")", ";", "}", "$", "func", "=", "f", "\\", ...
Converts 'doggy_dog_world_id' to 'doggyDogWorldId' @param string $str @param bool $ucfirst Wether to uppercase the fist character @return string
[ "Converts", "doggy_dog_world_id", "to", "doggyDogWorldId" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L114-L120
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.mbstringBinarySafeEncoding
static public function mbstringBinarySafeEncoding($reset = false) { static $encodings = array(); static $overloaded = null; if (is_null($overloaded)) { $overloaded = function_exists('mb_internal_encoding') && (ini_get('mbstring.func_overload') & 2); } if (false === $overloaded) { return; } if (!$reset) { $encoding = mb_internal_encoding(); array_push($encodings, $encoding); mb_internal_encoding('ISO-8859-1'); } if ($reset && $encodings) { $encoding = array_pop($encodings); mb_internal_encoding($encoding); } }
php
static public function mbstringBinarySafeEncoding($reset = false) { static $encodings = array(); static $overloaded = null; if (is_null($overloaded)) { $overloaded = function_exists('mb_internal_encoding') && (ini_get('mbstring.func_overload') & 2); } if (false === $overloaded) { return; } if (!$reset) { $encoding = mb_internal_encoding(); array_push($encodings, $encoding); mb_internal_encoding('ISO-8859-1'); } if ($reset && $encodings) { $encoding = array_pop($encodings); mb_internal_encoding($encoding); } }
[ "static", "public", "function", "mbstringBinarySafeEncoding", "(", "$", "reset", "=", "false", ")", "{", "static", "$", "encodings", "=", "array", "(", ")", ";", "static", "$", "overloaded", "=", "null", ";", "if", "(", "is_null", "(", "$", "overloaded", ...
Set the mbstring internal encoding to a binary safe encoding when func_overload is enabled. When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and similar functions respect the utf8 characters, causing binary data to return incorrect lengths. This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the users expected encoding afterwards through the `resetMbstringEncoding` function. It is safe to recursively call this function, however each `mbstring_binary_safe_encoding()` call must be followed up with an equal number of `resetMbstringEncoding()` calls. @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding. Default false. @return void @since 3.7.0 @see resetMbstringEncoding()
[ "Set", "the", "mbstring", "internal", "encoding", "to", "a", "binary", "safe", "encoding", "when", "func_overload", "is", "enabled", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L546-L569
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.humanList
static public function humanList(array $list, $decorator = null, $lastItemSeperator = 'and') { $listCount = count($list); if ($listCount === 1) { return $decorator . current($list) . $decorator; } elseif ($listCount === 2) { return $decorator . implode( $decorator . " {$lastItemSeperator} " . $decorator, $list ) . $decorator; } elseif ($listCount > 2) { $last = array_pop($list); return $decorator . implode( $decorator . ", " . $decorator, $list ) . $decorator . " {$lastItemSeperator} " . $decorator . $last . $decorator; } }
php
static public function humanList(array $list, $decorator = null, $lastItemSeperator = 'and') { $listCount = count($list); if ($listCount === 1) { return $decorator . current($list) . $decorator; } elseif ($listCount === 2) { return $decorator . implode( $decorator . " {$lastItemSeperator} " . $decorator, $list ) . $decorator; } elseif ($listCount > 2) { $last = array_pop($list); return $decorator . implode( $decorator . ", " . $decorator, $list ) . $decorator . " {$lastItemSeperator} " . $decorator . $last . $decorator; } }
[ "static", "public", "function", "humanList", "(", "array", "$", "list", ",", "$", "decorator", "=", "null", ",", "$", "lastItemSeperator", "=", "'and'", ")", "{", "$", "listCount", "=", "count", "(", "$", "list", ")", ";", "if", "(", "$", "listCount", ...
Creates a human-readable string of an array. @param array $list Numeric Array of String elements, @param string $decorator Element decorator, f.i. a quote. @param string $lastItemSeperator Seperates the last item from the rest instead of a comma, for instance: 'and' or 'or'. @return string Listed elements, like "Snoop, Dre and Devin".
[ "Creates", "a", "human", "-", "readable", "string", "of", "an", "array", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L591-L605
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.linkUrls
static public function linkUrls($text, array $attribs = array()) { $htmlAttribs = array(); foreach ($attribs as $name => $value) { $htmlAttribs[] = $name . '="' . $value . '"'; } $htmlAttribs = implode(' ', $htmlAttribs); $htmlAttribs = $htmlAttribs ? ' ' . $htmlAttribs : ''; $regexpProtocol = "/(?:^|\s)((http|https|ftp):\/\/[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i"; $regexpWww = "/(?:^|\s)((www\.)[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i"; $text = preg_replace($regexpProtocol, " <a href=\"\\1\"$htmlAttribs>\\1</a>\\3 ", $text); $text = preg_replace($regexpWww, " <a href=\"http://\\1\"$htmlAttribs>\\1</a>\\3 ", $text); return trim($text); }
php
static public function linkUrls($text, array $attribs = array()) { $htmlAttribs = array(); foreach ($attribs as $name => $value) { $htmlAttribs[] = $name . '="' . $value . '"'; } $htmlAttribs = implode(' ', $htmlAttribs); $htmlAttribs = $htmlAttribs ? ' ' . $htmlAttribs : ''; $regexpProtocol = "/(?:^|\s)((http|https|ftp):\/\/[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i"; $regexpWww = "/(?:^|\s)((www\.)[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i"; $text = preg_replace($regexpProtocol, " <a href=\"\\1\"$htmlAttribs>\\1</a>\\3 ", $text); $text = preg_replace($regexpWww, " <a href=\"http://\\1\"$htmlAttribs>\\1</a>\\3 ", $text); return trim($text); }
[ "static", "public", "function", "linkUrls", "(", "$", "text", ",", "array", "$", "attribs", "=", "array", "(", ")", ")", "{", "$", "htmlAttribs", "=", "array", "(", ")", ";", "foreach", "(", "$", "attribs", "as", "$", "name", "=>", "$", "value", ")...
Link URLs. @param string $text @param array $attribs HTML attributes @return string
[ "Link", "URLs", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L706-L720
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.linkEmailAddresses
static public function linkEmailAddresses($text, array $attribs = array()) { $htmlAttribs = array(); foreach ($attribs as $name => $value) { $htmlAttribs[] = $name . '="' . $value . '"'; } $htmlAttribs = implode(' ', $htmlAttribs); $htmlAttribs = $htmlAttribs ? ' ' . $htmlAttribs : ''; $regexp = '/[a-zA-Z0-9\.-_+]+@[a-zA-Z0-9\.\-_]+\.([a-zA-Z]{2,})/'; $text = preg_replace($regexp, "<a href=\"mailto:$0\"$htmlAttribs>$0</a>", $text); return $text; }
php
static public function linkEmailAddresses($text, array $attribs = array()) { $htmlAttribs = array(); foreach ($attribs as $name => $value) { $htmlAttribs[] = $name . '="' . $value . '"'; } $htmlAttribs = implode(' ', $htmlAttribs); $htmlAttribs = $htmlAttribs ? ' ' . $htmlAttribs : ''; $regexp = '/[a-zA-Z0-9\.-_+]+@[a-zA-Z0-9\.\-_]+\.([a-zA-Z]{2,})/'; $text = preg_replace($regexp, "<a href=\"mailto:$0\"$htmlAttribs>$0</a>", $text); return $text; }
[ "static", "public", "function", "linkEmailAddresses", "(", "$", "text", ",", "array", "$", "attribs", "=", "array", "(", ")", ")", "{", "$", "htmlAttribs", "=", "array", "(", ")", ";", "foreach", "(", "$", "attribs", "as", "$", "name", "=>", "$", "va...
Link email addresses @param string $text @param array $attribs HTML attributes @return string
[ "Link", "email", "addresses" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L729-L740
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.scrambleEmail
static public function scrambleEmail($email, $mailTo = false) { for ($i = 0, $c = strlen($email), $out = ''; $i < $c; $i++) { $out .= '&#' . ord($email[$i]) . ';'; } if ($mailTo) { $out = self::scrambleEmail('mailto:') . $out; } return $out; }
php
static public function scrambleEmail($email, $mailTo = false) { for ($i = 0, $c = strlen($email), $out = ''; $i < $c; $i++) { $out .= '&#' . ord($email[$i]) . ';'; } if ($mailTo) { $out = self::scrambleEmail('mailto:') . $out; } return $out; }
[ "static", "public", "function", "scrambleEmail", "(", "$", "email", ",", "$", "mailTo", "=", "false", ")", "{", "for", "(", "$", "i", "=", "0", ",", "$", "c", "=", "strlen", "(", "$", "email", ")", ",", "$", "out", "=", "''", ";", "$", "i", "...
Output email address as entities @param string $email @param boolean $mailTo Wether to append "mailto:" for embedding in <a href=""> @return string
[ "Output", "email", "address", "as", "entities" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L749-L757
train
grrr-amsterdam/garp3
library/Garp/Util/String.php
Garp_Util_String.interpolate
static public function interpolate($str, array $vars) { $keys = array_keys($vars); $vals = array_values($vars); // surround keys by "%" array_walk( $keys, function (&$s) { $s = '%' . $s . '%'; } ); $str = str_replace($keys, $vals, $str); return $str; }
php
static public function interpolate($str, array $vars) { $keys = array_keys($vars); $vals = array_values($vars); // surround keys by "%" array_walk( $keys, function (&$s) { $s = '%' . $s . '%'; } ); $str = str_replace($keys, $vals, $str); return $str; }
[ "static", "public", "function", "interpolate", "(", "$", "str", ",", "array", "$", "vars", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "vars", ")", ";", "$", "vals", "=", "array_values", "(", "$", "vars", ")", ";", "// surround keys by \"%\"", ...
Interpolate strings with variables @param string $str The string @param array $vars The variables @return string The interpolated string
[ "Interpolate", "strings", "with", "variables" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Util/String.php#L789-L800
train
grrr-amsterdam/garp3
library/Garp/Deploy/Config.php
Garp_Deploy_Config.isConfigured
public function isConfigured($env) { if (!file_exists($this->_createPathFromEnv($env))) { return false; } return !!$this->_fetchEnvContent($env); }
php
public function isConfigured($env) { if (!file_exists($this->_createPathFromEnv($env))) { return false; } return !!$this->_fetchEnvContent($env); }
[ "public", "function", "isConfigured", "(", "$", "env", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "_createPathFromEnv", "(", "$", "env", ")", ")", ")", "{", "return", "false", ";", "}", "return", "!", "!", "$", "this", "->", "...
Returns whether the deployment setup is configured for this environmentparameters for a specific environment. @param String $env The environment to get parameters for (i.e. 'integration' or 'production'). @return Bool Whether the deploy configuration is set.
[ "Returns", "whether", "the", "deployment", "setup", "is", "configured", "for", "this", "environmentparameters", "for", "a", "specific", "environment", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Deploy/Config.php#L32-L37
train
grrr-amsterdam/garp3
library/Garp/Deploy/Config.php
Garp_Deploy_Config.getParams
public function getParams($env) { $genericParams = $this->_parseContent($this->_genericContent); $envParams = $this->_parseContent($this->_fetchEnvContent($env)); $output = $genericParams + $envParams; return $output; }
php
public function getParams($env) { $genericParams = $this->_parseContent($this->_genericContent); $envParams = $this->_parseContent($this->_fetchEnvContent($env)); $output = $genericParams + $envParams; return $output; }
[ "public", "function", "getParams", "(", "$", "env", ")", "{", "$", "genericParams", "=", "$", "this", "->", "_parseContent", "(", "$", "this", "->", "_genericContent", ")", ";", "$", "envParams", "=", "$", "this", "->", "_parseContent", "(", "$", "this",...
Returns the deploy parameters for a specific environment. @param String $env The environment to get parameters for (i.e. 'integration' or 'production'). @return Array List of deploy parameters: 'server' => 'myhost.example.com', 'deploy_to' => '/var/www/mylittlepony', 'user' => 'SSH user'
[ "Returns", "the", "deploy", "parameters", "for", "a", "specific", "environment", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Deploy/Config.php#L49-L55
train
grrr-amsterdam/garp3
library/Garp/Deploy/Config.php
Garp_Deploy_Config._parseContent
protected function _parseContent($content) { $output = array(); $matches = array(); $paramsString = implode('|', $this->_deployParams); $pattern = '/:?(?P<paramName>' . $paramsString . ')[,:]? [\'"](?P<paramValue>[^\'"]*)[\'"]/'; if (!preg_match_all($pattern, $content, $matches)) { throw new Exception( "Could not extract deploy parameters from " . self::GENERIC_CONFIG_PATH ); } foreach ($this->_deployParams as $p) { $indices = array_keys( array_filter( $matches['paramName'], function ($pn) use ($p) { return $pn === $p; } ) ); if (!count($indices)) { continue; } $output[$p] = array_values(array_get_subset($matches['paramValue'], $indices)); // For now: only treat the server param as array (since it's common for it to be an // array, in the case of a multi-server setup) if ($p !== 'server') { $output[$p] = $output[$p][0]; } } // explode server into user and server parts if (!empty($output['server'])) { $output['server'] = array_map( function ($serverConfig) { $bits = explode('@', $serverConfig, 2); return array( 'user' => $bits[0], 'server' => $bits[1] ); }, $output['server'] ); } return $output; }
php
protected function _parseContent($content) { $output = array(); $matches = array(); $paramsString = implode('|', $this->_deployParams); $pattern = '/:?(?P<paramName>' . $paramsString . ')[,:]? [\'"](?P<paramValue>[^\'"]*)[\'"]/'; if (!preg_match_all($pattern, $content, $matches)) { throw new Exception( "Could not extract deploy parameters from " . self::GENERIC_CONFIG_PATH ); } foreach ($this->_deployParams as $p) { $indices = array_keys( array_filter( $matches['paramName'], function ($pn) use ($p) { return $pn === $p; } ) ); if (!count($indices)) { continue; } $output[$p] = array_values(array_get_subset($matches['paramValue'], $indices)); // For now: only treat the server param as array (since it's common for it to be an // array, in the case of a multi-server setup) if ($p !== 'server') { $output[$p] = $output[$p][0]; } } // explode server into user and server parts if (!empty($output['server'])) { $output['server'] = array_map( function ($serverConfig) { $bits = explode('@', $serverConfig, 2); return array( 'user' => $bits[0], 'server' => $bits[1] ); }, $output['server'] ); } return $output; }
[ "protected", "function", "_parseContent", "(", "$", "content", ")", "{", "$", "output", "=", "array", "(", ")", ";", "$", "matches", "=", "array", "(", ")", ";", "$", "paramsString", "=", "implode", "(", "'|'", ",", "$", "this", "->", "_deployParams", ...
Parses the generic configuration. @param String $content @return Array
[ "Parses", "the", "generic", "configuration", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Deploy/Config.php#L78-L126
train
grrr-amsterdam/garp3
library/Garp/Content/Db/Server/Abstract.php
Garp_Content_Db_Server_Abstract.backup
public function backup() { $dbConfigParams = $this->getDbConfigParams(); $backupDir = $this->getBackupDir(); $environment = $this->getEnvironment(); if (!$this->databaseExists()) { return; } $createBackupDir = new Garp_Shell_Command_CreateDir($backupDir); $dumpToFile = new Garp_Shell_Command_DumpDatabaseToFile($dbConfigParams, $backupDir, $environment); $this->shellExec($createBackupDir); $this->shellExec($dumpToFile); /** * @todo: verifiëren of: * - backupbestand bestaat * - backupbestand meer dan 0 bytes heeft */ }
php
public function backup() { $dbConfigParams = $this->getDbConfigParams(); $backupDir = $this->getBackupDir(); $environment = $this->getEnvironment(); if (!$this->databaseExists()) { return; } $createBackupDir = new Garp_Shell_Command_CreateDir($backupDir); $dumpToFile = new Garp_Shell_Command_DumpDatabaseToFile($dbConfigParams, $backupDir, $environment); $this->shellExec($createBackupDir); $this->shellExec($dumpToFile); /** * @todo: verifiëren of: * - backupbestand bestaat * - backupbestand meer dan 0 bytes heeft */ }
[ "public", "function", "backup", "(", ")", "{", "$", "dbConfigParams", "=", "$", "this", "->", "getDbConfigParams", "(", ")", ";", "$", "backupDir", "=", "$", "this", "->", "getBackupDir", "(", ")", ";", "$", "environment", "=", "$", "this", "->", "getE...
Backs up the database and writes it to a file on the server itself.
[ "Backs", "up", "the", "database", "and", "writes", "it", "to", "a", "file", "on", "the", "server", "itself", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Db/Server/Abstract.php#L121-L141
train
grrr-amsterdam/garp3
library/Garp/Content/Db/Server/Abstract.php
Garp_Content_Db_Server_Abstract.restore
public function restore(&$dump) { $this->_adjustDumpToEnvironment($dump); //$dump = $this->_lowerCaseTableAndViewNames($dump); $this->_removeDefinerCalls($dump); $dbConfig = $this->getDbConfigParams(); $restoreFile = $this->getRestoreFilePath(); $restoreDir = $this->getBackupDir(); $executeFile = new Garp_Shell_Command_CreateDatabase($dbConfig); $this->shellExec($executeFile); if (!$this->_validateDump($dump)) { throw new Exception("The fetched database seems invalid."); } $createRestoreDir = new Garp_Shell_Command_CreateDir($restoreDir); $this->shellExec($createRestoreDir); if ($this->store($restoreFile, $dump)) { $executeFile = new Garp_Shell_Command_ExecuteDatabaseDumpFile($dbConfig, $restoreFile); $this->shellExec($executeFile); $removeFile = new Garp_Shell_Command_RemoveFile($restoreFile); $this->shellExec($removeFile); } }
php
public function restore(&$dump) { $this->_adjustDumpToEnvironment($dump); //$dump = $this->_lowerCaseTableAndViewNames($dump); $this->_removeDefinerCalls($dump); $dbConfig = $this->getDbConfigParams(); $restoreFile = $this->getRestoreFilePath(); $restoreDir = $this->getBackupDir(); $executeFile = new Garp_Shell_Command_CreateDatabase($dbConfig); $this->shellExec($executeFile); if (!$this->_validateDump($dump)) { throw new Exception("The fetched database seems invalid."); } $createRestoreDir = new Garp_Shell_Command_CreateDir($restoreDir); $this->shellExec($createRestoreDir); if ($this->store($restoreFile, $dump)) { $executeFile = new Garp_Shell_Command_ExecuteDatabaseDumpFile($dbConfig, $restoreFile); $this->shellExec($executeFile); $removeFile = new Garp_Shell_Command_RemoveFile($restoreFile); $this->shellExec($removeFile); } }
[ "public", "function", "restore", "(", "&", "$", "dump", ")", "{", "$", "this", "->", "_adjustDumpToEnvironment", "(", "$", "dump", ")", ";", "//$dump = $this->_lowerCaseTableAndViewNames($dump);", "$", "this", "->", "_removeDefinerCalls", "(", "$", "dump", ...
Restores a database from a MySQL dump result, executing the contained SQL queries. @param String $dump The MySQL dump output
[ "Restores", "a", "database", "from", "a", "MySQL", "dump", "result", "executing", "the", "contained", "SQL", "queries", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Db/Server/Abstract.php#L153-L178
train
grrr-amsterdam/garp3
library/Garp/Content/Db/Server/Abstract.php
Garp_Content_Db_Server_Abstract._adjustDumpToEnvironment
protected function _adjustDumpToEnvironment(&$dump) { $dbParams = $this->getDbConfigParams(); $thisDbName = $dbParams->dbname; $otherDbParams = $this->_fetchOtherDatabaseParams(); $otherDbName = $otherDbParams->dbname; // Firstly, adjust the USE DATABASE statements. $oldUseDbSql = sprintf(self::SQL_USE_STATEMENT, $otherDbName); $newUseDbSql = sprintf(self::SQL_USE_STATEMENT, $thisDbName); $dump = str_replace($oldUseDbSql, $newUseDbSql, $dump); // Then adjust the CREATE DATABASE queries. $oldCreateDbSql = sprintf(self::SQL_CREATE_DB_STATEMENT, $otherDbName); $newCreateDbSql = sprintf(self::SQL_CREATE_DB_STATEMENT, $thisDbName); $dump = str_replace($oldCreateDbSql, $newCreateDbSql, $dump); // Fixes an incompatibility issue between MySQL 5.1 and 5.6, where keys can have comments. // Note that this only fixes keys that get a null comment from mysqldump, not keys with // actual comments. But who would ever do that? // @see http://9seeds.com/tech/import-export-issues-between-mysql-5-1-and-5-6/ $dump = str_replace(" COMMENT '(null)'", '', $dump); // preg_replace seems to be way too demanding for large (180 MB) mysqldump files. Using str_replace now. }
php
protected function _adjustDumpToEnvironment(&$dump) { $dbParams = $this->getDbConfigParams(); $thisDbName = $dbParams->dbname; $otherDbParams = $this->_fetchOtherDatabaseParams(); $otherDbName = $otherDbParams->dbname; // Firstly, adjust the USE DATABASE statements. $oldUseDbSql = sprintf(self::SQL_USE_STATEMENT, $otherDbName); $newUseDbSql = sprintf(self::SQL_USE_STATEMENT, $thisDbName); $dump = str_replace($oldUseDbSql, $newUseDbSql, $dump); // Then adjust the CREATE DATABASE queries. $oldCreateDbSql = sprintf(self::SQL_CREATE_DB_STATEMENT, $otherDbName); $newCreateDbSql = sprintf(self::SQL_CREATE_DB_STATEMENT, $thisDbName); $dump = str_replace($oldCreateDbSql, $newCreateDbSql, $dump); // Fixes an incompatibility issue between MySQL 5.1 and 5.6, where keys can have comments. // Note that this only fixes keys that get a null comment from mysqldump, not keys with // actual comments. But who would ever do that? // @see http://9seeds.com/tech/import-export-issues-between-mysql-5-1-and-5-6/ $dump = str_replace(" COMMENT '(null)'", '', $dump); // preg_replace seems to be way too demanding for large (180 MB) mysqldump files. Using str_replace now. }
[ "protected", "function", "_adjustDumpToEnvironment", "(", "&", "$", "dump", ")", "{", "$", "dbParams", "=", "$", "this", "->", "getDbConfigParams", "(", ")", ";", "$", "thisDbName", "=", "$", "dbParams", "->", "dbname", ";", "$", "otherDbParams", "=", "$",...
Replace the environment values in the given MySQL dump with the environment values for the target. @param String &$dump Output of MySQL dump. @return Void The dump input is changed and not returned, for the sake of memory conservation.
[ "Replace", "the", "environment", "values", "in", "the", "given", "MySQL", "dump", "with", "the", "environment", "values", "for", "the", "target", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Db/Server/Abstract.php#L196-L219
train
grrr-amsterdam/garp3
library/Garp/Content/Db/Server/Abstract.php
Garp_Content_Db_Server_Abstract._fetchOtherDatabaseParams
protected function _fetchOtherDatabaseParams() { $otherEnvironment = $this->getOtherEnvironment(); $appConfigParams = $this->_fetchAppConfigParams($otherEnvironment); $params = $appConfigParams->resources->db->params; return $params; }
php
protected function _fetchOtherDatabaseParams() { $otherEnvironment = $this->getOtherEnvironment(); $appConfigParams = $this->_fetchAppConfigParams($otherEnvironment); $params = $appConfigParams->resources->db->params; return $params; }
[ "protected", "function", "_fetchOtherDatabaseParams", "(", ")", "{", "$", "otherEnvironment", "=", "$", "this", "->", "getOtherEnvironment", "(", ")", ";", "$", "appConfigParams", "=", "$", "this", "->", "_fetchAppConfigParams", "(", "$", "otherEnvironment", ")", ...
Returns the database name of the counterpart server, i.e. source if this is target, and vice versa. @return String The other database name
[ "Returns", "the", "database", "name", "of", "the", "counterpart", "server", "i", ".", "e", ".", "source", "if", "this", "is", "target", "and", "vice", "versa", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Db/Server/Abstract.php#L226-L232
train
grrr-amsterdam/garp3
library/Garp/Content/Db/Server/Abstract.php
Garp_Content_Db_Server_Abstract._lowerCaseTableAndViewNames
protected function _lowerCaseTableAndViewNames(&$dump) { $configDir = APPLICATION_PATH."/modules/default/Model/config/"; $extension = 'json'; $patterns = array(); $replacements = array(); $hardcodedTables = array('AuthFacebook', 'AuthLocal', 'Video'); foreach ($hardcodedTables as $hardcodedTable) { $patterns[] = "`{$hardcodedTable}`"; $replacements[] = "`" . strtolower($hardcodedTable) ."`"; } $modelConfig = new Garp_Model_Spawn_Config_Model_Set( new Garp_Model_Spawn_Config_Storage_File($configDir, $extension), new Garp_Model_Spawn_Config_Format_Json ); $modelSet = new Garp_Model_Spawn_ModelSet($modelConfig); foreach ($modelSet as $model) { $lcModel = strtolower($model->id); $patterns[] = "`{$model->id}`"; $replacements[] = "`{$lcModel}`"; $relations = $model->relations->getRelations(); foreach ($relations as $relation) { if ($relation->type === 'hasAndBelongsToMany') { $bindingModel = $relation->getBindingModel(); $bindingName = '_' . $bindingModel->id; $lcRelation = strtolower($bindingName); $patterns[] = "`{$bindingName}`"; $replacements[] = "`{$lcRelation}`"; } else { $lcRelation = strtolower($relation->name); $patterns[] = "`{$relation->name}`"; $replacements[] = "`{$lcRelation}`"; } } } $dump = str_replace($patterns, $replacements, $dump); return $dump; }
php
protected function _lowerCaseTableAndViewNames(&$dump) { $configDir = APPLICATION_PATH."/modules/default/Model/config/"; $extension = 'json'; $patterns = array(); $replacements = array(); $hardcodedTables = array('AuthFacebook', 'AuthLocal', 'Video'); foreach ($hardcodedTables as $hardcodedTable) { $patterns[] = "`{$hardcodedTable}`"; $replacements[] = "`" . strtolower($hardcodedTable) ."`"; } $modelConfig = new Garp_Model_Spawn_Config_Model_Set( new Garp_Model_Spawn_Config_Storage_File($configDir, $extension), new Garp_Model_Spawn_Config_Format_Json ); $modelSet = new Garp_Model_Spawn_ModelSet($modelConfig); foreach ($modelSet as $model) { $lcModel = strtolower($model->id); $patterns[] = "`{$model->id}`"; $replacements[] = "`{$lcModel}`"; $relations = $model->relations->getRelations(); foreach ($relations as $relation) { if ($relation->type === 'hasAndBelongsToMany') { $bindingModel = $relation->getBindingModel(); $bindingName = '_' . $bindingModel->id; $lcRelation = strtolower($bindingName); $patterns[] = "`{$bindingName}`"; $replacements[] = "`{$lcRelation}`"; } else { $lcRelation = strtolower($relation->name); $patterns[] = "`{$relation->name}`"; $replacements[] = "`{$lcRelation}`"; } } } $dump = str_replace($patterns, $replacements, $dump); return $dump; }
[ "protected", "function", "_lowerCaseTableAndViewNames", "(", "&", "$", "dump", ")", "{", "$", "configDir", "=", "APPLICATION_PATH", ".", "\"/modules/default/Model/config/\"", ";", "$", "extension", "=", "'json'", ";", "$", "patterns", "=", "array", "(", ")", ";"...
Lowercase the table and view names, for compatibility's sake. Can we deprecate this method already? @param String &$dump Output of MySQL dump. @return String The dump output, with adjusted casing.
[ "Lowercase", "the", "table", "and", "view", "names", "for", "compatibility", "s", "sake", ".", "Can", "we", "deprecate", "this", "method", "already?" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Db/Server/Abstract.php#L241-L284
train
grrr-amsterdam/garp3
library/Garp/Content/Relation/Manager.php
Garp_Content_Relation_Manager.relate
public static function relate($options) { self::_normalizeOptionsForRelate($options); $modelA = $options['modelA']; $modelB = $options['modelB']; /** * If bindingModel is set, we can safely skip all those difficult checks below. */ if (is_object($options['bindingModel'])) { return self::_relateHasAndBelongsToMany($options); } try { /** * If this succeeds, it's a regular relationship where the foreign key * resides inside modelA. Continue as usual. */ $reference = $modelA->getReference(get_class($modelB), $options['rule']); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } try { /** * If this succeeds, the foreign key resides in the modelA. * Flip modelA and modelB and keyA and keyB in order to normalize * the given configuration. * Call self::relate() recursively with these new options. */ $reference = $modelB->getReference(get_class($modelA), $options['rule']); $keyA = $options['keyA']; $keyB = $options['keyB']; $options['modelA'] = $modelB; $options['modelB'] = $modelA; $options['keyA'] = $keyB; $options['keyB'] = $keyA; return Garp_Content_Relation_Manager::relate($options); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } /** * Goody, we're dealing with a hasAndBelongsToMany relationship here. * Try to construct the intersection model and save the relation * that way. */ return self::_relateHasAndBelongsToMany($options); } } $rowA = call_user_func_array(array($options['modelA'], 'find'), (array)$options['keyA']); if (!count($rowA)) { $errorMsg = sprintf( self::EXCEPTION_ROW_NOT_FOUND_BY_PRIMARY_KEY, $modelA->getName(), implode(',', (array)$options['keyA']) ); throw new Garp_Content_Relation_Exception($errorMsg); } $rowA = $rowA->current(); self::_addForeignKeysToRow($rowA, $reference, $options['keyB']); return $rowA->save(); }
php
public static function relate($options) { self::_normalizeOptionsForRelate($options); $modelA = $options['modelA']; $modelB = $options['modelB']; /** * If bindingModel is set, we can safely skip all those difficult checks below. */ if (is_object($options['bindingModel'])) { return self::_relateHasAndBelongsToMany($options); } try { /** * If this succeeds, it's a regular relationship where the foreign key * resides inside modelA. Continue as usual. */ $reference = $modelA->getReference(get_class($modelB), $options['rule']); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } try { /** * If this succeeds, the foreign key resides in the modelA. * Flip modelA and modelB and keyA and keyB in order to normalize * the given configuration. * Call self::relate() recursively with these new options. */ $reference = $modelB->getReference(get_class($modelA), $options['rule']); $keyA = $options['keyA']; $keyB = $options['keyB']; $options['modelA'] = $modelB; $options['modelB'] = $modelA; $options['keyA'] = $keyB; $options['keyB'] = $keyA; return Garp_Content_Relation_Manager::relate($options); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } /** * Goody, we're dealing with a hasAndBelongsToMany relationship here. * Try to construct the intersection model and save the relation * that way. */ return self::_relateHasAndBelongsToMany($options); } } $rowA = call_user_func_array(array($options['modelA'], 'find'), (array)$options['keyA']); if (!count($rowA)) { $errorMsg = sprintf( self::EXCEPTION_ROW_NOT_FOUND_BY_PRIMARY_KEY, $modelA->getName(), implode(',', (array)$options['keyA']) ); throw new Garp_Content_Relation_Exception($errorMsg); } $rowA = $rowA->current(); self::_addForeignKeysToRow($rowA, $reference, $options['keyB']); return $rowA->save(); }
[ "public", "static", "function", "relate", "(", "$", "options", ")", "{", "self", "::", "_normalizeOptionsForRelate", "(", "$", "options", ")", ";", "$", "modelA", "=", "$", "options", "[", "'modelA'", "]", ";", "$", "modelB", "=", "$", "options", "[", ...
Relate records. @param array|Garp_Util_Configuration $options Lots o' options: 'modelA' string|Garp_Model_Db The first model or classname thereof 'modelB' string|Garp_Model_Db The second model or classname thereof 'keyA' mixed Primary key(s) of the first model 'keyB' mixed Primary key(s) of the second model 'rule' string The rule that stores this relationship in one of the reference maps 'extraFields' Array Extra fields that can be saved with a HABTM record @return bool Success
[ "Relate", "records", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Relation/Manager.php#L28-L89
train
grrr-amsterdam/garp3
library/Garp/Content/Relation/Manager.php
Garp_Content_Relation_Manager.unrelate
public static function unrelate($options) { self::_normalizeOptionsForUnrelate($options); $modelA = $options['modelA']; $modelB = $options['modelB']; /** * If bindingModel is set, we can safely skip all those difficult checks below. */ if (is_object($options['bindingModel'])) { return self::_unrelateHasAndBelongsToMany($options); } try { /** * If this succeeds, it's a regular relationship where the foreign key * resides inside modelA. Continue as usual. */ $reference = $modelA->getReference(get_class($modelB), $options['rule']); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } try { /** * If this succeeds, the foreign key resides in the modelA. * Flip modelA and modelB and keyA and keyB in order to normalize the * given configuration. * Call self::relate() recursively with these new options. */ $reference = $modelB->getReference(get_class($modelA), $options['rule']); $keyA = $options['keyA']; $keyB = $options['keyB']; $options['modelA'] = $modelB; $options['modelB'] = $modelA; $options['keyA'] = $keyB; $options['keyB'] = $keyA; return Garp_Content_Relation_Manager::unrelate($options); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } /** * Goody, we're dealing with a hasAndBelongsToMany relationship here. * Try to construct the intersection model and save the relation * that way. */ return self::_unrelateHasAndBelongsToMany($options); } } /** * Figure out which model is leading. This depends on which of the two keys is provided. * This kind of flips the query around. For instance, when keyA is given, the query is * something like this: * UPDATE modelA SET foreignkey = NULL WHERE primarykey = keyA * When keyB is given however, the query goes something like this: * UPDATE modelA SET foreignkey = NULL WHERE foreignkey = keyB */ $query = 'UPDATE `' . $modelA->getName() . '` SET '; $columnsToValues = array(); foreach ($reference['columns'] as $column) { $columnsToValues[] = '`' . $column . '` = NULL'; } $columnsToValues = implode(' AND ', $columnsToValues); $query .= $columnsToValues; $whereColumnsToValues = array(); if ($options['keyA']) { $useColumns = 'refColumns'; $useKeys = 'keyA'; } else { $useColumns = 'columns'; $useKeys = 'keyB'; } foreach ($reference[$useColumns] as $i => $column) { $whereColumnsToValues[] = '`' . $column . '` = ' . $options[$useKeys][$i]; } $whereColumnsToValues = implode(' AND ', $whereColumnsToValues); $query .= ' WHERE '; $query .= $whereColumnsToValues; return $modelA->getAdapter()->query($query); }
php
public static function unrelate($options) { self::_normalizeOptionsForUnrelate($options); $modelA = $options['modelA']; $modelB = $options['modelB']; /** * If bindingModel is set, we can safely skip all those difficult checks below. */ if (is_object($options['bindingModel'])) { return self::_unrelateHasAndBelongsToMany($options); } try { /** * If this succeeds, it's a regular relationship where the foreign key * resides inside modelA. Continue as usual. */ $reference = $modelA->getReference(get_class($modelB), $options['rule']); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } try { /** * If this succeeds, the foreign key resides in the modelA. * Flip modelA and modelB and keyA and keyB in order to normalize the * given configuration. * Call self::relate() recursively with these new options. */ $reference = $modelB->getReference(get_class($modelA), $options['rule']); $keyA = $options['keyA']; $keyB = $options['keyB']; $options['modelA'] = $modelB; $options['modelB'] = $modelA; $options['keyA'] = $keyB; $options['keyB'] = $keyA; return Garp_Content_Relation_Manager::unrelate($options); } catch (Exception $e) { if (!self::isInvalidReferenceException($e)) { throw $e; } /** * Goody, we're dealing with a hasAndBelongsToMany relationship here. * Try to construct the intersection model and save the relation * that way. */ return self::_unrelateHasAndBelongsToMany($options); } } /** * Figure out which model is leading. This depends on which of the two keys is provided. * This kind of flips the query around. For instance, when keyA is given, the query is * something like this: * UPDATE modelA SET foreignkey = NULL WHERE primarykey = keyA * When keyB is given however, the query goes something like this: * UPDATE modelA SET foreignkey = NULL WHERE foreignkey = keyB */ $query = 'UPDATE `' . $modelA->getName() . '` SET '; $columnsToValues = array(); foreach ($reference['columns'] as $column) { $columnsToValues[] = '`' . $column . '` = NULL'; } $columnsToValues = implode(' AND ', $columnsToValues); $query .= $columnsToValues; $whereColumnsToValues = array(); if ($options['keyA']) { $useColumns = 'refColumns'; $useKeys = 'keyA'; } else { $useColumns = 'columns'; $useKeys = 'keyB'; } foreach ($reference[$useColumns] as $i => $column) { $whereColumnsToValues[] = '`' . $column . '` = ' . $options[$useKeys][$i]; } $whereColumnsToValues = implode(' AND ', $whereColumnsToValues); $query .= ' WHERE '; $query .= $whereColumnsToValues; return $modelA->getAdapter()->query($query); }
[ "public", "static", "function", "unrelate", "(", "$", "options", ")", "{", "self", "::", "_normalizeOptionsForUnrelate", "(", "$", "options", ")", ";", "$", "modelA", "=", "$", "options", "[", "'modelA'", "]", ";", "$", "modelB", "=", "$", "options", "["...
Unrelate records. @param array|Garp_Util_Configuration $options Lots o' options: 'modelA' string|Garp_Model_Db The first model or classname thereof 'modelB' string|Garp_Model_Db The second model or classname thereof 'keyA' mixed Primary key(s) of the first model 'keyB' mixed Primary key(s) of the second model 'rule' string The rule that stores this relationship in one of the reference maps @return bool Success
[ "Unrelate", "records", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Relation/Manager.php#L194-L275
train
grrr-amsterdam/garp3
library/Garp/Content/Relation/Manager.php
Garp_Content_Relation_Manager._addForeignKeysToRow
protected static function _addForeignKeysToRow(Zend_Db_Table_Row_Abstract &$row, array $reference, array $values ) { // Normalize array keys $values = array_values($values); foreach ($reference['columns'] as $i => $column) { if (!isset($values[$i])) { throw new Garp_Content_Relation_Exception( sprintf(static::EXCEPTION_MISSING_VALUE, $column) ); } $row->{$column} = $values[$i]; } }
php
protected static function _addForeignKeysToRow(Zend_Db_Table_Row_Abstract &$row, array $reference, array $values ) { // Normalize array keys $values = array_values($values); foreach ($reference['columns'] as $i => $column) { if (!isset($values[$i])) { throw new Garp_Content_Relation_Exception( sprintf(static::EXCEPTION_MISSING_VALUE, $column) ); } $row->{$column} = $values[$i]; } }
[ "protected", "static", "function", "_addForeignKeysToRow", "(", "Zend_Db_Table_Row_Abstract", "&", "$", "row", ",", "array", "$", "reference", ",", "array", "$", "values", ")", "{", "// Normalize array keys", "$", "values", "=", "array_values", "(", "$", "values",...
Fill foreign key columns in a row. @param Zend_Db_Table_Row_Abstract $row The row object @param array $reference The reference from the referencemap @param array $values The foreign key values @return void Edits the row by reference
[ "Fill", "foreign", "key", "columns", "in", "a", "row", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Relation/Manager.php#L397-L410
train