Author: david
Date: Mon Jan 9 17:33:16 2012
New Revision: 10602
Log:
Add ISAAR to CSV conversion class
Added:
trunk/plugins/sfIsaarPlugin/lib/sfIsaarCsv.class.php
- copied, changed from r10599,
trunk/plugins/sfIsaarPlugin/lib/sfIsaarPlugin.class.php
Copied and modified: trunk/plugins/sfIsaarPlugin/lib/sfIsaarCsv.class.php (from
r10599, trunk/plugins/sfIsaarPlugin/lib/sfIsaarPlugin.class.php)
==============================================================================
--- trunk/plugins/sfIsaarPlugin/lib/sfIsaarPlugin.class.php Mon Jan 9
00:03:05 2012 (r10599, copy source)
+++ trunk/plugins/sfIsaarPlugin/lib/sfIsaarCsv.class.php Mon Jan 9
17:33:16 2012 (r10602)
@@ -1,92 +1,72 @@
<?php
/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
-class sfIsaarPlugin implements ArrayAccess
+/**
+ * Map between ISAAR CSV format and Qubit data model
+ *
+ * @package qubit
+ * @subpackage sfIsaarPlugin
+ * @version svn: $Id$
+ * @author David Juhasz <[email protected]>
+ */
+class sfIsaarCsvPlugin extends sfIsaarPlugin
{
- protected
- $resource,
- $maintenanceNote;
-
- public function __construct(QubitActor $resource)
+ public function __get($name)
{
- $this->resource = $resource;
}
- public function offsetExists($offset)
+ public function __set($name, $value)
{
- $args = func_get_args();
-
- return call_user_func_array(array($this, '__isset'), $args);
}
- public function __get($name)
+ /**
+ * Parse $csv and create new ISAAR actor objects
+ *
+ * @param string csv path to a CSV file
+ *
+ * @return int number of rows parsed
+ */
+ public static function parse($csv)
{
- switch ($name)
- {
- case '_maintenanceNote':
-
- if (!isset($this->maintenanceNote))
- {
- $criteria = new Criteria;
- $criteria->add(QubitNote::OBJECT_ID, $this->resource->id);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
-
- if (1 == count($query = QubitNote::get($criteria)))
- {
- $this->maintenanceNote = $query[0];
- }
- else
- {
- $this->maintenanceNote = new QubitNote;
- $this->maintenanceNote->typeId = QubitTerm::MAINTENANCE_NOTE_ID;
-
- $this->resource->notes[] = $this->maintenanceNote;
- }
- }
-
- return $this->maintenanceNote;
-
- case 'maintenanceNotes':
-
- return $this->_maintenanceNote->content;
-
- case 'sourceCulture':
+ $count = 0;
- return $this->resource->sourceCulture;
+ if (false === ($fh = fopen($csv, 'r'))
+ {
+ throw sfException("Couldn't read file $csv.");
}
- }
- public function offsetGet($offset)
- {
- $args = func_get_args();
+ $headers = fgetcsv($fh);
- return call_user_func_array(array($this, '__get'), $args);
- }
-
- public function __set($name, $value)
- {
- switch ($name)
+ while ($row = $fgetcsv($fh))
{
- case 'maintenanceNotes':
- $this->_maintenanceNote->content = $value;
+ $isaarCsv = new sfIsaarCsvPlugin(new QubitActor);
- return $this;
- }
- }
+ foreach ($row as $i => $item)
+ {
+ $isaarCsv->__set($headers[$i], $item);
+ }
- public function offsetSet($offset, $value)
- {
- $args = func_get_args();
+ $isaarCsv->save();
- return call_user_func_array(array($this, '__set'), $args);
- }
-
- public function offsetUnset($offset)
- {
- $args = func_get_args();
+ $count++;
+ }
- return call_user_func_array(array($this, '__unset'), $args);
+ return $count;
}
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.