* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBNLS_Extractor'); /** * Native Lanauge Support: Extractor PHP System Files * * Extract translatable strings from PHP files in Wombat project folder * and from patForms * * @version 0.2.1 * @package WB * @subpackage nls */ abstract class WBNLS_Extractor_Table extends WBNLS_Extractor { /** * limit each SELECT to number of records to avoid running out of memory */ const FETCH_LIMIT = 100; /** * Table access using * @var WBDatasource_Table */ protected $ta; /** * Table's name * @var string */ protected $table = ''; /** * Table's columns * @var array */ protected $fields = array(); /** * setup extractor * * Implement concrete behaviour in child classes */ protected function onStart() { $this->ta = WBClass::create('WBDatasource_Table'); // translations would mess up import strings $this->ta->switchTranslation(false); } /** * Actually extract messages * * Extract messages from any table * * @return int total count */ protected function extract() { $cnt = 0; if (empty($this->table) || empty($this->fields)) { return $cnt; } $offset = 0; try { $total = $this->ta->count($this->table); } catch (WBException $e) { $err = array( 'msg' => $e->getMessage(), 'type' => 'exception' ); $this->addError($err); return $cnt; } if ($total < 1) { return $cnt; } $options = array( 'limit' => self::FETCH_LIMIT, 'offset' => $offset, 'column' => $this->fields ); while ($offset < $total) { $options['offset'] = $offset; $list = $this->ta->get($this->table, null, null, array(), $options); foreach ($list as $l) { $cnt += $this->extractFields($l); } $offset += self::FETCH_LIMIT; } return $cnt; } /** * Extract translatable strings from row * * Add translatable messages for each fields marked for translation. * Count how many messages where found and return the number * * @var array $row * @return int */ private function extractFields($row) { $cnt = 0; foreach ($this->fields as $f) { $msg = trim($row[$f]); if (!isset($row[$f]) || empty($msg)) { continue; } $mid = $this->imp->addMsg($msg); $this->imp->setXid($mid, $this->table, $row['id']); ++$cnt; } return $cnt; } }