Skip to content

Commit

Permalink
Making some changes - wanted one last commit before full changes
Browse files Browse the repository at this point in the history
  • Loading branch information
druid628 committed Feb 2, 2012
1 parent 53a4b47 commit 831b10b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 45 deletions.
13 changes: 13 additions & 0 deletions lib/import/base/BsdImporterInterface.class.php
@@ -0,0 +1,13 @@
<?PHP

interface PluginBsdImporterInterface
{

protected $requiredHeaders = array();

public function setHeaders();

public function getHeaders();


}
102 changes: 96 additions & 6 deletions lib/import/base/PluginBsdImporter.class.php
@@ -1,13 +1,103 @@
<?PHP

interface PluginBsdImporter {

abstract PluginBsdImporter implements PluginBsdImporterInterface
{

protected $requiredHeaders = array();
protected $requiredFields = array();

/**
*
* @param array $headers
*/
public function setHeaders(array $headers)
{
$this->requiredHeaders = $headers;
}

public function getHeaders()
{
return $this->requiredHeaders;
}

/**
*
* hooray for magic!!
*
* @param string $method
* @param mixed $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
try {
$verb = substr($method, 0, 3);
if (in_array($verb, array('set', 'get'))) {
$name = substr($method, 3);
}

if (method_exists($this, $verb)) {
if (property_exists($this, $name)) {
return call_user_func_array(array($this, $verb), array_merge(array($name), $arguments));
} elseif (property_exists($this, lcfirst($name))) {
return call_user_func_array(array($this, $verb), array_merge(array(lcfirst($name)), $arguments));
} else {
throw new Exception("Variable ($name) Not Found");
}
} else {
throw new Exception("Function ($verb) Not Defined");
}
} catch (Exception $e) {
printf("You done yucked up!");
var_dump($e);
}
}

/**
*
* standard getter
*
* @param string $fieldName
* @return mixed
*/
public function get($fieldName)
{
if (!property_exists($this, $fieldName)) {
trigger_error("Variable ($fieldName) Not Found", E_USER_ERROR);
}

return $this->$fieldName;
}

/**
* standard setter
*
* @param string $fieldName
* @param mixed $value
* @return boolean
*/
public function set($fieldName, $value)
{
if (!property_exists($this, $fieldName)) {
trigger_error("Variable ($fieldName) Not Found", E_USER_ERROR);
}

public function setHeaders() { }
$this->$fieldName = $value;
return true;
}

public function getHeaders() { }
/**
*
* For some reason there is no lcfirst function but there
* is a ucfirst... oh well that's fixed. :)
*
* @param string $string
* @return string
*/
public function lcfirst($string)
{
$string{0} = strtolower($string{0});
return $string;
}


}
}
21 changes: 2 additions & 19 deletions lib/import/base/PluginBsdImporterCsv.class.php
@@ -1,22 +1,5 @@
<?PHP

abstract class PluginBsdImporterCsv implements PluginBsdImporter
class PluginBsdImporterCsv extends PluginBsdImporter
{
protected $requiredHeaders = array();

/**
*
* @param array $headers
*/
public function setHeaders(array $headers)
{
$this->requiredHeaders = $headers;
}

public function getHeaders()
{
return $this->requiredHeaders;
}


}
}
37 changes: 17 additions & 20 deletions lib/import/base/PluginBsdImporterExcel.class.php
@@ -1,10 +1,9 @@

<?PHP

abstract class PluginBsdImporterExcel implements PluginBsdImporter
class PluginBsdImporterExcel extends PluginBsdImporter
{
protected $requiredHeaders = array();
protected $headerRow;
protected $activeSheet;


/**
Expand All @@ -26,31 +25,29 @@ public function getHeaderRow()
}


/**
*
* @param array $headers
*/
public function setHeaders(array $headers)
{
$this->requiredHeaders = $headers;
}
/**
*
* @param int|String $activeSheet
*/
public function setActiveSheet($sheetNumber)
{
$this->activeSheet = $sheetNumber;
}

/**
*
* @return array
* @return int|String
*/
public function getHeaders()
{
return $this->requiredHeaders;
}


public function getActiveSheet()
{
return $this->activeSheet;
}

public function openFileForReading($uploadFile)
{
$baseFileReader = new ExcelExplorer();
$status = $baseFileReader->ExploreFile($uploadFile);
$baseFile = $baseFileReader->Worksheet(0);
$baseFile = $baseFileReader->Worksheet($this->getActiveSheet());

if ($status != EE_OK)
{
Expand Down Expand Up @@ -78,4 +75,4 @@ public function openFileForReading($uploadFile)

}

}
}

0 comments on commit 831b10b

Please sign in to comment.