Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
636a529
Make charts resizable
invalid-email-address May 4, 2017
a32eba9
Pin chart resizers so they are always visible
habbes May 8, 2017
3a0c88c
Hide pie chart labels for small sections
habbes May 9, 2017
4ce01c6
Add comments in pie chart renderer function
habbes May 11, 2017
a3fe64e
Merge pull request #1 from habbes/task_#392
habbes May 11, 2017
76db1e5
Merge pull request #3 from huridocs/v1-devel
habbes May 15, 2017
1d14c71
test method for updating object translations
habbes May 18, 2017
06cb469
Add functions to read csv file in translations import script
habbes May 18, 2017
61c7095
Complete objects translations import script
habbes May 18, 2017
1202d0c
Allow option to not skipping security when loading objects for field
habbes Jun 12, 2017
543b89e
Merge pull request #5 from huridocs/task-666
habbes Jun 12, 2017
4eeb313
Merge pull request #6 from huridocs/v1-devel
habbes Jun 12, 2017
9bb65d4
Merge pull request #4 from huridocs/task_563
habbes Jun 16, 2017
05ce6ec
Merge pull request #7 from huridocs/v1-devel
habbes Jun 16, 2017
afac58f
Fix undefined constant warning.
habbes Jun 16, 2017
90b19da
add sys/solr_configsets/default_config/
Jun 16, 2017
886fa9a
add DM\Tree::getOwner method and implemented
Jun 19, 2017
6eafd7f
Merge pull request #8 from huridocs/task_680
habbes Jun 21, 2017
3dd4233
Do not truncate tooltips on charts
habbes Jun 27, 2017
3b9b2ac
Merge pull request #9 from huridocs/task-735
elric-wamugu Jun 27, 2017
2ce7ad0
Merge branch 'v1-devel' into v1
Jun 27, 2017
e6a7746
Merge pull request #10 from huridocs/v1-devel
habbes Jun 28, 2017
82ce79b
Merge pull request #9 from huridocs/task-735
elric-wamugu Jun 27, 2017
65bf0e7
Add export feature for charts as a PNG image
elric-wamugu Jul 5, 2017
e2cb5fa
Merge branch 'task-483' of https://github.com/huridocs/casebox into t…
elric-wamugu Jul 5, 2017
4e0cf43
Add export feature for charts to a PNG image
elric-wamugu Jul 5, 2017
38b1dd2
Fix for PHP 7 in how it resolves variables strictly from left to right
elric-wamugu Jul 5, 2017
b98219c
add int option in switch sentence
Jul 6, 2017
46fbbd8
Create script to update object field names
habbes Jul 6, 2017
8fcb8c4
Add comments to update_fields script
habbes Jul 6, 2017
75c30f4
Enable object fields update code
habbes Jul 6, 2017
17243cd
Merge branch 'v1-devel' into v1
Jul 6, 2017
3c7d16a
fix git ignore [ssl] folder
Jul 6, 2017
cf72d4a
display error in DB settings on installation script
Jul 6, 2017
aeb7764
Merge pull request #12 from huridocs/task-483
elric-wamugu Jul 7, 2017
697df16
Fix bugs in update_fields script
habbes Jul 7, 2017
af61135
Update .gitignore
emamut Jul 7, 2017
e1bfc68
Merge pull request #11 from huridocs/quick_fix
habbes Jul 7, 2017
ad3ccb1
Merge branch 'v1-devel' into v1
Jul 8, 2017
980d3c0
Fix errors in update_fields script
habbes Jul 10, 2017
099bac6
Update debug statements for update_fields.php script
habbes Jul 10, 2017
cf92685
Use different colors for bars in bar and column charts
habbes Jul 10, 2017
2c73a16
Merge pull request #13 from huridocs/task-743
habbes Jul 12, 2017
27ce911
Merge pull request #14 from huridocs/task-391
habbes Jul 13, 2017
c95b48b
Merge pull request #15 from huridocs/v1-devel
habbes Jul 13, 2017
4cb34b6
Update README.md
bertver Nov 6, 2017
e4f99cc
Update README.md
bertver Nov 6, 2017
596ef38
fix typo on invite email and add extra details of the person invited
elric-wamugu Aug 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
backup/

sys/solr_configsets/default_config/*.unloaded
sys/solr_configsets/default_config/
!sys/solr_configsets/default_config/conf

ssl/
\[ssl\]/

# ignore custom import scripts
install/import/
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Casebox

Casebox is a Content Management Platform for record, file and task management.

Full documentation can be found on the website:
http://docs.casebox.org/en/latest/
Casebox was developed jointly by HURIDOCS and KETSE.com.

Made at Ketse & HURIDOCS
-------------------------
Starting in 2017, HURIDOCS manages its own version of the Casebox codebase for human rights organisations and KETSE.com continues to support the original code.

If you are working with a human rights organisation, contact casebox at huridocs.org

Casebox is being developed by [Ketse](https://www.ketse.com/) & [HURIDOCS](https://www.huridocs.org/).
If your request is not related to human rights work and you are not a non-profit, then please contact Ketse at info at ketse.com for more information on the commercial services they can provide.


Code status
Expand Down
180 changes: 180 additions & 0 deletions bin/import_objects_translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#!/usr/bin/php
<?php
/*
Import translations for objects from CSV file

The first column of the CSV file should be the object id,
followed by a column for each language, each language
should be specified by its 2-character ISO code.
So each row contains translations for one object.

Command parameters:
-c : core
-f : filename

Example usage:

php import_objects_translations -c mycore -f filename.csv
*/

namespace CB;

ini_set('max_execution_time', 0);

// include cron init script
// sets up the environment and also
// the DB based on the selected core
$cronPath = realpath(
dirname(__FILE__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'sys' . DIRECTORY_SEPARATOR .
'crons' . DIRECTORY_SEPARATOR
) . DIRECTORY_SEPARATOR;

$cron_id = 'dummy';
include $cronPath.'init.php';

\CB\Config::setFlag('disableActivityLog', true);


// run the script
run();


/**
* runs the import script based on cmd option
*/
function run () {
$options = getopt('c:f:');
// the `c` (core) param is already checked by the cron init script
if(!array_key_exists('f', $options)) {
printLine("Error: please specify filename");
printUsage();
return;
}
$filename = $options['f'];
printLine("Opening $filename...");
$file = fopen($filename, 'r');
if(!$file) {
printLine("Error: could not open file");
return;
}

printLine("Importing translations...");
importTranslationsFromFile($file);

fclose($file);
printLine("Done!");
}


/**
* reads the speficied csv file handle
* and imports translations for each row into the DB
* for the object specified at that row
* the csv file should have column header as the first line,
* the first column should be for the object id and the remaining
* columns for the languages to translate, each language should
* be specifed by its language code in the header
* @param handle $file
*/
function importTranslationsFromFile ($file) {
$langs = parseHeader($file);
while (!feof($file)) {
$row = parseNextTranslations($file, $langs);
if(!$row) continue; // skip empty lines
updateObjectTranslations($row['id'], $row['translations']);
}
}


/**
* updates language translations of the object
* with the specified id
* @param number $id
* @param array $translations associative array mapping
* language codes and the corresponding text translations
* for this object, e.g. ["en"=>"Cheeze","fr"=>"Fromage"]
*/
function updateObjectTranslations ($id, $translations) {
$obj = Objects::getCustomClassByObjectId($id);
if(!$obj) {
printLine("Object #".$id." not found");
return;
}
// load data from DB first in order not to overwrite/lose
// existing data that's not part of the update
$obj->load();
$data = $obj->getData();
foreach($translations as $lg=>$text) {
$data['data']['title_'.$lg] = $text;
}
$obj->update($data);
}

/**
* reads the next line of the specified csv
* file handle in an attempt to get the languages
* in the translation, this should be used to
* read the first line of the file, before other
* reads are done
* @param handle $file
* @return array array of language codes from the csv
* header row
*/
function parseHeader ($file) {
$header = fgetcsv($file);
$langs = array_map('trim', array_slice($header, 1));
return $langs;
}

/**
* reads the next line of the specified csv file
* handle and maps languages to translations of
* the object at that row
* the first column of the row is considered the object
* id and the remaining columns as translations
* the number of columns should therefore be 1 + the
* size of the $langs array
* @param handle $file
* @param array $langs array of language codes
* @return array|null associative array with keys id and
* translations, where translations is an associative
* array mapping languages to translations for the given object id
* returns null if the line is empty
*/
function parseNextTranslations ($file, $langs) {
$row = fgetcsv($file);
if (empty($row)) {
// return null on empty lines
return null;
}
$id = $row[0];
// clean id if it starts with # character
if($id[0] == '#') {
$id = substr($id, 1);
}
$id = (int) $id;
$values = array_slice($row, 1);
$trans = array_combine($langs, $values);
return [
"id" => $id,
"translations" => $trans
];
}

/**
* helper to echo logs
* @param string $str
*/
function printLine ($str) {
echo $str."\n";
}

/**
* prints usage example and instructions
*/
function printUsage () {
printLine("USAGE:");
printLine("php import_objects_translations -c corename -f filename");
}
Loading