本文整理汇总了PHP中ORM::Factory方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::Factory方法的具体用法?PHP ORM::Factory怎么用?PHP ORM::Factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ORM
的用法示例。
在下文中一共展示了ORM::Factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDateOutOfRange
/**
* Test that a basic date out of range test works.
*/
public function testDateOutOfRange()
{
// Need a test rule we can use to check it works
$ruleArr = array('verification_rule:title' => 'test', 'verification_rule:test_type' => 'PeriodWithinYear', 'verification_rule:error_message' => 'test error', 'metaFields:metadata' => "Tvk=TESTKEY\nStartDate=0801\nEndDate=0831", 'metaFields:data' => "");
$rule = ORM::Factory('verification_rule');
$rule->set_submission_data($ruleArr, false);
if (!$rule->submit()) {
echo kohana::debug($rule->getAllErrors());
throw new exception('Failed to create test rule');
}
try {
$response = data_entry_helper::http_post($this->request, array('sample' => json_encode(array('sample:survey_id' => 1, 'sample:date' => '12/09/2012', 'sample:entered_sref' => 'SU1234', 'sample:entered_sref_system' => 'osgb')), 'occurrences' => json_encode(array(array('occurrence:taxa_taxon_list_id' => $this->ttl->id))), 'rule_types' => json_encode(array('PeriodWithinYear'))));
$errors = json_decode($response['output'], true);
$this->assertTrue(is_array($errors), 'Errors list not returned');
$this->assertTrue(isset($errors[0]['taxa_taxon_list_id']) && $errors[0]['taxa_taxon_list_id'] === $this->ttl->id, 'Incorrect taxa_taxon_list_id returned');
$this->assertTrue(isset($errors[0]['message']) && $errors[0]['message'] === 'test error', 'Incorrect message returned');
foreach ($rule->verification_rule_metadata as $m) {
$m->delete();
}
$rule->delete();
} catch (Exception $e) {
foreach ($rule->verification_rule_metadata as $m) {
$m->delete();
}
$rule->delete();
}
}
示例2: _execute
protected function _execute()
{
if (!isset($this->_data->email) or !$this->_data->email or !isset($this->_data->password) or !$this->_data->password) {
throw new Exception("Login error: missing email and/or password.");
}
$user = ORM::Factory('user')->where('email', 'LIKE', $this->_data->email)->find();
if (!$user->loaded()) {
throw new Exception("Login error: that email address was not found.");
}
if ($user->password != $this->_beans_auth_password($user->id, $this->_data->password)) {
throw new Exception("Login error: that password was incorrect.");
}
if (!$user->role->loaded()) {
throw new Exception("Login error: that user does not have any defined role.");
}
if ($user->password_change) {
$user->reset = $this->_generate_reset($user->id);
$user->reset_expiration = time() + 2 * 60;
$user->save();
return (object) array("reset" => $user->reset);
}
$expiration = $user->role->auth_expiration_length != 0 ? time() + $user->role->auth_expiration_length : rand(11111, 99999);
$user->auth_expiration = $expiration;
$user->save();
return (object) array("auth" => $this->_return_auth_element($user, $expiration));
}
示例3: _execute
protected function _execute()
{
if (!$this->_search_vendor_id) {
throw new Exception("Missing required parameter: vendor_id");
}
// This effectively limits the results only to a vendor with the ID.
$this->_transactions = $this->_transactions->where('entity_id', '=', $this->_search_vendor_id)->and_where_open()->or_where('payment', '=', 'vendor')->or_where('payment', '=', 'expense')->and_where_close();
$this->_transactions = $this->_transactions->and_where_open();
$this->_transactions = $this->_transactions->where('id', 'IS NOT', NULL);
// $this->_search_keywords
if ($this->_search_keywords) {
$forms = ORM::Factory('form')->where('entity_id', '=', $this->_search_vendor_id);
$query = FALSE;
foreach (explode(' ', $this->_search_keywords) as $keyword) {
$term = trim($keyword);
if ($term) {
$query = TRUE;
$forms = $forms->and_where_open()->or_where('code', 'LIKE', '%' . $term . '%')->or_where('reference', 'LIKE', '%' . $term . '%')->or_where('alt_reference', 'LIKE', '%' . $term . '%')->or_where('aux_reference', 'LIKE', '%' . $term . '%')->and_where_close();
}
}
if ($query) {
$forms = $forms->find_all();
} else {
$forms = array();
}
$form_ids = array();
foreach ($forms as $form) {
$form_ids[] = $form->id;
}
$account_transactions = ORM::Factory('account_transaction')->join('account_transaction_forms', 'LEFT')->on('account_transaction_forms.account_transaction_id', '=', 'account_transaction.id');
$account_transactions = $account_transactions->where('account_transaction_forms.form_id', 'IN', $form_ids);
$account_transactions = $account_transactions->find_all();
$transaction_ids = array();
foreach ($account_transactions as $account_transaction) {
$transaction_ids[] = $account_transaction->transaction_id;
}
if ($this->_search_and) {
$this->_transactions = $this->_transactions->where('id', 'IN', $transaction_ids);
} else {
$this->_transactions = $this->_transactions->or_where('id', 'IN', $transaction_ids);
}
}
if ($this->_search_date) {
if ($this->_search_and) {
$this->_transactions = $this->_transactions->where('transaction.date', '=', $this->_search_date);
} else {
$this->_transactions = $this->_transactions->or_where('transaction.date', '=', $this->_search_date);
}
}
if ($this->_search_check_number) {
if ($this->_search_and) {
$this->_transactions = $this->_transactions->where('transaction.reference', 'LIKE', '%' . $this->_search_check_number . '%');
} else {
$this->_transactions = $this->_transactions->or_where('transaction.reference', 'LIKE', '%' . $this->_search_check_number . '%');
}
}
$this->_transactions = $this->_transactions->and_where_close();
$result_object = $this->_find_transactions();
return (object) array("total_results" => $result_object->total_results, "sort_by" => $this->_sort_by, "pages" => $result_object->pages, "page" => $result_object->page, "transactions" => $this->_return_transactions_array($result_object->transactions));
}
示例4: _execute
protected function _execute()
{
if (!$this->_account_id) {
throw new Exception("Invalid report account: none provided.");
}
$account = $this->_load_account($this->_account_id);
if (!$account->loaded()) {
throw new Exception("Invalid report account: not found.");
}
if (!$this->_date_start) {
throw new Exception("Invalid report start date: none provided.");
}
if ($this->_date_start != date("Y-m-d", strtotime($this->_date_start))) {
throw new Exception("Invalid report start date: must be in format YYYY-MM-DD.");
}
if (!$this->_date_end) {
throw new Exception("Invalid report end date: none provided.");
}
if ($this->_date_end != date("Y-m-d", strtotime($this->_date_end))) {
throw new Exception("Invalid report end date: must be in format YYYY-MM-DD.");
}
$this->_account_transactions = ORM::Factory('account_transaction')->where('account_id', '=', $account->id)->where('date', '>=', $this->_date_start)->where('date', '<=', $this->_date_end)->order_by('date', 'asc')->order_by('close_books', 'desc')->order_by('transaction_id', 'asc')->find_all();
$balance = NULL;
// Calculate balance on-the-fly to avoid an error when pulling massive account transactions with balances mid-update.
foreach ($this->_account_transactions as $i => $account_transaction) {
if ($balance === NULL) {
$balance = $this->_beans_round($account_transaction->balance);
} else {
$this->_account_transactions[$i]->balance = $this->_beans_round($balance + $account_transaction->amount);
$balance = $this->_account_transactions[$i]->balance;
}
}
return (object) array('date_start' => $this->_date_start, 'date_end' => $this->_date_end, 'account' => $this->_return_account_element($account), 'account_transactions' => $this->_return_ledger_transactions_array($this->_account_transactions));
}
示例5: _execute
protected function _execute()
{
if (!$this->_date) {
throw new Exception("Invalid report date: none provided.");
}
if ($this->_date != date("Y-m-d", strtotime($this->_date))) {
throw new Exception("Invalid report date: must be in format YYYY-MM-DD.");
}
// We'll exclude these two accounts from our generated chart.
$excluded_account_ids = array($this->_transaction_sale_deferred_income_account_id, $this->_transaction_sale_deferred_liability_account_id);
// T2 Accounts ( just below top level )
$t2_accounts = array();
foreach (ORM::Factory('account')->where('parent_account_id', 'IS', NULL)->find_all() as $top_level_account) {
foreach ($top_level_account->child_accounts->find_all() as $t2_account) {
$t2_accounts[] = $t2_account;
}
}
//
// Query for our accounts - we're interested in
//
$account_types = array();
$account_types['cash'] = new stdClass();
$account_types['cash']->name = "Cash";
$account_types['cash']->balance = 0.0;
$account_types['cash']->direction = 1;
$account_types['cash']->codes = array('cash', 'bankaccount');
$account_types['cash']->accounts = array();
$account_types['accountsreceivable'] = new stdClass();
$account_types['accountsreceivable']->name = "Accounts Receivable";
$account_types['accountsreceivable']->balance = 0.0;
$account_types['accountsreceivable']->direction = 1;
$account_types['accountsreceivable']->codes = array('accountsreceivable', 'pending_ar');
$account_types['accountsreceivable']->accounts = array();
$account_types['shorttermdebt'] = new stdClass();
$account_types['shorttermdebt']->name = "Short Term Debt";
$account_types['shorttermdebt']->balance = 0.0;
$account_types['shorttermdebt']->direction = -1;
$account_types['shorttermdebt']->codes = array('shorttermdebt', 'accountspayable', 'pending_ap');
$account_types['shorttermdebt']->accounts = array();
// $array is blank - fill it in.
foreach ($account_types as $code => $account_type) {
foreach ($t2_accounts as $t2_account) {
$t2_result = $this->_build_code_chart($t2_account, $account_type->codes, TRUE, $excluded_account_ids);
if ($t2_result) {
$account_types[$code]->accounts[] = $t2_result;
}
}
}
foreach ($account_types as $type => $account_type) {
foreach ($account_type->accounts as $index => $account) {
$account_types[$type]->accounts[$index] = $this->_generate_account_balance($account, $this->_date);
}
}
$net = 0.0;
foreach ($account_types as $type => $account_type) {
$account_types[$type]->balance_total = $this->_generate_account_balance_total($account_type->accounts);
$net = $this->_beans_round($net + $account_types[$type]->direction * $account_types[$type]->balance_total);
}
return (object) array('date' => $this->_date, 'account_types' => $account_types, 'net' => $net);
}
示例6: index
public function index()
{
$procedimentos = ORM::Factory('procedimento')->lista_semana();
$view = View::Factory('home/index');
$view->set('procedimentos', $procedimentos);
$this->template->content = $view;
}
示例7: _execute
protected function _execute()
{
// One-off use case of looking up role by code.
if (isset($this->_data->role_code) and $this->_data->role_code) {
$role = ORM::Factory('role')->where('code', '=', $this->_data->role_code)->find();
if ($role->loaded()) {
$this->_data->role_id = $role->id;
}
}
if (isset($this->_data->name)) {
$this->_user->name = $this->_data->name;
}
if (isset($this->_data->email)) {
$this->_user->email = $this->_data->email;
}
if (isset($this->_data->role_id)) {
$this->_user->role_id = $this->_data->role_id;
}
if (isset($this->_data->password)) {
$this->_user->password = $this->_beans_auth_password($this->_user->id, $this->_data->password);
}
$this->_validate_user($this->_user);
$this->_user->save();
return (object) array("user" => $this->_return_user_element($this->_user));
}
示例8: cleanup
public function cleanup()
{
$this->auto_render = false;
if (empty($_POST['survey_id']) || empty($_POST['mode'])) {
header(' ', true, 400);
$this->auto_render = false;
echo 'Cannot cleanup without a survey ID and mode';
return;
}
$survey = ORM::Factory('survey', $_POST['survey_id']);
if (!($this->auth->logged_in('CoreAdmin') || $this->auth->has_website_access('admin', $survey->website_id))) {
header(' ', true, 401);
echo 'Access denied';
return;
}
$occListQuery = 'select o.id, o.sample_id into temporary occlist from occurrences o ' . 'join samples s on s.id=o.sample_id and s.survey_id=' . $survey->id;
switch ($_POST['mode']) {
case 'deleted':
$occListQuery .= ' where o.deleted=true';
break;
case 'test':
$occListQuery .= " where o.record_status='T'";
break;
case 'all':
// no extra filter
break;
default:
header(' ', true, 400);
echo 'Invalid mode parameter';
return;
}
$this->database = new Database();
$this->database->query($occListQuery);
$this->database->query('delete from occurrence_attribute_values where occurrence_id in (select id from occlist)');
$this->database->query('delete from occurrence_comments where occurrence_id in (select id from occlist)');
$this->database->query('delete from occurrence_images where occurrence_id in (select id from occlist)');
$this->database->query('delete from determinations where occurrence_id in (select id from occlist)');
// the number of occurrences deleted is the fact we need to report back
$qry = $this->database->query('delete from occurrences where id in (select id from occlist)');
$count = $qry->count();
$this->database->query('delete from cache_occurrences where id in (select id from occlist)');
// remove any samples that this query has left as empty
$this->database->query('select s.id, s.parent_id into temporary smplist from samples s ' . 'join occlist o on o.sample_id=s.id ' . 'left join occurrences occ on occ.sample_id=s.id ' . 'where occ.id is null');
// first any child samples
$this->database->query('delete from sample_attribute_values where sample_id in (select id from smplist)');
$this->database->query('delete from sample_comments where sample_id in (select id from smplist)');
$this->database->query('delete from sample_images where sample_id in (select id from smplist)');
$this->database->query('delete from samples where id in (select id from smplist)');
// then the parents
$this->database->query('select s.id into temporary parentlist from samples s ' . 'join smplist child on child.parent_id=s.id ' . 'left join samples smpcheck on smpcheck.id=s.id ' . 'where smpcheck.id is null');
$this->database->query('delete from sample_attribute_values where sample_id in (select id from parentlist)');
$this->database->query('delete from sample_comments where sample_id in (select id from parentlist)');
$this->database->query('delete from sample_images where sample_id in (select id from parentlist)');
$this->database->query('delete from samples where id in (select id from parentlist)');
// cleanup
$this->database->query('drop table occlist');
$this->database->query('drop table smplist');
$this->database->query('drop table parentlist');
echo "{$count} occurrences deleted";
}
示例9: before
/**
* Attempt to load the Topic using the 'ID' parameter in the url.
*
* @throws HTTP_Exception_404 if topic is not found
*/
public function before()
{
parent::before();
$this->topic = ORM::Factory('Forum_Topic', $this->request->param('id'));
if (!$this->topic->loaded()) {
throw HTTP_Exception::factory('404', 'Forum topic not found');
}
}
示例10: excluir
public function excluir($id)
{
$procedimento = ORM::Factory('procedimento', $id);
$processo = $procedimento->processo;
$procedimento->delete();
html::flash_message('Procedimento excluído com sucesso!', 'success');
url::redirect('processos/formulario/' . $processo->id);
}
示例11: _execute
protected function _execute()
{
if (!$this->_account->loaded()) {
throw new Exception("Account could not be found.");
}
if (ORM::Factory('account')->where('parent_account_id', '=', $this->_account->id)->count_all()) {
throw new Exception("Please remove all child accounts before deleting.");
}
// Query for all transactions associated to this account.
$transaction_id_rows = DB::query(Database::SELECT, 'SELECT DISTINCT(transaction_id) as transaction_id FROM account_transactions WHERE account_id = "' . $this->_account->id . '"')->execute()->as_array();
if (count($transaction_id_rows) and !$this->_transfer_account->loaded()) {
throw new Exception("Please select a transfer account.");
}
if (count($transaction_id_rows) and $this->_account->id == $this->_transfer_account->id) {
throw new Exception("Transfer account cannot match the account being removed.");
}
// Loop each transaction and update appropriately.
foreach ($transaction_id_rows as $transaction_id_row) {
$transaction = $this->_load_transaction($transaction_id_row['transaction_id']);
if (!$transaction->loaded()) {
throw new Exception("An unexpected error has occurred: transaction not found.");
}
// Array for $account_id => $amount
$new_account_transactions = array();
$new_account_transactions[$this->_transfer_account->id] = 0.0;
foreach ($transaction->account_transactions->find_all() as $account_transaction) {
if ($account_transaction->account_reconcile_id) {
throw new Exception("Cannot delete accounts that have reconciled transactions.");
}
if ($account_transaction->account_transaction_forms->count_all()) {
throw new Exception("This account contains transactions that are associated with a form ( invoice, purchase, payment, etc. ). At this time transactions associated with a form cannot be transferred.");
}
if ($account_transaction->account_id == $this->_account->id) {
$new_account_transactions[$this->_transfer_account->id] = $this->_beans_round($new_account_transactions[$this->_transfer_account->id] + $account_transaction->amount * $account_transaction->account->account_type->table_sign * $this->_transfer_account->account_type->table_sign);
} else {
if (!isset($new_account_transactions[$account_transaction->account_id])) {
$new_account_transactions[$account_transaction->account_id] = 0.0;
}
$new_account_transactions[$account_transaction->account_id] = $this->_beans_round($new_account_transactions[$account_transaction->account_id] + $account_transaction->amount);
}
}
// Array for $account_id => $amount
$account_transaction_update_data = new stdClass();
$account_transaction_update_data->id = $transaction->id;
$account_transaction_update_data->account_transactions = array();
foreach ($new_account_transactions as $account_id => $amount) {
$account_transaction_update_data->account_transactions[] = (object) array('account_id' => $account_id, 'amount' => $amount);
}
$account_transaction_update = new Beans_Account_Transaction_Update($this->_beans_data_auth($account_transaction_update_data));
$account_transaction_update_result = $account_transaction_update->execute();
if (!$account_transaction_update_result->success) {
throw new Exception("Error updating account transaction: " . $account_transaction_update_result->error);
}
}
// Now delete account.
$this->_account->delete();
return (object) array();
}
示例12: create
/**
* Create a new movie.
* @param integer $parent_id id of parent album
* @param string $filename path to the photo file on disk
* @param string $name the filename to use for this photo in the album
* @param integer $title the title of the new photo
* @param string $description (optional) the longer description of this photo
* @return Item_Model
*/
static function create($parent, $filename, $name, $title, $description = null, $owner_id = null)
{
if (!$parent->loaded || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
if (!is_file($filename)) {
throw new Exception("@todo MISSING_MOVIE_FILE");
}
if (strpos($name, "/")) {
throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
}
// We don't allow trailing periods as a security measure
// ref: http://dev.kohanaphp.com/issues/684
if (rtrim($name, ".") != $name) {
throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
}
$movie_info = movie::getmoviesize($filename);
// Force an extension onto the name
$pi = pathinfo($filename);
if (empty($pi["extension"])) {
$pi["extension"] = image_type_to_extension($movie_info[2], false);
$name .= "." . $pi["extension"];
}
$movie = ORM::factory("item");
$movie->type = "movie";
$movie->title = $title;
$movie->description = $description;
$movie->name = $name;
$movie->owner_id = $owner_id ? $owner_id : user::active();
$movie->width = $movie_info[0];
$movie->height = $movie_info[1];
$movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv";
$movie->thumb_dirty = 1;
$movie->resize_dirty = 1;
$movie->sort_column = "weight";
$movie->rand_key = (double) mt_rand() / (double) mt_getrandmax();
// Randomize the name if there's a conflict
while (ORM::Factory("item")->where("parent_id", $parent->id)->where("name", $movie->name)->find()->id) {
// @todo Improve this. Random numbers are not user friendly
$movie->name = rand() . "." . $pi["extension"];
}
// This saves the photo
$movie->add_to_parent($parent);
// If the thumb or resize already exists then rename it
if (file_exists($movie->resize_path()) || file_exists($movie->thumb_path())) {
$movie->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
$movie->save();
}
copy($filename, $movie->file_path());
module::event("item_created", $movie);
// Build our thumbnail
graphics::generate($movie);
// If the parent has no cover item, make this it.
if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
item::make_album_cover($movie);
}
return $movie;
}
示例13: __construct
public function __construct($data = NULL)
{
parent::__construct($data);
$this->_addresses = ORM::Factory('entity_address')->distinct(TRUE);
$this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0;
$this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50;
$this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest";
$this->_search_customer_id = isset($data->search_customer_id) ? (int) $data->search_customer_id : FALSE;
}
示例14: diff
public function diff($id = FALSE)
{
if (!$id) {
throw new Kohana_404_Exception();
}
$this->template->this_page = 'revision';
$this->template->content = new View('admin/reports/revision');
$this->template->content->revisions = ORM::Factory('revision_incident')->where('incident_id', $id)->orderby('time', 'DESC')->find_all();
}
示例15: getModelValues
/**
* Setup the default values to use when loading this controller to edit an existing code.
*/
protected function getModelValues()
{
$r = parent::getModelValues();
// The code is linked to a taxon meaning, but we need to use this to link back to the
// preferred taxa in taxon list, so when you save it knows where to go back to.
$ttl = ORM::Factory('taxa_taxon_list')->where(array('taxon_meaning_id' => $this->model->taxon_meaning_id, 'preferred' => 'true'))->find();
$r['taxa_taxon_list:id'] = $ttl->id;
return $r;
}