function handle(&$params) { //echo "Hello World from the controller class!!"; //to do interesting stuff here we get info from the Dataface_Application object $app =& Dataface_Application::getInstance(); // reference to Dataface_Application object $auth =& Dataface_AuthenticationTool::getInstance(); // reference to Dataface_Authentication object //if ( !isset($_POST['--bid-amount']) ) { //$request =& $app->getQuery(); // Request vars: e.g. [-table]=>'Students', [-action]=>'hello' $records =& df_get_records('detail', $query); $user =& $auth->getLoggedInUser(); // Dataface_Record object of currently logged in user. $current_tablename =& $request['-table']; $current_record =& $app->getRecord(); // Currently selected record (Dataface_Record object) $results =& $app->getResultSet(); // Current found set (Dataface_QueryTool object). // Iterating through the results $it =& $results->iterator(); while ($it->hasNext()) { $record =& $it->next(); // $record is a Dataface_Record object print_r($record->strvals()); unset($record); // necessary so that PHP doesn't just keep overwriting the same object. } // Perform a custom SQL Query: //$res = mysql_query("select * from foo inner join bar on foo.x=bar.y", $app->db()); // .. etc ... // Obtain parameters from the actions.ini file for this action: $template_name = $params['action']['template']; // The value of the template parameter //df_display(array(), $template_name); // this form allows you to change the template to use by modifying the actions.ini file. df_display(array(), 'JobWorld.html'); }
function &df_get_records_array($table, $query = null, $start = null, $limit = null, $preview = true) { $records = array(); $it = df_get_records($table, $query, $start, $limit, $preview); if (PEAR::isError($it)) { return $it; } while ($it->hasNext()) { $records[] = $it->next(); } return $records; }
function getChildren($record) { return df_get_records('payments', array('date' == '=' . $record->val('paymentdate1'))); }
function processForm($values) { ini_set('max_execution_time', 900); import('Dataface/IO.php'); import('Dataface/TranslationTool.php'); $tt = new Dataface_TranslationTool(); $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); if (strlen($values['-sourceLanguage']) != 2 || strlen($values['-destinationLanguage']) != 2) { trigger_error('Invalid input for languages. Expected a 2 digit language code.', E_USER_ERROR); } $values['-limit'] = 500; //$qt = new Dataface_QueryTool($this->table->tablename, $app->db(), $values); //$qt->loadSet(); //$it =& $qt->iterator(); $q = $query; $q['-limit'] = 9999; if (@$q['--limit']) { $q['-limit'] = $q['--limit']; } $it =& df_get_records($this->table->tablename, $q); $keycols = array_keys($this->table->keys()); $cols = $this->table->getTranslation($values['-destinationLanguage']); if (!is_array($cols)) { trigger_error('Could not find any columns to be translated in table ' . $values['-destinationLanguage'] . Dataface_Error::printStackTrace(), E_USER_ERROR); } $babelfish = $this->getTranslator(); //new babelfish(); if (isset($app->_conf['google_translate_url'])) { $babelfish->google_url_webpage = $app->_conf['google_translate_url']; } $ioSrc = new Dataface_IO($this->table->tablename); $ioSrc->lang = $values['-sourceLanguage']; $languageCodes = new I18Nv2_Language('en'); $ioDest = new Dataface_IO($this->table->tablename); $ioDest->lang = $values['-destinationLanguage']; $count = 0; $to_be_translated = array(); $destObjects = array(); while ($it->hasNext()) { $curr =& $it->next(); $translationInfo =& $tt->getTranslationRecord($curr, $values['-destinationLanguage']); if ($translationInfo and $translationInfo->val('translation_status') == TRANSLATION_STATUS_NEEDS_UPDATE_MACHINE) { $t_needsUpdate = true; } else { $t_needsUpdate = false; } $translation_text = array(); $keyvals = $curr->vals($keycols); $srcObject = new Dataface_Record($this->table->tablename, array()); $destObject = new Dataface_Record($this->table->tablename, array()); $ioSrc->read($keyvals, $srcObject); $ioDest->read($keyvals, $destObject); $keyvalsQuery = $keyvals; foreach ($keyvals as $key => $val) { $keyvalsQuery[$key] = '=' . $keyvals[$key]; } $qb = new Dataface_QueryBuilder($this->table->tablename, $keyvalsQuery); $sql = "select * from `" . $this->table->tablename . "_" . $values['-destinationLanguage'] . "` " . $qb->_where(); $res = mysql_query($sql, $app->db()); if (!$res) { trigger_error(mysql_error($app->db()) . 'SQL : ' . $sql . " Stacktrace:" . Dataface_Error::printStackTrace(), E_USER_ERROR); } $queryResult = mysql_fetch_array($res); if (!$queryResult) { $queryResult = array(); } foreach ($cols as $col) { if (in_array($col, $keycols)) { continue; } if (!$this->table->isText($col) and !$this->table->isChar($col)) { continue; } if (!isset($queryResult[$col]) || $t_needsUpdate) { //$updateRequired = true; } else { continue; } $translation_text[$col] = $srcObject->getValue($col); } if (count($translation_text) > 0) { $to_be_translated[] =& $translation_text; $destObjects[] =& $destObject; } unset($curr); unset($srcObject); unset($destObject); unset($qb); unset($translatedRecord); unset($translation_text); unset($translationInfo); } $translated = $this->translate($to_be_translated, $values['-sourceLanguage'], $values['-destinationLanguage'], $babelfish); if (PEAR::isError($translated)) { return $translated; } foreach ($translated as $rowid => $row) { if ($translated[$rowid] == $to_be_translated[$rowid]) { continue; } $update = false; foreach ($row as $col => $val) { if (strlen(trim($val)) === 0) { continue; } $destObjects[$rowid]->setValue($col, $val); $update = true; } if ($update) { $res = $ioDest->write($destObjects[$rowid]); if (PEAR::isError($res)) { trigger_error($res->toString() . Dataface_Error::printStackTrace(), E_USER_ERROR); } $tt->setTranslationStatus($destObjects[$rowid], $ioDest->lang, TRANSLATION_STATUS_MACHINE); } } }
/** * Invalidates the non-original translations. This will set the translation * statuses as follows: * Unknown -> Unknown * Machine -> Out-of-date (Machine translation) * Approved -> Out-of-date * Unverified -> Out-of-date (Unverified) * Original -> Original * Out-of-date * -> Out-of-date * */ function invalidateTranslations(&$record) { $records = df_get_records('dataface__translations', array('record_id' => '=' . $this->getRecordId($record), 'table' => $record->_table->tablename)); if (PEAR::isError($records)) { throw new Exception($records->toString(), E_USER_ERROR); } while ($records->hasNext()) { $trecord = $records->next(); $update = true; switch ($trecord->val('translation_status')) { case TRANSLATION_STATUS_MACHINE: $trecord->setValue('translation_status', TRANSLATION_STATUS_NEEDS_UPDATE_MACHINE); break; case TRANSLATION_STATUS_UNVERIFIED: $trecord->setValue('translation_status', TRANSLATION_STATUS_NEEDS_UPDATE_UNVERIFIED); break; case TRANSLATION_STATUS_APPROVED: $trecord->setValue('translation_status', TRANSLATION_STATUS_NEEDS_UPDATE); break; default: $update = false; // no update necessary } if ($update) { $res = $trecord->save(); if (PEAR::isError($res)) { return $res; } } unset($trecord); } return true; }
function delete($values) { require_once 'Dataface/IO.php'; $query = $this->_buildDeleteQuery($values); if (PEAR::isError($query)) { return $query; } $io = new Dataface_IO($this->_tablename); $it =& df_get_records($this->_tablename, $query); $warnings = array(); while ($it->hasNext()) { $record =& $it->next(); $res = $io->delete($record); if (PEAR::isError($res) && Dataface_Error::isError($res)) { // this is a serious error... kill it return $res; } else { if (PEAR::isError($res)) { // this is a warning or a notice $warnings[] = $res; } } unset($record); } if (count($warnings) > 0) { return $warnings; } return true; }