Commit 178775cd authored by Doris Tam's avatar Doris Tam
Browse files

Bug 1810990: blocktypes: entireresume, resumefield, reduce code duplication

        additional: external feed (small), documentation

Change-Id: Id6c764fa4d67ccd43436439daa7a40e390874d76
parent 19bad994
......@@ -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();
......@@ -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,23 +1077,15 @@ 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);
......@@ -1150,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);
}
......@@ -1208,29 +1165,26 @@ 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;
list($key, $value) = explode('=', $data);
$key=trim($key);
$value=trim($value);
public static function generate_configdata_pdf($sortedfields, $ownertype, $ownerid) {
foreach ($sortedfields as $key => $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;
}
......@@ -1238,22 +1192,14 @@ EOD;
/**
* generate configdata for the blocktype: plans
*
* @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_plans($data, $ownertype, $ownerid) {
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) {
......@@ -1276,20 +1222,15 @@ EOD;
* 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 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_profileinfo($data, $ownertype, $ownerid) {
if (!$data) return;
public static function generate_configdata_profileinfo($sortedfields, $ownertype, $ownerid) {
$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 == 'introtext') {
require_once('embeddedimage.php');
$newtext = EmbeddedImage::prepare_embedded_images($value, 'introtext', 0);
......@@ -1331,19 +1272,15 @@ EOD;
/**
* 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
......@@ -1359,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);
}
return $configdata = array('artefactids' => $artefactid);
}
}
......@@ -1400,9 +1352,14 @@ EOD;
* @param string inside data column in behat test
* @return array $configdata of key and values for db table
*/
public static function generate_configdata_text($data) {
if (!$data) return;
return $configdata = array('text' => $data);
public static function generate_configdata_text($sortedfields) {
$configdata = array();
foreach ($sortedfields as $key => $value) {
if ($key == 'textinput') {
$configdata['text'] = $value;
}
}
return $configdata;
}
/**
......@@ -1412,15 +1369,14 @@ EOD;
* holding an html artefact
* NOTE:the title of a textbox block is the same as the html artefact the textbox it is associated with; not the title of a block instance
*
* @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_textbox($data, $ownertype, $ownerid, $title, $view) {
if (!$data) return;
public static function generate_configdata_textbox($sortedfields, $ownertype, $ownerid, $title, $view) {
$configdata = array();
$artefactdata = array();
$bi = null;
......@@ -1429,9 +1385,7 @@ EOD;
$existingtextboxfound = false;
$htmlartefactid = null;
$fields = explode(';', $data);
foreach ($fields as $field) {
list($key, $value) = explode('=', $field, 2);
foreach ($sortedfields as $key => $value) {
if ($key == 'notetitle') {
$artefactdata['title'] = trim($value);
}
......@@ -1449,7 +1403,6 @@ EOD;
$tagstring[] = trim($tag);
}
$artefactdata['tags'] = $tagstring;
}
if ($key == 'attachments') {
$attachmentfiles = explode(',', $value);
......@@ -1572,6 +1525,31 @@ EOD;
}
}
/**
* tidying up and organising the table data into an array
* @param string $data text from data columm
* @return array $sortedfields array of $key $value pairs containing fields their entries