Commit b3d4158c authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge changes from topic 'WR 304034'

* changes:
  Bug 1810990: blocktypes: entireresume, resumefield, reduce code duplication         additional: external feed (small), documentation
  Bug 1810990: blocktypes: profile information and others for get_field checks     additional:         - added tabledata for all file information for table artefact_files_file         - profileicon set for user acccording to latest block (will move to create_user later)         - found bugs after testing with logging in different users, small bug fixes here and there
parents 420bec32 178775cd
......@@ -724,15 +724,16 @@ EOD;
throw new SystemException("Invalid block type '" . $record['type'] . "'. The block type is either not installed or not active.");
}
$title = trim($record['title']);
$functionname = 'generate_configdata_'.$record['type'];
$classname = 'TestingDataGenerator';
// build configdata
$configdata = $this->setup_retractable($record['retractable']);
$data = trim($record['data']);
$functionname = 'generate_configdata_'.$record['type'];
$classname = 'TestingDataGenerator';
$sortedfields = $this->setup_configdata($data);
if (is_callable($classname . '::'.$functionname)) {
$result = call_static_method($classname, $functionname, $data, $ownertype, $ownerid, $title, $view);
if (is_callable($classname . '::' . $functionname)) {
$result = call_static_method($classname, $functionname, $sortedfields, $ownertype, $ownerid, $title, $view);
$configdata = array_merge($configdata, (array)$result);
}
else {
......@@ -773,19 +774,13 @@ EOD;
* displaying the blogs that were created using the function create_blog
* given a matching blog title
*
* @param string $data inside data column in behat test
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_blog($data) {
if (!$data) return;
$configdata = array();
$fields = explode(';',$data);
foreach($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
public static function generate_configdata_blog($sortedfields) {
$configdata = array();
foreach($sortedfields as $key => $value) {
if ($key == 'journaltitle') {
if (!$blogid = get_field('artefact', 'id', 'title', $value, 'artefacttype', 'blog')) {
throw new SystemException("A blog/journal with the name " . $value . " doesn't exist!");
......@@ -807,22 +802,16 @@ EOD;
* displaying the blogposts that were created using the function create_blogpost
* matching a given blog and entry title
*
* @param string $data inside data column in behat test
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_blogpost($data) {
if (!$data) return;
$configdata = array();
public static function generate_configdata_blogpost($sortedfields) {
$configdata = array();
$blogpostid;
$blogid;
$fields = explode(';',$data);
foreach($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
foreach($sortedfields as $key => $value) {
if ($key == 'journaltitle') {
if (!$blogid = get_field('artefact', 'id', 'title', $value, 'artefacttype','blog')) {
throw new SystemException("A blog/journal named " . $value . " doesn't exist!");
......@@ -843,7 +832,7 @@ EOD;
/**
* generate a comment blocktype.
* @param string data inside the columm for data in behat table
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array with redundant information as there is no specific artefact connected to it.
*/
public static function generate_configdata_comment($data) {
......@@ -852,18 +841,13 @@ EOD;
/**
* generate configdata and instance for blocktype: creativecommons
* @param string data inside the columm for data in behat table
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_creativecommons($data) {
public static function generate_configdata_creativecommons($sortedfields) {
$configdata = array();
$fields = explode(';', $data);
foreach( $fields as $field) {
list($key, $value) = explode('=', $field);
$value = trim(strtolower($value));
foreach ($sortedfields as $key => $value) {
switch ($key) {
case 'commercialuse':
//yes=0, no=1
......@@ -890,20 +874,39 @@ EOD;
return $configdata;
}
/**
* generate configdata for the blocktype: entireresume
*
* doesn't work in group pages
*
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_entireresume($sortedfields, $ownertype, $ownerid) {
foreach ($sortedfields as $key => $value) {
if ($key == 'tags') {
$tags = explode(',', $value);
$tagstring = array();
foreach($tags as $tag) {
$tagstring[] = trim($tag);
}
$artefactdata['tags'] = $tagstring;
}
}
}
/**
* generate configdata for the blocktype: rss feeds/external feeds
* @param string $data inside data column in behat test
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_externalfeed($data) {
if (!$data) return;
$configdata = array();
$fields = explode(';', $data);
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
public static function generate_configdata_externalfeed($sortedfields) {
$configdata = array();
$configdata['full'] = 1;
foreach ($sortedfields as $key => $value) {
if ($key == 'source') {
$wheredata = array('url' => $value);
$feeddata = PluginBlocktypeExternalfeed::parse_feed($value);
......@@ -921,37 +924,28 @@ EOD;
/**
* generate configdata for the blocktype: external video
* @param string $data inside data column in behat test
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_externalvideo($data) {
if (!$data) return;
list($key, $value) = explode('=', $data);
if ($key == 'source') {
$sourceinfo = PluginBlocktypeExternalvideo::process_url($value);
return $sourceinfo;
public static function generate_configdata_externalvideo($sortedfields) {
foreach ($sortedfields as $key => $value) {
if ($key == 'source') {
$sourceinfo = PluginBlocktypeExternalvideo::process_url($value);
return $sourceinfo;
}
}
}
/**
* generate configdata for the blocktype: filedownload
* @param string $data inside data column in behat test
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_filedownload($data, $ownertype, $ownerid) {
if (!$data) return;
$fields = explode(';', $data);
public static function generate_configdata_filedownload($sortedfields, $ownertype, $ownerid) {
$configdata = array();
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key=trim($key);
$value=trim($value);
foreach ($sortedfields as $key => $value) {
if ($key == 'attachments') {
$fileattachments = explode(',',$value);
foreach ($fileattachments as $file) {
......@@ -969,17 +963,12 @@ EOD;
* @param $owenerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_folder($data, $ownertype, $ownerid) {
if (!$data) return;
public static function generate_configdata_folder($sortedfields, $ownertype, $ownerid) {
$folderfiles = array();
$configdata = array();
$fields = explode(';', $data);
$foldername = -1;
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
foreach ($sortedfields as $key => $value) {
if ($key == 'dirname') {
$foldername = $value;
}
......@@ -1007,24 +996,16 @@ EOD;
/**
* generate configdata for blocktype: gallery
* @param string $data inside data column in behat test
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_gallery($data, $ownertype, $ownerid) {
if (!$data) return;
public static function generate_configdata_gallery($sortedfields, $ownertype, $ownerid) {
$configdata = array();
//separate gallery_images, select, width, style etc.
$fields = explode(';', $data);
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
foreach ($sortedfields as $key => $value) {
if ($key == 'attachments') {
$galleryimagefiles = explode(',', $value);
$value = array();
......@@ -1035,7 +1016,7 @@ EOD;
}
if ($key == 'imagesel' || $key == 'width' || $key == 'showdesc' || $key == 'imagestyle' || $key == 'photoframe' ) {
//imageselection options are 0,1,2 in the table, changed for tester -_-
//imageselection options are 0,1,2 in the table
if ($key == 'imagesel') {
$value -= 1;
$configdata['select'] = $value;
......@@ -1058,21 +1039,15 @@ EOD;
/**
* generate configdata for blocktype: html
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_html($data, $ownertype, $ownerid) {
if (!$data) return;
$fields = explode(';', $data);
public static function generate_configdata_html($sortedfields, $ownertype, $ownerid) {
$configdata = array();
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
foreach ($sortedfields as $key => $value) {
if ($key == 'attachment') {
$configdata['artefactid'] = self::process_attachment($value, $ownertype, $ownerid);
}
......@@ -1082,19 +1057,14 @@ EOD;
/**
* generate configdata for the blocktype: image
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_image($data, $ownertype, $ownerid) {
if (!$data) return;
$fields = explode(';', $data);
public static function generate_configdata_image($sortedfields, $ownertype, $ownerid) {
$configdata = array();
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
foreach ($sortedfields as $key => $value) {
if ($key == 'attachment') {
$configdata = array('artefactid' => self::process_attachment($value, $ownertype, $ownerid));
}
......@@ -1107,30 +1077,23 @@ EOD;
/**
* generate configdata for the blocktype: internalmedia aka 'embeddedmedia
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_internalmedia($data, $ownertype, $ownerid) {
if (!$data) return;
public static function generate_configdata_internalmedia($sortedfields, $ownertype, $ownerid) {
$mediatype;
$configdata = array();
$fields = explode(';', $data);
foreach ($fields as $field) {
list($key,$value) = explode('=', $field);
$key=trim($key);
$value=trim($value);
foreach ($sortedfields as $key => $value) {
if ($key == 'attachment') {
$filename = $value;
$filenameparts = explode('.', $filename);
$ext = end($filenameparts);
// we need to find the id of the item we are trying to attach and save it as artefactid
if (!$artefactid = get_field('artefact', 'id', 'title', $filename)) {
if (!$artefactid = get_field('artefact', 'id', 'title', $filename, 'owner', $ownerid)) {
if ($ext == 'wmv' || $ext == 'webm' || $ext == 'mov'|| $ext == 'ogv' || $ext == 'mpeg' || $ext == 'mp4' || $ext == 'flv' || $ext == 'avi' || $ext == '3gp') {
$artefactid = TestingDataGenerator::create_artefact($filename, $ownertype, $ownerid, 'video');
TestingDataGenerator::file_creation($artefactid, $filename, $ownertype, $ownerid);
......@@ -1149,24 +1112,19 @@ EOD;
/**
* generate configdata for the blocktype: navigation and create navblocks*
* **when copytoall is true**
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @param string $title of block to be created* (when copytoall is true)
* @param object the current view to create block on
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_navigation($data, $ownertype, $ownerid, $title, $view) {
if (!$data) return;
public static function generate_configdata_navigation($sortedfields, $ownertype, $ownerid, $title, $view) {
$configdata = array();
$copytoall = true;
$collectionid;
$fields = explode(';', $data);
foreach($fields as $field) {
$field = trim(strtolower($field));
list($key, $value) = explode('=', $field);
foreach ($sortedfields as $key => $value) {
if ($key == 'collection') {
$configdata[$key] = $collectionid = get_field('collection', 'id', 'name', $value);
}
......@@ -1207,53 +1165,45 @@ EOD;
/**
* generate configdata for the bloctype: peerassessment
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @return array redundant info as there is no data directly connected in this case
*/
public static function generate_configdata_peerassessment($data) {
public static function generate_configdata_peerassessment($fields) {
return array();
}
/**
* generate configdata for the blocktype: pdf
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_pdf($data, $ownertype, $ownerid) {
if (!$data) return;
public static function generate_configdata_pdf($sortedfields, $ownertype, $ownerid) {
foreach ($sortedfields as $key => $value) {
list($key, $value) = explode('=', $data);
$key=trim($key);
$value=trim($value);
if ($key == 'attachment') {
$configdata['artefactid'] = self::process_attachment($value, $ownertype, $ownerid);
if ($key == 'attachment') {
$configdata['artefactid'] = self::process_attachment($value, $ownertype, $ownerid);
}
}
return $configdata;
}
/**
* generate configdata for the blocktype: plans
* @param string $data inside data column in blocktype tables
* @return array $configdata of key and values of db table
* generate configdata for the blocktype: plans
*
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_plans($data) {
if (!$data) return;
public static function generate_configdata_plans($sortedfields, $ownertype, $ownerid) {
$configdata = array();
$fields = explode(';', $data);
foreach($fields as $field) {
$field = trim($field);
list($key,$value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
foreach ($sortedfields as $key => $value) {
if ($key == 'plans') {
$plans = explode(',',$value);
foreach ($plans as $plan) {
if (!$planid = get_field('artefact', 'id', 'title', $plan, 'artefacttype', 'plan')) {
if (!$planid = get_field('artefact', 'id', 'title', $plan, 'artefacttype', 'plan', 'owner', $ownerid)) {
throw new SystemException("Invalid Plan '" . $plan . "'");
}
$configdata['artefactids'][] = $planid;
......@@ -1266,22 +1216,71 @@ EOD;
return $configdata;
}
/**
* generate configdata for the blocktype: profileinformation
*
* As well as going thorugh the general fields in the data column of the table,
* an ArtefactTypeProfileIcon is created as there are none created in bulk.
*
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_profileinfo($sortedfields, $ownertype, $ownerid) {
$configdata = array();
foreach ($sortedfields as $key => $value) {
if ($key == 'introtext') {
require_once('embeddedimage.php');
$newtext = EmbeddedImage::prepare_embedded_images($value, 'introtext', 0);
$configdata['introtext'] = $newtext;
}
if ($key == 'profileicon') {
if (!$artefactprofileiconid = get_field('artefact', 'id', 'title', $value, 'owner', $ownerid, 'artefacttype', 'profileicon')) {
$folderartefactid = ArtefactTypeFolder::get_folder_id(get_string('imagesdir', 'artefact.file'), get_string('imagesdirdesc', 'artefact.file'), null, true, $ownerid);
$artefactprofileiconid = self::create_artefact($value, $ownertype, $ownerid, 'profileicon', $folderartefactid);
self::file_creation($artefactprofileiconid, $value, $ownertype, $ownerid, true);
execute_sql("UPDATE {usr}
SET profileicon = $artefactprofileiconid
WHERE id = $ownerid");
}
$configdata['profileicon'] = $artefactprofileiconid;
}
}
// gather the user's social profiles data
safe_require('artefact', 'internal');
$element_list = ArtefactTypeProfile::get_all_fields();
foreach ($element_list as $element=>$type) {
if ($artefactid = get_field('artefact', 'id', 'artefacttype', $element, 'owner', $ownerid)) {
$configdata['artefactids'][] = $artefactid;
}
else if ($element == 'socialprofile') {
$artefacttypes = ArtefactTypeSocialprofile::$socialnetworks;
foreach ($artefacttypes as $type) {
if ($artefactid = get_field('artefact', 'id', 'artefacttype', 'socialprofile', 'owner', $ownerid, 'note', $type)) {
$configdata['artefactids'][] = $artefactid;
}
}
}
}
return $configdata;
}
/**
* generate configdata for blocktype: recentforumposts
*
* @param string $data inside data column in blocktype tables
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_recentforumposts($data, $ownertype, $ownerid) {
if (!$data) return;
public static function generate_configdata_recentforumposts($sortedfields, $ownertype, $ownerid) {
$configdata = array();
$fields = explode(';',$data);
foreach ($fields as $field) {
$field = trim($field);
list($key, $value) = explode('=',$field);
foreach ($sortedfields as $key => $value) {
if ($key == 'groupname') {
$groupid;
//make sure the group exists
......@@ -1297,39 +1296,54 @@ EOD;
$configdata[$key] = $value > 0 ? $value : 5;
}
}
$configdata[] = $data;
return $configdata;
}
/**
* generate configdata for the blocktype: social profile
* @param string $data inside data column in behat test
* generate configdata for the blocktype: resumefield
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_socialprofile($data, $ownertype, $ownerid) {
if (!$data) return;
list($key, $value) = explode('=', $data);
$key = trim($key);
$value = trim($value);
public static function generate_configdata_resumefield($sortedfields, $ownertype, $ownerid) {
foreach ($sortedfields as $key => $value) {
if ($key == 'artefacttype') {
if ($artefactid = get_field('artefact', 'id', 'owner', $ownerid, 'artefacttype', $value)) {
return array('artefactid' => $artefactid);
}
else {
throw new SystemException('The user ' . find_by_id($ownerid) . ' does not have a ' . $key);
}
}
}
}
if ($key == 'sns') {
//split the values for multiple social profile creation
$medialist = explode(',', $value);
$value = array();
foreach($medialist as $media) {
$newprofile = new ArtefactTypeSocialprofile();
$newprofile->set('owner', $ownerid);
$newprofile->set('author',$ownerid);
$newprofile->set('title', $media);
$newprofile->set('description', $media);
$newprofile->set('note', $media);
$id = $newprofile->commit(); //update the contents of the artefact table only
$artefactid[] = $newprofile->get('id');
/**
* generate configdata for the blocktype: social profile
* @param array $fields holding each chunk of data between the ; in the behat data column
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_socialprofile($sortedfields, $ownertype, $ownerid) {
foreach ($sortedfields as $key => $value) {
if ($key == 'sns') {
//split the values for multiple social profile creation
$medialist = explode(',', $value);
$value = array();
foreach($medialist as $media) {
$newprofile = new ArtefactTypeSocialprofile();
$newprofile->set('owner', $ownerid);
$newprofile->set('author',$ownerid);
$newprofile->set('title', $media);
$newprofile->set('description', $media);
$newprofile->set('note', $media);
$id = $newprofile->commit(); //update the contents of the artefact table only
$artefactid[] = $newprofile->get('id');
}
return $configdata = array('artefactids' => $artefactid);