* @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.1.3 * @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 */ protected function extract() { $cnt = 0; if (empty($this->table) || empty($this->fields)) { return $cnt; } $offset = 0; $total = $this->ta->count($this->table); 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; } }