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
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.loadDocument
public function loadDocument($documentId, \DmsLoaderParams $params) { $objDocument = $this->Database->prepare("SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name " . "FROM tl_dms_documents d " . "LEFT JOIN tl_member m1 ON m1.id = d.upload_member " . "LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member " . "WHERE d.id = ?") ->limit(1) ->execute($documentId); $document = null; if ($objDocument->numRows) { $document = $this->buildDocument($objDocument); if ($params->loadCategory) { $document->category = $this->loadCategory($document->categoryId, $params); } } return $document; }
php
public function loadDocument($documentId, \DmsLoaderParams $params) { $objDocument = $this->Database->prepare("SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name " . "FROM tl_dms_documents d " . "LEFT JOIN tl_member m1 ON m1.id = d.upload_member " . "LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member " . "WHERE d.id = ?") ->limit(1) ->execute($documentId); $document = null; if ($objDocument->numRows) { $document = $this->buildDocument($objDocument); if ($params->loadCategory) { $document->category = $this->loadCategory($document->categoryId, $params); } } return $document; }
[ "public", "function", "loadDocument", "(", "$", "documentId", ",", "\\", "DmsLoaderParams", "$", "params", ")", "{", "$", "objDocument", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name \"", ".", "\"FROM tl_dms_documents d \"", ".", "\"LEFT JOIN tl_member m1 ON m1.id = d.upload_member \"", ".", "\"LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member \"", ".", "\"WHERE d.id = ?\"", ")", "->", "limit", "(", "1", ")", "->", "execute", "(", "$", "documentId", ")", ";", "$", "document", "=", "null", ";", "if", "(", "$", "objDocument", "->", "numRows", ")", "{", "$", "document", "=", "$", "this", "->", "buildDocument", "(", "$", "objDocument", ")", ";", "if", "(", "$", "params", "->", "loadCategory", ")", "{", "$", "document", "->", "category", "=", "$", "this", "->", "loadCategory", "(", "$", "document", "->", "categoryId", ",", "$", "params", ")", ";", "}", "}", "return", "$", "document", ";", "}" ]
Load the document with the given id. @param int $documentId The id of the document to load. @param DmsLoaderParams $params The configured params to use while loading. @return document Returns the document.
[ "Load", "the", "document", "with", "the", "given", "id", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L162-L183
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.loadDocuments
public function loadDocuments($strFileName, $strFileType, \DmsLoaderParams $params) { $arrDocuments = array(); $objDocument = $this->Database->prepare("SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name " . "FROM tl_dms_documents d " . "LEFT JOIN tl_member m1 ON m1.id = d.upload_member " . "LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member " . "WHERE d.data_file_name = ? AND d.data_file_type = ? " . "ORDER BY d.version_major, d.version_minor, d.version_patch") ->execute(array($strFileName, $strFileType)); $document = null; while ($objDocument->next()) { $document = $this->buildDocument($objDocument); if ($params->loadCategory) { $document->category = $this->loadCategory($document->categoryId, $params); } $arrDocuments[] = $document; } return $arrDocuments; }
php
public function loadDocuments($strFileName, $strFileType, \DmsLoaderParams $params) { $arrDocuments = array(); $objDocument = $this->Database->prepare("SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name " . "FROM tl_dms_documents d " . "LEFT JOIN tl_member m1 ON m1.id = d.upload_member " . "LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member " . "WHERE d.data_file_name = ? AND d.data_file_type = ? " . "ORDER BY d.version_major, d.version_minor, d.version_patch") ->execute(array($strFileName, $strFileType)); $document = null; while ($objDocument->next()) { $document = $this->buildDocument($objDocument); if ($params->loadCategory) { $document->category = $this->loadCategory($document->categoryId, $params); } $arrDocuments[] = $document; } return $arrDocuments; }
[ "public", "function", "loadDocuments", "(", "$", "strFileName", ",", "$", "strFileType", ",", "\\", "DmsLoaderParams", "$", "params", ")", "{", "$", "arrDocuments", "=", "array", "(", ")", ";", "$", "objDocument", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name \"", ".", "\"FROM tl_dms_documents d \"", ".", "\"LEFT JOIN tl_member m1 ON m1.id = d.upload_member \"", ".", "\"LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member \"", ".", "\"WHERE d.data_file_name = ? AND d.data_file_type = ? \"", ".", "\"ORDER BY d.version_major, d.version_minor, d.version_patch\"", ")", "->", "execute", "(", "array", "(", "$", "strFileName", ",", "$", "strFileType", ")", ")", ";", "$", "document", "=", "null", ";", "while", "(", "$", "objDocument", "->", "next", "(", ")", ")", "{", "$", "document", "=", "$", "this", "->", "buildDocument", "(", "$", "objDocument", ")", ";", "if", "(", "$", "params", "->", "loadCategory", ")", "{", "$", "document", "->", "category", "=", "$", "this", "->", "loadCategory", "(", "$", "document", "->", "categoryId", ",", "$", "params", ")", ";", "}", "$", "arrDocuments", "[", "]", "=", "$", "document", ";", "}", "return", "$", "arrDocuments", ";", "}" ]
Load the documents for the given file name and type. @param string $strFileName The common file name for the documents to load. @param string $strFileType The common file type for the documents to load. @param DmsLoaderParams $params The configured params to use while loading. @return array Returns an array of matching the documents.
[ "Load", "the", "documents", "for", "the", "given", "file", "name", "and", "type", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L193-L216
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.getCategoryLevel
protected function getCategoryLevel($parentCategoryId, \Category $parentCategory=null, \DmsLoaderParams $params) { $arrCategories = array(); $objCategory = $this->Database->prepare("SELECT * FROM tl_dms_categories WHERE pid = ? ORDER BY sorting") ->execute($parentCategoryId); $category = null; while ($objCategory->next()) { $category = $this->buildCategory($objCategory); $category->parentCategory = $parentCategory; $category->subCategories = $this->getCategoryLevel($category->id, $category, $params); if ($params->loadAccessRights) { $category->accessRights = $this->getAccessRights($category, $params); } if ($params->loadDocuments) { $category->documents = $this->getDocuments($category, $params); } $arrCategories[$category->id] = $category; } return $arrCategories; }
php
protected function getCategoryLevel($parentCategoryId, \Category $parentCategory=null, \DmsLoaderParams $params) { $arrCategories = array(); $objCategory = $this->Database->prepare("SELECT * FROM tl_dms_categories WHERE pid = ? ORDER BY sorting") ->execute($parentCategoryId); $category = null; while ($objCategory->next()) { $category = $this->buildCategory($objCategory); $category->parentCategory = $parentCategory; $category->subCategories = $this->getCategoryLevel($category->id, $category, $params); if ($params->loadAccessRights) { $category->accessRights = $this->getAccessRights($category, $params); } if ($params->loadDocuments) { $category->documents = $this->getDocuments($category, $params); } $arrCategories[$category->id] = $category; } return $arrCategories; }
[ "protected", "function", "getCategoryLevel", "(", "$", "parentCategoryId", ",", "\\", "Category", "$", "parentCategory", "=", "null", ",", "\\", "DmsLoaderParams", "$", "params", ")", "{", "$", "arrCategories", "=", "array", "(", ")", ";", "$", "objCategory", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT * FROM tl_dms_categories WHERE pid = ? ORDER BY sorting\"", ")", "->", "execute", "(", "$", "parentCategoryId", ")", ";", "$", "category", "=", "null", ";", "while", "(", "$", "objCategory", "->", "next", "(", ")", ")", "{", "$", "category", "=", "$", "this", "->", "buildCategory", "(", "$", "objCategory", ")", ";", "$", "category", "->", "parentCategory", "=", "$", "parentCategory", ";", "$", "category", "->", "subCategories", "=", "$", "this", "->", "getCategoryLevel", "(", "$", "category", "->", "id", ",", "$", "category", ",", "$", "params", ")", ";", "if", "(", "$", "params", "->", "loadAccessRights", ")", "{", "$", "category", "->", "accessRights", "=", "$", "this", "->", "getAccessRights", "(", "$", "category", ",", "$", "params", ")", ";", "}", "if", "(", "$", "params", "->", "loadDocuments", ")", "{", "$", "category", "->", "documents", "=", "$", "this", "->", "getDocuments", "(", "$", "category", ",", "$", "params", ")", ";", "}", "$", "arrCategories", "[", "$", "category", "->", "id", "]", "=", "$", "category", ";", "}", "return", "$", "arrCategories", ";", "}" ]
Recursively reading the categories
[ "Recursively", "reading", "the", "categories" ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L221-L245
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.getAccessRights
private function getAccessRights(\Category $category, \DmsLoaderParams $params) { $objAccessRight = $this->Database->prepare("SELECT * FROM tl_dms_access_rights WHERE pid = ?") ->execute($category->id); $arrAccessRights = array(); while ($objAccessRight->next()) { $accessRight = $this->buildAccessRight($objAccessRight); $accessRight->category = $category; $arrAccessRights[$accessRight->id] = $accessRight; } return $arrAccessRights; }
php
private function getAccessRights(\Category $category, \DmsLoaderParams $params) { $objAccessRight = $this->Database->prepare("SELECT * FROM tl_dms_access_rights WHERE pid = ?") ->execute($category->id); $arrAccessRights = array(); while ($objAccessRight->next()) { $accessRight = $this->buildAccessRight($objAccessRight); $accessRight->category = $category; $arrAccessRights[$accessRight->id] = $accessRight; } return $arrAccessRights; }
[ "private", "function", "getAccessRights", "(", "\\", "Category", "$", "category", ",", "\\", "DmsLoaderParams", "$", "params", ")", "{", "$", "objAccessRight", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT * FROM tl_dms_access_rights WHERE pid = ?\"", ")", "->", "execute", "(", "$", "category", "->", "id", ")", ";", "$", "arrAccessRights", "=", "array", "(", ")", ";", "while", "(", "$", "objAccessRight", "->", "next", "(", ")", ")", "{", "$", "accessRight", "=", "$", "this", "->", "buildAccessRight", "(", "$", "objAccessRight", ")", ";", "$", "accessRight", "->", "category", "=", "$", "category", ";", "$", "arrAccessRights", "[", "$", "accessRight", "->", "id", "]", "=", "$", "accessRight", ";", "}", "return", "$", "arrAccessRights", ";", "}" ]
Get all access rights for the given category. @param category $category The category to get the access rights for. @param DmsLoaderParams $params The configured params to use while loading. @return arr Returns array of access rights.
[ "Get", "all", "access", "rights", "for", "the", "given", "category", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L254-L266
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.getDocuments
private function getDocuments(\Category $category, \DmsLoaderParams $params) { $whereClause = "WHERE d.pid = ? "; $whereParams = array(); $whereParams[] = $category->id; if ($params->hasDocumentSearchText()) { if ($params->documentSearchType == \DmsLoaderParams::DOCUMENT_SEARCH_LIKE) { $whereClause .= "AND (UPPER(d.name) LIKE ? OR UPPER(d.description) LIKE ? OR UPPER(d.keywords) LIKE ?) "; $seachText = "%" . $params->documentSearchText . "%"; } else { $whereClause .= "AND (d.name = ? OR d.description = ? OR d.keywords = ?) "; $seachText = $params->documentSearchText; } // add the search text 3 times for ($i = 0; $i < 3; $i++) { $whereParams[] = $seachText; } } $objDocument = $this->Database->prepare("SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name " . "FROM tl_dms_documents d " . "LEFT JOIN tl_member m1 ON m1.id = d.upload_member " . "LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member " . $whereClause . "ORDER BY d.name, d.version_major, d.version_minor, d.version_patch") ->execute($whereParams); $arrDocuments = array(); while ($objDocument->next()) { $document = $this->buildDocument($objDocument); $document->category = $category; $arrDocuments[$document->id] = $document; } return $arrDocuments; }
php
private function getDocuments(\Category $category, \DmsLoaderParams $params) { $whereClause = "WHERE d.pid = ? "; $whereParams = array(); $whereParams[] = $category->id; if ($params->hasDocumentSearchText()) { if ($params->documentSearchType == \DmsLoaderParams::DOCUMENT_SEARCH_LIKE) { $whereClause .= "AND (UPPER(d.name) LIKE ? OR UPPER(d.description) LIKE ? OR UPPER(d.keywords) LIKE ?) "; $seachText = "%" . $params->documentSearchText . "%"; } else { $whereClause .= "AND (d.name = ? OR d.description = ? OR d.keywords = ?) "; $seachText = $params->documentSearchText; } // add the search text 3 times for ($i = 0; $i < 3; $i++) { $whereParams[] = $seachText; } } $objDocument = $this->Database->prepare("SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name " . "FROM tl_dms_documents d " . "LEFT JOIN tl_member m1 ON m1.id = d.upload_member " . "LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member " . $whereClause . "ORDER BY d.name, d.version_major, d.version_minor, d.version_patch") ->execute($whereParams); $arrDocuments = array(); while ($objDocument->next()) { $document = $this->buildDocument($objDocument); $document->category = $category; $arrDocuments[$document->id] = $document; } return $arrDocuments; }
[ "private", "function", "getDocuments", "(", "\\", "Category", "$", "category", ",", "\\", "DmsLoaderParams", "$", "params", ")", "{", "$", "whereClause", "=", "\"WHERE d.pid = ? \"", ";", "$", "whereParams", "=", "array", "(", ")", ";", "$", "whereParams", "[", "]", "=", "$", "category", "->", "id", ";", "if", "(", "$", "params", "->", "hasDocumentSearchText", "(", ")", ")", "{", "if", "(", "$", "params", "->", "documentSearchType", "==", "\\", "DmsLoaderParams", "::", "DOCUMENT_SEARCH_LIKE", ")", "{", "$", "whereClause", ".=", "\"AND (UPPER(d.name) LIKE ? OR UPPER(d.description) LIKE ? OR UPPER(d.keywords) LIKE ?) \"", ";", "$", "seachText", "=", "\"%\"", ".", "$", "params", "->", "documentSearchText", ".", "\"%\"", ";", "}", "else", "{", "$", "whereClause", ".=", "\"AND (d.name = ? OR d.description = ? OR d.keywords = ?) \"", ";", "$", "seachText", "=", "$", "params", "->", "documentSearchText", ";", "}", "// add the search text 3 times", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "3", ";", "$", "i", "++", ")", "{", "$", "whereParams", "[", "]", "=", "$", "seachText", ";", "}", "}", "$", "objDocument", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT d.*, CONCAT(m1.firstname, ' ', m1.lastname) AS upload_member_name, CONCAT(m2.firstname, ' ', m2.lastname) AS lastedit_member_name \"", ".", "\"FROM tl_dms_documents d \"", ".", "\"LEFT JOIN tl_member m1 ON m1.id = d.upload_member \"", ".", "\"LEFT JOIN tl_member m2 ON m2.id = d.lastedit_member \"", ".", "$", "whereClause", ".", "\"ORDER BY d.name, d.version_major, d.version_minor, d.version_patch\"", ")", "->", "execute", "(", "$", "whereParams", ")", ";", "$", "arrDocuments", "=", "array", "(", ")", ";", "while", "(", "$", "objDocument", "->", "next", "(", ")", ")", "{", "$", "document", "=", "$", "this", "->", "buildDocument", "(", "$", "objDocument", ")", ";", "$", "document", "->", "category", "=", "$", "category", ";", "$", "arrDocuments", "[", "$", "document", "->", "id", "]", "=", "$", "document", ";", "}", "return", "$", "arrDocuments", ";", "}" ]
Get all documents for the given category. @param category $category The category to get the access rights for. @param DmsLoaderParams $params The configured params to use while loading. @return arr Returns array of documents.
[ "Get", "all", "documents", "for", "the", "given", "category", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L275-L317
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.buildCategory
private function buildCategory($objCategory) { $category = new \Category($objCategory->id, $objCategory->name); $category->parentCategoryId = $objCategory->pid; $category->description = $objCategory->description; $category->fileTypes = $objCategory->file_types; $category->fileTypesInherit = $objCategory->file_types_inherit; $category->publishDocumentsPerDefault = $objCategory->publish_documents_per_default; $category->generalReadPermission = $objCategory->general_read_permission; $category->generalManagePermission = $objCategory->general_manage_permission; $category->cssId = $objCategory->cssID; $category->published = $objCategory->published; $category->publicationStart = $objCategory->start; $category->publicationStop = $objCategory->stop; // HOOK: modify the category if (isset($GLOBALS['TL_HOOKS']['dmsModifyLoadedCategory']) && is_array($GLOBALS['TL_HOOKS']['dmsModifyLoadedCategory'])) { foreach ($GLOBALS['TL_HOOKS']['dmsModifyLoadedCategory'] as $callback) { $this->import($callback[0]); $category = $this->{$callback[0]}->{$callback[1]}($category, $objCategory); } } return $category; }
php
private function buildCategory($objCategory) { $category = new \Category($objCategory->id, $objCategory->name); $category->parentCategoryId = $objCategory->pid; $category->description = $objCategory->description; $category->fileTypes = $objCategory->file_types; $category->fileTypesInherit = $objCategory->file_types_inherit; $category->publishDocumentsPerDefault = $objCategory->publish_documents_per_default; $category->generalReadPermission = $objCategory->general_read_permission; $category->generalManagePermission = $objCategory->general_manage_permission; $category->cssId = $objCategory->cssID; $category->published = $objCategory->published; $category->publicationStart = $objCategory->start; $category->publicationStop = $objCategory->stop; // HOOK: modify the category if (isset($GLOBALS['TL_HOOKS']['dmsModifyLoadedCategory']) && is_array($GLOBALS['TL_HOOKS']['dmsModifyLoadedCategory'])) { foreach ($GLOBALS['TL_HOOKS']['dmsModifyLoadedCategory'] as $callback) { $this->import($callback[0]); $category = $this->{$callback[0]}->{$callback[1]}($category, $objCategory); } } return $category; }
[ "private", "function", "buildCategory", "(", "$", "objCategory", ")", "{", "$", "category", "=", "new", "\\", "Category", "(", "$", "objCategory", "->", "id", ",", "$", "objCategory", "->", "name", ")", ";", "$", "category", "->", "parentCategoryId", "=", "$", "objCategory", "->", "pid", ";", "$", "category", "->", "description", "=", "$", "objCategory", "->", "description", ";", "$", "category", "->", "fileTypes", "=", "$", "objCategory", "->", "file_types", ";", "$", "category", "->", "fileTypesInherit", "=", "$", "objCategory", "->", "file_types_inherit", ";", "$", "category", "->", "publishDocumentsPerDefault", "=", "$", "objCategory", "->", "publish_documents_per_default", ";", "$", "category", "->", "generalReadPermission", "=", "$", "objCategory", "->", "general_read_permission", ";", "$", "category", "->", "generalManagePermission", "=", "$", "objCategory", "->", "general_manage_permission", ";", "$", "category", "->", "cssId", "=", "$", "objCategory", "->", "cssID", ";", "$", "category", "->", "published", "=", "$", "objCategory", "->", "published", ";", "$", "category", "->", "publicationStart", "=", "$", "objCategory", "->", "start", ";", "$", "category", "->", "publicationStop", "=", "$", "objCategory", "->", "stop", ";", "// HOOK: modify the category", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'dmsModifyLoadedCategory'", "]", ")", "&&", "is_array", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'dmsModifyLoadedCategory'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'dmsModifyLoadedCategory'", "]", "as", "$", "callback", ")", "{", "$", "this", "->", "import", "(", "$", "callback", "[", "0", "]", ")", ";", "$", "category", "=", "$", "this", "->", "{", "$", "callback", "[", "0", "]", "}", "->", "{", "$", "callback", "[", "1", "]", "}", "(", "$", "category", ",", "$", "objCategory", ")", ";", "}", "}", "return", "$", "category", ";", "}" ]
Builds a category from a database result. @param DatabaseResult $objCategory The database result. @return category The created category.
[ "Builds", "a", "category", "from", "a", "database", "result", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L325-L351
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsLoader.php
DmsLoader.buildAccessRight
private function buildAccessRight($objAccessRight) { $accessRight = new \AccessRight($objAccessRight->id, $objAccessRight->member_group); $accessRight->categoryId = $objAccessRight->pid; $strRight = \AccessRight::READ; $accessRight->$strRight = $objAccessRight->right_read; $strRight = \AccessRight::UPLOAD; $accessRight->$strRight = $objAccessRight->right_upload; $strRight = \AccessRight::DELETE; $accessRight->$strRight = $objAccessRight->right_delete; $strRight = \AccessRight::EDIT; $accessRight->$strRight = $objAccessRight->right_edit; $strRight = \AccessRight::PUBLISH; $accessRight->$strRight = $objAccessRight->right_publish; $accessRight->active = $objAccessRight->published; $accessRight->activationStart = $objAccessRight->start; $accessRight->activationStop = $objAccessRight->stop; // HOOK: modify the access right if (isset($GLOBALS['TL_HOOKS']['dmsModifyLoadedAccessRight']) && is_array($GLOBALS['TL_HOOKS']['dmsModifyLoadedAccessRight'])) { foreach ($GLOBALS['TL_HOOKS']['dmsModifyLoadedAccessRight'] as $callback) { $this->import($callback[0]); $accessRight = $this->{$callback[0]}->{$callback[1]}($accessRight, $objAccessRight); } } return $accessRight; }
php
private function buildAccessRight($objAccessRight) { $accessRight = new \AccessRight($objAccessRight->id, $objAccessRight->member_group); $accessRight->categoryId = $objAccessRight->pid; $strRight = \AccessRight::READ; $accessRight->$strRight = $objAccessRight->right_read; $strRight = \AccessRight::UPLOAD; $accessRight->$strRight = $objAccessRight->right_upload; $strRight = \AccessRight::DELETE; $accessRight->$strRight = $objAccessRight->right_delete; $strRight = \AccessRight::EDIT; $accessRight->$strRight = $objAccessRight->right_edit; $strRight = \AccessRight::PUBLISH; $accessRight->$strRight = $objAccessRight->right_publish; $accessRight->active = $objAccessRight->published; $accessRight->activationStart = $objAccessRight->start; $accessRight->activationStop = $objAccessRight->stop; // HOOK: modify the access right if (isset($GLOBALS['TL_HOOKS']['dmsModifyLoadedAccessRight']) && is_array($GLOBALS['TL_HOOKS']['dmsModifyLoadedAccessRight'])) { foreach ($GLOBALS['TL_HOOKS']['dmsModifyLoadedAccessRight'] as $callback) { $this->import($callback[0]); $accessRight = $this->{$callback[0]}->{$callback[1]}($accessRight, $objAccessRight); } } return $accessRight; }
[ "private", "function", "buildAccessRight", "(", "$", "objAccessRight", ")", "{", "$", "accessRight", "=", "new", "\\", "AccessRight", "(", "$", "objAccessRight", "->", "id", ",", "$", "objAccessRight", "->", "member_group", ")", ";", "$", "accessRight", "->", "categoryId", "=", "$", "objAccessRight", "->", "pid", ";", "$", "strRight", "=", "\\", "AccessRight", "::", "READ", ";", "$", "accessRight", "->", "$", "strRight", "=", "$", "objAccessRight", "->", "right_read", ";", "$", "strRight", "=", "\\", "AccessRight", "::", "UPLOAD", ";", "$", "accessRight", "->", "$", "strRight", "=", "$", "objAccessRight", "->", "right_upload", ";", "$", "strRight", "=", "\\", "AccessRight", "::", "DELETE", ";", "$", "accessRight", "->", "$", "strRight", "=", "$", "objAccessRight", "->", "right_delete", ";", "$", "strRight", "=", "\\", "AccessRight", "::", "EDIT", ";", "$", "accessRight", "->", "$", "strRight", "=", "$", "objAccessRight", "->", "right_edit", ";", "$", "strRight", "=", "\\", "AccessRight", "::", "PUBLISH", ";", "$", "accessRight", "->", "$", "strRight", "=", "$", "objAccessRight", "->", "right_publish", ";", "$", "accessRight", "->", "active", "=", "$", "objAccessRight", "->", "published", ";", "$", "accessRight", "->", "activationStart", "=", "$", "objAccessRight", "->", "start", ";", "$", "accessRight", "->", "activationStop", "=", "$", "objAccessRight", "->", "stop", ";", "// HOOK: modify the access right", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'dmsModifyLoadedAccessRight'", "]", ")", "&&", "is_array", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'dmsModifyLoadedAccessRight'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'dmsModifyLoadedAccessRight'", "]", "as", "$", "callback", ")", "{", "$", "this", "->", "import", "(", "$", "callback", "[", "0", "]", ")", ";", "$", "accessRight", "=", "$", "this", "->", "{", "$", "callback", "[", "0", "]", "}", "->", "{", "$", "callback", "[", "1", "]", "}", "(", "$", "accessRight", ",", "$", "objAccessRight", ")", ";", "}", "}", "return", "$", "accessRight", ";", "}" ]
Builds an access right from a database result. @param DatabaseResult $objAccessRight The database result. @return accessRight The created access right.
[ "Builds", "an", "access", "right", "from", "a", "database", "result", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L359-L388
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsConfig.php
DmsConfig.getBaseDirectory
public static function getBaseDirectory($blnAppendTrailingSlash) { $path = \FilesModel::findByUuid($GLOBALS['TL_CONFIG']['dmsBaseDirectory'])->path; if ($blnAppendTrailingSlash) { $path .= "/"; } return $path; }
php
public static function getBaseDirectory($blnAppendTrailingSlash) { $path = \FilesModel::findByUuid($GLOBALS['TL_CONFIG']['dmsBaseDirectory'])->path; if ($blnAppendTrailingSlash) { $path .= "/"; } return $path; }
[ "public", "static", "function", "getBaseDirectory", "(", "$", "blnAppendTrailingSlash", ")", "{", "$", "path", "=", "\\", "FilesModel", "::", "findByUuid", "(", "$", "GLOBALS", "[", "'TL_CONFIG'", "]", "[", "'dmsBaseDirectory'", "]", ")", "->", "path", ";", "if", "(", "$", "blnAppendTrailingSlash", ")", "{", "$", "path", ".=", "\"/\"", ";", "}", "return", "$", "path", ";", "}" ]
Return base directory for the DMS documents, defined in system settings. @param bool $blnAppendTrailingSlash True if a trailing slash should be appended. @return string The path to the base directory.
[ "Return", "base", "directory", "for", "the", "DMS", "documents", "defined", "in", "system", "settings", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsConfig.php#L53-L62
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsConfig.php
DmsConfig.getPreviewDirectory
public static function getPreviewDirectory($blnAppendTrailingSlash) { $path = self::getBaseDirectory(true) . self::DIRECTORY_NAME_PREVIEW; if ($blnAppendTrailingSlash) { $path .= "/"; } return $path; }
php
public static function getPreviewDirectory($blnAppendTrailingSlash) { $path = self::getBaseDirectory(true) . self::DIRECTORY_NAME_PREVIEW; if ($blnAppendTrailingSlash) { $path .= "/"; } return $path; }
[ "public", "static", "function", "getPreviewDirectory", "(", "$", "blnAppendTrailingSlash", ")", "{", "$", "path", "=", "self", "::", "getBaseDirectory", "(", "true", ")", ".", "self", "::", "DIRECTORY_NAME_PREVIEW", ";", "if", "(", "$", "blnAppendTrailingSlash", ")", "{", "$", "path", ".=", "\"/\"", ";", "}", "return", "$", "path", ";", "}" ]
Return preview directory for the DMS document preview images. @param bool $blnAppendTrailingSlash True if a trailing slash should be appended. @return string The path to the preview directory.
[ "Return", "preview", "directory", "for", "the", "DMS", "document", "preview", "images", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsConfig.php#L70-L79
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsConfig.php
DmsConfig.getTempDirectory
public static function getTempDirectory($blnAppendTrailingSlash) { $path = self::getBaseDirectory(true) . self::DIRECTORY_NAME_TEMP; if ($blnAppendTrailingSlash) { $path .= "/"; } return $path; }
php
public static function getTempDirectory($blnAppendTrailingSlash) { $path = self::getBaseDirectory(true) . self::DIRECTORY_NAME_TEMP; if ($blnAppendTrailingSlash) { $path .= "/"; } return $path; }
[ "public", "static", "function", "getTempDirectory", "(", "$", "blnAppendTrailingSlash", ")", "{", "$", "path", "=", "self", "::", "getBaseDirectory", "(", "true", ")", ".", "self", "::", "DIRECTORY_NAME_TEMP", ";", "if", "(", "$", "blnAppendTrailingSlash", ")", "{", "$", "path", ".=", "\"/\"", ";", "}", "return", "$", "path", ";", "}" ]
Return temp directory for the DMS documents. @param bool $blnAppendTrailingSlash True if a trailing slash should be appended. @return string The path to the temp directory.
[ "Return", "temp", "directory", "for", "the", "DMS", "documents", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsConfig.php#L87-L96
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/classes/DmsConfig.php
DmsConfig.getMaxUploadFileSize
public static function getMaxUploadFileSize($strUnit, $blnFormatted) { $arrValue = deserialize($GLOBALS['TL_CONFIG']['dmsMaxUploadFileSize']); $dmsUnit = $arrValue['unit']; $dmsVal = \Document::convertFileSize((double) $arrValue['value'], $dmsUnit, $strUnit); if ($blnFormatted) { return \Document::formatFileSize($dmsVal, $strUnit); } return $dmsVal; }
php
public static function getMaxUploadFileSize($strUnit, $blnFormatted) { $arrValue = deserialize($GLOBALS['TL_CONFIG']['dmsMaxUploadFileSize']); $dmsUnit = $arrValue['unit']; $dmsVal = \Document::convertFileSize((double) $arrValue['value'], $dmsUnit, $strUnit); if ($blnFormatted) { return \Document::formatFileSize($dmsVal, $strUnit); } return $dmsVal; }
[ "public", "static", "function", "getMaxUploadFileSize", "(", "$", "strUnit", ",", "$", "blnFormatted", ")", "{", "$", "arrValue", "=", "deserialize", "(", "$", "GLOBALS", "[", "'TL_CONFIG'", "]", "[", "'dmsMaxUploadFileSize'", "]", ")", ";", "$", "dmsUnit", "=", "$", "arrValue", "[", "'unit'", "]", ";", "$", "dmsVal", "=", "\\", "Document", "::", "convertFileSize", "(", "(", "double", ")", "$", "arrValue", "[", "'value'", "]", ",", "$", "dmsUnit", ",", "$", "strUnit", ")", ";", "if", "(", "$", "blnFormatted", ")", "{", "return", "\\", "Document", "::", "formatFileSize", "(", "$", "dmsVal", ",", "$", "strUnit", ")", ";", "}", "return", "$", "dmsVal", ";", "}" ]
Return the maximum allowed upload file size, defined in system settings. @param string $strUnit The file size unit. @param bool $blnFormatted True if the file size should be returned as formatted string (with unit). @return mixed The file size for the given unit (as int or formatted as string).
[ "Return", "the", "maximum", "allowed", "upload", "file", "size", "defined", "in", "system", "settings", "." ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsConfig.php#L116-L129
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/config/initialize.php
DocumentManagementSystemInitializer.initDirectoryStructure
private function initDirectoryStructure() { if (!file_exists(TL_ROOT . '/' . $this->getDmsBaseDirectory())) { mkdir(TL_ROOT . '/' . $this->getDmsBaseDirectory(), 0775, true); $objDir = \Dbafs::addResource($this->getDmsBaseDirectory()); $objFolder = new \Folder($this->getDmsBaseDirectory()); $objFolder->unprotect(); mkdir(TL_ROOT . '/' . $this->getDmsBaseDirectory() . "/temp", 0775, true); $objDir = \Dbafs::addResource($this->getDmsBaseDirectory() . "/temp"); } }
php
private function initDirectoryStructure() { if (!file_exists(TL_ROOT . '/' . $this->getDmsBaseDirectory())) { mkdir(TL_ROOT . '/' . $this->getDmsBaseDirectory(), 0775, true); $objDir = \Dbafs::addResource($this->getDmsBaseDirectory()); $objFolder = new \Folder($this->getDmsBaseDirectory()); $objFolder->unprotect(); mkdir(TL_ROOT . '/' . $this->getDmsBaseDirectory() . "/temp", 0775, true); $objDir = \Dbafs::addResource($this->getDmsBaseDirectory() . "/temp"); } }
[ "private", "function", "initDirectoryStructure", "(", ")", "{", "if", "(", "!", "file_exists", "(", "TL_ROOT", ".", "'/'", ".", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ")", ")", "{", "mkdir", "(", "TL_ROOT", ".", "'/'", ".", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ",", "0775", ",", "true", ")", ";", "$", "objDir", "=", "\\", "Dbafs", "::", "addResource", "(", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ")", ";", "$", "objFolder", "=", "new", "\\", "Folder", "(", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ")", ";", "$", "objFolder", "->", "unprotect", "(", ")", ";", "mkdir", "(", "TL_ROOT", ".", "'/'", ".", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ".", "\"/temp\"", ",", "0775", ",", "true", ")", ";", "$", "objDir", "=", "\\", "Dbafs", "::", "addResource", "(", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ".", "\"/temp\"", ")", ";", "}", "}" ]
Init the directory structure Create structure if not exists
[ "Init", "the", "directory", "structure", "Create", "structure", "if", "not", "exists" ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/config/initialize.php#L67-L80
train
ContaoDMS/dms
system/modules/DocumentManagementSystem/config/initialize.php
DocumentManagementSystemInitializer.initSystemSettings
private function initSystemSettings() { if (\Config::get(self::DMS_BASE_DIRECTORY_KEY) && \Config::get(self::DMS_MAX_UPLOAD_FILE_SIZE_KEY)) { return; } \System::log('Running init script for setting default DMS settings, if missing.', __METHOD__, TL_CONFIGURATION); if (!\Config::get(self::DMS_BASE_DIRECTORY_KEY)) { \System::log('Setting default DMS base directory to "' . $this->getDmsBaseDirectory() . '".', __METHOD__, TL_CONFIGURATION); $uuid = null; $objDatabase = \Database::getInstance(); $objDir = $objDatabase->prepare("SELECT * FROM tl_files WHERE path=?") ->limit(1) ->execute($this->getDmsBaseDirectory()); if ($objDir->next()) { $uuid = \StringUtil::binToUuid($objDir->uuid); } if ($uuid == null) { if (file_exists(TL_ROOT . '/' . $this->getDmsBaseDirectory())) { $objDir = \Dbafs::addResource($this->getDmsBaseDirectory()); $uuid = \StringUtil::binToUuid($objDir->uuid); } else { \System::log('Initialization of system setting for DMS failed, because default base directory does not exists.', __METHOD__, TL_ERROR); return; } } if ($uuid != null) { \Config::persist(self::DMS_BASE_DIRECTORY_KEY, $uuid); } } if (!\Config::get(self::DMS_MAX_UPLOAD_FILE_SIZE_KEY)) { \System::log('Setting default DMS max. upload file size to "5 MB".', __METHOD__, TL_CONFIGURATION); \Config::persist(self::DMS_MAX_UPLOAD_FILE_SIZE_KEY, serialize(self::DMS_MAX_UPLOAD_FILE_SIZE_VALUE)); } }
php
private function initSystemSettings() { if (\Config::get(self::DMS_BASE_DIRECTORY_KEY) && \Config::get(self::DMS_MAX_UPLOAD_FILE_SIZE_KEY)) { return; } \System::log('Running init script for setting default DMS settings, if missing.', __METHOD__, TL_CONFIGURATION); if (!\Config::get(self::DMS_BASE_DIRECTORY_KEY)) { \System::log('Setting default DMS base directory to "' . $this->getDmsBaseDirectory() . '".', __METHOD__, TL_CONFIGURATION); $uuid = null; $objDatabase = \Database::getInstance(); $objDir = $objDatabase->prepare("SELECT * FROM tl_files WHERE path=?") ->limit(1) ->execute($this->getDmsBaseDirectory()); if ($objDir->next()) { $uuid = \StringUtil::binToUuid($objDir->uuid); } if ($uuid == null) { if (file_exists(TL_ROOT . '/' . $this->getDmsBaseDirectory())) { $objDir = \Dbafs::addResource($this->getDmsBaseDirectory()); $uuid = \StringUtil::binToUuid($objDir->uuid); } else { \System::log('Initialization of system setting for DMS failed, because default base directory does not exists.', __METHOD__, TL_ERROR); return; } } if ($uuid != null) { \Config::persist(self::DMS_BASE_DIRECTORY_KEY, $uuid); } } if (!\Config::get(self::DMS_MAX_UPLOAD_FILE_SIZE_KEY)) { \System::log('Setting default DMS max. upload file size to "5 MB".', __METHOD__, TL_CONFIGURATION); \Config::persist(self::DMS_MAX_UPLOAD_FILE_SIZE_KEY, serialize(self::DMS_MAX_UPLOAD_FILE_SIZE_VALUE)); } }
[ "private", "function", "initSystemSettings", "(", ")", "{", "if", "(", "\\", "Config", "::", "get", "(", "self", "::", "DMS_BASE_DIRECTORY_KEY", ")", "&&", "\\", "Config", "::", "get", "(", "self", "::", "DMS_MAX_UPLOAD_FILE_SIZE_KEY", ")", ")", "{", "return", ";", "}", "\\", "System", "::", "log", "(", "'Running init script for setting default DMS settings, if missing.'", ",", "__METHOD__", ",", "TL_CONFIGURATION", ")", ";", "if", "(", "!", "\\", "Config", "::", "get", "(", "self", "::", "DMS_BASE_DIRECTORY_KEY", ")", ")", "{", "\\", "System", "::", "log", "(", "'Setting default DMS base directory to \"'", ".", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ".", "'\".'", ",", "__METHOD__", ",", "TL_CONFIGURATION", ")", ";", "$", "uuid", "=", "null", ";", "$", "objDatabase", "=", "\\", "Database", "::", "getInstance", "(", ")", ";", "$", "objDir", "=", "$", "objDatabase", "->", "prepare", "(", "\"SELECT * FROM tl_files WHERE path=?\"", ")", "->", "limit", "(", "1", ")", "->", "execute", "(", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ")", ";", "if", "(", "$", "objDir", "->", "next", "(", ")", ")", "{", "$", "uuid", "=", "\\", "StringUtil", "::", "binToUuid", "(", "$", "objDir", "->", "uuid", ")", ";", "}", "if", "(", "$", "uuid", "==", "null", ")", "{", "if", "(", "file_exists", "(", "TL_ROOT", ".", "'/'", ".", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ")", ")", "{", "$", "objDir", "=", "\\", "Dbafs", "::", "addResource", "(", "$", "this", "->", "getDmsBaseDirectory", "(", ")", ")", ";", "$", "uuid", "=", "\\", "StringUtil", "::", "binToUuid", "(", "$", "objDir", "->", "uuid", ")", ";", "}", "else", "{", "\\", "System", "::", "log", "(", "'Initialization of system setting for DMS failed, because default base directory does not exists.'", ",", "__METHOD__", ",", "TL_ERROR", ")", ";", "return", ";", "}", "}", "if", "(", "$", "uuid", "!=", "null", ")", "{", "\\", "Config", "::", "persist", "(", "self", "::", "DMS_BASE_DIRECTORY_KEY", ",", "$", "uuid", ")", ";", "}", "}", "if", "(", "!", "\\", "Config", "::", "get", "(", "self", "::", "DMS_MAX_UPLOAD_FILE_SIZE_KEY", ")", ")", "{", "\\", "System", "::", "log", "(", "'Setting default DMS max. upload file size to \"5 MB\".'", ",", "__METHOD__", ",", "TL_CONFIGURATION", ")", ";", "\\", "Config", "::", "persist", "(", "self", "::", "DMS_MAX_UPLOAD_FILE_SIZE_KEY", ",", "serialize", "(", "self", "::", "DMS_MAX_UPLOAD_FILE_SIZE_VALUE", ")", ")", ";", "}", "}" ]
Init the system setting Set base directoy, if not set
[ "Init", "the", "system", "setting", "Set", "base", "directoy", "if", "not", "set" ]
dd6856ac87fdc7fc93dc6274fad678e416712059
https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/config/initialize.php#L86-L136
train
FreeDSx/ASN1
src/FreeDSx/Asn1/Encoder/BerEncoder.php
BerEncoder.setTagMap
public function setTagMap(int $class, array $map) { if (isset($this->tagMap[$class])) { $this->tagMap[$class] = $map; } return $this; }
php
public function setTagMap(int $class, array $map) { if (isset($this->tagMap[$class])) { $this->tagMap[$class] = $map; } return $this; }
[ "public", "function", "setTagMap", "(", "int", "$", "class", ",", "array", "$", "map", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "tagMap", "[", "$", "class", "]", ")", ")", "{", "$", "this", "->", "tagMap", "[", "$", "class", "]", "=", "$", "map", ";", "}", "return", "$", "this", ";", "}" ]
Map universal types to specific tag class values when decoding. @param int $class @param array $map @return $this
[ "Map", "universal", "types", "to", "specific", "tag", "class", "values", "when", "decoding", "." ]
0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5
https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Encoder/BerEncoder.php#L211-L218
train
FreeDSx/ASN1
src/FreeDSx/Asn1/Encoder/BerEncoder.php
BerEncoder.setOptions
public function setOptions(array $options) { if (isset($options['bitstring_padding']) && \is_string($options['bitstring_padding'])) { $this->options['bitstring_padding'] = $options['bitstring_padding']; } return $this; }
php
public function setOptions(array $options) { if (isset($options['bitstring_padding']) && \is_string($options['bitstring_padding'])) { $this->options['bitstring_padding'] = $options['bitstring_padding']; } return $this; }
[ "public", "function", "setOptions", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'bitstring_padding'", "]", ")", "&&", "\\", "is_string", "(", "$", "options", "[", "'bitstring_padding'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'bitstring_padding'", "]", "=", "$", "options", "[", "'bitstring_padding'", "]", ";", "}", "return", "$", "this", ";", "}" ]
Set the options for the encoder. @param array $options @return $this
[ "Set", "the", "options", "for", "the", "encoder", "." ]
0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5
https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Encoder/BerEncoder.php#L236-L243
train
FreeDSx/ASN1
src/FreeDSx/Asn1/Encoder/BerEncoder.php
BerEncoder.getVlqBytesToInt
protected function getVlqBytesToInt() { $value = 0; $isBigInt = false; for ($this->pos; $this->pos < $this->maxLen; $this->pos++) { if (!$isBigInt) { $lshift = $value << 7; # An overflow bitshift will result in a negative number. This will check if GMP is available and flip it # to a bigint safe method in one shot. if ($lshift < 0) { $isBigInt = true; $this->throwIfBigIntGmpNeeded(true); $value = \gmp_init($value); } } if ($isBigInt) { $lshift = \gmp_mul($value, \gmp_pow('2', 7)); } $orVal = (\ord($this->binary[$this->pos]) & 0x7f); if ($isBigInt) { $value = \gmp_or($lshift, \gmp_init($orVal)); } else { $value = $lshift | $orVal; } # We have reached the last byte if the MSB is not set. if ((\ord($this->binary[$this->pos]) & 0x80) === 0) { $this->pos++; return $isBigInt ? \gmp_strval($value) : $value; } } throw new EncoderException('Expected an ending byte to decode a VLQ, but none was found.'); }
php
protected function getVlqBytesToInt() { $value = 0; $isBigInt = false; for ($this->pos; $this->pos < $this->maxLen; $this->pos++) { if (!$isBigInt) { $lshift = $value << 7; # An overflow bitshift will result in a negative number. This will check if GMP is available and flip it # to a bigint safe method in one shot. if ($lshift < 0) { $isBigInt = true; $this->throwIfBigIntGmpNeeded(true); $value = \gmp_init($value); } } if ($isBigInt) { $lshift = \gmp_mul($value, \gmp_pow('2', 7)); } $orVal = (\ord($this->binary[$this->pos]) & 0x7f); if ($isBigInt) { $value = \gmp_or($lshift, \gmp_init($orVal)); } else { $value = $lshift | $orVal; } # We have reached the last byte if the MSB is not set. if ((\ord($this->binary[$this->pos]) & 0x80) === 0) { $this->pos++; return $isBigInt ? \gmp_strval($value) : $value; } } throw new EncoderException('Expected an ending byte to decode a VLQ, but none was found.'); }
[ "protected", "function", "getVlqBytesToInt", "(", ")", "{", "$", "value", "=", "0", ";", "$", "isBigInt", "=", "false", ";", "for", "(", "$", "this", "->", "pos", ";", "$", "this", "->", "pos", "<", "$", "this", "->", "maxLen", ";", "$", "this", "->", "pos", "++", ")", "{", "if", "(", "!", "$", "isBigInt", ")", "{", "$", "lshift", "=", "$", "value", "<<", "7", ";", "# An overflow bitshift will result in a negative number. This will check if GMP is available and flip it", "# to a bigint safe method in one shot.", "if", "(", "$", "lshift", "<", "0", ")", "{", "$", "isBigInt", "=", "true", ";", "$", "this", "->", "throwIfBigIntGmpNeeded", "(", "true", ")", ";", "$", "value", "=", "\\", "gmp_init", "(", "$", "value", ")", ";", "}", "}", "if", "(", "$", "isBigInt", ")", "{", "$", "lshift", "=", "\\", "gmp_mul", "(", "$", "value", ",", "\\", "gmp_pow", "(", "'2'", ",", "7", ")", ")", ";", "}", "$", "orVal", "=", "(", "\\", "ord", "(", "$", "this", "->", "binary", "[", "$", "this", "->", "pos", "]", ")", "&", "0x7f", ")", ";", "if", "(", "$", "isBigInt", ")", "{", "$", "value", "=", "\\", "gmp_or", "(", "$", "lshift", ",", "\\", "gmp_init", "(", "$", "orVal", ")", ")", ";", "}", "else", "{", "$", "value", "=", "$", "lshift", "|", "$", "orVal", ";", "}", "# We have reached the last byte if the MSB is not set.", "if", "(", "(", "\\", "ord", "(", "$", "this", "->", "binary", "[", "$", "this", "->", "pos", "]", ")", "&", "0x80", ")", "===", "0", ")", "{", "$", "this", "->", "pos", "++", ";", "return", "$", "isBigInt", "?", "\\", "gmp_strval", "(", "$", "value", ")", ":", "$", "value", ";", "}", "}", "throw", "new", "EncoderException", "(", "'Expected an ending byte to decode a VLQ, but none was found.'", ")", ";", "}" ]
Given what should be VLQ bytes represent an int, get the int and the length of bytes. @return string|int @throws EncoderException
[ "Given", "what", "should", "be", "VLQ", "bytes", "represent", "an", "int", "get", "the", "int", "and", "the", "length", "of", "bytes", "." ]
0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5
https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Encoder/BerEncoder.php#L496-L529
train
FreeDSx/ASN1
src/FreeDSx/Asn1/Encoder/BerEncoder.php
BerEncoder.intToVlqBytes
protected function intToVlqBytes($int) { $bigint = \is_float($int + 0); $this->throwIfBigIntGmpNeeded($bigint); if ($bigint) { $int = \gmp_init($int); $bytes = \chr(\gmp_intval(\gmp_and(\gmp_init(0x7f), $int))); $int = \gmp_div($int, \gmp_pow(2, 7)); $intVal = \gmp_intval($int); } else { $bytes = \chr(0x7f & $int); $int >>= 7; $intVal = $int; } while ($intVal > 0) { if ($bigint) { $bytes = \chr(\gmp_intval(\gmp_or(\gmp_and(\gmp_init(0x7f), $int), \gmp_init(0x80)))).$bytes; $int = \gmp_div($int, \gmp_pow('2', 7)); $intVal = \gmp_intval($int); } else { $bytes = \chr((0x7f & $int) | 0x80).$bytes; $int >>= 7; $intVal = $int; } } return $bytes; }
php
protected function intToVlqBytes($int) { $bigint = \is_float($int + 0); $this->throwIfBigIntGmpNeeded($bigint); if ($bigint) { $int = \gmp_init($int); $bytes = \chr(\gmp_intval(\gmp_and(\gmp_init(0x7f), $int))); $int = \gmp_div($int, \gmp_pow(2, 7)); $intVal = \gmp_intval($int); } else { $bytes = \chr(0x7f & $int); $int >>= 7; $intVal = $int; } while ($intVal > 0) { if ($bigint) { $bytes = \chr(\gmp_intval(\gmp_or(\gmp_and(\gmp_init(0x7f), $int), \gmp_init(0x80)))).$bytes; $int = \gmp_div($int, \gmp_pow('2', 7)); $intVal = \gmp_intval($int); } else { $bytes = \chr((0x7f & $int) | 0x80).$bytes; $int >>= 7; $intVal = $int; } } return $bytes; }
[ "protected", "function", "intToVlqBytes", "(", "$", "int", ")", "{", "$", "bigint", "=", "\\", "is_float", "(", "$", "int", "+", "0", ")", ";", "$", "this", "->", "throwIfBigIntGmpNeeded", "(", "$", "bigint", ")", ";", "if", "(", "$", "bigint", ")", "{", "$", "int", "=", "\\", "gmp_init", "(", "$", "int", ")", ";", "$", "bytes", "=", "\\", "chr", "(", "\\", "gmp_intval", "(", "\\", "gmp_and", "(", "\\", "gmp_init", "(", "0x7f", ")", ",", "$", "int", ")", ")", ")", ";", "$", "int", "=", "\\", "gmp_div", "(", "$", "int", ",", "\\", "gmp_pow", "(", "2", ",", "7", ")", ")", ";", "$", "intVal", "=", "\\", "gmp_intval", "(", "$", "int", ")", ";", "}", "else", "{", "$", "bytes", "=", "\\", "chr", "(", "0x7f", "&", "$", "int", ")", ";", "$", "int", ">>=", "7", ";", "$", "intVal", "=", "$", "int", ";", "}", "while", "(", "$", "intVal", ">", "0", ")", "{", "if", "(", "$", "bigint", ")", "{", "$", "bytes", "=", "\\", "chr", "(", "\\", "gmp_intval", "(", "\\", "gmp_or", "(", "\\", "gmp_and", "(", "\\", "gmp_init", "(", "0x7f", ")", ",", "$", "int", ")", ",", "\\", "gmp_init", "(", "0x80", ")", ")", ")", ")", ".", "$", "bytes", ";", "$", "int", "=", "\\", "gmp_div", "(", "$", "int", ",", "\\", "gmp_pow", "(", "'2'", ",", "7", ")", ")", ";", "$", "intVal", "=", "\\", "gmp_intval", "(", "$", "int", ")", ";", "}", "else", "{", "$", "bytes", "=", "\\", "chr", "(", "(", "0x7f", "&", "$", "int", ")", "|", "0x80", ")", ".", "$", "bytes", ";", "$", "int", ">>=", "7", ";", "$", "intVal", "=", "$", "int", ";", "}", "}", "return", "$", "bytes", ";", "}" ]
Get the bytes that represent variable length quantity. @param string|int $int @return string @throws EncoderException
[ "Get", "the", "bytes", "that", "represent", "variable", "length", "quantity", "." ]
0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5
https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Encoder/BerEncoder.php#L538-L567
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/EventsController.php
EventsController.import
public function import(Event $event, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $event, 'tabs' => 'adminarea.events.tabs', 'url' => route('adminarea.events.stash'), 'id' => "adminarea-events-{$event->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function import(Event $event, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $event, 'tabs' => 'adminarea.events.tabs', 'url' => route('adminarea.events.stash'), 'id' => "adminarea-events-{$event->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "import", "(", "Event", "$", "event", ",", "ImportRecordsDataTable", "$", "importRecordsDataTable", ")", "{", "return", "$", "importRecordsDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "event", ",", "'tabs'", "=>", "'adminarea.events.tabs'", ",", "'url'", "=>", "route", "(", "'adminarea.events.stash'", ")", ",", "'id'", "=>", "\"adminarea-events-{$event->getRouteKey()}-import-table\"", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
Import events. @param \Cortex\Bookings\Models\Event $event @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable @return \Illuminate\View\View
[ "Import", "events", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/EventsController.php#L65-L73
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceBookingsController.php
ServiceBookingsController.import
public function import(Service $service, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $service, 'tabs' => 'adminarea.services.tabs', 'url' => route('adminarea.services.stash'), 'id' => "adminarea-services-{$service->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function import(Service $service, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $service, 'tabs' => 'adminarea.services.tabs', 'url' => route('adminarea.services.stash'), 'id' => "adminarea-services-{$service->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "import", "(", "Service", "$", "service", ",", "ImportRecordsDataTable", "$", "importRecordsDataTable", ")", "{", "return", "$", "importRecordsDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "service", ",", "'tabs'", "=>", "'adminarea.services.tabs'", ",", "'url'", "=>", "route", "(", "'adminarea.services.stash'", ")", ",", "'id'", "=>", "\"adminarea-services-{$service->getRouteKey()}-import-table\"", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
Import services. @param \Cortex\Bookings\Models\Service $service @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable @return \Illuminate\View\View
[ "Import", "services", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceBookingsController.php#L84-L92
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceBookingsController.php
ServiceBookingsController.hoard
public function hoard(ImportFormRequest $request) { foreach ((array) $request->get('selected_ids') as $recordId) { $record = app('cortex.foundation.import_record')->find($recordId); try { $fillable = collect($record['data'])->intersectByKeys(array_flip(app('rinvex.bookings.service')->getFillable()))->toArray(); tap(app('rinvex.bookings.service')->firstOrNew($fillable), function ($instance) use ($record) { $instance->save() && $record->delete(); }); } catch (Exception $exception) { $record->notes = $exception->getMessage().(method_exists($exception, 'getMessageBag') ? "\n".json_encode($exception->getMessageBag())."\n\n" : ''); $record->status = 'fail'; $record->save(); } } return intend([ 'back' => true, 'with' => ['success' => trans('cortex/foundation::messages.import_complete')], ]); }
php
public function hoard(ImportFormRequest $request) { foreach ((array) $request->get('selected_ids') as $recordId) { $record = app('cortex.foundation.import_record')->find($recordId); try { $fillable = collect($record['data'])->intersectByKeys(array_flip(app('rinvex.bookings.service')->getFillable()))->toArray(); tap(app('rinvex.bookings.service')->firstOrNew($fillable), function ($instance) use ($record) { $instance->save() && $record->delete(); }); } catch (Exception $exception) { $record->notes = $exception->getMessage().(method_exists($exception, 'getMessageBag') ? "\n".json_encode($exception->getMessageBag())."\n\n" : ''); $record->status = 'fail'; $record->save(); } } return intend([ 'back' => true, 'with' => ['success' => trans('cortex/foundation::messages.import_complete')], ]); }
[ "public", "function", "hoard", "(", "ImportFormRequest", "$", "request", ")", "{", "foreach", "(", "(", "array", ")", "$", "request", "->", "get", "(", "'selected_ids'", ")", "as", "$", "recordId", ")", "{", "$", "record", "=", "app", "(", "'cortex.foundation.import_record'", ")", "->", "find", "(", "$", "recordId", ")", ";", "try", "{", "$", "fillable", "=", "collect", "(", "$", "record", "[", "'data'", "]", ")", "->", "intersectByKeys", "(", "array_flip", "(", "app", "(", "'rinvex.bookings.service'", ")", "->", "getFillable", "(", ")", ")", ")", "->", "toArray", "(", ")", ";", "tap", "(", "app", "(", "'rinvex.bookings.service'", ")", "->", "firstOrNew", "(", "$", "fillable", ")", ",", "function", "(", "$", "instance", ")", "use", "(", "$", "record", ")", "{", "$", "instance", "->", "save", "(", ")", "&&", "$", "record", "->", "delete", "(", ")", ";", "}", ")", ";", "}", "catch", "(", "Exception", "$", "exception", ")", "{", "$", "record", "->", "notes", "=", "$", "exception", "->", "getMessage", "(", ")", ".", "(", "method_exists", "(", "$", "exception", ",", "'getMessageBag'", ")", "?", "\"\\n\"", ".", "json_encode", "(", "$", "exception", "->", "getMessageBag", "(", ")", ")", ".", "\"\\n\\n\"", ":", "''", ")", ";", "$", "record", "->", "status", "=", "'fail'", ";", "$", "record", "->", "save", "(", ")", ";", "}", "}", "return", "intend", "(", "[", "'back'", "=>", "true", ",", "'with'", "=>", "[", "'success'", "=>", "trans", "(", "'cortex/foundation::messages.import_complete'", ")", "]", ",", "]", ")", ";", "}" ]
Hoard services. @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Hoard", "services", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceBookingsController.php#L116-L138
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceBookingsController.php
ServiceBookingsController.update
public function update(BookingFormRequest $request, ServiceBooking $serviceBooking): int { return $this->process($request, $serviceBooking); }
php
public function update(BookingFormRequest $request, ServiceBooking $serviceBooking): int { return $this->process($request, $serviceBooking); }
[ "public", "function", "update", "(", "BookingFormRequest", "$", "request", ",", "ServiceBooking", "$", "serviceBooking", ")", ":", "int", "{", "return", "$", "this", "->", "process", "(", "$", "request", ",", "$", "serviceBooking", ")", ";", "}" ]
Update given booking. @param \Cortex\Bookings\Http\Requests\Adminarea\BookingFormRequest $request @param \Cortex\Bookings\Models\ServiceBooking $serviceBooking @return int
[ "Update", "given", "booking", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceBookingsController.php#L230-L233
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceBookingsController.php
ServiceBookingsController.destroy
public function destroy(Service $service, ServiceBooking $serviceBooking) { $service->bookings()->where($serviceBooking->getKeyName(), $serviceBooking->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.services.bookings.index'), 'with' => [ 'warning' => trans('cortex/foundation::messages.resource_deleted', [ 'resource' => trans('cortex/bookings::common.service_booking'), 'identifier' => $service->name.':'.$serviceBooking->id, ]), ], ]); return $serviceBooking->getKey(); }
php
public function destroy(Service $service, ServiceBooking $serviceBooking) { $service->bookings()->where($serviceBooking->getKeyName(), $serviceBooking->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.services.bookings.index'), 'with' => [ 'warning' => trans('cortex/foundation::messages.resource_deleted', [ 'resource' => trans('cortex/bookings::common.service_booking'), 'identifier' => $service->name.':'.$serviceBooking->id, ]), ], ]); return $serviceBooking->getKey(); }
[ "public", "function", "destroy", "(", "Service", "$", "service", ",", "ServiceBooking", "$", "serviceBooking", ")", "{", "$", "service", "->", "bookings", "(", ")", "->", "where", "(", "$", "serviceBooking", "->", "getKeyName", "(", ")", ",", "$", "serviceBooking", "->", "getKey", "(", ")", ")", "->", "first", "(", ")", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.services.bookings.index'", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/bookings::common.service_booking'", ")", ",", "'identifier'", "=>", "$", "service", "->", "name", ".", "':'", ".", "$", "serviceBooking", "->", "id", ",", "]", ")", ",", "]", ",", "]", ")", ";", "return", "$", "serviceBooking", "->", "getKey", "(", ")", ";", "}" ]
Destroy given booking. @param \Cortex\Bookings\Models\Service $service @param \Cortex\Bookings\Models\ServiceBooking $serviceBooking @throws \Exception @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "booking", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceBookingsController.php#L264-L279
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/EventBookingsController.php
EventBookingsController.import
public function import(Contact $contact, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $contact, 'tabs' => 'adminarea.contacts.tabs', 'url' => route('adminarea.contacts.stash'), 'id' => "adminarea-contacts-{$contact->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function import(Contact $contact, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $contact, 'tabs' => 'adminarea.contacts.tabs', 'url' => route('adminarea.contacts.stash'), 'id' => "adminarea-contacts-{$contact->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "import", "(", "Contact", "$", "contact", ",", "ImportRecordsDataTable", "$", "importRecordsDataTable", ")", "{", "return", "$", "importRecordsDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "contact", ",", "'tabs'", "=>", "'adminarea.contacts.tabs'", ",", "'url'", "=>", "route", "(", "'adminarea.contacts.stash'", ")", ",", "'id'", "=>", "\"adminarea-contacts-{$contact->getRouteKey()}-import-table\"", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
Import contacts. @TODO: Refactor required! Do we need import for bookings? Yes? refactor then! @param \Cortex\Contacts\Models\Contact $contact @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable @return \Illuminate\View\View
[ "Import", "contacts", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/EventBookingsController.php#L51-L59
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/EventBookingsController.php
EventBookingsController.stash
public function stash(ImportFormRequest $request, DefaultImporter $importer, Event $event) { // Handle the import $importer->config['resource'] = $this->resource; $importer->handleImport(); }
php
public function stash(ImportFormRequest $request, DefaultImporter $importer, Event $event) { // Handle the import $importer->config['resource'] = $this->resource; $importer->handleImport(); }
[ "public", "function", "stash", "(", "ImportFormRequest", "$", "request", ",", "DefaultImporter", "$", "importer", ",", "Event", "$", "event", ")", "{", "// Handle the import", "$", "importer", "->", "config", "[", "'resource'", "]", "=", "$", "this", "->", "resource", ";", "$", "importer", "->", "handleImport", "(", ")", ";", "}" ]
Stash events. @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request @param \Cortex\Foundation\Importers\DefaultImporter $importer @param \Cortex\Bookings\Models\Event $event @return void
[ "Stash", "events", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/EventBookingsController.php#L70-L75
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/EventMediaController.php
EventMediaController.index
public function index(Event $event, MediaDataTable $mediaDataTable) { return $mediaDataTable->with([ 'resource' => $event, 'tabs' => 'adminarea.events.tabs', 'id' => "adminarea-events-{$event->getRouteKey()}-media-table", 'url' => route('adminarea.events.media.store', ['event' => $event]), ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function index(Event $event, MediaDataTable $mediaDataTable) { return $mediaDataTable->with([ 'resource' => $event, 'tabs' => 'adminarea.events.tabs', 'id' => "adminarea-events-{$event->getRouteKey()}-media-table", 'url' => route('adminarea.events.media.store', ['event' => $event]), ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "index", "(", "Event", "$", "event", ",", "MediaDataTable", "$", "mediaDataTable", ")", "{", "return", "$", "mediaDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "event", ",", "'tabs'", "=>", "'adminarea.events.tabs'", ",", "'id'", "=>", "\"adminarea-events-{$event->getRouteKey()}-media-table\"", ",", "'url'", "=>", "route", "(", "'adminarea.events.media.store'", ",", "[", "'event'", "=>", "$", "event", "]", ")", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
List event media. @param \Cortex\Bookings\Models\Event $event @param \Cortex\Foundation\DataTables\MediaDataTable $mediaDataTable @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "List", "event", "media", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/EventMediaController.php#L48-L56
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/EventMediaController.php
EventMediaController.store
public function store(ImageFormRequest $request, Event $event): void { $event->addMediaFromRequest('file') ->sanitizingFileName(function ($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) ->toMediaCollection('default', config('cortex.bookings.media.disk')); }
php
public function store(ImageFormRequest $request, Event $event): void { $event->addMediaFromRequest('file') ->sanitizingFileName(function ($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) ->toMediaCollection('default', config('cortex.bookings.media.disk')); }
[ "public", "function", "store", "(", "ImageFormRequest", "$", "request", ",", "Event", "$", "event", ")", ":", "void", "{", "$", "event", "->", "addMediaFromRequest", "(", "'file'", ")", "->", "sanitizingFileName", "(", "function", "(", "$", "fileName", ")", "{", "return", "md5", "(", "$", "fileName", ")", ".", "'.'", ".", "pathinfo", "(", "$", "fileName", ",", "PATHINFO_EXTENSION", ")", ";", "}", ")", "->", "toMediaCollection", "(", "'default'", ",", "config", "(", "'cortex.bookings.media.disk'", ")", ")", ";", "}" ]
Store new event media. @param \Cortex\Foundation\Http\Requests\ImageFormRequest $request @param \Cortex\Bookings\Models\Event $event @return void
[ "Store", "new", "event", "media", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/EventMediaController.php#L66-L73
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/EventMediaController.php
EventMediaController.destroy
public function destroy(Event $event, Media $media) { $event->media()->where($media->getKeyName(), $media->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.events.media.index', ['event' => $event]), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])], ]); }
php
public function destroy(Event $event, Media $media) { $event->media()->where($media->getKeyName(), $media->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.events.media.index', ['event' => $event]), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])], ]); }
[ "public", "function", "destroy", "(", "Event", "$", "event", ",", "Media", "$", "media", ")", "{", "$", "event", "->", "media", "(", ")", "->", "where", "(", "$", "media", "->", "getKeyName", "(", ")", ",", "$", "media", "->", "getKey", "(", ")", ")", "->", "first", "(", ")", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.events.media.index'", ",", "[", "'event'", "=>", "$", "event", "]", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/foundation::common.media'", ")", ",", "'identifier'", "=>", "$", "media", "->", "getRouteKey", "(", ")", "]", ")", "]", ",", "]", ")", ";", "}" ]
Destroy given event media. @param \Cortex\Bookings\Models\Event $event @param \Spatie\MediaLibrary\Models\Media $media @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "event", "media", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/EventMediaController.php#L83-L91
train
ArkEcosystem/php-client
src/ConnectionManager.php
ConnectionManager.connect
public function connect(array $config, string $name = 'main'): Connection { if (isset($this->connections[$name])) { throw new InvalidArgumentException("Connection [$name] is already configured."); } $this->connections[$name] = new Connection($config); return $this->connections[$name]; }
php
public function connect(array $config, string $name = 'main'): Connection { if (isset($this->connections[$name])) { throw new InvalidArgumentException("Connection [$name] is already configured."); } $this->connections[$name] = new Connection($config); return $this->connections[$name]; }
[ "public", "function", "connect", "(", "array", "$", "config", ",", "string", "$", "name", "=", "'main'", ")", ":", "Connection", "{", "if", "(", "isset", "(", "$", "this", "->", "connections", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Connection [$name] is already configured.\"", ")", ";", "}", "$", "this", "->", "connections", "[", "$", "name", "]", "=", "new", "Connection", "(", "$", "config", ")", ";", "return", "$", "this", "->", "connections", "[", "$", "name", "]", ";", "}" ]
Connect to the given connection. @param array $config @param string $name @return \ArkEcosystem\Client\Connection
[ "Connect", "to", "the", "given", "connection", "." ]
9ea15b72e2fdc959f1810bbd1394c334ea6c2a8b
https://github.com/ArkEcosystem/php-client/blob/9ea15b72e2fdc959f1810bbd1394c334ea6c2a8b/src/ConnectionManager.php#L47-L56
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServicesController.php
ServicesController.destroy
public function destroy(Service $service) { $service->delete(); return intend([ 'url' => route('adminarea.services.index'), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/bookings::common.service'), 'identifier' => $service->name])], ]); }
php
public function destroy(Service $service) { $service->delete(); return intend([ 'url' => route('adminarea.services.index'), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/bookings::common.service'), 'identifier' => $service->name])], ]); }
[ "public", "function", "destroy", "(", "Service", "$", "service", ")", "{", "$", "service", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.services.index'", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/bookings::common.service'", ")", ",", "'identifier'", "=>", "$", "service", "->", "name", "]", ")", "]", ",", "]", ")", ";", "}" ]
Destroy given service. @param \Cortex\Bookings\Models\Service $service @throws \Exception @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "service", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServicesController.php#L286-L294
train
ArkEcosystem/php-client
src/Connection.php
Connection.api
public function api(string $name): API\AbstractAPI { $name = ucfirst($name); $class = "ArkEcosystem\\Client\\API\\{$name}"; if (! class_exists($class)) { throw new RuntimeException("Class [$class] does not exist."); } return new $class($this); }
php
public function api(string $name): API\AbstractAPI { $name = ucfirst($name); $class = "ArkEcosystem\\Client\\API\\{$name}"; if (! class_exists($class)) { throw new RuntimeException("Class [$class] does not exist."); } return new $class($this); }
[ "public", "function", "api", "(", "string", "$", "name", ")", ":", "API", "\\", "AbstractAPI", "{", "$", "name", "=", "ucfirst", "(", "$", "name", ")", ";", "$", "class", "=", "\"ArkEcosystem\\\\Client\\\\API\\\\{$name}\"", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Class [$class] does not exist.\"", ")", ";", "}", "return", "new", "$", "class", "(", "$", "this", ")", ";", "}" ]
Make a new resource instance. @param string $name @return \ArkEcosystem\Client\API\AbstractAPI
[ "Make", "a", "new", "resource", "instance", "." ]
9ea15b72e2fdc959f1810bbd1394c334ea6c2a8b
https://github.com/ArkEcosystem/php-client/blob/9ea15b72e2fdc959f1810bbd1394c334ea6c2a8b/src/Connection.php#L82-L92
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceMediaController.php
ServiceMediaController.index
public function index(Service $service, MediaDataTable $mediaDataTable) { return $mediaDataTable->with([ 'resource' => $service, 'tabs' => 'adminarea.services.tabs', 'id' => "adminarea-services-{$service->getRouteKey()}-media-table", 'url' => route('adminarea.services.media.store', ['service' => $service]), ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function index(Service $service, MediaDataTable $mediaDataTable) { return $mediaDataTable->with([ 'resource' => $service, 'tabs' => 'adminarea.services.tabs', 'id' => "adminarea-services-{$service->getRouteKey()}-media-table", 'url' => route('adminarea.services.media.store', ['service' => $service]), ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "index", "(", "Service", "$", "service", ",", "MediaDataTable", "$", "mediaDataTable", ")", "{", "return", "$", "mediaDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "service", ",", "'tabs'", "=>", "'adminarea.services.tabs'", ",", "'id'", "=>", "\"adminarea-services-{$service->getRouteKey()}-media-table\"", ",", "'url'", "=>", "route", "(", "'adminarea.services.media.store'", ",", "[", "'service'", "=>", "$", "service", "]", ")", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
List service media. @param \Cortex\Bookings\Models\Service $service @param \Cortex\Foundation\DataTables\MediaDataTable $mediaDataTable @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "List", "service", "media", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceMediaController.php#L48-L56
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceMediaController.php
ServiceMediaController.store
public function store(ImageFormRequest $request, Service $service): void { $service->addMediaFromRequest('file') ->sanitizingFileName(function ($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) ->toMediaCollection('default', config('cortex.bookings.media.disk')); }
php
public function store(ImageFormRequest $request, Service $service): void { $service->addMediaFromRequest('file') ->sanitizingFileName(function ($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) ->toMediaCollection('default', config('cortex.bookings.media.disk')); }
[ "public", "function", "store", "(", "ImageFormRequest", "$", "request", ",", "Service", "$", "service", ")", ":", "void", "{", "$", "service", "->", "addMediaFromRequest", "(", "'file'", ")", "->", "sanitizingFileName", "(", "function", "(", "$", "fileName", ")", "{", "return", "md5", "(", "$", "fileName", ")", ".", "'.'", ".", "pathinfo", "(", "$", "fileName", ",", "PATHINFO_EXTENSION", ")", ";", "}", ")", "->", "toMediaCollection", "(", "'default'", ",", "config", "(", "'cortex.bookings.media.disk'", ")", ")", ";", "}" ]
Store new service media. @param \Cortex\Foundation\Http\Requests\ImageFormRequest $request @param \Cortex\Bookings\Models\Service $service @return void
[ "Store", "new", "service", "media", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceMediaController.php#L66-L73
train
rinvex/cortex-bookings
src/Http/Controllers/Adminarea/ServiceMediaController.php
ServiceMediaController.destroy
public function destroy(Service $service, Media $media) { $service->media()->where($media->getKeyName(), $media->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.services.media.index', ['service' => $service]), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])], ]); }
php
public function destroy(Service $service, Media $media) { $service->media()->where($media->getKeyName(), $media->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.services.media.index', ['service' => $service]), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])], ]); }
[ "public", "function", "destroy", "(", "Service", "$", "service", ",", "Media", "$", "media", ")", "{", "$", "service", "->", "media", "(", ")", "->", "where", "(", "$", "media", "->", "getKeyName", "(", ")", ",", "$", "media", "->", "getKey", "(", ")", ")", "->", "first", "(", ")", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.services.media.index'", ",", "[", "'service'", "=>", "$", "service", "]", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/foundation::common.media'", ")", ",", "'identifier'", "=>", "$", "media", "->", "getRouteKey", "(", ")", "]", ")", "]", ",", "]", ")", ";", "}" ]
Destroy given service media. @param \Cortex\Bookings\Models\Service $service @param \Spatie\MediaLibrary\Models\Media $media @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "service", "media", "." ]
059d48faf856aae4f640db3d746a615286af477f
https://github.com/rinvex/cortex-bookings/blob/059d48faf856aae4f640db3d746a615286af477f/src/Http/Controllers/Adminarea/ServiceMediaController.php#L83-L91
train
kg-bot/laravel-localization-to-vue
src/Classes/ExportLocalizations.php
ExportLocalizations.export
public function export() { // Check if value is cached and set array to cached version if (Cache::has(config('laravel-localization.caches.key'))) { $this->strings = Cache::get(config('laravel-localization.caches.key')); return $this; } foreach (config('laravel-localization.paths.lang_dirs') as $dir) { try { // Collect language files and build array with translations $files = $this->findLanguageFiles($dir); // Parse translations and create final array array_walk($files['lang'], [$this, 'parseLangFiles'], $dir); array_walk($files['vendor'], [$this, 'parseVendorFiles'], $dir); array_walk($files['json'], [$this, 'parseJsonFiles'], $dir); } catch (\Exception $exception) { \Log::critical('Can\'t read lang directory '.$dir.', error: '.$exception->getMessage()); } } // Trigger event for final translated array event(new LaravelLocalizationExported($this->strings)); // If timeout > 0 save array to cache if (config('laravel-localization.caches.timeout', 0) > 0) { Cache::store(config('laravel-localization.caches.driver', 'file')) ->put( config('laravel-localization.caches.key', 'localization.array'), $this->strings, config('laravel-localization.caches.timeout', 60) ); } return $this; }
php
public function export() { // Check if value is cached and set array to cached version if (Cache::has(config('laravel-localization.caches.key'))) { $this->strings = Cache::get(config('laravel-localization.caches.key')); return $this; } foreach (config('laravel-localization.paths.lang_dirs') as $dir) { try { // Collect language files and build array with translations $files = $this->findLanguageFiles($dir); // Parse translations and create final array array_walk($files['lang'], [$this, 'parseLangFiles'], $dir); array_walk($files['vendor'], [$this, 'parseVendorFiles'], $dir); array_walk($files['json'], [$this, 'parseJsonFiles'], $dir); } catch (\Exception $exception) { \Log::critical('Can\'t read lang directory '.$dir.', error: '.$exception->getMessage()); } } // Trigger event for final translated array event(new LaravelLocalizationExported($this->strings)); // If timeout > 0 save array to cache if (config('laravel-localization.caches.timeout', 0) > 0) { Cache::store(config('laravel-localization.caches.driver', 'file')) ->put( config('laravel-localization.caches.key', 'localization.array'), $this->strings, config('laravel-localization.caches.timeout', 60) ); } return $this; }
[ "public", "function", "export", "(", ")", "{", "// Check if value is cached and set array to cached version", "if", "(", "Cache", "::", "has", "(", "config", "(", "'laravel-localization.caches.key'", ")", ")", ")", "{", "$", "this", "->", "strings", "=", "Cache", "::", "get", "(", "config", "(", "'laravel-localization.caches.key'", ")", ")", ";", "return", "$", "this", ";", "}", "foreach", "(", "config", "(", "'laravel-localization.paths.lang_dirs'", ")", "as", "$", "dir", ")", "{", "try", "{", "// Collect language files and build array with translations", "$", "files", "=", "$", "this", "->", "findLanguageFiles", "(", "$", "dir", ")", ";", "// Parse translations and create final array", "array_walk", "(", "$", "files", "[", "'lang'", "]", ",", "[", "$", "this", ",", "'parseLangFiles'", "]", ",", "$", "dir", ")", ";", "array_walk", "(", "$", "files", "[", "'vendor'", "]", ",", "[", "$", "this", ",", "'parseVendorFiles'", "]", ",", "$", "dir", ")", ";", "array_walk", "(", "$", "files", "[", "'json'", "]", ",", "[", "$", "this", ",", "'parseJsonFiles'", "]", ",", "$", "dir", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "\\", "Log", "::", "critical", "(", "'Can\\'t read lang directory '", ".", "$", "dir", ".", "', error: '", ".", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "}", "}", "// Trigger event for final translated array", "event", "(", "new", "LaravelLocalizationExported", "(", "$", "this", "->", "strings", ")", ")", ";", "// If timeout > 0 save array to cache", "if", "(", "config", "(", "'laravel-localization.caches.timeout'", ",", "0", ")", ">", "0", ")", "{", "Cache", "::", "store", "(", "config", "(", "'laravel-localization.caches.driver'", ",", "'file'", ")", ")", "->", "put", "(", "config", "(", "'laravel-localization.caches.key'", ",", "'localization.array'", ")", ",", "$", "this", "->", "strings", ",", "config", "(", "'laravel-localization.caches.timeout'", ",", "60", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Method to return generate array with contents of parsed language files. @return object
[ "Method", "to", "return", "generate", "array", "with", "contents", "of", "parsed", "language", "files", "." ]
73994b7e613980dad249a92e2f540810f9a620a9
https://github.com/kg-bot/laravel-localization-to-vue/blob/73994b7e613980dad249a92e2f540810f9a620a9/src/Classes/ExportLocalizations.php#L46-L84
train
kg-bot/laravel-localization-to-vue
src/Classes/ExportLocalizations.php
ExportLocalizations.findLanguageFiles
protected function findLanguageFiles($path) { // Loop through directories $dirIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); $recIterator = new \RecursiveIteratorIterator($dirIterator); // Fetch only php files - skip others $phpFiles = array_values( array_map('current', iterator_to_array( new \RegexIterator($recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH) ) ) ); $jsonFiles = array_values( array_map('current', iterator_to_array( new \RegexIterator($recIterator, $this->jsonRegex, \RecursiveRegexIterator::GET_MATCH) ) ) ); $files = array_merge($phpFiles, $jsonFiles); // Sort array by filepath sort($files); // Remove full path from items array_walk($files, function (&$item) use ($path) { $item = str_replace($path, '', $item); }); // Fetch non-vendor files from filtered php files $nonVendorFiles = array_filter($files, function ($file) { return strpos($file, $this->excludePath) === false && strpos($file, '.json') === false; }); // Fetch vendor files from filtered php files $vendorFiles = array_filter(array_diff($files, $nonVendorFiles), function ($file) { return strpos($file, 'json') === false; }); // Fetch .json files from filtered files $jsonFiles = array_filter($files, function ($file) { return strpos($file, '.json') !== false; }); return [ 'lang' => array_values($nonVendorFiles), 'vendor' => array_values($vendorFiles), 'json' => array_values($jsonFiles), ]; }
php
protected function findLanguageFiles($path) { // Loop through directories $dirIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); $recIterator = new \RecursiveIteratorIterator($dirIterator); // Fetch only php files - skip others $phpFiles = array_values( array_map('current', iterator_to_array( new \RegexIterator($recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH) ) ) ); $jsonFiles = array_values( array_map('current', iterator_to_array( new \RegexIterator($recIterator, $this->jsonRegex, \RecursiveRegexIterator::GET_MATCH) ) ) ); $files = array_merge($phpFiles, $jsonFiles); // Sort array by filepath sort($files); // Remove full path from items array_walk($files, function (&$item) use ($path) { $item = str_replace($path, '', $item); }); // Fetch non-vendor files from filtered php files $nonVendorFiles = array_filter($files, function ($file) { return strpos($file, $this->excludePath) === false && strpos($file, '.json') === false; }); // Fetch vendor files from filtered php files $vendorFiles = array_filter(array_diff($files, $nonVendorFiles), function ($file) { return strpos($file, 'json') === false; }); // Fetch .json files from filtered files $jsonFiles = array_filter($files, function ($file) { return strpos($file, '.json') !== false; }); return [ 'lang' => array_values($nonVendorFiles), 'vendor' => array_values($vendorFiles), 'json' => array_values($jsonFiles), ]; }
[ "protected", "function", "findLanguageFiles", "(", "$", "path", ")", "{", "// Loop through directories", "$", "dirIterator", "=", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "path", ",", "\\", "RecursiveDirectoryIterator", "::", "SKIP_DOTS", ")", ";", "$", "recIterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "$", "dirIterator", ")", ";", "// Fetch only php files - skip others", "$", "phpFiles", "=", "array_values", "(", "array_map", "(", "'current'", ",", "iterator_to_array", "(", "new", "\\", "RegexIterator", "(", "$", "recIterator", ",", "$", "this", "->", "phpRegex", ",", "\\", "RecursiveRegexIterator", "::", "GET_MATCH", ")", ")", ")", ")", ";", "$", "jsonFiles", "=", "array_values", "(", "array_map", "(", "'current'", ",", "iterator_to_array", "(", "new", "\\", "RegexIterator", "(", "$", "recIterator", ",", "$", "this", "->", "jsonRegex", ",", "\\", "RecursiveRegexIterator", "::", "GET_MATCH", ")", ")", ")", ")", ";", "$", "files", "=", "array_merge", "(", "$", "phpFiles", ",", "$", "jsonFiles", ")", ";", "// Sort array by filepath", "sort", "(", "$", "files", ")", ";", "// Remove full path from items", "array_walk", "(", "$", "files", ",", "function", "(", "&", "$", "item", ")", "use", "(", "$", "path", ")", "{", "$", "item", "=", "str_replace", "(", "$", "path", ",", "''", ",", "$", "item", ")", ";", "}", ")", ";", "// Fetch non-vendor files from filtered php files", "$", "nonVendorFiles", "=", "array_filter", "(", "$", "files", ",", "function", "(", "$", "file", ")", "{", "return", "strpos", "(", "$", "file", ",", "$", "this", "->", "excludePath", ")", "===", "false", "&&", "strpos", "(", "$", "file", ",", "'.json'", ")", "===", "false", ";", "}", ")", ";", "// Fetch vendor files from filtered php files", "$", "vendorFiles", "=", "array_filter", "(", "array_diff", "(", "$", "files", ",", "$", "nonVendorFiles", ")", ",", "function", "(", "$", "file", ")", "{", "return", "strpos", "(", "$", "file", ",", "'json'", ")", "===", "false", ";", "}", ")", ";", "// Fetch .json files from filtered files", "$", "jsonFiles", "=", "array_filter", "(", "$", "files", ",", "function", "(", "$", "file", ")", "{", "return", "strpos", "(", "$", "file", ",", "'.json'", ")", "!==", "false", ";", "}", ")", ";", "return", "[", "'lang'", "=>", "array_values", "(", "$", "nonVendorFiles", ")", ",", "'vendor'", "=>", "array_values", "(", "$", "vendorFiles", ")", ",", "'json'", "=>", "array_values", "(", "$", "jsonFiles", ")", ",", "]", ";", "}" ]
Find available language files and parse them to array. @param string $path @return array
[ "Find", "available", "language", "files", "and", "parse", "them", "to", "array", "." ]
73994b7e613980dad249a92e2f540810f9a620a9
https://github.com/kg-bot/laravel-localization-to-vue/blob/73994b7e613980dad249a92e2f540810f9a620a9/src/Classes/ExportLocalizations.php#L93-L146
train
kg-bot/laravel-localization-to-vue
src/Classes/ExportLocalizations.php
ExportLocalizations.parseLangFiles
protected function parseLangFiles($file, $key, $dir) { // Base package name without file ending $packageName = basename($file, '.php'); // Get package, language and file contents from language file // /<language_code>/(<package/)<filename>.php $language = explode(DIRECTORY_SEPARATOR, $file)[1]; $fileContents = require $dir.DIRECTORY_SEPARATOR.$file; // Check if language already exists in array if (array_key_exists($language, $this->strings)) { if (array_key_exists($packageName, $this->strings[$language])) { $this->strings[$language][$packageName] = array_replace_recursive((array) $this->strings[$language][$packageName], (array) $fileContents); } else { $this->strings[$language][$packageName] = $fileContents; } } else { $this->strings[$language] = [ $packageName => $fileContents, ]; } }
php
protected function parseLangFiles($file, $key, $dir) { // Base package name without file ending $packageName = basename($file, '.php'); // Get package, language and file contents from language file // /<language_code>/(<package/)<filename>.php $language = explode(DIRECTORY_SEPARATOR, $file)[1]; $fileContents = require $dir.DIRECTORY_SEPARATOR.$file; // Check if language already exists in array if (array_key_exists($language, $this->strings)) { if (array_key_exists($packageName, $this->strings[$language])) { $this->strings[$language][$packageName] = array_replace_recursive((array) $this->strings[$language][$packageName], (array) $fileContents); } else { $this->strings[$language][$packageName] = $fileContents; } } else { $this->strings[$language] = [ $packageName => $fileContents, ]; } }
[ "protected", "function", "parseLangFiles", "(", "$", "file", ",", "$", "key", ",", "$", "dir", ")", "{", "// Base package name without file ending", "$", "packageName", "=", "basename", "(", "$", "file", ",", "'.php'", ")", ";", "// Get package, language and file contents from language file", "// /<language_code>/(<package/)<filename>.php", "$", "language", "=", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "file", ")", "[", "1", "]", ";", "$", "fileContents", "=", "require", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ";", "// Check if language already exists in array", "if", "(", "array_key_exists", "(", "$", "language", ",", "$", "this", "->", "strings", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "packageName", ",", "$", "this", "->", "strings", "[", "$", "language", "]", ")", ")", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "packageName", "]", "=", "array_replace_recursive", "(", "(", "array", ")", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "packageName", "]", ",", "(", "array", ")", "$", "fileContents", ")", ";", "}", "else", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "packageName", "]", "=", "$", "fileContents", ";", "}", "}", "else", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "=", "[", "$", "packageName", "=>", "$", "fileContents", ",", "]", ";", "}", "}" ]
Method to parse language files. @param string $file
[ "Method", "to", "parse", "language", "files", "." ]
73994b7e613980dad249a92e2f540810f9a620a9
https://github.com/kg-bot/laravel-localization-to-vue/blob/73994b7e613980dad249a92e2f540810f9a620a9/src/Classes/ExportLocalizations.php#L234-L258
train
kg-bot/laravel-localization-to-vue
src/Classes/ExportLocalizations.php
ExportLocalizations.parseVendorFiles
protected function parseVendorFiles($file, $key, $dir) { // Base package name without file ending $packageName = basename($file, '.php'); // Get package, language and file contents from language file // /vendor/<package>/<language_code>/<filename>.php $package = explode(DIRECTORY_SEPARATOR, $file)[2]; $language = explode(DIRECTORY_SEPARATOR, $file)[3]; $fileContents = require $dir.DIRECTORY_SEPARATOR.$file; // Check if language already exists in array if (array_key_exists($language, $this->strings)) { // Check if package already exists in language if (array_key_exists($package, $this->strings[$language])) { if (array_key_exists($packageName, $this->strings[$language][$package])) { $this->strings[$language][$package][$packageName] = array_replace_recursive((array) $this->strings[$language][$package][$packageName], (array) $fileContents); } else { $this->strings[$language][$package][$packageName] = $fileContents; } } else { $this->strings[$language][$package] = [$packageName => $fileContents]; } } else { $this->strings[$language] = [ $package => [ $packageName => $fileContents, ], ]; } }
php
protected function parseVendorFiles($file, $key, $dir) { // Base package name without file ending $packageName = basename($file, '.php'); // Get package, language and file contents from language file // /vendor/<package>/<language_code>/<filename>.php $package = explode(DIRECTORY_SEPARATOR, $file)[2]; $language = explode(DIRECTORY_SEPARATOR, $file)[3]; $fileContents = require $dir.DIRECTORY_SEPARATOR.$file; // Check if language already exists in array if (array_key_exists($language, $this->strings)) { // Check if package already exists in language if (array_key_exists($package, $this->strings[$language])) { if (array_key_exists($packageName, $this->strings[$language][$package])) { $this->strings[$language][$package][$packageName] = array_replace_recursive((array) $this->strings[$language][$package][$packageName], (array) $fileContents); } else { $this->strings[$language][$package][$packageName] = $fileContents; } } else { $this->strings[$language][$package] = [$packageName => $fileContents]; } } else { $this->strings[$language] = [ $package => [ $packageName => $fileContents, ], ]; } }
[ "protected", "function", "parseVendorFiles", "(", "$", "file", ",", "$", "key", ",", "$", "dir", ")", "{", "// Base package name without file ending", "$", "packageName", "=", "basename", "(", "$", "file", ",", "'.php'", ")", ";", "// Get package, language and file contents from language file", "// /vendor/<package>/<language_code>/<filename>.php", "$", "package", "=", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "file", ")", "[", "2", "]", ";", "$", "language", "=", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "file", ")", "[", "3", "]", ";", "$", "fileContents", "=", "require", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ";", "// Check if language already exists in array", "if", "(", "array_key_exists", "(", "$", "language", ",", "$", "this", "->", "strings", ")", ")", "{", "// Check if package already exists in language", "if", "(", "array_key_exists", "(", "$", "package", ",", "$", "this", "->", "strings", "[", "$", "language", "]", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "packageName", ",", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "package", "]", ")", ")", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "package", "]", "[", "$", "packageName", "]", "=", "array_replace_recursive", "(", "(", "array", ")", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "package", "]", "[", "$", "packageName", "]", ",", "(", "array", ")", "$", "fileContents", ")", ";", "}", "else", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "package", "]", "[", "$", "packageName", "]", "=", "$", "fileContents", ";", "}", "}", "else", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "[", "$", "package", "]", "=", "[", "$", "packageName", "=>", "$", "fileContents", "]", ";", "}", "}", "else", "{", "$", "this", "->", "strings", "[", "$", "language", "]", "=", "[", "$", "package", "=>", "[", "$", "packageName", "=>", "$", "fileContents", ",", "]", ",", "]", ";", "}", "}" ]
Method to parse language files from vendor folder. @param string $file
[ "Method", "to", "parse", "language", "files", "from", "vendor", "folder", "." ]
73994b7e613980dad249a92e2f540810f9a620a9
https://github.com/kg-bot/laravel-localization-to-vue/blob/73994b7e613980dad249a92e2f540810f9a620a9/src/Classes/ExportLocalizations.php#L265-L300
train
dafiti-group/dto-url
src/DTOUrl/Url.php
Url.getFullUrl
public function getFullUrl() { $parts = $this->toArray(); unset($parts['full_url'], $parts['pass']); foreach ($parts as $method => $param) { if ($param) { $method = 'add' . ucfirst($method); $this->$method($param); } } return ltrim(implode($this->fullUrl), '/'); }
php
public function getFullUrl() { $parts = $this->toArray(); unset($parts['full_url'], $parts['pass']); foreach ($parts as $method => $param) { if ($param) { $method = 'add' . ucfirst($method); $this->$method($param); } } return ltrim(implode($this->fullUrl), '/'); }
[ "public", "function", "getFullUrl", "(", ")", "{", "$", "parts", "=", "$", "this", "->", "toArray", "(", ")", ";", "unset", "(", "$", "parts", "[", "'full_url'", "]", ",", "$", "parts", "[", "'pass'", "]", ")", ";", "foreach", "(", "$", "parts", "as", "$", "method", "=>", "$", "param", ")", "{", "if", "(", "$", "param", ")", "{", "$", "method", "=", "'add'", ".", "ucfirst", "(", "$", "method", ")", ";", "$", "this", "->", "$", "method", "(", "$", "param", ")", ";", "}", "}", "return", "ltrim", "(", "implode", "(", "$", "this", "->", "fullUrl", ")", ",", "'/'", ")", ";", "}" ]
Build the final url based on the structure defined @return string
[ "Build", "the", "final", "url", "based", "on", "the", "structure", "defined" ]
343fb8061223b053eb1c086ac9a0b87dfd919f4e
https://github.com/dafiti-group/dto-url/blob/343fb8061223b053eb1c086ac9a0b87dfd919f4e/src/DTOUrl/Url.php#L92-L105
train
dafiti-group/dto-url
src/DTOUrl/Url.php
Url.addUser
public function addUser($user) { //only add the information if there are username and password if ($user && $this->getPass()) { $this->fullUrl['credentials'] = $user . ':' . $this->getPass() . '@'; } return $this; }
php
public function addUser($user) { //only add the information if there are username and password if ($user && $this->getPass()) { $this->fullUrl['credentials'] = $user . ':' . $this->getPass() . '@'; } return $this; }
[ "public", "function", "addUser", "(", "$", "user", ")", "{", "//only add the information if there are username and password", "if", "(", "$", "user", "&&", "$", "this", "->", "getPass", "(", ")", ")", "{", "$", "this", "->", "fullUrl", "[", "'credentials'", "]", "=", "$", "user", ".", "':'", ".", "$", "this", "->", "getPass", "(", ")", ".", "'@'", ";", "}", "return", "$", "this", ";", "}" ]
Add the credentials to the final url, both username and password are added in this stage @param string $user @return Url
[ "Add", "the", "credentials", "to", "the", "final", "url", "both", "username", "and", "password", "are", "added", "in", "this", "stage" ]
343fb8061223b053eb1c086ac9a0b87dfd919f4e
https://github.com/dafiti-group/dto-url/blob/343fb8061223b053eb1c086ac9a0b87dfd919f4e/src/DTOUrl/Url.php#L150-L158
train
dafiti-group/dto-url
src/DTOUrl/Url.php
Url.addQuery
public function addQuery(array $query) { $queryParts = []; foreach ($query as $key => $value) { $queryParts[] = "{$key}={$value}"; } $this->fullUrl['query'] = '?' . implode('&', $queryParts); return $this; }
php
public function addQuery(array $query) { $queryParts = []; foreach ($query as $key => $value) { $queryParts[] = "{$key}={$value}"; } $this->fullUrl['query'] = '?' . implode('&', $queryParts); return $this; }
[ "public", "function", "addQuery", "(", "array", "$", "query", ")", "{", "$", "queryParts", "=", "[", "]", ";", "foreach", "(", "$", "query", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "queryParts", "[", "]", "=", "\"{$key}={$value}\"", ";", "}", "$", "this", "->", "fullUrl", "[", "'query'", "]", "=", "'?'", ".", "implode", "(", "'&'", ",", "$", "queryParts", ")", ";", "return", "$", "this", ";", "}" ]
Add query string to the final url @param array $query @return Url
[ "Add", "query", "string", "to", "the", "final", "url" ]
343fb8061223b053eb1c086ac9a0b87dfd919f4e
https://github.com/dafiti-group/dto-url/blob/343fb8061223b053eb1c086ac9a0b87dfd919f4e/src/DTOUrl/Url.php#L178-L188
train
rokka-io/rokka-client-php
src/DynamicMetadataHelper.php
DynamicMetadataHelper.getDynamicMetadataClassName
public static function getDynamicMetadataClassName($name) { // Convert to a CamelCase class name. // See Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::denormalize() $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $name); return 'Rokka\Client\Core\DynamicMetadata\\'.$camelCasedName; }
php
public static function getDynamicMetadataClassName($name) { // Convert to a CamelCase class name. // See Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::denormalize() $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $name); return 'Rokka\Client\Core\DynamicMetadata\\'.$camelCasedName; }
[ "public", "static", "function", "getDynamicMetadataClassName", "(", "$", "name", ")", "{", "// Convert to a CamelCase class name.", "// See Symfony\\Component\\Serializer\\NameConverter\\CamelCaseToSnakeCaseNameConverter::denormalize()", "$", "camelCasedName", "=", "preg_replace_callback", "(", "'/(^|_|\\.)+(.)/'", ",", "function", "(", "$", "match", ")", "{", "return", "(", "'.'", "===", "$", "match", "[", "1", "]", "?", "'_'", ":", "''", ")", ".", "strtoupper", "(", "$", "match", "[", "2", "]", ")", ";", "}", ",", "$", "name", ")", ";", "return", "'Rokka\\Client\\Core\\DynamicMetadata\\\\'", ".", "$", "camelCasedName", ";", "}" ]
Returns the Dynamic Metadata class name from the API name. @param string $name The Metadata name from the API @return string The DynamicMetadata class name, as fully qualified class name
[ "Returns", "the", "Dynamic", "Metadata", "class", "name", "from", "the", "API", "name", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/DynamicMetadataHelper.php#L33-L42
train
bearsunday/BEAR.Resource
src/OptionsRenderer.php
OptionsRenderer.getAllows
private function getAllows(array $methods) { $allows = []; foreach ($methods as $method) { if (in_array($method->name, ['onGet', 'onPost', 'onPut', 'onPatch', 'onDelete', 'onHead'], true)) { $allows[] = strtoupper(substr($method->name, 2)); } } return $allows; }
php
private function getAllows(array $methods) { $allows = []; foreach ($methods as $method) { if (in_array($method->name, ['onGet', 'onPost', 'onPut', 'onPatch', 'onDelete', 'onHead'], true)) { $allows[] = strtoupper(substr($method->name, 2)); } } return $allows; }
[ "private", "function", "getAllows", "(", "array", "$", "methods", ")", "{", "$", "allows", "=", "[", "]", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "in_array", "(", "$", "method", "->", "name", ",", "[", "'onGet'", ",", "'onPost'", ",", "'onPut'", ",", "'onPatch'", ",", "'onDelete'", ",", "'onHead'", "]", ",", "true", ")", ")", "{", "$", "allows", "[", "]", "=", "strtoupper", "(", "substr", "(", "$", "method", "->", "name", ",", "2", ")", ")", ";", "}", "}", "return", "$", "allows", ";", "}" ]
Return allowed methods @param \ReflectionMethod[] $methods @return array
[ "Return", "allowed", "methods" ]
c3b396a6c725ecce9345565b1e4d563d95e11bec
https://github.com/bearsunday/BEAR.Resource/blob/c3b396a6c725ecce9345565b1e4d563d95e11bec/src/OptionsRenderer.php#L48-L58
train
bearsunday/BEAR.Resource
src/OptionsRenderer.php
OptionsRenderer.getEntityBody
private function getEntityBody(ResourceObject $ro, array $allows) : array { $mehtodList = []; foreach ($allows as $method) { $mehtodList[$method] = ($this->optionsMethod)($ro, $method); } return $mehtodList; }
php
private function getEntityBody(ResourceObject $ro, array $allows) : array { $mehtodList = []; foreach ($allows as $method) { $mehtodList[$method] = ($this->optionsMethod)($ro, $method); } return $mehtodList; }
[ "private", "function", "getEntityBody", "(", "ResourceObject", "$", "ro", ",", "array", "$", "allows", ")", ":", "array", "{", "$", "mehtodList", "=", "[", "]", ";", "foreach", "(", "$", "allows", "as", "$", "method", ")", "{", "$", "mehtodList", "[", "$", "method", "]", "=", "(", "$", "this", "->", "optionsMethod", ")", "(", "$", "ro", ",", "$", "method", ")", ";", "}", "return", "$", "mehtodList", ";", "}" ]
Return OPTIONS entity body
[ "Return", "OPTIONS", "entity", "body" ]
c3b396a6c725ecce9345565b1e4d563d95e11bec
https://github.com/bearsunday/BEAR.Resource/blob/c3b396a6c725ecce9345565b1e4d563d95e11bec/src/OptionsRenderer.php#L63-L71
train
tsugiproject/tsugi-php
src/Util/Mersenne_Twister.php
Mersenne_Twister.getNext
public function getNext($min = null, $max = null) { if (($min === null && $max !== null) || ($min !== null && $max === null)) throw new Exception('Invalid arguments'); if ($this->index === 0) { $this->generateTwister(); } $y = $this->state[$this->index]; $y = ($y ^ ($y >> 11)) & 0xffffffff; $y = ($y ^ (($y << 7) & 0x9d2c5680)) & 0xffffffff; $y = ($y ^ (($y << 15) & 0xefc60000)) & 0xffffffff; $y = ($y ^ ($y >> 18)) & 0xffffffff; $this->index = ($this->index + 1) % 624; if ($min === null && $max === null) return $y; $range = abs($max - $min); return min($min, $max) + ($y % ($range + 1)); }
php
public function getNext($min = null, $max = null) { if (($min === null && $max !== null) || ($min !== null && $max === null)) throw new Exception('Invalid arguments'); if ($this->index === 0) { $this->generateTwister(); } $y = $this->state[$this->index]; $y = ($y ^ ($y >> 11)) & 0xffffffff; $y = ($y ^ (($y << 7) & 0x9d2c5680)) & 0xffffffff; $y = ($y ^ (($y << 15) & 0xefc60000)) & 0xffffffff; $y = ($y ^ ($y >> 18)) & 0xffffffff; $this->index = ($this->index + 1) % 624; if ($min === null && $max === null) return $y; $range = abs($max - $min); return min($min, $max) + ($y % ($range + 1)); }
[ "public", "function", "getNext", "(", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "if", "(", "(", "$", "min", "===", "null", "&&", "$", "max", "!==", "null", ")", "||", "(", "$", "min", "!==", "null", "&&", "$", "max", "===", "null", ")", ")", "throw", "new", "Exception", "(", "'Invalid arguments'", ")", ";", "if", "(", "$", "this", "->", "index", "===", "0", ")", "{", "$", "this", "->", "generateTwister", "(", ")", ";", "}", "$", "y", "=", "$", "this", "->", "state", "[", "$", "this", "->", "index", "]", ";", "$", "y", "=", "(", "$", "y", "^", "(", "$", "y", ">>", "11", ")", ")", "&", "0xffffffff", ";", "$", "y", "=", "(", "$", "y", "^", "(", "(", "$", "y", "<<", "7", ")", "&", "0x9d2c5680", ")", ")", "&", "0xffffffff", ";", "$", "y", "=", "(", "$", "y", "^", "(", "(", "$", "y", "<<", "15", ")", "&", "0xefc60000", ")", ")", "&", "0xffffffff", ";", "$", "y", "=", "(", "$", "y", "^", "(", "$", "y", ">>", "18", ")", ")", "&", "0xffffffff", ";", "$", "this", "->", "index", "=", "(", "$", "this", "->", "index", "+", "1", ")", "%", "624", ";", "if", "(", "$", "min", "===", "null", "&&", "$", "max", "===", "null", ")", "return", "$", "y", ";", "$", "range", "=", "abs", "(", "$", "max", "-", "$", "min", ")", ";", "return", "min", "(", "$", "min", ",", "$", "max", ")", "+", "(", "$", "y", "%", "(", "$", "range", "+", "1", ")", ")", ";", "}" ]
Get the next pseudo-random number in the sequence Returns the next pseudo-random number in the range specified. The $max and $min are inclusive. If $max and $min are omitted a large integer is returned. @param $min The low end of the range (optional) @param $max The high end of the range (optional)
[ "Get", "the", "next", "pseudo", "-", "random", "number", "in", "the", "sequence" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/Mersenne_Twister.php#L71-L93
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getHashMaybeUpload
public function getHashMaybeUpload(AbstractLocalImage $image) { if ($hash = $image->getRokkaHash()) { return $hash; } if (!$hash = $this->callbacks->getHash($image)) { if (!$this->isImage($image)) { return null; } $sourceImage = $this->imageUpload($image); if (null !== $sourceImage) { $hash = $this->callbacks->saveHash($image, $sourceImage); } } return $hash; }
php
public function getHashMaybeUpload(AbstractLocalImage $image) { if ($hash = $image->getRokkaHash()) { return $hash; } if (!$hash = $this->callbacks->getHash($image)) { if (!$this->isImage($image)) { return null; } $sourceImage = $this->imageUpload($image); if (null !== $sourceImage) { $hash = $this->callbacks->saveHash($image, $sourceImage); } } return $hash; }
[ "public", "function", "getHashMaybeUpload", "(", "AbstractLocalImage", "$", "image", ")", "{", "if", "(", "$", "hash", "=", "$", "image", "->", "getRokkaHash", "(", ")", ")", "{", "return", "$", "hash", ";", "}", "if", "(", "!", "$", "hash", "=", "$", "this", "->", "callbacks", "->", "getHash", "(", "$", "image", ")", ")", "{", "if", "(", "!", "$", "this", "->", "isImage", "(", "$", "image", ")", ")", "{", "return", "null", ";", "}", "$", "sourceImage", "=", "$", "this", "->", "imageUpload", "(", "$", "image", ")", ";", "if", "(", "null", "!==", "$", "sourceImage", ")", "{", "$", "hash", "=", "$", "this", "->", "callbacks", "->", "saveHash", "(", "$", "image", ",", "$", "sourceImage", ")", ";", "}", "}", "return", "$", "hash", ";", "}" ]
Returns the hash of an image. If we don't have an image stored locally, it uploads it to rokka. @since 1.3.0 @param AbstractLocalImage $image @throws \GuzzleHttp\Exception\GuzzleException @throws \RuntimeException @return string|null
[ "Returns", "the", "hash", "of", "an", "image", ".", "If", "we", "don", "t", "have", "an", "image", "stored", "locally", "it", "uploads", "it", "to", "rokka", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L96-L112
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getStackUrl
public function getStackUrl( $image, $stack, $format = 'jpg', $seo = null, $seoLanguage = 'de' ) { if (null == $image) { return ''; } $image = $this->getImageObject($image); if (!$hash = self::getHashMaybeUpload($image)) { return ''; } if (null === $seo) { return $this->generateRokkaUrlWithImage($hash, $stack, $format, $image, $seoLanguage); } return $this->generateRokkaUrl($hash, $stack, $format, $seo, $seoLanguage); }
php
public function getStackUrl( $image, $stack, $format = 'jpg', $seo = null, $seoLanguage = 'de' ) { if (null == $image) { return ''; } $image = $this->getImageObject($image); if (!$hash = self::getHashMaybeUpload($image)) { return ''; } if (null === $seo) { return $this->generateRokkaUrlWithImage($hash, $stack, $format, $image, $seoLanguage); } return $this->generateRokkaUrl($hash, $stack, $format, $seo, $seoLanguage); }
[ "public", "function", "getStackUrl", "(", "$", "image", ",", "$", "stack", ",", "$", "format", "=", "'jpg'", ",", "$", "seo", "=", "null", ",", "$", "seoLanguage", "=", "'de'", ")", "{", "if", "(", "null", "==", "$", "image", ")", "{", "return", "''", ";", "}", "$", "image", "=", "$", "this", "->", "getImageObject", "(", "$", "image", ")", ";", "if", "(", "!", "$", "hash", "=", "self", "::", "getHashMaybeUpload", "(", "$", "image", ")", ")", "{", "return", "''", ";", "}", "if", "(", "null", "===", "$", "seo", ")", "{", "return", "$", "this", "->", "generateRokkaUrlWithImage", "(", "$", "hash", ",", "$", "stack", ",", "$", "format", ",", "$", "image", ",", "$", "seoLanguage", ")", ";", "}", "return", "$", "this", "->", "generateRokkaUrl", "(", "$", "hash", ",", "$", "stack", ",", "$", "format", ",", "$", "seo", ",", "$", "seoLanguage", ")", ";", "}" ]
Gets the rokka URL for an image Uploads it, if we don't have a hash locally. @since 1.3.0 @param AbstractLocalImage|string|\SplFileInfo $image The image @param string $stack The stack name @param string|null $format The image format of the image (jpg, png, webp, ...) @param string|null $seo if you want a different seo string than the default @param string|null $seoLanguage Optional language to be used for slugifying (eg. 'de' slugifies 'ö' to 'oe') @throws \GuzzleHttp\Exception\GuzzleException @throws \RuntimeException @return string
[ "Gets", "the", "rokka", "URL", "for", "an", "image", "Uploads", "it", "if", "we", "don", "t", "have", "a", "hash", "locally", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L131-L151
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getResizeUrl
public function getResizeUrl($image, $width, $height = null, $format = 'jpg', $seo = null, $seoLanguage = 'de') { $imageObject = $this->getImageObject($image); if (null !== $height) { $heightString = "-height-$height"; } else { $heightString = ''; } $stack = "dynamic/resize-width-$width$heightString--options-autoformat-true-jpg.transparency.autoformat-true"; return $this->getStackUrl($imageObject, $stack, $format, $seo, $seoLanguage); }
php
public function getResizeUrl($image, $width, $height = null, $format = 'jpg', $seo = null, $seoLanguage = 'de') { $imageObject = $this->getImageObject($image); if (null !== $height) { $heightString = "-height-$height"; } else { $heightString = ''; } $stack = "dynamic/resize-width-$width$heightString--options-autoformat-true-jpg.transparency.autoformat-true"; return $this->getStackUrl($imageObject, $stack, $format, $seo, $seoLanguage); }
[ "public", "function", "getResizeUrl", "(", "$", "image", ",", "$", "width", ",", "$", "height", "=", "null", ",", "$", "format", "=", "'jpg'", ",", "$", "seo", "=", "null", ",", "$", "seoLanguage", "=", "'de'", ")", "{", "$", "imageObject", "=", "$", "this", "->", "getImageObject", "(", "$", "image", ")", ";", "if", "(", "null", "!==", "$", "height", ")", "{", "$", "heightString", "=", "\"-height-$height\"", ";", "}", "else", "{", "$", "heightString", "=", "''", ";", "}", "$", "stack", "=", "\"dynamic/resize-width-$width$heightString--options-autoformat-true-jpg.transparency.autoformat-true\"", ";", "return", "$", "this", "->", "getStackUrl", "(", "$", "imageObject", ",", "$", "stack", ",", "$", "format", ",", "$", "seo", ",", "$", "seoLanguage", ")", ";", "}" ]
Return the rokka URL for getting a resized image. @since 1.3.0 @param AbstractLocalImage|string|\SplFileInfo $image The image to be resized @param string|int $width The width of the image @param string|int|null $height The height of the image @param string $format The image format of the image (jpg, png, webp, ...) @param string|null $seo @param string $seoLanguage @throws \GuzzleHttp\Exception\GuzzleException @throws \RuntimeException @return string
[ "Return", "the", "rokka", "URL", "for", "getting", "a", "resized", "image", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L170-L181
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getOriginalSizeUrl
public function getOriginalSizeUrl($image, $format = 'jpg', $seo = null, $seoLanguage = '') { $imageObject = $this->getImageObject($image); $stack = 'dynamic/noop--options-autoformat-true-jpg.transparency.autoformat-true'; return $this->getStackUrl($imageObject, $stack, $format, $seo, $seoLanguage); }
php
public function getOriginalSizeUrl($image, $format = 'jpg', $seo = null, $seoLanguage = '') { $imageObject = $this->getImageObject($image); $stack = 'dynamic/noop--options-autoformat-true-jpg.transparency.autoformat-true'; return $this->getStackUrl($imageObject, $stack, $format, $seo, $seoLanguage); }
[ "public", "function", "getOriginalSizeUrl", "(", "$", "image", ",", "$", "format", "=", "'jpg'", ",", "$", "seo", "=", "null", ",", "$", "seoLanguage", "=", "''", ")", "{", "$", "imageObject", "=", "$", "this", "->", "getImageObject", "(", "$", "image", ")", ";", "$", "stack", "=", "'dynamic/noop--options-autoformat-true-jpg.transparency.autoformat-true'", ";", "return", "$", "this", "->", "getStackUrl", "(", "$", "imageObject", ",", "$", "stack", ",", "$", "format", ",", "$", "seo", ",", "$", "seoLanguage", ")", ";", "}" ]
Return the rokka URL for getting the image in it's original size. @since 1.3.0 @param AbstractLocalImage|string|\SplFileInfo $image The image to be resized @param string $format The image format of the image (jpg, png, webp, ...) @param string|null $seo @param string $seoLanguage @throws \GuzzleHttp\Exception\GuzzleException @throws \RuntimeException @return string
[ "Return", "the", "rokka", "URL", "for", "getting", "the", "image", "in", "it", "s", "original", "size", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L224-L231
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getImagename
public function getImagename(AbstractLocalImage $image = null) { if (null === $image) { return ''; } if (null === $image->getFilename()) { return ''; } return pathinfo($image->getFilename(), PATHINFO_FILENAME); }
php
public function getImagename(AbstractLocalImage $image = null) { if (null === $image) { return ''; } if (null === $image->getFilename()) { return ''; } return pathinfo($image->getFilename(), PATHINFO_FILENAME); }
[ "public", "function", "getImagename", "(", "AbstractLocalImage", "$", "image", "=", "null", ")", "{", "if", "(", "null", "===", "$", "image", ")", "{", "return", "''", ";", "}", "if", "(", "null", "===", "$", "image", "->", "getFilename", "(", ")", ")", "{", "return", "''", ";", "}", "return", "pathinfo", "(", "$", "image", "->", "getFilename", "(", ")", ",", "PATHINFO_FILENAME", ")", ";", "}" ]
Returns the filename of the image without extension. @since 1.3.0 @param AbstractLocalImage|null $image @return string
[ "Returns", "the", "filename", "of", "the", "image", "without", "extension", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L319-L329
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.generateRokkaUrl
public function generateRokkaUrl( $hash, $stack, $format = 'jpg', $seo = null, $seoLanguage = 'de' ) { if (null === $format) { $format = 'jpg'; } $slug = null; if (!empty($seo) && null !== $seo) { if (null === $seoLanguage) { $seoLanguage = 'de'; } $slug = self::slugify($seo, $seoLanguage); } $path = UriHelper::composeUri(['stack' => $stack, 'hash' => $hash, 'format' => $format, 'filename' => $slug]); return $this->rokkaDomain.$path->getPath(); }
php
public function generateRokkaUrl( $hash, $stack, $format = 'jpg', $seo = null, $seoLanguage = 'de' ) { if (null === $format) { $format = 'jpg'; } $slug = null; if (!empty($seo) && null !== $seo) { if (null === $seoLanguage) { $seoLanguage = 'de'; } $slug = self::slugify($seo, $seoLanguage); } $path = UriHelper::composeUri(['stack' => $stack, 'hash' => $hash, 'format' => $format, 'filename' => $slug]); return $this->rokkaDomain.$path->getPath(); }
[ "public", "function", "generateRokkaUrl", "(", "$", "hash", ",", "$", "stack", ",", "$", "format", "=", "'jpg'", ",", "$", "seo", "=", "null", ",", "$", "seoLanguage", "=", "'de'", ")", "{", "if", "(", "null", "===", "$", "format", ")", "{", "$", "format", "=", "'jpg'", ";", "}", "$", "slug", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "seo", ")", "&&", "null", "!==", "$", "seo", ")", "{", "if", "(", "null", "===", "$", "seoLanguage", ")", "{", "$", "seoLanguage", "=", "'de'", ";", "}", "$", "slug", "=", "self", "::", "slugify", "(", "$", "seo", ",", "$", "seoLanguage", ")", ";", "}", "$", "path", "=", "UriHelper", "::", "composeUri", "(", "[", "'stack'", "=>", "$", "stack", ",", "'hash'", "=>", "$", "hash", ",", "'format'", "=>", "$", "format", ",", "'filename'", "=>", "$", "slug", "]", ")", ";", "return", "$", "this", "->", "rokkaDomain", ".", "$", "path", "->", "getPath", "(", ")", ";", "}" ]
Gets the rokka URL for an image hash and stack with optional seo filename in the URL. Doesn't upload it, if we don't have a local hash for it. Use getStackUrl for that. @since 1.3.0 @see TemplateHelper::getStackUrl() @param string $hash The rokka hash @param string|StackUri $stack The stack name or a StackUrl object @param string|null $format The image format of the image (jpg, png, webp, ...) @param string|null $seo If you want to use a seo string in the URL @param string|null $seoLanguage Optional language to be used for slugifying (eg. 'de' slugifies 'ö' to 'oe') @throws \RuntimeException @return string
[ "Gets", "the", "rokka", "URL", "for", "an", "image", "hash", "and", "stack", "with", "optional", "seo", "filename", "in", "the", "URL", ".", "Doesn", "t", "upload", "it", "if", "we", "don", "t", "have", "a", "local", "hash", "for", "it", ".", "Use", "getStackUrl", "for", "that", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L348-L368
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getRokkaClient
public function getRokkaClient() { if (null === $this->imageClient) { $this->imageClient = Factory::getImageClient($this->rokkaOrg, $this->rokkaApiKey, $this->rokkaClientOptions); } return $this->imageClient; }
php
public function getRokkaClient() { if (null === $this->imageClient) { $this->imageClient = Factory::getImageClient($this->rokkaOrg, $this->rokkaApiKey, $this->rokkaClientOptions); } return $this->imageClient; }
[ "public", "function", "getRokkaClient", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "imageClient", ")", "{", "$", "this", "->", "imageClient", "=", "Factory", "::", "getImageClient", "(", "$", "this", "->", "rokkaOrg", ",", "$", "this", "->", "rokkaApiKey", ",", "$", "this", "->", "rokkaClientOptions", ")", ";", "}", "return", "$", "this", "->", "imageClient", ";", "}" ]
Gets the rokka image client used by this class. @since 1.3.0 @throws \RuntimeException @return \Rokka\Client\Image
[ "Gets", "the", "rokka", "image", "client", "used", "by", "this", "class", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L379-L386
train
rokka-io/rokka-client-php
src/TemplateHelper.php
TemplateHelper.getImageObject
public function getImageObject($input, $identifier = null, $context = null) { if ($input instanceof AbstractLocalImage) { if (null !== $identifier) { $input->setIdentifier($identifier); } if (null !== $context) { $input->setContext($context); } return $input; } if ($input instanceof \SplFileInfo) { return new FileInfo($input, $identifier, $context); } elseif (\is_string($input)) { if (preg_match('/^[0-9a-f]{6,40}$/', $input)) { return new RokkaHash($input, $identifier, $context, $this); } return new FileInfo(new \SplFileInfo($input), $identifier, $context); } throw new \RuntimeException('getImageObject: Input could not be converted to a LocalImageAbstract object'); }
php
public function getImageObject($input, $identifier = null, $context = null) { if ($input instanceof AbstractLocalImage) { if (null !== $identifier) { $input->setIdentifier($identifier); } if (null !== $context) { $input->setContext($context); } return $input; } if ($input instanceof \SplFileInfo) { return new FileInfo($input, $identifier, $context); } elseif (\is_string($input)) { if (preg_match('/^[0-9a-f]{6,40}$/', $input)) { return new RokkaHash($input, $identifier, $context, $this); } return new FileInfo(new \SplFileInfo($input), $identifier, $context); } throw new \RuntimeException('getImageObject: Input could not be converted to a LocalImageAbstract object'); }
[ "public", "function", "getImageObject", "(", "$", "input", ",", "$", "identifier", "=", "null", ",", "$", "context", "=", "null", ")", "{", "if", "(", "$", "input", "instanceof", "AbstractLocalImage", ")", "{", "if", "(", "null", "!==", "$", "identifier", ")", "{", "$", "input", "->", "setIdentifier", "(", "$", "identifier", ")", ";", "}", "if", "(", "null", "!==", "$", "context", ")", "{", "$", "input", "->", "setContext", "(", "$", "context", ")", ";", "}", "return", "$", "input", ";", "}", "if", "(", "$", "input", "instanceof", "\\", "SplFileInfo", ")", "{", "return", "new", "FileInfo", "(", "$", "input", ",", "$", "identifier", ",", "$", "context", ")", ";", "}", "elseif", "(", "\\", "is_string", "(", "$", "input", ")", ")", "{", "if", "(", "preg_match", "(", "'/^[0-9a-f]{6,40}$/'", ",", "$", "input", ")", ")", "{", "return", "new", "RokkaHash", "(", "$", "input", ",", "$", "identifier", ",", "$", "context", ",", "$", "this", ")", ";", "}", "return", "new", "FileInfo", "(", "new", "\\", "SplFileInfo", "(", "$", "input", ")", ",", "$", "identifier", ",", "$", "context", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "'getImageObject: Input could not be converted to a LocalImageAbstract object'", ")", ";", "}" ]
Returns a LocalImage object depending on the input. If input is - LocalImageAbstract: returns that, sets $identidier and $context, if set - SplFileInfo: returns \Rokka\Client\LocalImage\FileInfo - string with hash pattern (/^[0-9a-f]{6,40}$/): returns \Rokka\Client\LocalImage\RokkaHash - other strings: returns \Rokka\Client\LocalImage\FileInfo with $input as the path to the image @since 1.3.1 @param AbstractLocalImage|string|\SplFileInfo $input @param string|null $identifier @param mixed $context @throws \RuntimeException @return AbstractLocalImage
[ "Returns", "a", "LocalImage", "object", "depending", "on", "the", "input", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/TemplateHelper.php#L437-L460
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.queryReturnError
function queryReturnError($sql, $arr=FALSE, $error_log=TRUE) { $errormode = $this->getAttribute(\PDO::ATTR_ERRMODE); if ( $errormode != \PDO::ERRMODE_EXCEPTION) { $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } $q = FALSE; $success = FALSE; $message = ''; if ( $arr !== FALSE && ! is_array($arr) ) $arr = Array($arr); $start = microtime(true); // debug_log($sql, $arr); try { $q = $this->prepare($sql); if ( $arr === FALSE ) { $success = $q->execute(); } else { $success = $q->execute($arr); } } catch(\Exception $e) { $success = FALSE; $message = $e->getMessage(); if ( $error_log ) error_log($message); } if ( ! is_object($q) ) $q = new \stdClass(); if ( isset( $q->success ) ) { error_log("\PDO::Statement should not have success member"); die("\PDO::Statement should not have success member"); // with error_log } $q->success = $success; if ( isset( $q->ellapsed_time ) ) { error_log("\PDO::Statement should not have ellapsed_time member"); die("\PDO::Statement should not have ellapsed_time member"); // with error_log } $q->ellapsed_time = microtime(true)-$start; if ( $this->slow_query < 0 || ($this->slow_query > 0 && $q->ellapsed_time > $this->slow_query ) ) { $dbt = U::getCaller(2); $caller_uri = U::get($_SERVER,'REQUEST_URI'); error_log("PDOX Slow Query:".$q->ellapsed_time.' '.$caller_uri.' '.$dbt); } // In case we build this... if ( !isset($q->errorCode) ) $q->errorCode = '42000'; if ( !isset($q->errorInfo) ) $q->errorInfo = Array('42000', '42000', $message); if ( !isset($q->errorImplode) ) $q->errorImplode = implode(':',$q->errorInfo); // Restore ERRMODE if we changed it if ( $errormode != \PDO::ERRMODE_EXCEPTION) { $this->setAttribute(\PDO::ATTR_ERRMODE, $errormode); } return $q; }
php
function queryReturnError($sql, $arr=FALSE, $error_log=TRUE) { $errormode = $this->getAttribute(\PDO::ATTR_ERRMODE); if ( $errormode != \PDO::ERRMODE_EXCEPTION) { $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } $q = FALSE; $success = FALSE; $message = ''; if ( $arr !== FALSE && ! is_array($arr) ) $arr = Array($arr); $start = microtime(true); // debug_log($sql, $arr); try { $q = $this->prepare($sql); if ( $arr === FALSE ) { $success = $q->execute(); } else { $success = $q->execute($arr); } } catch(\Exception $e) { $success = FALSE; $message = $e->getMessage(); if ( $error_log ) error_log($message); } if ( ! is_object($q) ) $q = new \stdClass(); if ( isset( $q->success ) ) { error_log("\PDO::Statement should not have success member"); die("\PDO::Statement should not have success member"); // with error_log } $q->success = $success; if ( isset( $q->ellapsed_time ) ) { error_log("\PDO::Statement should not have ellapsed_time member"); die("\PDO::Statement should not have ellapsed_time member"); // with error_log } $q->ellapsed_time = microtime(true)-$start; if ( $this->slow_query < 0 || ($this->slow_query > 0 && $q->ellapsed_time > $this->slow_query ) ) { $dbt = U::getCaller(2); $caller_uri = U::get($_SERVER,'REQUEST_URI'); error_log("PDOX Slow Query:".$q->ellapsed_time.' '.$caller_uri.' '.$dbt); } // In case we build this... if ( !isset($q->errorCode) ) $q->errorCode = '42000'; if ( !isset($q->errorInfo) ) $q->errorInfo = Array('42000', '42000', $message); if ( !isset($q->errorImplode) ) $q->errorImplode = implode(':',$q->errorInfo); // Restore ERRMODE if we changed it if ( $errormode != \PDO::ERRMODE_EXCEPTION) { $this->setAttribute(\PDO::ATTR_ERRMODE, $errormode); } return $q; }
[ "function", "queryReturnError", "(", "$", "sql", ",", "$", "arr", "=", "FALSE", ",", "$", "error_log", "=", "TRUE", ")", "{", "$", "errormode", "=", "$", "this", "->", "getAttribute", "(", "\\", "PDO", "::", "ATTR_ERRMODE", ")", ";", "if", "(", "$", "errormode", "!=", "\\", "PDO", "::", "ERRMODE_EXCEPTION", ")", "{", "$", "this", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_ERRMODE", ",", "\\", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "}", "$", "q", "=", "FALSE", ";", "$", "success", "=", "FALSE", ";", "$", "message", "=", "''", ";", "if", "(", "$", "arr", "!==", "FALSE", "&&", "!", "is_array", "(", "$", "arr", ")", ")", "$", "arr", "=", "Array", "(", "$", "arr", ")", ";", "$", "start", "=", "microtime", "(", "true", ")", ";", "// debug_log($sql, $arr);", "try", "{", "$", "q", "=", "$", "this", "->", "prepare", "(", "$", "sql", ")", ";", "if", "(", "$", "arr", "===", "FALSE", ")", "{", "$", "success", "=", "$", "q", "->", "execute", "(", ")", ";", "}", "else", "{", "$", "success", "=", "$", "q", "->", "execute", "(", "$", "arr", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "success", "=", "FALSE", ";", "$", "message", "=", "$", "e", "->", "getMessage", "(", ")", ";", "if", "(", "$", "error_log", ")", "error_log", "(", "$", "message", ")", ";", "}", "if", "(", "!", "is_object", "(", "$", "q", ")", ")", "$", "q", "=", "new", "\\", "stdClass", "(", ")", ";", "if", "(", "isset", "(", "$", "q", "->", "success", ")", ")", "{", "error_log", "(", "\"\\PDO::Statement should not have success member\"", ")", ";", "die", "(", "\"\\PDO::Statement should not have success member\"", ")", ";", "// with error_log", "}", "$", "q", "->", "success", "=", "$", "success", ";", "if", "(", "isset", "(", "$", "q", "->", "ellapsed_time", ")", ")", "{", "error_log", "(", "\"\\PDO::Statement should not have ellapsed_time member\"", ")", ";", "die", "(", "\"\\PDO::Statement should not have ellapsed_time member\"", ")", ";", "// with error_log", "}", "$", "q", "->", "ellapsed_time", "=", "microtime", "(", "true", ")", "-", "$", "start", ";", "if", "(", "$", "this", "->", "slow_query", "<", "0", "||", "(", "$", "this", "->", "slow_query", ">", "0", "&&", "$", "q", "->", "ellapsed_time", ">", "$", "this", "->", "slow_query", ")", ")", "{", "$", "dbt", "=", "U", "::", "getCaller", "(", "2", ")", ";", "$", "caller_uri", "=", "U", "::", "get", "(", "$", "_SERVER", ",", "'REQUEST_URI'", ")", ";", "error_log", "(", "\"PDOX Slow Query:\"", ".", "$", "q", "->", "ellapsed_time", ".", "' '", ".", "$", "caller_uri", ".", "' '", ".", "$", "dbt", ")", ";", "}", "// In case we build this...", "if", "(", "!", "isset", "(", "$", "q", "->", "errorCode", ")", ")", "$", "q", "->", "errorCode", "=", "'42000'", ";", "if", "(", "!", "isset", "(", "$", "q", "->", "errorInfo", ")", ")", "$", "q", "->", "errorInfo", "=", "Array", "(", "'42000'", ",", "'42000'", ",", "$", "message", ")", ";", "if", "(", "!", "isset", "(", "$", "q", "->", "errorImplode", ")", ")", "$", "q", "->", "errorImplode", "=", "implode", "(", "':'", ",", "$", "q", "->", "errorInfo", ")", ";", "// Restore ERRMODE if we changed it", "if", "(", "$", "errormode", "!=", "\\", "PDO", "::", "ERRMODE_EXCEPTION", ")", "{", "$", "this", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_ERRMODE", ",", "$", "errormode", ")", ";", "}", "return", "$", "q", ";", "}" ]
Prepare and execute an SQL query with lots of error checking. This routine will call prepare() and then execute() with the resulting PDOStatement and return the PDOStatement. If the prepare() fails, we fake up a stdClass() with a few fields that mimic a simple failed execute(). $stmt->errorCode $stmt->errorInfo We also augment the real or fake PDOStatement with these fields: $stmt->success $stmt->ellapsed_time $stmt->errorImplode <var>$stmt->success</var> is TRUE/FALSE based on the success of the operation to simplify error checking <var>$stmt->ellapsed_time</var> includes the length of time the query took <var>$stmt->errorImplode</var> an imploded version of errorInfo suitable for dropping into a log. @param $sql The SQL to execute in a string. @param $arr An optional array of the substitition values if needed by the query @param $error_log Indicates whether or not errors are to be logged. Default is TRUE. @return \PDOStatement This is either the real PDOStatement from the prepare() call or a stdClass mocked to have error indications as described above.
[ "Prepare", "and", "execute", "an", "SQL", "query", "with", "lots", "of", "error", "checking", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L80-L129
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.rowDie
function rowDie($sql, $arr=FALSE, $error_log=TRUE) { $stmt = self::queryDie($sql, $arr, $error_log); $row = $stmt->fetch(\PDO::FETCH_ASSOC); return $row; }
php
function rowDie($sql, $arr=FALSE, $error_log=TRUE) { $stmt = self::queryDie($sql, $arr, $error_log); $row = $stmt->fetch(\PDO::FETCH_ASSOC); return $row; }
[ "function", "rowDie", "(", "$", "sql", ",", "$", "arr", "=", "FALSE", ",", "$", "error_log", "=", "TRUE", ")", "{", "$", "stmt", "=", "self", "::", "queryDie", "(", "$", "sql", ",", "$", "arr", ",", "$", "error_log", ")", ";", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "row", ";", "}" ]
Prepare and execute an SQL query and retrieve a single row. @param $sql The SQL to execute in a string. If the SQL is badly formed this function will die. @param $arr An optional array of the substitition values if needed by the query @param $error_log Indicates whether or not errors are to be logged. Default is TRUE. @return array This is either the row that was returned or FALSE if no rows were returned.
[ "Prepare", "and", "execute", "an", "SQL", "query", "and", "retrieve", "a", "single", "row", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L163-L167
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.allRowsDie
function allRowsDie($sql, $arr=FALSE, $error_log=TRUE) { $stmt = self::queryDie($sql, $arr, $error_log); $rows = array(); while ( $row = $stmt->fetch(\PDO::FETCH_ASSOC) ) { array_push($rows, $row); } return $rows; }
php
function allRowsDie($sql, $arr=FALSE, $error_log=TRUE) { $stmt = self::queryDie($sql, $arr, $error_log); $rows = array(); while ( $row = $stmt->fetch(\PDO::FETCH_ASSOC) ) { array_push($rows, $row); } return $rows; }
[ "function", "allRowsDie", "(", "$", "sql", ",", "$", "arr", "=", "FALSE", ",", "$", "error_log", "=", "TRUE", ")", "{", "$", "stmt", "=", "self", "::", "queryDie", "(", "$", "sql", ",", "$", "arr", ",", "$", "error_log", ")", ";", "$", "rows", "=", "array", "(", ")", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "array_push", "(", "$", "rows", ",", "$", "row", ")", ";", "}", "return", "$", "rows", ";", "}" ]
Prepare and execute an SQL query and retrieve all the rows as an array While this might seem like a bad idea, the coding style for Tsugi is to make every query a paged query with a limited number of records to be retrieved to in most cases, it is quite reasonable to retrieve 10-30 rows into an array. If code wants to stream the results of a query, they should do their own query and loop through the rows in their own code. @param $sql The SQL to execute in a string. If the SQL is badly formed this function will die. @param $arr An optional array of the substitition values if needed by the query @param $error_log Indicates whether or not errors are to be logged. Default is TRUE. @return array This is either the rows that were retrieved or or an empty array if there were no rows.
[ "Prepare", "and", "execute", "an", "SQL", "query", "and", "retrieve", "all", "the", "rows", "as", "an", "array" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L186-L193
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.metadata
function metadata($tablename) { $sql = "SHOW COLUMNS FROM ".$tablename; $q = self::queryReturnError($sql); if ( $q->success ) { return $q->fetchAll(); } else { return false; } }
php
function metadata($tablename) { $sql = "SHOW COLUMNS FROM ".$tablename; $q = self::queryReturnError($sql); if ( $q->success ) { return $q->fetchAll(); } else { return false; } }
[ "function", "metadata", "(", "$", "tablename", ")", "{", "$", "sql", "=", "\"SHOW COLUMNS FROM \"", ".", "$", "tablename", ";", "$", "q", "=", "self", "::", "queryReturnError", "(", "$", "sql", ")", ";", "if", "(", "$", "q", "->", "success", ")", "{", "return", "$", "q", "->", "fetchAll", "(", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Retrieve the metadata for a table.
[ "Retrieve", "the", "metadata", "for", "a", "table", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L200-L208
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.describeColumn
function describeColumn($fieldname, $source) { if ( ! is_array($source) ) { if ( ! is_string($source) ) { throw new \Exception('Source must be an array of metadata or a table name'); } $source = self::describe($source); if ( ! is_array($source) ) return null; } foreach( $source as $column ) { $name = U::get($column, "Field"); if ( $fieldname == $name ) return $column; } return null; }
php
function describeColumn($fieldname, $source) { if ( ! is_array($source) ) { if ( ! is_string($source) ) { throw new \Exception('Source must be an array of metadata or a table name'); } $source = self::describe($source); if ( ! is_array($source) ) return null; } foreach( $source as $column ) { $name = U::get($column, "Field"); if ( $fieldname == $name ) return $column; } return null; }
[ "function", "describeColumn", "(", "$", "fieldname", ",", "$", "source", ")", "{", "if", "(", "!", "is_array", "(", "$", "source", ")", ")", "{", "if", "(", "!", "is_string", "(", "$", "source", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Source must be an array of metadata or a table name'", ")", ";", "}", "$", "source", "=", "self", "::", "describe", "(", "$", "source", ")", ";", "if", "(", "!", "is_array", "(", "$", "source", ")", ")", "return", "null", ";", "}", "foreach", "(", "$", "source", "as", "$", "column", ")", "{", "$", "name", "=", "U", "::", "get", "(", "$", "column", ",", "\"Field\"", ")", ";", "if", "(", "$", "fieldname", "==", "$", "name", ")", "return", "$", "column", ";", "}", "return", "null", ";", "}" ]
Retrieve the metadata for a column in a table. For the output format for MySQL, see: https://dev.mysql.com/doc/refman/5.7/en/explain.html @param $fieldname The name of the column @param $source Either an array of the column metadata or the name of the table @return mixed An array of the column metadata or null
[ "Retrieve", "the", "metadata", "for", "a", "column", "in", "a", "table", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L234-L247
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.columnIsNull
function columnIsNull($fieldname, $source) { $column = self::describeColumn($fieldname, $source); if ( ! $column ) throw new \Exception("Could not find $fieldname"); return U::get($column, "Null") == "YES"; }
php
function columnIsNull($fieldname, $source) { $column = self::describeColumn($fieldname, $source); if ( ! $column ) throw new \Exception("Could not find $fieldname"); return U::get($column, "Null") == "YES"; }
[ "function", "columnIsNull", "(", "$", "fieldname", ",", "$", "source", ")", "{", "$", "column", "=", "self", "::", "describeColumn", "(", "$", "fieldname", ",", "$", "source", ")", ";", "if", "(", "!", "$", "column", ")", "throw", "new", "\\", "Exception", "(", "\"Could not find $fieldname\"", ")", ";", "return", "U", "::", "get", "(", "$", "column", ",", "\"Null\"", ")", "==", "\"YES\"", ";", "}" ]
Check if a column is null @param $fieldname The name of the column @param $source Either an array of the column metadata or the name of the table @return mixed Returns true / false if the columns exists and null if the column does not exist.
[ "Check", "if", "a", "column", "is", "null" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L257-L262
train
tsugiproject/tsugi-php
src/Util/PDOX.php
PDOX.columnType
function columnType($fieldname, $source) { $column = self::describeColumn($fieldname, $source); if ( ! $column ) throw new \Exception("Could not find $fieldname"); $type = U::get($column, "Type"); if ( ! $type ) return null; if ( strpos($type, '(') === false ) return $type; $matches = array(); preg_match('/([a-z]+)\([0-9]+\)/', $type, $matches); if ( count($matches) == 2 ) return $matches[1]; return null; }
php
function columnType($fieldname, $source) { $column = self::describeColumn($fieldname, $source); if ( ! $column ) throw new \Exception("Could not find $fieldname"); $type = U::get($column, "Type"); if ( ! $type ) return null; if ( strpos($type, '(') === false ) return $type; $matches = array(); preg_match('/([a-z]+)\([0-9]+\)/', $type, $matches); if ( count($matches) == 2 ) return $matches[1]; return null; }
[ "function", "columnType", "(", "$", "fieldname", ",", "$", "source", ")", "{", "$", "column", "=", "self", "::", "describeColumn", "(", "$", "fieldname", ",", "$", "source", ")", ";", "if", "(", "!", "$", "column", ")", "throw", "new", "\\", "Exception", "(", "\"Could not find $fieldname\"", ")", ";", "$", "type", "=", "U", "::", "get", "(", "$", "column", ",", "\"Type\"", ")", ";", "if", "(", "!", "$", "type", ")", "return", "null", ";", "if", "(", "strpos", "(", "$", "type", ",", "'('", ")", "===", "false", ")", "return", "$", "type", ";", "$", "matches", "=", "array", "(", ")", ";", "preg_match", "(", "'/([a-z]+)\\([0-9]+\\)/'", ",", "$", "type", ",", "$", "matches", ")", ";", "if", "(", "count", "(", "$", "matches", ")", "==", "2", ")", "return", "$", "matches", "[", "1", "]", ";", "return", "null", ";", "}" ]
Get the column type @param $fieldname The name of the column @param $source Either an array of the column metadata or the name of the table @return mixed Returns a string if the columns exists and null if the column does not exist.
[ "Get", "the", "column", "type" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/PDOX.php#L290-L301
train
tsugiproject/tsugi-php
src/Util/DeepLinkResponse.php
DeepLinkResponse.getContentItemSelection
function getContentItemSelection() { $this->json->{self::CONTENT_ITEMS} = $this->items; unset($this->json->{self::DATA_CLAIM}); if ( isset($this->claim->data) ) { $this->json->{self::DATA_CLAIM} = $this->claim->data; } return $this->json; }
php
function getContentItemSelection() { $this->json->{self::CONTENT_ITEMS} = $this->items; unset($this->json->{self::DATA_CLAIM}); if ( isset($this->claim->data) ) { $this->json->{self::DATA_CLAIM} = $this->claim->data; } return $this->json; }
[ "function", "getContentItemSelection", "(", ")", "{", "$", "this", "->", "json", "->", "{", "self", "::", "CONTENT_ITEMS", "}", "=", "$", "this", "->", "items", ";", "unset", "(", "$", "this", "->", "json", "->", "{", "self", "::", "DATA_CLAIM", "}", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "claim", "->", "data", ")", ")", "{", "$", "this", "->", "json", "->", "{", "self", "::", "DATA_CLAIM", "}", "=", "$", "this", "->", "claim", "->", "data", ";", "}", "return", "$", "this", "->", "json", ";", "}" ]
Return the claims array to send back to the LMS
[ "Return", "the", "claims", "array", "to", "send", "back", "to", "the", "LMS" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkResponse.php#L35-L43
train
tsugiproject/tsugi-php
src/Util/DeepLinkResponse.php
DeepLinkResponse.addContentItem
public function addContentItem($url, $title=false, $text=false, $icon=false, $fa_icon=false, $additionalParams = array()) { $params = array( 'url' => $url, 'title' => $title, 'text' => $text, 'icon' => $icon, 'fa_icon' => $fa_icon, ); // package the parameter list into an array for the helper function if (! empty($additionalParams['placementTarget'])) $params['placementTarget'] = $additionalParams['placementTarget']; if (! empty($additionalParams['placementWidth'])) $params['placementWidth'] = $additionalParams['placementWidth']; if (! empty($additionalParams['placementHeight'])) $params['placementHeight'] = $additionalParams['placementHeight']; $this->addContentItemExtended($params); }
php
public function addContentItem($url, $title=false, $text=false, $icon=false, $fa_icon=false, $additionalParams = array()) { $params = array( 'url' => $url, 'title' => $title, 'text' => $text, 'icon' => $icon, 'fa_icon' => $fa_icon, ); // package the parameter list into an array for the helper function if (! empty($additionalParams['placementTarget'])) $params['placementTarget'] = $additionalParams['placementTarget']; if (! empty($additionalParams['placementWidth'])) $params['placementWidth'] = $additionalParams['placementWidth']; if (! empty($additionalParams['placementHeight'])) $params['placementHeight'] = $additionalParams['placementHeight']; $this->addContentItemExtended($params); }
[ "public", "function", "addContentItem", "(", "$", "url", ",", "$", "title", "=", "false", ",", "$", "text", "=", "false", ",", "$", "icon", "=", "false", ",", "$", "fa_icon", "=", "false", ",", "$", "additionalParams", "=", "array", "(", ")", ")", "{", "$", "params", "=", "array", "(", "'url'", "=>", "$", "url", ",", "'title'", "=>", "$", "title", ",", "'text'", "=>", "$", "text", ",", "'icon'", "=>", "$", "icon", ",", "'fa_icon'", "=>", "$", "fa_icon", ",", ")", ";", "// package the parameter list into an array for the helper function", "if", "(", "!", "empty", "(", "$", "additionalParams", "[", "'placementTarget'", "]", ")", ")", "$", "params", "[", "'placementTarget'", "]", "=", "$", "additionalParams", "[", "'placementTarget'", "]", ";", "if", "(", "!", "empty", "(", "$", "additionalParams", "[", "'placementWidth'", "]", ")", ")", "$", "params", "[", "'placementWidth'", "]", "=", "$", "additionalParams", "[", "'placementWidth'", "]", ";", "if", "(", "!", "empty", "(", "$", "additionalParams", "[", "'placementHeight'", "]", ")", ")", "$", "params", "[", "'placementHeight'", "]", "=", "$", "additionalParams", "[", "'placementHeight'", "]", ";", "$", "this", "->", "addContentItemExtended", "(", "$", "params", ")", ";", "}" ]
addContentItem - Add an Content Item @param url The launch URL of the tool that is about to be placed @param title A plain text title of the content-item. @param text A plain text description of the content-item. @param icon An image URL of an icon @param fa_icon The class name of a FontAwesome icon
[ "addContentItem", "-", "Add", "an", "Content", "Item" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkResponse.php#L228-L247
train
tsugiproject/tsugi-php
src/Util/DeepLinkResponse.php
DeepLinkResponse.addContentItemExtended
public function addContentItemExtended($params = array()) { if (empty($params['title'])) $params['title'] = false; if (empty($params['text'])) $params['text'] = false; if (empty($params['icon'])) $params['icon'] = false; if (empty($params['fa_icon'])) $params['fa_icon'] = false; if (empty($params['placementTarget'])) $params['placementTarget'] = 'iframe'; if (empty($params['placementWindowTarget'])) $params['placementWindowTarget'] = ''; if (empty($params['placementWidth'])) $params['placementWidth'] = ''; if (empty($params['placementHeight'])) $params['placementHeight'] = ''; $item = '{ "@type" : "ContentItem", "@id" : ":item2", "title" : "A cool tool hosted in the Tsugi environment.", "mediaType" : "text/html", "text" : "For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org", "url" : "http://www.tsugi.org/", "placementAdvice" : { "presentationDocumentTarget" : "iframe" }, "icon" : { "@id" : "https://static.tsugi.org/img/default-icon.png", "fa_icon" : "fa-magic", "width" : 64, "height" : 64 } }'; $json = json_decode($item); $json->url = $params['url']; if ( $params['title'] ) $json->{'title'} = $params['title']; if ( $params['text'] ) $json->{'text'} = $params['text']; if ( $params['icon'] ) $json->{'icon'}->{'@id'} = $params['icon']; if ( $params['fa_icon'] ) $json->icon->fa_icon = $params['fa_icon']; if ($params['placementTarget']) $json->placementAdvice->presentationDocumentTarget = $params['placementTarget']; if ($params['placementWindowTarget']) $json->placementAdvice->windowTarget = $params['placementWindowTarget']; if (! empty($params['placementWidth'])) $json->placementAdvice->displayWidth = $params['placementWidth']; if (! empty($params['placementHeight'])) $json->placementAdvice->displayHeight = $params['placementHeight']; $json->{'@id'} = ':item'.(count($this->json->{'@graph'})+1); $this->json->{'@graph'}[] = $json; }
php
public function addContentItemExtended($params = array()) { if (empty($params['title'])) $params['title'] = false; if (empty($params['text'])) $params['text'] = false; if (empty($params['icon'])) $params['icon'] = false; if (empty($params['fa_icon'])) $params['fa_icon'] = false; if (empty($params['placementTarget'])) $params['placementTarget'] = 'iframe'; if (empty($params['placementWindowTarget'])) $params['placementWindowTarget'] = ''; if (empty($params['placementWidth'])) $params['placementWidth'] = ''; if (empty($params['placementHeight'])) $params['placementHeight'] = ''; $item = '{ "@type" : "ContentItem", "@id" : ":item2", "title" : "A cool tool hosted in the Tsugi environment.", "mediaType" : "text/html", "text" : "For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org", "url" : "http://www.tsugi.org/", "placementAdvice" : { "presentationDocumentTarget" : "iframe" }, "icon" : { "@id" : "https://static.tsugi.org/img/default-icon.png", "fa_icon" : "fa-magic", "width" : 64, "height" : 64 } }'; $json = json_decode($item); $json->url = $params['url']; if ( $params['title'] ) $json->{'title'} = $params['title']; if ( $params['text'] ) $json->{'text'} = $params['text']; if ( $params['icon'] ) $json->{'icon'}->{'@id'} = $params['icon']; if ( $params['fa_icon'] ) $json->icon->fa_icon = $params['fa_icon']; if ($params['placementTarget']) $json->placementAdvice->presentationDocumentTarget = $params['placementTarget']; if ($params['placementWindowTarget']) $json->placementAdvice->windowTarget = $params['placementWindowTarget']; if (! empty($params['placementWidth'])) $json->placementAdvice->displayWidth = $params['placementWidth']; if (! empty($params['placementHeight'])) $json->placementAdvice->displayHeight = $params['placementHeight']; $json->{'@id'} = ':item'.(count($this->json->{'@graph'})+1); $this->json->{'@graph'}[] = $json; }
[ "public", "function", "addContentItemExtended", "(", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "params", "[", "'title'", "]", ")", ")", "$", "params", "[", "'title'", "]", "=", "false", ";", "if", "(", "empty", "(", "$", "params", "[", "'text'", "]", ")", ")", "$", "params", "[", "'text'", "]", "=", "false", ";", "if", "(", "empty", "(", "$", "params", "[", "'icon'", "]", ")", ")", "$", "params", "[", "'icon'", "]", "=", "false", ";", "if", "(", "empty", "(", "$", "params", "[", "'fa_icon'", "]", ")", ")", "$", "params", "[", "'fa_icon'", "]", "=", "false", ";", "if", "(", "empty", "(", "$", "params", "[", "'placementTarget'", "]", ")", ")", "$", "params", "[", "'placementTarget'", "]", "=", "'iframe'", ";", "if", "(", "empty", "(", "$", "params", "[", "'placementWindowTarget'", "]", ")", ")", "$", "params", "[", "'placementWindowTarget'", "]", "=", "''", ";", "if", "(", "empty", "(", "$", "params", "[", "'placementWidth'", "]", ")", ")", "$", "params", "[", "'placementWidth'", "]", "=", "''", ";", "if", "(", "empty", "(", "$", "params", "[", "'placementHeight'", "]", ")", ")", "$", "params", "[", "'placementHeight'", "]", "=", "''", ";", "$", "item", "=", "'{ \"@type\" : \"ContentItem\",\n \"@id\" : \":item2\",\n \"title\" : \"A cool tool hosted in the Tsugi environment.\",\n \"mediaType\" : \"text/html\",\n \"text\" : \"For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org\",\n \"url\" : \"http://www.tsugi.org/\",\n \"placementAdvice\" : {\n \"presentationDocumentTarget\" : \"iframe\"\n },\n \"icon\" : {\n \"@id\" : \"https://static.tsugi.org/img/default-icon.png\",\n \"fa_icon\" : \"fa-magic\",\n \"width\" : 64,\n \"height\" : 64\n }\n }'", ";", "$", "json", "=", "json_decode", "(", "$", "item", ")", ";", "$", "json", "->", "url", "=", "$", "params", "[", "'url'", "]", ";", "if", "(", "$", "params", "[", "'title'", "]", ")", "$", "json", "->", "{", "'title'", "}", "=", "$", "params", "[", "'title'", "]", ";", "if", "(", "$", "params", "[", "'text'", "]", ")", "$", "json", "->", "{", "'text'", "}", "=", "$", "params", "[", "'text'", "]", ";", "if", "(", "$", "params", "[", "'icon'", "]", ")", "$", "json", "->", "{", "'icon'", "}", "->", "{", "'@id'", "}", "=", "$", "params", "[", "'icon'", "]", ";", "if", "(", "$", "params", "[", "'fa_icon'", "]", ")", "$", "json", "->", "icon", "->", "fa_icon", "=", "$", "params", "[", "'fa_icon'", "]", ";", "if", "(", "$", "params", "[", "'placementTarget'", "]", ")", "$", "json", "->", "placementAdvice", "->", "presentationDocumentTarget", "=", "$", "params", "[", "'placementTarget'", "]", ";", "if", "(", "$", "params", "[", "'placementWindowTarget'", "]", ")", "$", "json", "->", "placementAdvice", "->", "windowTarget", "=", "$", "params", "[", "'placementWindowTarget'", "]", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'placementWidth'", "]", ")", ")", "$", "json", "->", "placementAdvice", "->", "displayWidth", "=", "$", "params", "[", "'placementWidth'", "]", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'placementHeight'", "]", ")", ")", "$", "json", "->", "placementAdvice", "->", "displayHeight", "=", "$", "params", "[", "'placementHeight'", "]", ";", "$", "json", "->", "{", "'@id'", "}", "=", "':item'", ".", "(", "count", "(", "$", "this", "->", "json", "->", "{", "'@graph'", "}", ")", "+", "1", ")", ";", "$", "this", "->", "json", "->", "{", "'@graph'", "}", "[", "]", "=", "$", "json", ";", "}" ]
addContentItemExtended - Add an Content Item @param $params Key/Value pair of configurable options for content item (see addContentItem)
[ "addContentItemExtended", "-", "Add", "an", "Content", "Item" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkResponse.php#L256-L311
train
tsugiproject/tsugi-php
src/Util/DeepLinkResponse.php
DeepLinkResponse.addFileItem
public function addFileItem($url, $title=false, $additionalParams = array()) { $item = '{ "@type" : "FileItem", "url" : "http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd", "copyAdvice" : "true", "expiresAt" : "2014-03-05T00:00:00Z", "mediaType" : "application/xml", "title" : "Imported from Tsugi", "placementAdvice" : { "windowTarget" : "_blank" } }'; if (empty($additionalParams['placementTarget'])) $additionalParams['placementTarget'] = 'window'; if (empty($additionalParams['placementWindowTarget'])) $additionalParams['placementWindowTarget'] = '_blank'; if (empty($additionalParams['placementWidth'])) $additionalParams['placementWidth'] = ''; if (empty($additionalParams['placementHeight'])) $additionalParams['placementHeight'] = ''; $json = json_decode($item); $json->url = $url; if ( $params['title'] ) $json->{'title'} = $params['title']; $datetime = (new \DateTime('+1 day'))->format(\DateTime::ATOM); $datetime = substr($datetime,0,19) . 'Z'; $json->expiresAt = $datetime; if ($additionalParams['placementTarget']) $json->placementAdvice->presentationDocumentTarget = $additionalParams['placementTarget']; if ($additionalParams['placementWindowTarget']) $json->placementAdvice->windowTarget = $additionalParams['placementWindowTarget']; if (! empty($additionalParams['placementWidth'])) $json->placementAdvice->displayWidth = $additionalParams['placementWidth']; if (! empty($additionalParams['placementHeight'])) $json->placementAdvice->displayHeight = $additionalParams['placementHeight']; $json->{'@id'} = ':item'.(count($this->json->{'@graph'})+1); $this->json->{'@graph'}[] = $json; }
php
public function addFileItem($url, $title=false, $additionalParams = array()) { $item = '{ "@type" : "FileItem", "url" : "http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd", "copyAdvice" : "true", "expiresAt" : "2014-03-05T00:00:00Z", "mediaType" : "application/xml", "title" : "Imported from Tsugi", "placementAdvice" : { "windowTarget" : "_blank" } }'; if (empty($additionalParams['placementTarget'])) $additionalParams['placementTarget'] = 'window'; if (empty($additionalParams['placementWindowTarget'])) $additionalParams['placementWindowTarget'] = '_blank'; if (empty($additionalParams['placementWidth'])) $additionalParams['placementWidth'] = ''; if (empty($additionalParams['placementHeight'])) $additionalParams['placementHeight'] = ''; $json = json_decode($item); $json->url = $url; if ( $params['title'] ) $json->{'title'} = $params['title']; $datetime = (new \DateTime('+1 day'))->format(\DateTime::ATOM); $datetime = substr($datetime,0,19) . 'Z'; $json->expiresAt = $datetime; if ($additionalParams['placementTarget']) $json->placementAdvice->presentationDocumentTarget = $additionalParams['placementTarget']; if ($additionalParams['placementWindowTarget']) $json->placementAdvice->windowTarget = $additionalParams['placementWindowTarget']; if (! empty($additionalParams['placementWidth'])) $json->placementAdvice->displayWidth = $additionalParams['placementWidth']; if (! empty($additionalParams['placementHeight'])) $json->placementAdvice->displayHeight = $additionalParams['placementHeight']; $json->{'@id'} = ':item'.(count($this->json->{'@graph'})+1); $this->json->{'@graph'}[] = $json; }
[ "public", "function", "addFileItem", "(", "$", "url", ",", "$", "title", "=", "false", ",", "$", "additionalParams", "=", "array", "(", ")", ")", "{", "$", "item", "=", "'{\n \"@type\" : \"FileItem\",\n \"url\" : \"http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd\",\n \"copyAdvice\" : \"true\",\n \"expiresAt\" : \"2014-03-05T00:00:00Z\",\n \"mediaType\" : \"application/xml\",\n \"title\" : \"Imported from Tsugi\",\n \"placementAdvice\" : {\n \"windowTarget\" : \"_blank\"\n }\n}'", ";", "if", "(", "empty", "(", "$", "additionalParams", "[", "'placementTarget'", "]", ")", ")", "$", "additionalParams", "[", "'placementTarget'", "]", "=", "'window'", ";", "if", "(", "empty", "(", "$", "additionalParams", "[", "'placementWindowTarget'", "]", ")", ")", "$", "additionalParams", "[", "'placementWindowTarget'", "]", "=", "'_blank'", ";", "if", "(", "empty", "(", "$", "additionalParams", "[", "'placementWidth'", "]", ")", ")", "$", "additionalParams", "[", "'placementWidth'", "]", "=", "''", ";", "if", "(", "empty", "(", "$", "additionalParams", "[", "'placementHeight'", "]", ")", ")", "$", "additionalParams", "[", "'placementHeight'", "]", "=", "''", ";", "$", "json", "=", "json_decode", "(", "$", "item", ")", ";", "$", "json", "->", "url", "=", "$", "url", ";", "if", "(", "$", "params", "[", "'title'", "]", ")", "$", "json", "->", "{", "'title'", "}", "=", "$", "params", "[", "'title'", "]", ";", "$", "datetime", "=", "(", "new", "\\", "DateTime", "(", "'+1 day'", ")", ")", "->", "format", "(", "\\", "DateTime", "::", "ATOM", ")", ";", "$", "datetime", "=", "substr", "(", "$", "datetime", ",", "0", ",", "19", ")", ".", "'Z'", ";", "$", "json", "->", "expiresAt", "=", "$", "datetime", ";", "if", "(", "$", "additionalParams", "[", "'placementTarget'", "]", ")", "$", "json", "->", "placementAdvice", "->", "presentationDocumentTarget", "=", "$", "additionalParams", "[", "'placementTarget'", "]", ";", "if", "(", "$", "additionalParams", "[", "'placementWindowTarget'", "]", ")", "$", "json", "->", "placementAdvice", "->", "windowTarget", "=", "$", "additionalParams", "[", "'placementWindowTarget'", "]", ";", "if", "(", "!", "empty", "(", "$", "additionalParams", "[", "'placementWidth'", "]", ")", ")", "$", "json", "->", "placementAdvice", "->", "displayWidth", "=", "$", "additionalParams", "[", "'placementWidth'", "]", ";", "if", "(", "!", "empty", "(", "$", "additionalParams", "[", "'placementHeight'", "]", ")", ")", "$", "json", "->", "placementAdvice", "->", "displayHeight", "=", "$", "additionalParams", "[", "'placementHeight'", "]", ";", "$", "json", "->", "{", "'@id'", "}", "=", "':item'", ".", "(", "count", "(", "$", "this", "->", "json", "->", "{", "'@graph'", "}", ")", "+", "1", ")", ";", "$", "this", "->", "json", "->", "{", "'@graph'", "}", "[", "]", "=", "$", "json", ";", "}" ]
addFileItem - Add an File Item @param url The launch URL of the tool that is about to be placed @param title A plain text title of the content-item. @params additionalParams Array of configurable parameters for LTI placement (options: placementTarget, placementWidth, placementHeight)
[ "addFileItem", "-", "Add", "an", "File", "Item" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkResponse.php#L321-L364
train
tsugiproject/tsugi-php
src/UI/MenuSet.php
MenuSet.setHome
public function setHome($link, $href) { $this->home = new \Tsugi\UI\MenuEntry($link, $href); return $this; }
php
public function setHome($link, $href) { $this->home = new \Tsugi\UI\MenuEntry($link, $href); return $this; }
[ "public", "function", "setHome", "(", "$", "link", ",", "$", "href", ")", "{", "$", "this", "->", "home", "=", "new", "\\", "Tsugi", "\\", "UI", "\\", "MenuEntry", "(", "$", "link", ",", "$", "href", ")", ";", "return", "$", "this", ";", "}" ]
Set the Home Menu @param $link The text of the link - can be text, HTML, or even an img tag @param $href An optional place to go when the link is clicked @return MenuSet The instance to allow for chaining
[ "Set", "the", "Home", "Menu" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/MenuSet.php#L39-L43
train
tsugiproject/tsugi-php
src/UI/MenuSet.php
MenuSet.addLeft
public function addLeft($link, $href, $push=false) { if ( $this->left == false ) $this->left = new Menu(); $x = new \Tsugi\UI\MenuEntry($link, $href, $push); $this->left->add($x, $push); return $this; }
php
public function addLeft($link, $href, $push=false) { if ( $this->left == false ) $this->left = new Menu(); $x = new \Tsugi\UI\MenuEntry($link, $href, $push); $this->left->add($x, $push); return $this; }
[ "public", "function", "addLeft", "(", "$", "link", ",", "$", "href", ",", "$", "push", "=", "false", ")", "{", "if", "(", "$", "this", "->", "left", "==", "false", ")", "$", "this", "->", "left", "=", "new", "Menu", "(", ")", ";", "$", "x", "=", "new", "\\", "Tsugi", "\\", "UI", "\\", "MenuEntry", "(", "$", "link", ",", "$", "href", ",", "$", "push", ")", ";", "$", "this", "->", "left", "->", "add", "(", "$", "x", ",", "$", "push", ")", ";", "return", "$", "this", ";", "}" ]
Add an entty to the Left Menu @param $link The text of the link - can be text, HTML, or even an img tag @param $href An optional place to go when the link is clicked @param $push Indicates to push down the other menu entries @return MenuSet The instance to allow for chaining
[ "Add", "an", "entty", "to", "the", "Left", "Menu" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/MenuSet.php#L54-L60
train
tsugiproject/tsugi-php
src/UI/MenuSet.php
MenuSet.addRight
public function addRight($link, $href, $push=true) { if ( $this->right == false ) $this->right = new Menu(); $x = new \Tsugi\UI\MenuEntry($link, $href, $push); $this->right->add($x, $push); return $this; }
php
public function addRight($link, $href, $push=true) { if ( $this->right == false ) $this->right = new Menu(); $x = new \Tsugi\UI\MenuEntry($link, $href, $push); $this->right->add($x, $push); return $this; }
[ "public", "function", "addRight", "(", "$", "link", ",", "$", "href", ",", "$", "push", "=", "true", ")", "{", "if", "(", "$", "this", "->", "right", "==", "false", ")", "$", "this", "->", "right", "=", "new", "Menu", "(", ")", ";", "$", "x", "=", "new", "\\", "Tsugi", "\\", "UI", "\\", "MenuEntry", "(", "$", "link", ",", "$", "href", ",", "$", "push", ")", ";", "$", "this", "->", "right", "->", "add", "(", "$", "x", ",", "$", "push", ")", ";", "return", "$", "this", ";", "}" ]
Add an entty to the Right Menu @param $link The text of the link - can be text, HTML, or even an img tag @param $href An optional place to go when the link is clicked @param $push Indicates to push down the other menu entries @return MenuSet The instance to allow for chaining
[ "Add", "an", "entty", "to", "the", "Right", "Menu" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/MenuSet.php#L71-L77
train
tsugiproject/tsugi-php
src/UI/MenuSet.php
MenuSet.export
public function export($pretty=false) { $tmp = new \stdClass(); if ( $this->home != false ) $tmp->home = $this->home; if ( $this->left != false ) $tmp->left = $this->left->menu; if ( $this->right != false ) $tmp->right = $this->right->menu; if ( $pretty ) { return json_encode($tmp, JSON_PRETTY_PRINT); } else { return json_encode($tmp); } }
php
public function export($pretty=false) { $tmp = new \stdClass(); if ( $this->home != false ) $tmp->home = $this->home; if ( $this->left != false ) $tmp->left = $this->left->menu; if ( $this->right != false ) $tmp->right = $this->right->menu; if ( $pretty ) { return json_encode($tmp, JSON_PRETTY_PRINT); } else { return json_encode($tmp); } }
[ "public", "function", "export", "(", "$", "pretty", "=", "false", ")", "{", "$", "tmp", "=", "new", "\\", "stdClass", "(", ")", ";", "if", "(", "$", "this", "->", "home", "!=", "false", ")", "$", "tmp", "->", "home", "=", "$", "this", "->", "home", ";", "if", "(", "$", "this", "->", "left", "!=", "false", ")", "$", "tmp", "->", "left", "=", "$", "this", "->", "left", "->", "menu", ";", "if", "(", "$", "this", "->", "right", "!=", "false", ")", "$", "tmp", "->", "right", "=", "$", "this", "->", "right", "->", "menu", ";", "if", "(", "$", "pretty", ")", "{", "return", "json_encode", "(", "$", "tmp", ",", "JSON_PRETTY_PRINT", ")", ";", "}", "else", "{", "return", "json_encode", "(", "$", "tmp", ")", ";", "}", "}" ]
Export a menu to JSON @param $pretty - True if we want pretty output @return string JSON string for the menu
[ "Export", "a", "menu", "to", "JSON" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/MenuSet.php#L86-L97
train
tsugiproject/tsugi-php
src/UI/MenuSet.php
MenuSet.import
public static function import($json_str) { try { $json = json_decode($json_str); // print_r($json); $retval = new MenuSet(); $retval->home = new \Tsugi\UI\MenuEntry($json->home->link, $json->home->href); if ( isset($json->left) ) $retval->left = self::importRecurse($json->left, 0); if ( isset($json->right) ) $retval->right = self::importRecurse($json->right, 0); return $retval; } catch (Exception $e) { return false; } }
php
public static function import($json_str) { try { $json = json_decode($json_str); // print_r($json); $retval = new MenuSet(); $retval->home = new \Tsugi\UI\MenuEntry($json->home->link, $json->home->href); if ( isset($json->left) ) $retval->left = self::importRecurse($json->left, 0); if ( isset($json->right) ) $retval->right = self::importRecurse($json->right, 0); return $retval; } catch (Exception $e) { return false; } }
[ "public", "static", "function", "import", "(", "$", "json_str", ")", "{", "try", "{", "$", "json", "=", "json_decode", "(", "$", "json_str", ")", ";", "// print_r($json);", "$", "retval", "=", "new", "MenuSet", "(", ")", ";", "$", "retval", "->", "home", "=", "new", "\\", "Tsugi", "\\", "UI", "\\", "MenuEntry", "(", "$", "json", "->", "home", "->", "link", ",", "$", "json", "->", "home", "->", "href", ")", ";", "if", "(", "isset", "(", "$", "json", "->", "left", ")", ")", "$", "retval", "->", "left", "=", "self", "::", "importRecurse", "(", "$", "json", "->", "left", ",", "0", ")", ";", "if", "(", "isset", "(", "$", "json", "->", "right", ")", ")", "$", "retval", "->", "right", "=", "self", "::", "importRecurse", "(", "$", "json", "->", "right", ",", "0", ")", ";", "return", "$", "retval", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Import a menu from JSON @param $json_str The menu as exported @return The MenuSet as parsed or false on error
[ "Import", "a", "menu", "from", "JSON" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/MenuSet.php#L106-L119
train
tsugiproject/tsugi-php
src/UI/MenuSet.php
MenuSet.importRecurse
private static function importRecurse($entry, $depth) { if ( isset($entry->menu) ) $entry = $entry->menu; // Skip right past these if ( ! is_array($entry) ) { $link = $entry->link; $href = $entry->href; if ( is_string($href) ) { return new \Tsugi\UI\MenuEntry($link, $href); } $submenu = self::importRecurse($href, $depth+1); return new \Tsugi\UI\MenuEntry($link, $submenu); } $submenu = new \Tsugi\UI\Menu(); foreach($entry as $child) { $submenu->add(self::importRecurse($child, $depth+1)); } return $submenu; }
php
private static function importRecurse($entry, $depth) { if ( isset($entry->menu) ) $entry = $entry->menu; // Skip right past these if ( ! is_array($entry) ) { $link = $entry->link; $href = $entry->href; if ( is_string($href) ) { return new \Tsugi\UI\MenuEntry($link, $href); } $submenu = self::importRecurse($href, $depth+1); return new \Tsugi\UI\MenuEntry($link, $submenu); } $submenu = new \Tsugi\UI\Menu(); foreach($entry as $child) { $submenu->add(self::importRecurse($child, $depth+1)); } return $submenu; }
[ "private", "static", "function", "importRecurse", "(", "$", "entry", ",", "$", "depth", ")", "{", "if", "(", "isset", "(", "$", "entry", "->", "menu", ")", ")", "$", "entry", "=", "$", "entry", "->", "menu", ";", "// Skip right past these", "if", "(", "!", "is_array", "(", "$", "entry", ")", ")", "{", "$", "link", "=", "$", "entry", "->", "link", ";", "$", "href", "=", "$", "entry", "->", "href", ";", "if", "(", "is_string", "(", "$", "href", ")", ")", "{", "return", "new", "\\", "Tsugi", "\\", "UI", "\\", "MenuEntry", "(", "$", "link", ",", "$", "href", ")", ";", "}", "$", "submenu", "=", "self", "::", "importRecurse", "(", "$", "href", ",", "$", "depth", "+", "1", ")", ";", "return", "new", "\\", "Tsugi", "\\", "UI", "\\", "MenuEntry", "(", "$", "link", ",", "$", "submenu", ")", ";", "}", "$", "submenu", "=", "new", "\\", "Tsugi", "\\", "UI", "\\", "Menu", "(", ")", ";", "foreach", "(", "$", "entry", "as", "$", "child", ")", "{", "$", "submenu", "->", "add", "(", "self", "::", "importRecurse", "(", "$", "child", ",", "$", "depth", "+", "1", ")", ")", ";", "}", "return", "$", "submenu", ";", "}" ]
Walk a JSON tree to import a hierarchy of menus
[ "Walk", "a", "JSON", "tree", "to", "import", "a", "hierarchy", "of", "menus" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/MenuSet.php#L124-L141
train
rokka-io/rokka-client-php
src/Base.php
Base.call
protected function call($method, $path, array $options = [], $needsCredentials = true) { $options['headers'][self::API_VERSION_HEADER] = $this->apiVersion; if ($needsCredentials) { $options['headers'][self::API_KEY_HEADER] = $this->credentials['key']; } return $this->client->request($method, $path, $options); }
php
protected function call($method, $path, array $options = [], $needsCredentials = true) { $options['headers'][self::API_VERSION_HEADER] = $this->apiVersion; if ($needsCredentials) { $options['headers'][self::API_KEY_HEADER] = $this->credentials['key']; } return $this->client->request($method, $path, $options); }
[ "protected", "function", "call", "(", "$", "method", ",", "$", "path", ",", "array", "$", "options", "=", "[", "]", ",", "$", "needsCredentials", "=", "true", ")", "{", "$", "options", "[", "'headers'", "]", "[", "self", "::", "API_VERSION_HEADER", "]", "=", "$", "this", "->", "apiVersion", ";", "if", "(", "$", "needsCredentials", ")", "{", "$", "options", "[", "'headers'", "]", "[", "self", "::", "API_KEY_HEADER", "]", "=", "$", "this", "->", "credentials", "[", "'key'", "]", ";", "}", "return", "$", "this", "->", "client", "->", "request", "(", "$", "method", ",", "$", "path", ",", "$", "options", ")", ";", "}" ]
Call the API rokka endpoint. @param string $method HTTP method to use @param string $path Path on the API @param array $options Request options @param bool $needsCredentials True if credentials are needed @throws GuzzleException @return ResponseInterface
[ "Call", "the", "API", "rokka", "endpoint", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Base.php#L85-L94
train
rokka-io/rokka-client-php
src/Base.php
Base.getOrganizationName
protected function getOrganizationName($organization = null) { $org = (empty($organization)) ? $this->defaultOrganization : $organization; if (null === $org) { throw new \RuntimeException('Organization is empty'); } return $org; }
php
protected function getOrganizationName($organization = null) { $org = (empty($organization)) ? $this->defaultOrganization : $organization; if (null === $org) { throw new \RuntimeException('Organization is empty'); } return $org; }
[ "protected", "function", "getOrganizationName", "(", "$", "organization", "=", "null", ")", "{", "$", "org", "=", "(", "empty", "(", "$", "organization", ")", ")", "?", "$", "this", "->", "defaultOrganization", ":", "$", "organization", ";", "if", "(", "null", "===", "$", "org", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Organization is empty'", ")", ";", "}", "return", "$", "org", ";", "}" ]
Return the organization or the default if empty. @param string|null $organization Organization @throws \RuntimeException @return string
[ "Return", "the", "organization", "or", "the", "default", "if", "empty", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Base.php#L105-L113
train
tsugiproject/tsugi-php
src/Core/Result.php
Result.lookupResultBypass
public static function lookupResultBypass($user_id) { global $CFG, $PDOX, $CONTEXT, $LINK; $stmt = $PDOX->queryDie( "SELECT result_id, R.link_id AS link_id, R.user_id AS user_id, sourcedid, service_id, grade, note, R.json AS json, R.note AS note FROM {$CFG->dbprefix}lti_result AS R JOIN {$CFG->dbprefix}lti_link AS L ON L.link_id = R.link_id AND R.link_id = :LID JOIN {$CFG->dbprefix}lti_user AS U ON U.user_id = R.user_id AND U.user_id = :UID JOIN {$CFG->dbprefix}lti_context AS C ON L.context_id = C.context_id AND C.context_id = :CID WHERE R.user_id = :UID and U.user_id = :UID AND L.link_id = :LID", array(":LID" => $LINK->id, ":CID" => $CONTEXT->id, ":UID" => $user_id) ); $row = $stmt->fetch(\PDO::FETCH_ASSOC); return $row; }
php
public static function lookupResultBypass($user_id) { global $CFG, $PDOX, $CONTEXT, $LINK; $stmt = $PDOX->queryDie( "SELECT result_id, R.link_id AS link_id, R.user_id AS user_id, sourcedid, service_id, grade, note, R.json AS json, R.note AS note FROM {$CFG->dbprefix}lti_result AS R JOIN {$CFG->dbprefix}lti_link AS L ON L.link_id = R.link_id AND R.link_id = :LID JOIN {$CFG->dbprefix}lti_user AS U ON U.user_id = R.user_id AND U.user_id = :UID JOIN {$CFG->dbprefix}lti_context AS C ON L.context_id = C.context_id AND C.context_id = :CID WHERE R.user_id = :UID and U.user_id = :UID AND L.link_id = :LID", array(":LID" => $LINK->id, ":CID" => $CONTEXT->id, ":UID" => $user_id) ); $row = $stmt->fetch(\PDO::FETCH_ASSOC); return $row; }
[ "public", "static", "function", "lookupResultBypass", "(", "$", "user_id", ")", "{", "global", "$", "CFG", ",", "$", "PDOX", ",", "$", "CONTEXT", ",", "$", "LINK", ";", "$", "stmt", "=", "$", "PDOX", "->", "queryDie", "(", "\"SELECT result_id, R.link_id AS link_id, R.user_id AS user_id,\n sourcedid, service_id, grade, note, R.json AS json, R.note AS note\n FROM {$CFG->dbprefix}lti_result AS R\n JOIN {$CFG->dbprefix}lti_link AS L\n ON L.link_id = R.link_id AND R.link_id = :LID\n JOIN {$CFG->dbprefix}lti_user AS U\n ON U.user_id = R.user_id AND U.user_id = :UID\n JOIN {$CFG->dbprefix}lti_context AS C\n ON L.context_id = C.context_id AND C.context_id = :CID\n WHERE R.user_id = :UID and U.user_id = :UID AND L.link_id = :LID\"", ",", "array", "(", "\":LID\"", "=>", "$", "LINK", "->", "id", ",", "\":CID\"", "=>", "$", "CONTEXT", "->", "id", ",", "\":UID\"", "=>", "$", "user_id", ")", ")", ";", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "row", ";", "}" ]
hence the complex query to make sure we don't cross silos
[ "hence", "the", "complex", "query", "to", "make", "sure", "we", "don", "t", "cross", "silos" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Result.php#L41-L59
train
tsugiproject/tsugi-php
src/Core/Result.php
Result.gradeGet
public static function gradeGet($row=false, &$debug_log=false) { global $CFG; $PDOX = LTIX::getConnection(); $key_key = LTIX::ltiParameter('key_key'); $secret = LTIX::decrypt_secret(LTIX::ltiParameter('secret')); if ( $row !== false ) { $sourcedid = isset($row['sourcedid']) ? $row['sourcedid'] : false; $service = isset($row['service']) ? $row['service'] : false; // Fall back to session if it is missing if ( $service === false ) $service = LTIX::ltiParameter('service'); $result_id = isset($row['result_id']) ? $row['result_id'] : false; } else { $sourcedid = LTIX::ltiParameter('sourcedid'); $service = LTIX::ltiParameter('service'); $result_id = LTIX::ltiParameter('result_id'); } if ( $key_key == false || $secret === false || $sourcedid === false || $service === false ) { error_log("Result::gradeGet is missing required data"); return false; } $grade = LTI::getPOXGrade($sourcedid, $service, $key_key, $secret, $debug_log); if ( is_string($grade) ) return $grade; // UPDATE our local copy of the server's view of the grade if ( $result_id !== false ) { $stmt = $PDOX->queryDie( "UPDATE {$CFG->dbprefix}lti_result SET server_grade = :server_grade, retrieved_at = NOW() WHERE result_id = :RID", array( ':server_grade' => $grade, ":RID" => $result_id) ); } return $grade; }
php
public static function gradeGet($row=false, &$debug_log=false) { global $CFG; $PDOX = LTIX::getConnection(); $key_key = LTIX::ltiParameter('key_key'); $secret = LTIX::decrypt_secret(LTIX::ltiParameter('secret')); if ( $row !== false ) { $sourcedid = isset($row['sourcedid']) ? $row['sourcedid'] : false; $service = isset($row['service']) ? $row['service'] : false; // Fall back to session if it is missing if ( $service === false ) $service = LTIX::ltiParameter('service'); $result_id = isset($row['result_id']) ? $row['result_id'] : false; } else { $sourcedid = LTIX::ltiParameter('sourcedid'); $service = LTIX::ltiParameter('service'); $result_id = LTIX::ltiParameter('result_id'); } if ( $key_key == false || $secret === false || $sourcedid === false || $service === false ) { error_log("Result::gradeGet is missing required data"); return false; } $grade = LTI::getPOXGrade($sourcedid, $service, $key_key, $secret, $debug_log); if ( is_string($grade) ) return $grade; // UPDATE our local copy of the server's view of the grade if ( $result_id !== false ) { $stmt = $PDOX->queryDie( "UPDATE {$CFG->dbprefix}lti_result SET server_grade = :server_grade, retrieved_at = NOW() WHERE result_id = :RID", array( ':server_grade' => $grade, ":RID" => $result_id) ); } return $grade; }
[ "public", "static", "function", "gradeGet", "(", "$", "row", "=", "false", ",", "&", "$", "debug_log", "=", "false", ")", "{", "global", "$", "CFG", ";", "$", "PDOX", "=", "LTIX", "::", "getConnection", "(", ")", ";", "$", "key_key", "=", "LTIX", "::", "ltiParameter", "(", "'key_key'", ")", ";", "$", "secret", "=", "LTIX", "::", "decrypt_secret", "(", "LTIX", "::", "ltiParameter", "(", "'secret'", ")", ")", ";", "if", "(", "$", "row", "!==", "false", ")", "{", "$", "sourcedid", "=", "isset", "(", "$", "row", "[", "'sourcedid'", "]", ")", "?", "$", "row", "[", "'sourcedid'", "]", ":", "false", ";", "$", "service", "=", "isset", "(", "$", "row", "[", "'service'", "]", ")", "?", "$", "row", "[", "'service'", "]", ":", "false", ";", "// Fall back to session if it is missing", "if", "(", "$", "service", "===", "false", ")", "$", "service", "=", "LTIX", "::", "ltiParameter", "(", "'service'", ")", ";", "$", "result_id", "=", "isset", "(", "$", "row", "[", "'result_id'", "]", ")", "?", "$", "row", "[", "'result_id'", "]", ":", "false", ";", "}", "else", "{", "$", "sourcedid", "=", "LTIX", "::", "ltiParameter", "(", "'sourcedid'", ")", ";", "$", "service", "=", "LTIX", "::", "ltiParameter", "(", "'service'", ")", ";", "$", "result_id", "=", "LTIX", "::", "ltiParameter", "(", "'result_id'", ")", ";", "}", "if", "(", "$", "key_key", "==", "false", "||", "$", "secret", "===", "false", "||", "$", "sourcedid", "===", "false", "||", "$", "service", "===", "false", ")", "{", "error_log", "(", "\"Result::gradeGet is missing required data\"", ")", ";", "return", "false", ";", "}", "$", "grade", "=", "LTI", "::", "getPOXGrade", "(", "$", "sourcedid", ",", "$", "service", ",", "$", "key_key", ",", "$", "secret", ",", "$", "debug_log", ")", ";", "if", "(", "is_string", "(", "$", "grade", ")", ")", "return", "$", "grade", ";", "// UPDATE our local copy of the server's view of the grade", "if", "(", "$", "result_id", "!==", "false", ")", "{", "$", "stmt", "=", "$", "PDOX", "->", "queryDie", "(", "\"UPDATE {$CFG->dbprefix}lti_result SET server_grade = :server_grade,\n retrieved_at = NOW() WHERE result_id = :RID\"", ",", "array", "(", "':server_grade'", "=>", "$", "grade", ",", "\":RID\"", "=>", "$", "result_id", ")", ")", ";", "}", "return", "$", "grade", ";", "}" ]
Load the grade for a particular row and update our local copy Call the right LTI service to retrieve the server's grade and update our local cached copy of the server_grade and the date retrieved. This routine pulls the key and secret from the LTIX session to avoid crossing cross tennant boundaries. TODO: Add LTI 2.x support for the JSON style services to this @param $row An optional array with the data that has the result_id, sourcedid, and service (url) if this is not present, the data is pulled from the LTI session for the current user/link combination. @param $debug_log An (optional) array (by reference) that returns the steps that were taken. Each entry is an array with the [0] element a message and an optional [1] element as some detail (i.e. like a POST body) @return mixed If this work this returns a float. If not you get a string with an error.
[ "Load", "the", "grade", "for", "a", "particular", "row", "and", "update", "our", "local", "copy" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Result.php#L83-L121
train
tsugiproject/tsugi-php
src/Core/Result.php
Result.gradeSendDueDate
public function gradeSendDueDate($gradetosend, $oldgrade=false, $dueDate=false) { if ( $gradetosend == 1.0 ) { $scorestr = "Your answer is correct, score saved."; } else { $scorestr = "Your score of ".($gradetosend*100.0)."% has been saved."; } if ( $dueDate && $dueDate->penalty > 0 ) { $gradetosend = $gradetosend * (1.0 - $dueDate->penalty); $scorestr = "Effective Score = ".($gradetosend*100.0)."% after ".$dueDate->penalty*100.0." percent late penalty"; } if ( $oldgrade && $oldgrade > $gradetosend ) { $scorestr = "New score of ".($gradetosend*100.0)."% is < than previous grade of ".($oldgrade*100.0)."%, previous grade kept"; $gradetosend = $oldgrade; } // Use LTIX to store the grade in out database send the grade back to the LMS. $debug_log = array(); $retval = $this->gradeSend($gradetosend, false, $debug_log); $this->session_put('debug_log', $debug_log); if ( $retval === true ) { $this->session_put('success', $scorestr); } else if ( $retval === false ) { // Stored locally $this->session_put('success', $scorestr); } else if ( is_string($retval) ) { $this->session_put('error', "Grade not sent: ".$retval); } else { $svd = Output::safe_var_dump($retval); error_log("Grade sending error:".$svd); $this->session_put('error', "Grade sending error: ".substr($svd,0,100)); } }
php
public function gradeSendDueDate($gradetosend, $oldgrade=false, $dueDate=false) { if ( $gradetosend == 1.0 ) { $scorestr = "Your answer is correct, score saved."; } else { $scorestr = "Your score of ".($gradetosend*100.0)."% has been saved."; } if ( $dueDate && $dueDate->penalty > 0 ) { $gradetosend = $gradetosend * (1.0 - $dueDate->penalty); $scorestr = "Effective Score = ".($gradetosend*100.0)."% after ".$dueDate->penalty*100.0." percent late penalty"; } if ( $oldgrade && $oldgrade > $gradetosend ) { $scorestr = "New score of ".($gradetosend*100.0)."% is < than previous grade of ".($oldgrade*100.0)."%, previous grade kept"; $gradetosend = $oldgrade; } // Use LTIX to store the grade in out database send the grade back to the LMS. $debug_log = array(); $retval = $this->gradeSend($gradetosend, false, $debug_log); $this->session_put('debug_log', $debug_log); if ( $retval === true ) { $this->session_put('success', $scorestr); } else if ( $retval === false ) { // Stored locally $this->session_put('success', $scorestr); } else if ( is_string($retval) ) { $this->session_put('error', "Grade not sent: ".$retval); } else { $svd = Output::safe_var_dump($retval); error_log("Grade sending error:".$svd); $this->session_put('error', "Grade sending error: ".substr($svd,0,100)); } }
[ "public", "function", "gradeSendDueDate", "(", "$", "gradetosend", ",", "$", "oldgrade", "=", "false", ",", "$", "dueDate", "=", "false", ")", "{", "if", "(", "$", "gradetosend", "==", "1.0", ")", "{", "$", "scorestr", "=", "\"Your answer is correct, score saved.\"", ";", "}", "else", "{", "$", "scorestr", "=", "\"Your score of \"", ".", "(", "$", "gradetosend", "*", "100.0", ")", ".", "\"% has been saved.\"", ";", "}", "if", "(", "$", "dueDate", "&&", "$", "dueDate", "->", "penalty", ">", "0", ")", "{", "$", "gradetosend", "=", "$", "gradetosend", "*", "(", "1.0", "-", "$", "dueDate", "->", "penalty", ")", ";", "$", "scorestr", "=", "\"Effective Score = \"", ".", "(", "$", "gradetosend", "*", "100.0", ")", ".", "\"% after \"", ".", "$", "dueDate", "->", "penalty", "*", "100.0", ".", "\" percent late penalty\"", ";", "}", "if", "(", "$", "oldgrade", "&&", "$", "oldgrade", ">", "$", "gradetosend", ")", "{", "$", "scorestr", "=", "\"New score of \"", ".", "(", "$", "gradetosend", "*", "100.0", ")", ".", "\"% is < than previous grade of \"", ".", "(", "$", "oldgrade", "*", "100.0", ")", ".", "\"%, previous grade kept\"", ";", "$", "gradetosend", "=", "$", "oldgrade", ";", "}", "// Use LTIX to store the grade in out database send the grade back to the LMS.", "$", "debug_log", "=", "array", "(", ")", ";", "$", "retval", "=", "$", "this", "->", "gradeSend", "(", "$", "gradetosend", ",", "false", ",", "$", "debug_log", ")", ";", "$", "this", "->", "session_put", "(", "'debug_log'", ",", "$", "debug_log", ")", ";", "if", "(", "$", "retval", "===", "true", ")", "{", "$", "this", "->", "session_put", "(", "'success'", ",", "$", "scorestr", ")", ";", "}", "else", "if", "(", "$", "retval", "===", "false", ")", "{", "// Stored locally", "$", "this", "->", "session_put", "(", "'success'", ",", "$", "scorestr", ")", ";", "}", "else", "if", "(", "is_string", "(", "$", "retval", ")", ")", "{", "$", "this", "->", "session_put", "(", "'error'", ",", "\"Grade not sent: \"", ".", "$", "retval", ")", ";", "}", "else", "{", "$", "svd", "=", "Output", "::", "safe_var_dump", "(", "$", "retval", ")", ";", "error_log", "(", "\"Grade sending error:\"", ".", "$", "svd", ")", ";", "$", "this", "->", "session_put", "(", "'error'", ",", "\"Grade sending error: \"", ".", "substr", "(", "$", "svd", ",", "0", ",", "100", ")", ")", ";", "}", "}" ]
Send a grade applying the due date logic and only increasing grades Puts messages in the session for a redirect. @param $gradetosend - The grade in the range 0.0 .. 1.0 @param $oldgrade - The previous grade in the range 0.0 .. 1.0 (optional) @param $dueDate - The due date for this assignment
[ "Send", "a", "grade", "applying", "the", "due", "date", "logic", "and", "only", "increasing", "grades" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Result.php#L325-L356
train
tsugiproject/tsugi-php
src/Core/Result.php
Result.getJSON
public function getJSON() { global $CFG; $PDOX = $this->launch->pdox; $stmt = $PDOX->queryDie( "SELECT json FROM {$CFG->dbprefix}lti_result WHERE result_id = :RID", array(':RID' => $this->id) ); $row = $stmt->fetch(\PDO::FETCH_ASSOC); return $row['json']; }
php
public function getJSON() { global $CFG; $PDOX = $this->launch->pdox; $stmt = $PDOX->queryDie( "SELECT json FROM {$CFG->dbprefix}lti_result WHERE result_id = :RID", array(':RID' => $this->id) ); $row = $stmt->fetch(\PDO::FETCH_ASSOC); return $row['json']; }
[ "public", "function", "getJSON", "(", ")", "{", "global", "$", "CFG", ";", "$", "PDOX", "=", "$", "this", "->", "launch", "->", "pdox", ";", "$", "stmt", "=", "$", "PDOX", "->", "queryDie", "(", "\"SELECT json FROM {$CFG->dbprefix}lti_result\n WHERE result_id = :RID\"", ",", "array", "(", "':RID'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "row", "[", "'json'", "]", ";", "}" ]
Get the JSON for this result
[ "Get", "the", "JSON", "for", "this", "result" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Result.php#L361-L373
train
tsugiproject/tsugi-php
src/Core/Result.php
Result.setJSON
public function setJSON($json) { global $CFG; $PDOX = $this->launch->pdox; $stmt = $PDOX->queryDie( "UPDATE {$CFG->dbprefix}lti_result SET json = :json, updated_at = NOW() WHERE result_id = :RID", array( ':json' => $json, ':RID' => $this->id) ); }
php
public function setJSON($json) { global $CFG; $PDOX = $this->launch->pdox; $stmt = $PDOX->queryDie( "UPDATE {$CFG->dbprefix}lti_result SET json = :json, updated_at = NOW() WHERE result_id = :RID", array( ':json' => $json, ':RID' => $this->id) ); }
[ "public", "function", "setJSON", "(", "$", "json", ")", "{", "global", "$", "CFG", ";", "$", "PDOX", "=", "$", "this", "->", "launch", "->", "pdox", ";", "$", "stmt", "=", "$", "PDOX", "->", "queryDie", "(", "\"UPDATE {$CFG->dbprefix}lti_result SET json = :json, updated_at = NOW()\n WHERE result_id = :RID\"", ",", "array", "(", "':json'", "=>", "$", "json", ",", "':RID'", "=>", "$", "this", "->", "id", ")", ")", ";", "}" ]
Set the JSON for this result
[ "Set", "the", "JSON", "for", "this", "result" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Result.php#L378-L390
train
tsugiproject/tsugi-php
src/Core/Result.php
Result.setNote
public function setNote($note) { global $CFG; $PDOX = $this->launch->pdox; $stmt = $PDOX->queryDie( "UPDATE {$CFG->dbprefix}lti_result SET note = :note, updated_at = NOW() WHERE result_id = :RID", array( ':note' => $note, ':RID' => $this->id) ); }
php
public function setNote($note) { global $CFG; $PDOX = $this->launch->pdox; $stmt = $PDOX->queryDie( "UPDATE {$CFG->dbprefix}lti_result SET note = :note, updated_at = NOW() WHERE result_id = :RID", array( ':note' => $note, ':RID' => $this->id) ); }
[ "public", "function", "setNote", "(", "$", "note", ")", "{", "global", "$", "CFG", ";", "$", "PDOX", "=", "$", "this", "->", "launch", "->", "pdox", ";", "$", "stmt", "=", "$", "PDOX", "->", "queryDie", "(", "\"UPDATE {$CFG->dbprefix}lti_result SET note = :note, updated_at = NOW()\n WHERE result_id = :RID\"", ",", "array", "(", "':note'", "=>", "$", "note", ",", "':RID'", "=>", "$", "this", "->", "id", ")", ")", ";", "}" ]
Set the Note for this result
[ "Set", "the", "Note", "for", "this", "result" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Result.php#L412-L424
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.bodyStart
function bodyStart($checkpost=true) { global $CFG; ob_start(); // If we are in an iframe use different margins ?> </head> <body prefix="oer: http://oerschema.org"> <div id="body_container"> <script> if (window!=window.top) { document.getElementById("body_container").className = "container_iframe"; } else { document.getElementById("body_container").className = "container"; } </script> <?php if ( $checkpost && count($_POST) > 0 ) { $dump = self::safe_var_dump($_POST); echo('<p style="color:red">Error - Unhandled POST request</p>'); echo("\n<pre>\n"); echo($dump); if ( count($_FILES) > 0 ) { $files = self::safe_var_dump($_FILES); echo($files); } echo("\n</pre>\n"); error_log($dump); die_with_error_log("Unhandled POST request"); } // Complain if this is a test key $key_key = $this->ltiParameter('key_key'); if ( $key_key == '12345' && strpos($CFG->wwwroot, '://localhost') === false ) { echo('<div style="background-color: orange; position: absolute; bottom: 5px; left: 5px;">'); echo(_m('Test Key - Do not use for production')); echo('</div>'); } $HEAD_CONTENT_SENT = true; $ob_output = ob_get_contents(); ob_end_clean(); if ( $this->buffer ) return $ob_output; echo($ob_output); }
php
function bodyStart($checkpost=true) { global $CFG; ob_start(); // If we are in an iframe use different margins ?> </head> <body prefix="oer: http://oerschema.org"> <div id="body_container"> <script> if (window!=window.top) { document.getElementById("body_container").className = "container_iframe"; } else { document.getElementById("body_container").className = "container"; } </script> <?php if ( $checkpost && count($_POST) > 0 ) { $dump = self::safe_var_dump($_POST); echo('<p style="color:red">Error - Unhandled POST request</p>'); echo("\n<pre>\n"); echo($dump); if ( count($_FILES) > 0 ) { $files = self::safe_var_dump($_FILES); echo($files); } echo("\n</pre>\n"); error_log($dump); die_with_error_log("Unhandled POST request"); } // Complain if this is a test key $key_key = $this->ltiParameter('key_key'); if ( $key_key == '12345' && strpos($CFG->wwwroot, '://localhost') === false ) { echo('<div style="background-color: orange; position: absolute; bottom: 5px; left: 5px;">'); echo(_m('Test Key - Do not use for production')); echo('</div>'); } $HEAD_CONTENT_SENT = true; $ob_output = ob_get_contents(); ob_end_clean(); if ( $this->buffer ) return $ob_output; echo($ob_output); }
[ "function", "bodyStart", "(", "$", "checkpost", "=", "true", ")", "{", "global", "$", "CFG", ";", "ob_start", "(", ")", ";", "// If we are in an iframe use different margins", "?>\n</head>\n<body prefix=\"oer: http://oerschema.org\">\n<div id=\"body_container\">\n<script>\nif (window!=window.top) {\n document.getElementById(\"body_container\").className = \"container_iframe\";\n} else {\n document.getElementById(\"body_container\").className = \"container\";\n}\n</script>\n<?php", "if", "(", "$", "checkpost", "&&", "count", "(", "$", "_POST", ")", ">", "0", ")", "{", "$", "dump", "=", "self", "::", "safe_var_dump", "(", "$", "_POST", ")", ";", "echo", "(", "'<p style=\"color:red\">Error - Unhandled POST request</p>'", ")", ";", "echo", "(", "\"\\n<pre>\\n\"", ")", ";", "echo", "(", "$", "dump", ")", ";", "if", "(", "count", "(", "$", "_FILES", ")", ">", "0", ")", "{", "$", "files", "=", "self", "::", "safe_var_dump", "(", "$", "_FILES", ")", ";", "echo", "(", "$", "files", ")", ";", "}", "echo", "(", "\"\\n</pre>\\n\"", ")", ";", "error_log", "(", "$", "dump", ")", ";", "die_with_error_log", "(", "\"Unhandled POST request\"", ")", ";", "}", "// Complain if this is a test key", "$", "key_key", "=", "$", "this", "->", "ltiParameter", "(", "'key_key'", ")", ";", "if", "(", "$", "key_key", "==", "'12345'", "&&", "strpos", "(", "$", "CFG", "->", "wwwroot", ",", "'://localhost'", ")", "===", "false", ")", "{", "echo", "(", "'<div style=\"background-color: orange; position: absolute; bottom: 5px; left: 5px;\">'", ")", ";", "echo", "(", "_m", "(", "'Test Key - Do not use for production'", ")", ")", ";", "echo", "(", "'</div>'", ")", ";", "}", "$", "HEAD_CONTENT_SENT", "=", "true", ";", "$", "ob_output", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "if", "(", "$", "this", "->", "buffer", ")", "return", "$", "ob_output", ";", "echo", "(", "$", "ob_output", ")", ";", "}" ]
Finish the head and start the body of a Tsugi HTML page. By default this demands that we are in a GET request. It is a fatal error to call this code if we are responding to a POST request unless this behavior is overidden. @param $checkpost (optional, boolean) This can be set to false to emit the body start even for a POST request.
[ "Finish", "the", "head", "and", "start", "the", "body", "of", "a", "Tsugi", "HTML", "page", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L269-L314
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.getUtilUrl
public static function getUtilUrl($path) { global $CFG; if ( isset($CFG->utilroot) ) { return $CFG->utilroot.$path; } // From wwwroot $path = str_replace('.php','',$path); $retval = $CFG->wwwroot . '/util' . $path; return $retval; // The old way from "vendor" // return $CFG->vendorroot.$path; }
php
public static function getUtilUrl($path) { global $CFG; if ( isset($CFG->utilroot) ) { return $CFG->utilroot.$path; } // From wwwroot $path = str_replace('.php','',$path); $retval = $CFG->wwwroot . '/util' . $path; return $retval; // The old way from "vendor" // return $CFG->vendorroot.$path; }
[ "public", "static", "function", "getUtilUrl", "(", "$", "path", ")", "{", "global", "$", "CFG", ";", "if", "(", "isset", "(", "$", "CFG", "->", "utilroot", ")", ")", "{", "return", "$", "CFG", "->", "utilroot", ".", "$", "path", ";", "}", "// From wwwroot", "$", "path", "=", "str_replace", "(", "'.php'", ",", "''", ",", "$", "path", ")", ";", "$", "retval", "=", "$", "CFG", "->", "wwwroot", ".", "'/util'", ".", "$", "path", ";", "return", "$", "retval", ";", "// The old way from \"vendor\"", "// return $CFG->vendorroot.$path;", "}" ]
getUtilUrl - Get a URL in the utility script space - does not add session @param $path - The path of the file - should start with a slash.
[ "getUtilUrl", "-", "Get", "a", "URL", "in", "the", "utility", "script", "space", "-", "does", "not", "add", "session" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L431-L445
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.handleHeartBeat
public static function handleHeartBeat($cookie) { global $CFG; self::headerJson(); session_start(); $session_object = null; // TODO: Make sure to do the right thing with the session eventially // See how long since the last update of the activity time $now = time(); $seconds = $now - LTIX::wrapped_session_get($session_object, 'LAST_ACTIVITY', $now); LTIX::wrapped_session_put($session_object, 'LAST_ACTIVITY', $now); // update last activity time stamp // Count the successive heartbeats without a request/response cycle $count = LTIX::wrapped_session_get($session_object, 'HEARTBEAT_COUNT', 0); $count++; LTIX::wrapped_session_put($session_object, 'HEARTBEAT_COUNT', $count); if ( $count > 10 && ( $count % 100 ) == 0 ) { error_log("Heartbeat.php ".session_id().' '.$count); } $retval = array("success" => true, "seconds" => $seconds, "now" => $now, "count" => $count, "cookie" => $cookie, "id" => session_id()); $lti = LTIX::wrapped_session_get($session_object, 'lti'); $retval['lti'] = is_array($lti) && U::get($lti, 'key_id'); $retval['sessionlifetime'] = $CFG->sessionlifetime; return $retval; }
php
public static function handleHeartBeat($cookie) { global $CFG; self::headerJson(); session_start(); $session_object = null; // TODO: Make sure to do the right thing with the session eventially // See how long since the last update of the activity time $now = time(); $seconds = $now - LTIX::wrapped_session_get($session_object, 'LAST_ACTIVITY', $now); LTIX::wrapped_session_put($session_object, 'LAST_ACTIVITY', $now); // update last activity time stamp // Count the successive heartbeats without a request/response cycle $count = LTIX::wrapped_session_get($session_object, 'HEARTBEAT_COUNT', 0); $count++; LTIX::wrapped_session_put($session_object, 'HEARTBEAT_COUNT', $count); if ( $count > 10 && ( $count % 100 ) == 0 ) { error_log("Heartbeat.php ".session_id().' '.$count); } $retval = array("success" => true, "seconds" => $seconds, "now" => $now, "count" => $count, "cookie" => $cookie, "id" => session_id()); $lti = LTIX::wrapped_session_get($session_object, 'lti'); $retval['lti'] = is_array($lti) && U::get($lti, 'key_id'); $retval['sessionlifetime'] = $CFG->sessionlifetime; return $retval; }
[ "public", "static", "function", "handleHeartBeat", "(", "$", "cookie", ")", "{", "global", "$", "CFG", ";", "self", "::", "headerJson", "(", ")", ";", "session_start", "(", ")", ";", "$", "session_object", "=", "null", ";", "// TODO: Make sure to do the right thing with the session eventially", "// See how long since the last update of the activity time", "$", "now", "=", "time", "(", ")", ";", "$", "seconds", "=", "$", "now", "-", "LTIX", "::", "wrapped_session_get", "(", "$", "session_object", ",", "'LAST_ACTIVITY'", ",", "$", "now", ")", ";", "LTIX", "::", "wrapped_session_put", "(", "$", "session_object", ",", "'LAST_ACTIVITY'", ",", "$", "now", ")", ";", "// update last activity time stamp", "// Count the successive heartbeats without a request/response cycle", "$", "count", "=", "LTIX", "::", "wrapped_session_get", "(", "$", "session_object", ",", "'HEARTBEAT_COUNT'", ",", "0", ")", ";", "$", "count", "++", ";", "LTIX", "::", "wrapped_session_put", "(", "$", "session_object", ",", "'HEARTBEAT_COUNT'", ",", "$", "count", ")", ";", "if", "(", "$", "count", ">", "10", "&&", "(", "$", "count", "%", "100", ")", "==", "0", ")", "{", "error_log", "(", "\"Heartbeat.php \"", ".", "session_id", "(", ")", ".", "' '", ".", "$", "count", ")", ";", "}", "$", "retval", "=", "array", "(", "\"success\"", "=>", "true", ",", "\"seconds\"", "=>", "$", "seconds", ",", "\"now\"", "=>", "$", "now", ",", "\"count\"", "=>", "$", "count", ",", "\"cookie\"", "=>", "$", "cookie", ",", "\"id\"", "=>", "session_id", "(", ")", ")", ";", "$", "lti", "=", "LTIX", "::", "wrapped_session_get", "(", "$", "session_object", ",", "'lti'", ")", ";", "$", "retval", "[", "'lti'", "]", "=", "is_array", "(", "$", "lti", ")", "&&", "U", "::", "get", "(", "$", "lti", ",", "'key_id'", ")", ";", "$", "retval", "[", "'sessionlifetime'", "]", "=", "$", "CFG", "->", "sessionlifetime", ";", "return", "$", "retval", ";", "}" ]
Handle the heartbeat calls. This is UI code basically. Make sure when you call this, you have handled whether the session is cookie based or not and included config.php appropriately if ( isset($_GET[session_name()]) ) { $cookie = false; } else { define('COOKIE_SESSION', true); $cookie = true; } require_once "../config.php"; \Tsugi\UI\Output::handleHeartBeat($cookie);
[ "Handle", "the", "heartbeat", "calls", ".", "This", "is", "UI", "code", "basically", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L466-L498
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.welcomeUserCourse
function welcomeUserCourse() { global $USER, $CONTEXT; if ( isset($USER->displayname) ) { if ( isset($CONTEXT->title) ) { printf(_m("<p>Welcome %s from %s"), htmlent_utf8($USER->displayname), htmlent_utf8($CONTEXT->title)); } else { printf(_m("<p>Welcome %s"), htmlent_utf8($USER->displayname)); } } else { if ( isset($CONTEXT->title) ) { printf(_m("<p>Welcome from %s"), htmlent_utf8($CONTEXT->title)); } else { printf(_m("<p>Welcome ")); } } if ( $USER->admin ) { echo(" "._m("(Instructor+Administrator)")); } else if ( $USER->instructor ) { echo(" "._m("(Instructor)")); } echo("</p>\n"); }
php
function welcomeUserCourse() { global $USER, $CONTEXT; if ( isset($USER->displayname) ) { if ( isset($CONTEXT->title) ) { printf(_m("<p>Welcome %s from %s"), htmlent_utf8($USER->displayname), htmlent_utf8($CONTEXT->title)); } else { printf(_m("<p>Welcome %s"), htmlent_utf8($USER->displayname)); } } else { if ( isset($CONTEXT->title) ) { printf(_m("<p>Welcome from %s"), htmlent_utf8($CONTEXT->title)); } else { printf(_m("<p>Welcome ")); } } if ( $USER->admin ) { echo(" "._m("(Instructor+Administrator)")); } else if ( $USER->instructor ) { echo(" "._m("(Instructor)")); } echo("</p>\n"); }
[ "function", "welcomeUserCourse", "(", ")", "{", "global", "$", "USER", ",", "$", "CONTEXT", ";", "if", "(", "isset", "(", "$", "USER", "->", "displayname", ")", ")", "{", "if", "(", "isset", "(", "$", "CONTEXT", "->", "title", ")", ")", "{", "printf", "(", "_m", "(", "\"<p>Welcome %s from %s\"", ")", ",", "htmlent_utf8", "(", "$", "USER", "->", "displayname", ")", ",", "htmlent_utf8", "(", "$", "CONTEXT", "->", "title", ")", ")", ";", "}", "else", "{", "printf", "(", "_m", "(", "\"<p>Welcome %s\"", ")", ",", "htmlent_utf8", "(", "$", "USER", "->", "displayname", ")", ")", ";", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "CONTEXT", "->", "title", ")", ")", "{", "printf", "(", "_m", "(", "\"<p>Welcome from %s\"", ")", ",", "htmlent_utf8", "(", "$", "CONTEXT", "->", "title", ")", ")", ";", "}", "else", "{", "printf", "(", "_m", "(", "\"<p>Welcome \"", ")", ")", ";", "}", "}", "if", "(", "$", "USER", "->", "admin", ")", "{", "echo", "(", "\" \"", ".", "_m", "(", "\"(Instructor+Administrator)\"", ")", ")", ";", "}", "else", "if", "(", "$", "USER", "->", "instructor", ")", "{", "echo", "(", "\" \"", ".", "_m", "(", "\"(Instructor)\"", ")", ")", ";", "}", "echo", "(", "\"</p>\\n\"", ")", ";", "}" ]
Welcome the user to the course
[ "Welcome", "the", "user", "to", "the", "course" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L538-L560
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.closeButton
function closeButton($text=false) { if ( $text === false ) $text = _m("Exit"); $button = "btn-success"; if ( $text == "Cancel" || $text == _m("Cancel") ) $button = "btn-warning"; echo("<a href=\"#\" onclick=\"window_close();\" class=\"btn ".$button."\">".$text."</a>\n"); }
php
function closeButton($text=false) { if ( $text === false ) $text = _m("Exit"); $button = "btn-success"; if ( $text == "Cancel" || $text == _m("Cancel") ) $button = "btn-warning"; echo("<a href=\"#\" onclick=\"window_close();\" class=\"btn ".$button."\">".$text."</a>\n"); }
[ "function", "closeButton", "(", "$", "text", "=", "false", ")", "{", "if", "(", "$", "text", "===", "false", ")", "$", "text", "=", "_m", "(", "\"Exit\"", ")", ";", "$", "button", "=", "\"btn-success\"", ";", "if", "(", "$", "text", "==", "\"Cancel\"", "||", "$", "text", "==", "_m", "(", "\"Cancel\"", ")", ")", "$", "button", "=", "\"btn-warning\"", ";", "echo", "(", "\"<a href=\\\"#\\\" onclick=\\\"window_close();\\\" class=\\\"btn \"", ".", "$", "button", ".", "\"\\\">\"", ".", "$", "text", ".", "\"</a>\\n\"", ")", ";", "}" ]
Emit a properly styled close button for use in own popup
[ "Emit", "a", "properly", "styled", "close", "button", "for", "use", "in", "own", "popup" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L600-L605
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.topNavSession
function topNavSession($menuset) { global $CFG; $export = $menuset->export(); $sess_key = 'tsugi_top_nav_'.$CFG->wwwroot; if ( $this->session_get($sess_key) !== $export) { $this->session_put($sess_key, $export); } }
php
function topNavSession($menuset) { global $CFG; $export = $menuset->export(); $sess_key = 'tsugi_top_nav_'.$CFG->wwwroot; if ( $this->session_get($sess_key) !== $export) { $this->session_put($sess_key, $export); } }
[ "function", "topNavSession", "(", "$", "menuset", ")", "{", "global", "$", "CFG", ";", "$", "export", "=", "$", "menuset", "->", "export", "(", ")", ";", "$", "sess_key", "=", "'tsugi_top_nav_'", ".", "$", "CFG", "->", "wwwroot", ";", "if", "(", "$", "this", "->", "session_get", "(", "$", "sess_key", ")", "!==", "$", "export", ")", "{", "$", "this", "->", "session_put", "(", "$", "sess_key", ",", "$", "export", ")", ";", "}", "}" ]
Store the top navigation in the session
[ "Store", "the", "top", "navigation", "in", "the", "session" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L711-L718
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.topNav
function topNav($menu_set=false) { global $CFG, $LAUNCH; $sess_key = 'tsugi_top_nav_'.$CFG->wwwroot; $launch_return_url = $LAUNCH->ltiRawParameter('launch_presentation_return_url', false); $same_host = false; if ( $CFG->apphome && startsWith($launch_return_url, $CFG->apphome) ) $same_host = true; if ( $CFG->wwwroot && startsWith($launch_return_url, $CFG->wwwroot) ) $same_host = true; // Canvas bug: launch_target is iframe even in new window (2017-01-10) $launch_target = LTIX::ltiRawParameter('launch_presentation_document_target', false); if ( $menu_set === false && $this->session_get($sess_key) ) { $menu_set = \Tsugi\UI\MenuSet::import($this->session_get($sess_key)); } else if ( $menu_set === true ) { $menu_set = self::defaultMenuSet(); } else if ( $same_host && $launch_return_url ) { // If we are in an iframe we will be hidden $menu_set = self::returnMenuSet($launch_return_url); } else if ( $launch_target !== false && strtolower($launch_target) == 'window' ) { $menu_set = self::closeMenuSet(); // Since Coursers sets precious little } else if ( $LAUNCH->isCoursera() ) { $menu_set = self::closeMenuSet(); // Since canvas does not set launch_target properly } else if ( $launch_target !== false && ( $LAUNCH->isCanvas() || $LAUNCH->isCoursera() ) ) { $menu_set = self::closeMenuSet(); } else if ( $launch_return_url !== false ) { $menu_set = self::returnMenuSet($launch_return_url); } // Always put something out if we are an outer page - in an iframe, it will be hidden if ( $menu_set === false && defined('COOKIE_SESSION') ) { $menu_set = self::defaultMenuSet(); } if ( $menu_set === false ) { $menu_set = self::closeMenuSet(); } $menu_txt = self::menuNav($menu_set); if ( $this->buffer ) return $menu_txt; echo($menu_txt); }
php
function topNav($menu_set=false) { global $CFG, $LAUNCH; $sess_key = 'tsugi_top_nav_'.$CFG->wwwroot; $launch_return_url = $LAUNCH->ltiRawParameter('launch_presentation_return_url', false); $same_host = false; if ( $CFG->apphome && startsWith($launch_return_url, $CFG->apphome) ) $same_host = true; if ( $CFG->wwwroot && startsWith($launch_return_url, $CFG->wwwroot) ) $same_host = true; // Canvas bug: launch_target is iframe even in new window (2017-01-10) $launch_target = LTIX::ltiRawParameter('launch_presentation_document_target', false); if ( $menu_set === false && $this->session_get($sess_key) ) { $menu_set = \Tsugi\UI\MenuSet::import($this->session_get($sess_key)); } else if ( $menu_set === true ) { $menu_set = self::defaultMenuSet(); } else if ( $same_host && $launch_return_url ) { // If we are in an iframe we will be hidden $menu_set = self::returnMenuSet($launch_return_url); } else if ( $launch_target !== false && strtolower($launch_target) == 'window' ) { $menu_set = self::closeMenuSet(); // Since Coursers sets precious little } else if ( $LAUNCH->isCoursera() ) { $menu_set = self::closeMenuSet(); // Since canvas does not set launch_target properly } else if ( $launch_target !== false && ( $LAUNCH->isCanvas() || $LAUNCH->isCoursera() ) ) { $menu_set = self::closeMenuSet(); } else if ( $launch_return_url !== false ) { $menu_set = self::returnMenuSet($launch_return_url); } // Always put something out if we are an outer page - in an iframe, it will be hidden if ( $menu_set === false && defined('COOKIE_SESSION') ) { $menu_set = self::defaultMenuSet(); } if ( $menu_set === false ) { $menu_set = self::closeMenuSet(); } $menu_txt = self::menuNav($menu_set); if ( $this->buffer ) return $menu_txt; echo($menu_txt); }
[ "function", "topNav", "(", "$", "menu_set", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "LAUNCH", ";", "$", "sess_key", "=", "'tsugi_top_nav_'", ".", "$", "CFG", "->", "wwwroot", ";", "$", "launch_return_url", "=", "$", "LAUNCH", "->", "ltiRawParameter", "(", "'launch_presentation_return_url'", ",", "false", ")", ";", "$", "same_host", "=", "false", ";", "if", "(", "$", "CFG", "->", "apphome", "&&", "startsWith", "(", "$", "launch_return_url", ",", "$", "CFG", "->", "apphome", ")", ")", "$", "same_host", "=", "true", ";", "if", "(", "$", "CFG", "->", "wwwroot", "&&", "startsWith", "(", "$", "launch_return_url", ",", "$", "CFG", "->", "wwwroot", ")", ")", "$", "same_host", "=", "true", ";", "// Canvas bug: launch_target is iframe even in new window (2017-01-10)", "$", "launch_target", "=", "LTIX", "::", "ltiRawParameter", "(", "'launch_presentation_document_target'", ",", "false", ")", ";", "if", "(", "$", "menu_set", "===", "false", "&&", "$", "this", "->", "session_get", "(", "$", "sess_key", ")", ")", "{", "$", "menu_set", "=", "\\", "Tsugi", "\\", "UI", "\\", "MenuSet", "::", "import", "(", "$", "this", "->", "session_get", "(", "$", "sess_key", ")", ")", ";", "}", "else", "if", "(", "$", "menu_set", "===", "true", ")", "{", "$", "menu_set", "=", "self", "::", "defaultMenuSet", "(", ")", ";", "}", "else", "if", "(", "$", "same_host", "&&", "$", "launch_return_url", ")", "{", "// If we are in an iframe we will be hidden", "$", "menu_set", "=", "self", "::", "returnMenuSet", "(", "$", "launch_return_url", ")", ";", "}", "else", "if", "(", "$", "launch_target", "!==", "false", "&&", "strtolower", "(", "$", "launch_target", ")", "==", "'window'", ")", "{", "$", "menu_set", "=", "self", "::", "closeMenuSet", "(", ")", ";", "// Since Coursers sets precious little", "}", "else", "if", "(", "$", "LAUNCH", "->", "isCoursera", "(", ")", ")", "{", "$", "menu_set", "=", "self", "::", "closeMenuSet", "(", ")", ";", "// Since canvas does not set launch_target properly", "}", "else", "if", "(", "$", "launch_target", "!==", "false", "&&", "(", "$", "LAUNCH", "->", "isCanvas", "(", ")", "||", "$", "LAUNCH", "->", "isCoursera", "(", ")", ")", ")", "{", "$", "menu_set", "=", "self", "::", "closeMenuSet", "(", ")", ";", "}", "else", "if", "(", "$", "launch_return_url", "!==", "false", ")", "{", "$", "menu_set", "=", "self", "::", "returnMenuSet", "(", "$", "launch_return_url", ")", ";", "}", "// Always put something out if we are an outer page - in an iframe, it will be hidden", "if", "(", "$", "menu_set", "===", "false", "&&", "defined", "(", "'COOKIE_SESSION'", ")", ")", "{", "$", "menu_set", "=", "self", "::", "defaultMenuSet", "(", ")", ";", "}", "if", "(", "$", "menu_set", "===", "false", ")", "{", "$", "menu_set", "=", "self", "::", "closeMenuSet", "(", ")", ";", "}", "$", "menu_txt", "=", "self", "::", "menuNav", "(", "$", "menu_set", ")", ";", "if", "(", "$", "this", "->", "buffer", ")", "return", "$", "menu_txt", ";", "echo", "(", "$", "menu_txt", ")", ";", "}" ]
Emit the top navigation block Priority order: (1) Navigation in the session (2) If we are launched via LTI w/o a session
[ "Emit", "the", "top", "navigation", "block" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L727-L769
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.embeddedMenu
public static function embeddedMenu($url, $profile_email, $user_email) { global $CFG; if ( ! $CFG->unify ) return ''; if ( isset($_COOKIE['TSUGILINKDISMISS']) ) return ''; $message = htmlentities($profile_email); return <<< EOF <div id="tsugi-link-dialog" title="Read Only Dialog" style="display: none;"> <p>{$CFG->servicename} Message: You already have an account on this web site. Your current system-wide login is: <pre> $message </pre> Would you like to link these two accounts? </p><p> <button type="button" class="btn btn-primary" onclick=" $.getJSON('$url', function(retval) { tsugiSetCookie('TSUGILINKDISMISS', 'true', 30); $('#tsugi-link-dialog').dialog( 'close' ); $('#tsugi-embed-menu').hide(); }).error(function() { alert('Error in JSON call'); }); return false; ">Link Accounts</button> <button type="button" class="btn btn-secondary" onclick=" tsugiSetCookie('TSUGILINKDISMISS', 'true', 30); $('#tsugi-link-dialog').dialog( 'close' ); $('#tsugi-embed-menu').hide(); return false ;">Dismiss this notification</button> </p> </div> <div id="tsugi-embed-menu" style="display:none; position: fixed; top: 100px; right: 5px; width: 150px; "> <button style="float: right" class="btn btn-default" onclick="tsugiEmbedKeep();showModal('Link Accounts','tsugi-link-dialog'); return false;" > <span class="fa-stack fa-2x has-badge" data-count="1"> <i class="fa fa-square fa-stack-2x"></i> <i class="fa fa-paper-plane fa-stack-1x fa-inverse"></i> </span> </button></div> EOF; }
php
public static function embeddedMenu($url, $profile_email, $user_email) { global $CFG; if ( ! $CFG->unify ) return ''; if ( isset($_COOKIE['TSUGILINKDISMISS']) ) return ''; $message = htmlentities($profile_email); return <<< EOF <div id="tsugi-link-dialog" title="Read Only Dialog" style="display: none;"> <p>{$CFG->servicename} Message: You already have an account on this web site. Your current system-wide login is: <pre> $message </pre> Would you like to link these two accounts? </p><p> <button type="button" class="btn btn-primary" onclick=" $.getJSON('$url', function(retval) { tsugiSetCookie('TSUGILINKDISMISS', 'true', 30); $('#tsugi-link-dialog').dialog( 'close' ); $('#tsugi-embed-menu').hide(); }).error(function() { alert('Error in JSON call'); }); return false; ">Link Accounts</button> <button type="button" class="btn btn-secondary" onclick=" tsugiSetCookie('TSUGILINKDISMISS', 'true', 30); $('#tsugi-link-dialog').dialog( 'close' ); $('#tsugi-embed-menu').hide(); return false ;">Dismiss this notification</button> </p> </div> <div id="tsugi-embed-menu" style="display:none; position: fixed; top: 100px; right: 5px; width: 150px; "> <button style="float: right" class="btn btn-default" onclick="tsugiEmbedKeep();showModal('Link Accounts','tsugi-link-dialog'); return false;" > <span class="fa-stack fa-2x has-badge" data-count="1"> <i class="fa fa-square fa-stack-2x"></i> <i class="fa fa-paper-plane fa-stack-1x fa-inverse"></i> </span> </button></div> EOF; }
[ "public", "static", "function", "embeddedMenu", "(", "$", "url", ",", "$", "profile_email", ",", "$", "user_email", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "$", "CFG", "->", "unify", ")", "return", "''", ";", "if", "(", "isset", "(", "$", "_COOKIE", "[", "'TSUGILINKDISMISS'", "]", ")", ")", "return", "''", ";", "$", "message", "=", "htmlentities", "(", "$", "profile_email", ")", ";", "return", " <<< EOF\n<div id=\"tsugi-link-dialog\" title=\"Read Only Dialog\" style=\"display: none;\">\n<p>{$CFG->servicename} Message: You already have an account on this web site. Your current\nsystem-wide login is:\n<pre>\n$message\n</pre>\nWould you like to link these two accounts? </p><p>\n<button type=\"button\" class=\"btn btn-primary\"\nonclick=\"\n$.getJSON('$url', function(retval) {\n tsugiSetCookie('TSUGILINKDISMISS', 'true', 30);\n $('#tsugi-link-dialog').dialog( 'close' );\n $('#tsugi-embed-menu').hide();\n}).error(function() {\n alert('Error in JSON call');\n});\nreturn false;\n\">Link Accounts</button>\n<button type=\"button\" class=\"btn btn-secondary\"\nonclick=\"\ntsugiSetCookie('TSUGILINKDISMISS', 'true', 30);\n$('#tsugi-link-dialog').dialog( 'close' );\n$('#tsugi-embed-menu').hide();\nreturn false\n;\">Dismiss this notification</button>\n</p>\n</div>\n<div id=\"tsugi-embed-menu\" style=\"display:none; position: fixed; top: 100px; right: 5px; width: 150px; \">\n<button\nstyle=\"float: right\" class=\"btn btn-default\"\nonclick=\"tsugiEmbedKeep();showModal('Link Accounts','tsugi-link-dialog'); return false;\"\n>\n<span class=\"fa-stack fa-2x has-badge\" data-count=\"1\">\n <i class=\"fa fa-square fa-stack-2x\"></i>\n <i class=\"fa fa-paper-plane fa-stack-1x fa-inverse\"></i>\n</span>\n</button></div>\nEOF", ";", "}" ]
The embedded menu - for now just one button...
[ "The", "embedded", "menu", "-", "for", "now", "just", "one", "button", "..." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L870-L914
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.dumpDebugArray
function dumpDebugArray($debug_log) { if ( ! is_array($debug_log) ) return; foreach ( $debug_log as $k => $v ) { if ( count($v) > 1 ) { $this->togglePre($v[0], $v[1]); } else if ( is_array($v) ) { line_out($v[0]); } else if ( is_string($v) ) { line_out($v); } } }
php
function dumpDebugArray($debug_log) { if ( ! is_array($debug_log) ) return; foreach ( $debug_log as $k => $v ) { if ( count($v) > 1 ) { $this->togglePre($v[0], $v[1]); } else if ( is_array($v) ) { line_out($v[0]); } else if ( is_string($v) ) { line_out($v); } } }
[ "function", "dumpDebugArray", "(", "$", "debug_log", ")", "{", "if", "(", "!", "is_array", "(", "$", "debug_log", ")", ")", "return", ";", "foreach", "(", "$", "debug_log", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "count", "(", "$", "v", ")", ">", "1", ")", "{", "$", "this", "->", "togglePre", "(", "$", "v", "[", "0", "]", ",", "$", "v", "[", "1", "]", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "line_out", "(", "$", "v", "[", "0", "]", ")", ";", "}", "else", "if", "(", "is_string", "(", "$", "v", ")", ")", "{", "line_out", "(", "$", "v", ")", ";", "}", "}", "}" ]
Dump a debug array with messages and optional detail This kind of debug array comes back from some of the grade calls. We loop through printing the messages and put the detail into a togglable pre tag is present.
[ "Dump", "a", "debug", "array", "with", "messages", "and", "optional", "detail" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L924-L936
train
tsugiproject/tsugi-php
src/UI/Output.php
Output.doRedirect
public static function doRedirect($location) { if ( headers_sent() ) { // TODO: Check if this is fixed in PHP 70200 // https://bugs.php.net/bug.php?id=74892 if ( PHP_VERSION_ID >= 70000 ) { $location = U::addSession($location); } echo('<a href="'.$location.'">Continue</a>'."\n"); } else { if ( ini_get('session.use_cookies') == 0 ) { $location = U::addSession($location); } header("Location: $location"); } }
php
public static function doRedirect($location) { if ( headers_sent() ) { // TODO: Check if this is fixed in PHP 70200 // https://bugs.php.net/bug.php?id=74892 if ( PHP_VERSION_ID >= 70000 ) { $location = U::addSession($location); } echo('<a href="'.$location.'">Continue</a>'."\n"); } else { if ( ini_get('session.use_cookies') == 0 ) { $location = U::addSession($location); } header("Location: $location"); } }
[ "public", "static", "function", "doRedirect", "(", "$", "location", ")", "{", "if", "(", "headers_sent", "(", ")", ")", "{", "// TODO: Check if this is fixed in PHP 70200", "// https://bugs.php.net/bug.php?id=74892", "if", "(", "PHP_VERSION_ID", ">=", "70000", ")", "{", "$", "location", "=", "U", "::", "addSession", "(", "$", "location", ")", ";", "}", "echo", "(", "'<a href=\"'", ".", "$", "location", ".", "'\">Continue</a>'", ".", "\"\\n\"", ")", ";", "}", "else", "{", "if", "(", "ini_get", "(", "'session.use_cookies'", ")", "==", "0", ")", "{", "$", "location", "=", "U", "::", "addSession", "(", "$", "location", ")", ";", "}", "header", "(", "\"Location: $location\"", ")", ";", "}", "}" ]
Redirect to a local URL, adding session if necessary Note that this is only needed for AJAX and header() calls as &lt;form> and &lt;a href tags are properly handled already by the PHP built-in "don't use cookies for session" support.
[ "Redirect", "to", "a", "local", "URL", "adding", "session", "if", "necessary" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Output.php#L993-L1007
train
tsugiproject/tsugi-php
src/Util/CC.php
CC.add_module
public function add_module($title) { $this->resource_count++; $resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT); $identifier = 'T_'.$resource_str; $xpath = new \DOMXpath($this); $items = $xpath->query(CC::item_xpath)->item(0); $module = $this->add_child_ns(CC::CC_1_1_CP, $items, 'item', null, array('identifier' => $identifier)); $new_title = $this->add_child_ns(CC::CC_1_1_CP, $module, 'title', $title); return $module; }
php
public function add_module($title) { $this->resource_count++; $resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT); $identifier = 'T_'.$resource_str; $xpath = new \DOMXpath($this); $items = $xpath->query(CC::item_xpath)->item(0); $module = $this->add_child_ns(CC::CC_1_1_CP, $items, 'item', null, array('identifier' => $identifier)); $new_title = $this->add_child_ns(CC::CC_1_1_CP, $module, 'title', $title); return $module; }
[ "public", "function", "add_module", "(", "$", "title", ")", "{", "$", "this", "->", "resource_count", "++", ";", "$", "resource_str", "=", "str_pad", "(", "$", "this", "->", "resource_count", ".", "''", ",", "6", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "identifier", "=", "'T_'", ".", "$", "resource_str", ";", "$", "xpath", "=", "new", "\\", "DOMXpath", "(", "$", "this", ")", ";", "$", "items", "=", "$", "xpath", "->", "query", "(", "CC", "::", "item_xpath", ")", "->", "item", "(", "0", ")", ";", "$", "module", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "items", ",", "'item'", ",", "null", ",", "array", "(", "'identifier'", "=>", "$", "identifier", ")", ")", ";", "$", "new_title", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "module", ",", "'title'", ",", "$", "title", ")", ";", "return", "$", "module", ";", "}" ]
Adds a module to the manifest @param $title The title of the module @return the DOMNode of the newly added module
[ "Adds", "a", "module", "to", "the", "manifest" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/CC.php#L128-L139
train
tsugiproject/tsugi-php
src/Util/CC.php
CC.add_sub_module
public function add_sub_module($module, $title) { $this->resource_count++; $resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT); $identifier = 'T_'.$resource_str; $sub_module = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $identifier)); $new_title = $this->add_child_ns(CC::CC_1_1_CP, $sub_module, 'title',$title); return $sub_module; }
php
public function add_sub_module($module, $title) { $this->resource_count++; $resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT); $identifier = 'T_'.$resource_str; $sub_module = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $identifier)); $new_title = $this->add_child_ns(CC::CC_1_1_CP, $sub_module, 'title',$title); return $sub_module; }
[ "public", "function", "add_sub_module", "(", "$", "module", ",", "$", "title", ")", "{", "$", "this", "->", "resource_count", "++", ";", "$", "resource_str", "=", "str_pad", "(", "$", "this", "->", "resource_count", ".", "''", ",", "6", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "identifier", "=", "'T_'", ".", "$", "resource_str", ";", "$", "sub_module", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "module", ",", "'item'", ",", "null", ",", "array", "(", "'identifier'", "=>", "$", "identifier", ")", ")", ";", "$", "new_title", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "sub_module", ",", "'title'", ",", "$", "title", ")", ";", "return", "$", "sub_module", ";", "}" ]
Adds a sub module to a module As a note, while some LMS's are happpy with deeply nested sub-module trees, other LMS's prefre a strict two-layer module / submodule structure. @param $sub_module DOMNode The module where we are adding the submodule @param $title The title of the sub module @return the DOMNode of the newly added sub module
[ "Adds", "a", "sub", "module", "to", "a", "module" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/CC.php#L153-L161
train
tsugiproject/tsugi-php
src/Util/CC.php
CC.add_resource_item
public function add_resource_item($module, $title=null, $type, $identifier, $file) { $identifier_ref = $identifier."_R"; $xpath = new \DOMXpath($this); $new_item = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $identifier, "identifierref" => $identifier_ref)); if ( $title != null ) { $new_title = $this->add_child_ns(CC::CC_1_1_CP, $new_item, 'title', $title); } $resources = $xpath->query(CC::resource_xpath)->item(0); $identifier_ref = $identifier."_R"; $new_resource = $this->add_child_ns(CC::CC_1_1_CP, $resources, 'resource', null, array('identifier' => $identifier_ref, "type" => $type)); $new_file = $this->add_child_ns(CC::CC_1_1_CP, $new_resource, 'file', null, array("href" => $file)); return $file; }
php
public function add_resource_item($module, $title=null, $type, $identifier, $file) { $identifier_ref = $identifier."_R"; $xpath = new \DOMXpath($this); $new_item = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $identifier, "identifierref" => $identifier_ref)); if ( $title != null ) { $new_title = $this->add_child_ns(CC::CC_1_1_CP, $new_item, 'title', $title); } $resources = $xpath->query(CC::resource_xpath)->item(0); $identifier_ref = $identifier."_R"; $new_resource = $this->add_child_ns(CC::CC_1_1_CP, $resources, 'resource', null, array('identifier' => $identifier_ref, "type" => $type)); $new_file = $this->add_child_ns(CC::CC_1_1_CP, $new_resource, 'file', null, array("href" => $file)); return $file; }
[ "public", "function", "add_resource_item", "(", "$", "module", ",", "$", "title", "=", "null", ",", "$", "type", ",", "$", "identifier", ",", "$", "file", ")", "{", "$", "identifier_ref", "=", "$", "identifier", ".", "\"_R\"", ";", "$", "xpath", "=", "new", "\\", "DOMXpath", "(", "$", "this", ")", ";", "$", "new_item", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "module", ",", "'item'", ",", "null", ",", "array", "(", "'identifier'", "=>", "$", "identifier", ",", "\"identifierref\"", "=>", "$", "identifier_ref", ")", ")", ";", "if", "(", "$", "title", "!=", "null", ")", "{", "$", "new_title", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "new_item", ",", "'title'", ",", "$", "title", ")", ";", "}", "$", "resources", "=", "$", "xpath", "->", "query", "(", "CC", "::", "resource_xpath", ")", "->", "item", "(", "0", ")", ";", "$", "identifier_ref", "=", "$", "identifier", ".", "\"_R\"", ";", "$", "new_resource", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "resources", ",", "'resource'", ",", "null", ",", "array", "(", "'identifier'", "=>", "$", "identifier_ref", ",", "\"type\"", "=>", "$", "type", ")", ")", ";", "$", "new_file", "=", "$", "this", "->", "add_child_ns", "(", "CC", "::", "CC_1_1_CP", ",", "$", "new_resource", ",", "'file'", ",", "null", ",", "array", "(", "\"href\"", "=>", "$", "file", ")", ")", ";", "return", "$", "file", ";", "}" ]
Add a resource to the manifest.
[ "Add", "a", "resource", "to", "the", "manifest", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/CC.php#L210-L225
train
tsugiproject/tsugi-php
src/Util/GitRepo.php
GitRepo.status
public function status($html = false) { $msg = $this->run("status"); if ($html == true) { $msg = str_replace("\n", "<br />", $msg); } return $msg; }
php
public function status($html = false) { $msg = $this->run("status"); if ($html == true) { $msg = str_replace("\n", "<br />", $msg); } return $msg; }
[ "public", "function", "status", "(", "$", "html", "=", "false", ")", "{", "$", "msg", "=", "$", "this", "->", "run", "(", "\"status\"", ")", ";", "if", "(", "$", "html", "==", "true", ")", "{", "$", "msg", "=", "str_replace", "(", "\"\\n\"", ",", "\"<br />\"", ",", "$", "msg", ")", ";", "}", "return", "$", "msg", ";", "}" ]
Runs a 'git status' call Accept a convert to HTML bool @access public @param bool return string with <br /> @return string
[ "Runs", "a", "git", "status", "call" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/GitRepo.php#L244-L250
train
tsugiproject/tsugi-php
src/Util/GitRepo.php
GitRepo.rm
public function rm($files = "*", $cached = false) { if (is_array($files)) { $files = '"'.implode('" "', $files).'"'; } return $this->run("rm ".($cached ? '--cached ' : '').$files); }
php
public function rm($files = "*", $cached = false) { if (is_array($files)) { $files = '"'.implode('" "', $files).'"'; } return $this->run("rm ".($cached ? '--cached ' : '').$files); }
[ "public", "function", "rm", "(", "$", "files", "=", "\"*\"", ",", "$", "cached", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "files", ")", ")", "{", "$", "files", "=", "'\"'", ".", "implode", "(", "'\" \"'", ",", "$", "files", ")", ".", "'\"'", ";", "}", "return", "$", "this", "->", "run", "(", "\"rm \"", ".", "(", "$", "cached", "?", "'--cached '", ":", "''", ")", ".", "$", "files", ")", ";", "}" ]
Runs a `git rm` call Accepts a list of files to remove @access public @param mixed files to remove @param Boolean use the --cached flag? @return string
[ "Runs", "a", "git", "rm", "call" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/GitRepo.php#L278-L283
train
tsugiproject/tsugi-php
src/Util/GitRepo.php
GitRepo.commit
public function commit($message = "", $commit_all = true) { $flags = $commit_all ? '-av' : '-v'; return $this->run("commit ".$flags." -m ".escapeshellarg($message)); }
php
public function commit($message = "", $commit_all = true) { $flags = $commit_all ? '-av' : '-v'; return $this->run("commit ".$flags." -m ".escapeshellarg($message)); }
[ "public", "function", "commit", "(", "$", "message", "=", "\"\"", ",", "$", "commit_all", "=", "true", ")", "{", "$", "flags", "=", "$", "commit_all", "?", "'-av'", ":", "'-v'", ";", "return", "$", "this", "->", "run", "(", "\"commit \"", ".", "$", "flags", ".", "\" -m \"", ".", "escapeshellarg", "(", "$", "message", ")", ")", ";", "}" ]
Runs a `git commit` call Accepts a commit message string @access public @param string commit message @param boolean should all files be committed automatically (-a flag) @return string
[ "Runs", "a", "git", "commit", "call" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/GitRepo.php#L296-L299
train
tsugiproject/tsugi-php
src/Util/GitRepo.php
GitRepo.list_tags
public function list_tags($pattern = null) { $tagArray = explode("\n", $this->run("tag -l $pattern")); foreach ($tagArray as $i => &$tag) { $tag = trim($tag); if ($tag == '') { unset($tagArray[$i]); } } return $tagArray; }
php
public function list_tags($pattern = null) { $tagArray = explode("\n", $this->run("tag -l $pattern")); foreach ($tagArray as $i => &$tag) { $tag = trim($tag); if ($tag == '') { unset($tagArray[$i]); } } return $tagArray; }
[ "public", "function", "list_tags", "(", "$", "pattern", "=", "null", ")", "{", "$", "tagArray", "=", "explode", "(", "\"\\n\"", ",", "$", "this", "->", "run", "(", "\"tag -l $pattern\"", ")", ")", ";", "foreach", "(", "$", "tagArray", "as", "$", "i", "=>", "&", "$", "tag", ")", "{", "$", "tag", "=", "trim", "(", "$", "tag", ")", ";", "if", "(", "$", "tag", "==", "''", ")", "{", "unset", "(", "$", "tagArray", "[", "$", "i", "]", ")", ";", "}", "}", "return", "$", "tagArray", ";", "}" ]
List all the available repository tags. Optionally, accept a shell wildcard pattern and return only tags matching it. @access public @param string $pattern Shell wildcard pattern to match tags against. @return array Available repository tags.
[ "List", "all", "the", "available", "repository", "tags", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/GitRepo.php#L505-L515
train
tsugiproject/tsugi-php
src/Util/GitRepo.php
GitRepo.log
public function log($format = null) { if ($format === null) return $this->run('log'); else return $this->run('log --pretty=format:"' . $format . '"'); }
php
public function log($format = null) { if ($format === null) return $this->run('log'); else return $this->run('log --pretty=format:"' . $format . '"'); }
[ "public", "function", "log", "(", "$", "format", "=", "null", ")", "{", "if", "(", "$", "format", "===", "null", ")", "return", "$", "this", "->", "run", "(", "'log'", ")", ";", "else", "return", "$", "this", "->", "run", "(", "'log --pretty=format:\"'", ".", "$", "format", ".", "'\"'", ")", ";", "}" ]
List log entries. @param strgin $format @return string
[ "List", "log", "entries", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/GitRepo.php#L549-L554
train
rokka-io/rokka-client-php
src/UriHelper.php
UriHelper.decomposeUri
public static function decomposeUri(UriInterface $uri) { $stackPattern = '(?<stack>.*([^-]|--)|-*)'; $hashPattern = '(?<hash>[0-9a-f]{6,40})'; $filenamePattern = '(?<filename>[A-Za-z\-\0-\9]+)'; $formatPattern = '(?<format>.{3,4})'; $pathPattern = '(?<hash>-.+-)'; $path = $uri->getPath(); // hash with seo-filename if (preg_match('#^/'.$stackPattern.'/'.$hashPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) || // hash without seo-filename preg_match('#^/'.$stackPattern.'/'.$hashPattern.'.'.$formatPattern.'$#', $path, $matches) || // remote_path with seo-filename preg_match('#^/'.$stackPattern.'/'.$pathPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) || // remote_path without seo-filename preg_match('#^/'.$stackPattern.'/'.$pathPattern.'.'.$formatPattern.'$#', $path, $matches)) { return UriComponents::createFromArray($matches); } }
php
public static function decomposeUri(UriInterface $uri) { $stackPattern = '(?<stack>.*([^-]|--)|-*)'; $hashPattern = '(?<hash>[0-9a-f]{6,40})'; $filenamePattern = '(?<filename>[A-Za-z\-\0-\9]+)'; $formatPattern = '(?<format>.{3,4})'; $pathPattern = '(?<hash>-.+-)'; $path = $uri->getPath(); // hash with seo-filename if (preg_match('#^/'.$stackPattern.'/'.$hashPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) || // hash without seo-filename preg_match('#^/'.$stackPattern.'/'.$hashPattern.'.'.$formatPattern.'$#', $path, $matches) || // remote_path with seo-filename preg_match('#^/'.$stackPattern.'/'.$pathPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) || // remote_path without seo-filename preg_match('#^/'.$stackPattern.'/'.$pathPattern.'.'.$formatPattern.'$#', $path, $matches)) { return UriComponents::createFromArray($matches); } }
[ "public", "static", "function", "decomposeUri", "(", "UriInterface", "$", "uri", ")", "{", "$", "stackPattern", "=", "'(?<stack>.*([^-]|--)|-*)'", ";", "$", "hashPattern", "=", "'(?<hash>[0-9a-f]{6,40})'", ";", "$", "filenamePattern", "=", "'(?<filename>[A-Za-z\\-\\0-\\9]+)'", ";", "$", "formatPattern", "=", "'(?<format>.{3,4})'", ";", "$", "pathPattern", "=", "'(?<hash>-.+-)'", ";", "$", "path", "=", "$", "uri", "->", "getPath", "(", ")", ";", "// hash with seo-filename", "if", "(", "preg_match", "(", "'#^/'", ".", "$", "stackPattern", ".", "'/'", ".", "$", "hashPattern", ".", "'/'", ".", "$", "filenamePattern", ".", "'\\.'", ".", "$", "formatPattern", ".", "'$#'", ",", "$", "path", ",", "$", "matches", ")", "||", "// hash without seo-filename", "preg_match", "(", "'#^/'", ".", "$", "stackPattern", ".", "'/'", ".", "$", "hashPattern", ".", "'.'", ".", "$", "formatPattern", ".", "'$#'", ",", "$", "path", ",", "$", "matches", ")", "||", "// remote_path with seo-filename", "preg_match", "(", "'#^/'", ".", "$", "stackPattern", ".", "'/'", ".", "$", "pathPattern", ".", "'/'", ".", "$", "filenamePattern", ".", "'\\.'", ".", "$", "formatPattern", ".", "'$#'", ",", "$", "path", ",", "$", "matches", ")", "||", "// remote_path without seo-filename", "preg_match", "(", "'#^/'", ".", "$", "stackPattern", ".", "'/'", ".", "$", "pathPattern", ".", "'.'", ".", "$", "formatPattern", ".", "'$#'", ",", "$", "path", ",", "$", "matches", ")", ")", "{", "return", "UriComponents", "::", "createFromArray", "(", "$", "matches", ")", ";", "}", "}" ]
Return components of a rokka URL. @since 1.2.0 @param UriInterface $uri @throws \RuntimeException @return UriComponents|null
[ "Return", "components", "of", "a", "rokka", "URL", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/UriHelper.php#L152-L170
train
rokka-io/rokka-client-php
src/UriHelper.php
UriHelper.getSrcSetUrl
public static function getSrcSetUrl(UriInterface $url, $size, $custom = null, $setWidthInUrl = true) { $identifier = substr($size, -1, 1); $size = substr($size, 0, -1); switch ($identifier) { case 'x': $uri = self::addOptionsToUri($url, 'options-dpr-'.$size); break; case 'w': if ($setWidthInUrl) { $uri = self::addOptionsToUri($url, 'resize-width-'.$size); } else { $uri = $url; } break; default: return $url; } if (null !== $custom) { $uri = self::getSrcSetUrlCustom($size, $custom, $setWidthInUrl, $uri); } return $uri; }
php
public static function getSrcSetUrl(UriInterface $url, $size, $custom = null, $setWidthInUrl = true) { $identifier = substr($size, -1, 1); $size = substr($size, 0, -1); switch ($identifier) { case 'x': $uri = self::addOptionsToUri($url, 'options-dpr-'.$size); break; case 'w': if ($setWidthInUrl) { $uri = self::addOptionsToUri($url, 'resize-width-'.$size); } else { $uri = $url; } break; default: return $url; } if (null !== $custom) { $uri = self::getSrcSetUrlCustom($size, $custom, $setWidthInUrl, $uri); } return $uri; }
[ "public", "static", "function", "getSrcSetUrl", "(", "UriInterface", "$", "url", ",", "$", "size", ",", "$", "custom", "=", "null", ",", "$", "setWidthInUrl", "=", "true", ")", "{", "$", "identifier", "=", "substr", "(", "$", "size", ",", "-", "1", ",", "1", ")", ";", "$", "size", "=", "substr", "(", "$", "size", ",", "0", ",", "-", "1", ")", ";", "switch", "(", "$", "identifier", ")", "{", "case", "'x'", ":", "$", "uri", "=", "self", "::", "addOptionsToUri", "(", "$", "url", ",", "'options-dpr-'", ".", "$", "size", ")", ";", "break", ";", "case", "'w'", ":", "if", "(", "$", "setWidthInUrl", ")", "{", "$", "uri", "=", "self", "::", "addOptionsToUri", "(", "$", "url", ",", "'resize-width-'", ".", "$", "size", ")", ";", "}", "else", "{", "$", "uri", "=", "$", "url", ";", "}", "break", ";", "default", ":", "return", "$", "url", ";", "}", "if", "(", "null", "!==", "$", "custom", ")", "{", "$", "uri", "=", "self", "::", "getSrcSetUrlCustom", "(", "$", "size", ",", "$", "custom", ",", "$", "setWidthInUrl", ",", "$", "uri", ")", ";", "}", "return", "$", "uri", ";", "}" ]
Returns a rokka URL to be used in srcset style attributes. $size can be eg. "2x" or "500w" $custom can be any rokka options you want to optionally add, or also a dpi identifier like "2x" This method will then generate the right rokka URLs to get what you want, see `\Rokka\Client\Tests\UriHelperTest::provideGetSrcSetUrl` for some examples and the expected returns. @param UriInterface $url The original rokka render URL to be adjusted @param string $size The size of the image, eg '300w' or '2x' @param null|string $custom Any rokka options you'd like to add, or are a dpi identifier like '2x' @param bool $setWidthInUrl If false, don't set the width as stack operation option, we provide it in $custom, usually as parameter @throws \RuntimeException @return UriInterface
[ "Returns", "a", "rokka", "URL", "to", "be", "used", "in", "srcset", "style", "attributes", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/UriHelper.php#L205-L230
train
rokka-io/rokka-client-php
src/UriHelper.php
UriHelper.getSrcSetUrlCustom
private static function getSrcSetUrlCustom($size, $custom, $setWidthInUrl, UriInterface $uri) { // if custom is eg '2x', add options-dpr- if (preg_match('#^([0-9]+)x$#', $custom, $matches)) { $uri = self::addOptionsToUri($uri, 'options-dpr-'.$matches[1]. ($setWidthInUrl ? '--resize-width-'.(int) ceil($size / $matches[1]) : '')); } else { $stack = new StackUri(); $stack->addOverridingOptions($custom); // if dpr is given in custom option, but not width, calculate correct width $resizeOperations = $stack->getStackOperationsByName('resize'); $widthIsNotSet = true; foreach ($resizeOperations as $resizeOperation) { if (isset($resizeOperation->options['width'])) { $widthIsNotSet = false; } } $options = $stack->getStackOptions(); if (isset($options['dpr']) && $widthIsNotSet && $setWidthInUrl) { $custom .= '--resize-width-'.(int) ceil($size / $options['dpr']); } $uri = self::addOptionsToUri($uri, $custom); } return $uri; }
php
private static function getSrcSetUrlCustom($size, $custom, $setWidthInUrl, UriInterface $uri) { // if custom is eg '2x', add options-dpr- if (preg_match('#^([0-9]+)x$#', $custom, $matches)) { $uri = self::addOptionsToUri($uri, 'options-dpr-'.$matches[1]. ($setWidthInUrl ? '--resize-width-'.(int) ceil($size / $matches[1]) : '')); } else { $stack = new StackUri(); $stack->addOverridingOptions($custom); // if dpr is given in custom option, but not width, calculate correct width $resizeOperations = $stack->getStackOperationsByName('resize'); $widthIsNotSet = true; foreach ($resizeOperations as $resizeOperation) { if (isset($resizeOperation->options['width'])) { $widthIsNotSet = false; } } $options = $stack->getStackOptions(); if (isset($options['dpr']) && $widthIsNotSet && $setWidthInUrl) { $custom .= '--resize-width-'.(int) ceil($size / $options['dpr']); } $uri = self::addOptionsToUri($uri, $custom); } return $uri; }
[ "private", "static", "function", "getSrcSetUrlCustom", "(", "$", "size", ",", "$", "custom", ",", "$", "setWidthInUrl", ",", "UriInterface", "$", "uri", ")", "{", "// if custom is eg '2x', add options-dpr-", "if", "(", "preg_match", "(", "'#^([0-9]+)x$#'", ",", "$", "custom", ",", "$", "matches", ")", ")", "{", "$", "uri", "=", "self", "::", "addOptionsToUri", "(", "$", "uri", ",", "'options-dpr-'", ".", "$", "matches", "[", "1", "]", ".", "(", "$", "setWidthInUrl", "?", "'--resize-width-'", ".", "(", "int", ")", "ceil", "(", "$", "size", "/", "$", "matches", "[", "1", "]", ")", ":", "''", ")", ")", ";", "}", "else", "{", "$", "stack", "=", "new", "StackUri", "(", ")", ";", "$", "stack", "->", "addOverridingOptions", "(", "$", "custom", ")", ";", "// if dpr is given in custom option, but not width, calculate correct width", "$", "resizeOperations", "=", "$", "stack", "->", "getStackOperationsByName", "(", "'resize'", ")", ";", "$", "widthIsNotSet", "=", "true", ";", "foreach", "(", "$", "resizeOperations", "as", "$", "resizeOperation", ")", "{", "if", "(", "isset", "(", "$", "resizeOperation", "->", "options", "[", "'width'", "]", ")", ")", "{", "$", "widthIsNotSet", "=", "false", ";", "}", "}", "$", "options", "=", "$", "stack", "->", "getStackOptions", "(", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'dpr'", "]", ")", "&&", "$", "widthIsNotSet", "&&", "$", "setWidthInUrl", ")", "{", "$", "custom", ".=", "'--resize-width-'", ".", "(", "int", ")", "ceil", "(", "$", "size", "/", "$", "options", "[", "'dpr'", "]", ")", ";", "}", "$", "uri", "=", "self", "::", "addOptionsToUri", "(", "$", "uri", ",", "$", "custom", ")", ";", "}", "return", "$", "uri", ";", "}" ]
Adds custom options to the URL. @param string $size @param string $custom @param bool $setWidthInUrl @param UriInterface $uri @throws \RuntimeException if stack configuration can't be parsed @return UriInterface
[ "Adds", "custom", "options", "to", "the", "URL", "." ]
ab037e0fd38b110211a0f7afb70f379e30756bdc
https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/UriHelper.php#L318-L344
train
tsugiproject/tsugi-php
src/Core/LTIX.php
LTIX.getConnection
public static function getConnection() { global $PDOX, $CFG; if ( isset($PDOX) && is_object($PDOX) && get_class($PDOX) == 'Tsugi\Util\PDOX' ) { return $PDOX; } if ( defined('PDO_WILL_CATCH') ) { $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass); $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } else { try { $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass); $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch(\PDOException $ex){ error_log("DB connection: ".$ex->getMessage()); die('Failure connecting to the database, see error log'); // with error_log } } if ( isset($CFG->slow_query) ) $PDOX->slow_query = $CFG->slow_query; return $PDOX; }
php
public static function getConnection() { global $PDOX, $CFG; if ( isset($PDOX) && is_object($PDOX) && get_class($PDOX) == 'Tsugi\Util\PDOX' ) { return $PDOX; } if ( defined('PDO_WILL_CATCH') ) { $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass); $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } else { try { $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass); $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch(\PDOException $ex){ error_log("DB connection: ".$ex->getMessage()); die('Failure connecting to the database, see error log'); // with error_log } } if ( isset($CFG->slow_query) ) $PDOX->slow_query = $CFG->slow_query; return $PDOX; }
[ "public", "static", "function", "getConnection", "(", ")", "{", "global", "$", "PDOX", ",", "$", "CFG", ";", "if", "(", "isset", "(", "$", "PDOX", ")", "&&", "is_object", "(", "$", "PDOX", ")", "&&", "get_class", "(", "$", "PDOX", ")", "==", "'Tsugi\\Util\\PDOX'", ")", "{", "return", "$", "PDOX", ";", "}", "if", "(", "defined", "(", "'PDO_WILL_CATCH'", ")", ")", "{", "$", "PDOX", "=", "new", "\\", "Tsugi", "\\", "Util", "\\", "PDOX", "(", "$", "CFG", "->", "pdo", ",", "$", "CFG", "->", "dbuser", ",", "$", "CFG", "->", "dbpass", ")", ";", "$", "PDOX", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_ERRMODE", ",", "\\", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "}", "else", "{", "try", "{", "$", "PDOX", "=", "new", "\\", "Tsugi", "\\", "Util", "\\", "PDOX", "(", "$", "CFG", "->", "pdo", ",", "$", "CFG", "->", "dbuser", ",", "$", "CFG", "->", "dbpass", ")", ";", "$", "PDOX", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_ERRMODE", ",", "\\", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "ex", ")", "{", "error_log", "(", "\"DB connection: \"", ".", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "die", "(", "'Failure connecting to the database, see error log'", ")", ";", "// with error_log", "}", "}", "if", "(", "isset", "(", "$", "CFG", "->", "slow_query", ")", ")", "$", "PDOX", "->", "slow_query", "=", "$", "CFG", "->", "slow_query", ";", "return", "$", "PDOX", ";", "}" ]
Get a singleton global connection or set it up if not already set up.
[ "Get", "a", "singleton", "global", "connection", "or", "set", "it", "up", "if", "not", "already", "set", "up", "." ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/LTIX.php#L54-L75
train
tsugiproject/tsugi-php
src/Core/LTIX.php
LTIX.launchCheck
public static function launchCheck($needed=self::ALL, $session_object=null,$request_data=false) { global $TSUGI_LAUNCH, $CFG; $needed = self::patchNeeded($needed); // Check if we are an LTI 1.1 or LTI 1.3 launch $LTI11 = false; $LTI13 = false; $detail = LTI13::isRequestDetail($request_data); if ( $detail === true ) { $LTI13 = true; } else { $lti11_request_data = $request_data; if ( $lti11_request_data === false ) $lti11_request_data = self::oauth_parameters(); $LTI11 = LTI::isRequestCheck($lti11_request_data); if ( is_string($LTI11) ) { self::abort_with_error_log($LTI11, $request_data); } } if ( $LTI11 === false && $LTI13 === false ) return $detail; $session_id = self::setupSession($needed,$session_object,$request_data); if ( $session_id === false ) return false; // Redirect back to ourselves... $url = self::curPageUrl(); if ( $session_object !== null ) { $TSUGI_LAUNCH->redirect_url = self::curPageUrl(); return true; } $location = U::addSession($url); session_write_close(); // To avoid any race conditions... if ( headers_sent() ) { echo('<p><a href="'.$url.'">Click to continue</a></p>'); } else { header('Location: '.$location); } exit(); }
php
public static function launchCheck($needed=self::ALL, $session_object=null,$request_data=false) { global $TSUGI_LAUNCH, $CFG; $needed = self::patchNeeded($needed); // Check if we are an LTI 1.1 or LTI 1.3 launch $LTI11 = false; $LTI13 = false; $detail = LTI13::isRequestDetail($request_data); if ( $detail === true ) { $LTI13 = true; } else { $lti11_request_data = $request_data; if ( $lti11_request_data === false ) $lti11_request_data = self::oauth_parameters(); $LTI11 = LTI::isRequestCheck($lti11_request_data); if ( is_string($LTI11) ) { self::abort_with_error_log($LTI11, $request_data); } } if ( $LTI11 === false && $LTI13 === false ) return $detail; $session_id = self::setupSession($needed,$session_object,$request_data); if ( $session_id === false ) return false; // Redirect back to ourselves... $url = self::curPageUrl(); if ( $session_object !== null ) { $TSUGI_LAUNCH->redirect_url = self::curPageUrl(); return true; } $location = U::addSession($url); session_write_close(); // To avoid any race conditions... if ( headers_sent() ) { echo('<p><a href="'.$url.'">Click to continue</a></p>'); } else { header('Location: '.$location); } exit(); }
[ "public", "static", "function", "launchCheck", "(", "$", "needed", "=", "self", "::", "ALL", ",", "$", "session_object", "=", "null", ",", "$", "request_data", "=", "false", ")", "{", "global", "$", "TSUGI_LAUNCH", ",", "$", "CFG", ";", "$", "needed", "=", "self", "::", "patchNeeded", "(", "$", "needed", ")", ";", "// Check if we are an LTI 1.1 or LTI 1.3 launch", "$", "LTI11", "=", "false", ";", "$", "LTI13", "=", "false", ";", "$", "detail", "=", "LTI13", "::", "isRequestDetail", "(", "$", "request_data", ")", ";", "if", "(", "$", "detail", "===", "true", ")", "{", "$", "LTI13", "=", "true", ";", "}", "else", "{", "$", "lti11_request_data", "=", "$", "request_data", ";", "if", "(", "$", "lti11_request_data", "===", "false", ")", "$", "lti11_request_data", "=", "self", "::", "oauth_parameters", "(", ")", ";", "$", "LTI11", "=", "LTI", "::", "isRequestCheck", "(", "$", "lti11_request_data", ")", ";", "if", "(", "is_string", "(", "$", "LTI11", ")", ")", "{", "self", "::", "abort_with_error_log", "(", "$", "LTI11", ",", "$", "request_data", ")", ";", "}", "}", "if", "(", "$", "LTI11", "===", "false", "&&", "$", "LTI13", "===", "false", ")", "return", "$", "detail", ";", "$", "session_id", "=", "self", "::", "setupSession", "(", "$", "needed", ",", "$", "session_object", ",", "$", "request_data", ")", ";", "if", "(", "$", "session_id", "===", "false", ")", "return", "false", ";", "// Redirect back to ourselves...", "$", "url", "=", "self", "::", "curPageUrl", "(", ")", ";", "if", "(", "$", "session_object", "!==", "null", ")", "{", "$", "TSUGI_LAUNCH", "->", "redirect_url", "=", "self", "::", "curPageUrl", "(", ")", ";", "return", "true", ";", "}", "$", "location", "=", "U", "::", "addSession", "(", "$", "url", ")", ";", "session_write_close", "(", ")", ";", "// To avoid any race conditions...", "if", "(", "headers_sent", "(", ")", ")", "{", "echo", "(", "'<p><a href=\"'", ".", "$", "url", ".", "'\">Click to continue</a></p>'", ")", ";", "}", "else", "{", "header", "(", "'Location: '", ".", "$", "location", ")", ";", "}", "exit", "(", ")", ";", "}" ]
Silently check if this is a launch and if so, handle it and redirect back to ourselves
[ "Silently", "check", "if", "this", "is", "a", "launch", "and", "if", "so", "handle", "it", "and", "redirect", "back", "to", "ourselves" ]
b5397a98540f6cf4dc3981f1802c450b90d1fa44
https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/LTIX.php#L81-L122
train