public function GuardarAlbaranes() { $db = new db(); $db->connect(); $C = new ActiveRecord('albaranes'); $C->fields["fecha"] = $this->fecha; $C->fields["operacion"] = $this->operacion; $C->fields["guia"] = $this->guia; $C->fields["remitente"] = $this->remitente; $C->fields["beneficiario"] = $this->beneficiario; $C->fields["documento"] = $this->documento; $C->fields["pais"] = $this->pais; $C->fields["direccion"] = $this->direccion; $C->fields["ciudad"] = $this->ciudad; $C->fields["telefono"] = $this->telefono; $C->fields["descripcion"] = $this->descripcion; $C->fields["peso"] = $this->peso; $C->fields["comision"] = $this->comision; $C->fields["seguro"] = $this->seguro; $C->fields["iv"] = $this->iv; $C->fields["total"] = $this->total; $C->fields["direccion_agencia"] = $this->direccion_agencia; $C->insert(); $db->close(); }
public static function delete(ActiveRecord $Record) { $modelName = $Record->getModel()->name; $primaryKey = $Record->getPrimaryKey(); $pool =& self::$_pool; unset($pool[$modelName][$primaryKey]); }
/** * @description Build WHERE Statement * * @param ActiveRecord $ar * * @throws arException * @return string */ public function asSQLStatement(ActiveRecord $ar) { if ($this->getType() == self::TYPE_REGULAR) { $arField = $ar->getArFieldList()->getFieldByName($this->getFieldname()); if ($arField instanceof arField) { $type = $arField->getFieldType(); $statement = $ar->getConnectorContainerName() . '.' . $this->getFieldname(); } else { $statement = $this->getFieldname(); } if (is_array($this->getValue())) { if (in_array($this->getOperator(), array('IN', 'NOT IN', 'NOTIN'))) { $statement .= ' ' . $this->getOperator() . ' ('; } else { $statement .= ' IN ('; } $values = array(); foreach ($this->getValue() as $value) { $values[] = $ar->getArConnector()->quote($value, $type); } $statement .= implode(', ', $values); $statement .= ')'; } else { if ($this->getValue() === NULL) { $this->setOperator('IS'); } $statement .= ' ' . $this->getOperator(); $statement .= ' ' . $ar->getArConnector()->quote($this->getValue(), $type); } $this->setStatement($statement); } return $this->getStatement(); }
public function test_should_destroy_the_thumbnail_even_when_not_loaded() { $Picture =& $this->Picture->find('first'); $Picture->destroy(); $this->assertFalse($this->Thumbnail->find('first'),'Issue #125'); }
public function test_destroying_should_cascade() { $Property = new Property(array('description' => 'This is a Property')); $Picture = $Property->picture->create(array('title' => 'Front')); $Property->destroy(); $this->assertFalse($this->Property->find('first', array('default' => false))); $this->assertFalse($this->Picture->find('first', array('default' => false))); }
public static function verEstado() { $db = new db(); $db->connect(); $C = new ActiveRecord('lista_estados'); $C->find(self::$id_estado); $db->close(); return $C->fields; }
public function __construct(\PDOStatement $stmt, ActiveRecord $model) { $this->stmt = $stmt; $this->model = $model; $stmt->setFetchMode(\PDO::FETCH_CLASS, $model->className(), array(false)); // $this->id=self::$idCount++; // // ZLog::Write(LOGLEVEL_DEBUG, $stmt->queryString); // self::$aliveStmts[$this->id]=$stmt->queryString; }
public function getPages() { $blog = new ActiveRecord(); $num = $blog->size(); $pages = $blog->pickout($num - 5, 5); $result = array(); for ($i = 0; $i < 5; $i++) { $result[$i] = array('title' => $pages[4 - $i]->title, 'url' => "/?page={$pages[4 - $i]->pagenum}"); } return $result; }
public static function onValidate(ActiveRecord $Record, RecordValidator $validator) { $validator->validate(array('field' => 'Handle', 'required' => false, 'validator' => 'handle', 'errorMessage' => 'Handle can only contain letters, numbers, hyphens, and underscores')); // check handle uniqueness if ($Record->isFieldDirty('Handle') && !$validator->hasErrors('Handle') && $Record->Handle) { $ExistingRecord = $Record::getByHandle($Record->Handle); if ($ExistingRecord && $ExistingRecord->ID != $Record->ID) { $validator->addError('Handle', 'Handle already registered'); } } }
public function getCategory() { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly'); $categories = $blog->getValueList('category'); $result = array(); foreach (array_reverse($categories) as $category) { $result[] = array('title' => $category, 'url' => sprintf("/?category=%s", urlencode($category))); } return $result; }
/** * * @return array|string */ public function run() { $data = $this->requestMethod === 'post' ? Yii::$app->getRequest()->post('Article') : Yii::$app->getRequest()->get('Article'); $this->model->setAttributes($data); $this->model->validate(); if ($this->controller === null) { return ['view' => $this->view, 'model' => $this->model]; } else { return $this->controller->renderPartial($this->view, ['model' => $this->model]); } }
protected function saveModel(ActiveRecord $model, $web_url) { if ($model->save()) { $model->grabImages($web_url); $model->grabTagsFromText(); $this->log("Сохранена модель #{$model->id}"); } else { $this->log("Не могу сохранить модель: ", impode("<br/>", $model->errors_flat_array)); } return $model; }
/** * ให้ค่า array ของ model ที่ได้จาก attributes + props * @param ActiveRecord $model * @return array */ public static function unpackProps($model) { if ($model->hasAttribute('props')) { $props = json_decode($model->props, true); if (!is_array($props)) { $props = array(); } } else { $props = array(); } return $props; }
/** * @param ActiveRecord $ar * * @return string */ public function asSQLStatement(ActiveRecord $ar) { $return = ' ' . $this->getType() . ' '; $return .= ' JOIN ' . $this->getTableName() . ' AS ' . $this->getTableNameAs(); if ($this->getBothExternal()) { $return .= ' ON ' . $this->getOnFirstField() . ' ' . $this->getOperator() . ' '; } else { $return .= ' ON ' . $ar->getConnectorContainerName() . '.' . $this->getOnFirstField() . ' ' . $this->getOperator() . ' '; } $return .= $this->getTableNameAs() . '.' . $this->getOnSecondField(); return $return; }
public function getPages($archive) { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly'); $result = $blog->findLike('date', sprintf("%s/%s", explode('-', $archive)[0], explode('-', $archive)[1]) . '%'); $pagenum_arr = array(); foreach ($result as $page) { $pagenum_arr[] = $page->pagenum; } array_multisort($pagenum_arr, SORT_ASC, $result); return $result; }
public function getKry() { $objAr = new ActiveRecord(); /*Query blm pake bind params, silahkan edit sendiri*/ $sql = "SELECT * FROM karyawan WHERE "; if ($this->getName()) { $sql .= " nama LIKE '%{$this->getName()}%' "; } if ($this->getNip()) { $sql .= " AND NIP LIKE '%{$this->getNip()}%' "; } return $objAr->fetchObject($sql); }
/** * @return bool */ protected function generateFields() { $fields = $this->active_record->getArFieldList()->getFields(); foreach ($fields as $standard_field) { $current_class = get_called_class(); $field_class = $current_class::FIELD_CLASS; /** * @var arViewField $field_class */ $field = $field_class::castFromFieldToViewField($standard_field); $this->addField($field); } return true; }
private function getAllMonths() { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly'); $dates = $blog->getValueList('date'); foreach ($dates as $date) { $ym[] = explode('/', $date)[0] . "-" . explode('/', $date)[1]; } $ym = array_unique($ym); asort($ym); foreach ($ym as $date) { $result[] = ["year" => explode('-', $date)[0], "month" => explode('-', $date)[1]]; } return $result; }
public function getNextLanguage() { if (!$this->languagesTruncated) { ActiveRecord::getDbConnection()->executeQuery('TRUNCATE TABLE Language'); $this->languagesTruncated = true; } if (!($data = $this->loadRecord('SELECT DISTINCT code FROM ' . $this->getTablePrefix() . 'languages'))) { return null; } $isDefault = $this->getConfigValue('default_customer_language') == $data['code']; $code = $data['code']; if ('US' == $data['code']) { $data['code'] = 'en'; } $data['code'] = strtolower($data['code']); if (!$isDefault) { $this->languages[$data['code']] = $code; } else { $this->defLang = $data['code']; } $lang = ActiveRecordModel::getNewInstance('Language'); $lang->setID($data['code']); $lang->isEnabled->set(true); $lang->isDefault->set($isDefault); return $lang; }
function __get($key) { if ($key == "id") { return $this->user_id; } return ActiveRecord::__get($key); }
public function __destruct() { if (self::$conn) { mysql_close(self::$conn); self::$conn = null; } }
function testTransactionCurrencyConverting() { $eur = Currency::getNewInstance('EUR'); $eur->rate->set('3.4528'); $eur->save(); $this->products[0]->setPrice($this->usd, '9.99'); $this->order->addProduct($this->products[0], 1); $this->order->save(); $this->order->changeCurrency($this->usd); //$this->order->finalize(); ActiveRecord::clearPool(); $order = CustomerOrder::getInstanceByID($this->order->getID(), true); $order->loadAll(); $details = new LiveCartTransaction($order, $eur); ActiveRecord::clearPool(); $order = CustomerOrder::getInstanceByID($this->order->getID(), true); $order->loadAll(); $this->assertEquals($details->amount->get(), '2.89'); $result = new TransactionResult(); $result->amount->set($details->amount->get()); $result->currency->set($details->currency->get()); $transaction = Transaction::getNewInstance($order, $result); $transaction->type->set(Transaction::TYPE_SALE); $this->assertEquals($transaction->amount->get(), '9.99'); $this->assertEquals($transaction->realAmount->get(), '2.89'); $transaction->save(); $this->assertFalse((bool) $order->isFinalized->get()); $order->finalize(); $this->assertTrue((bool) $order->isFinalized->get()); $this->assertEquals($order->getPaidAmount(), '9.99'); $this->assertEquals($order->totalAmount->get(), '9.99'); $this->assertTrue((bool) $order->isPaid->get()); }
/** set up */ public function setUp() { $this->createDatabase(); Registry::put($configurator = new MockConfigurator(), '__configurator'); Registry::put(new Logger($configurator), '__logger'); ActiveRecord::close_connection(); }
public function getPages($category) { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly'); $data = $blog->findFromKey('category', $category); $ids = array(); foreach ($data as $row) { $ids[] = $row->postid; } $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly'); $result = array(); foreach ($ids as $pagenum) { $result[] = $blog->find($pagenum); } return $result; }
/** * @return DeliveryZoneState */ public static function getNewInstance(DeliveryZone $zone, $mask) { $instance = ActiveRecord::getNewInstance(__CLASS__); $instance->deliveryZone->set($zone); $instance->mask->set($mask); return $instance; }
/** * Associate new role to user group * * @param UserGroup $userGroup User group * @param Role $role Associate group with this role * @return Tax */ public static function getNewInstance(UserGroup $userGroup, Role $role) { $instance = ActiveRecord::getNewInstance(__CLASS__); $instance->userGroup->set($userGroup); $instance->role->set($role); return $instance; }
public function getRoles($originalSorting = false) { $uid = $this->id; if (!$uid) { return [$this->role]; } ## get roles $roles = Role::model()->with('userRoles')->findAll(ActiveRecord::formatCriteria(['condition' => '|user_id| = :p', 'order' => '|is_default_role|', 'params' => [':p' => $uid]])); $roles = ActiveRecord::toArray($roles); if (empty($roles)) { return false; } $idx = 0; foreach ($roles as $k => $role) { ## find current role index if ($role['role_name'] == Yii::app()->user->getState('role') && $idx == 0) { $idx = $k; } } if ($originalSorting) { return $roles; } $role = array_splice($roles, $idx, 1); array_unshift($roles, $role[0]); $this->roles = $roles; return $roles; }
public function beforeSave() { if ($this->isNewRecord) { $this->user_id = user()->getId(); } return parent::beforeSave(); }
public function afterSave() { parent::afterSave(); $sql = "UPDATE p_nfy_subscription_categories " . "set category = 'role_{$this->role_name}.' " . "where category = 'role_{$this->oldName}.';"; Yii::app()->db->createCommand($sql)->execute(); return true; }
public function run() { $model = new ProGlobalEnquiry('create'); $model->country_id = ActiveRecord::getDefaultAreaCode(); if (isset(Yii::app()->user->id)) { $model->name = Yii::app()->user->title . ' ' . Yii::app()->user->first_name . ' ' . Yii::app()->user->last_name; $model->email = Yii::app()->user->email; if (Yii::app()->user->role_id != ROLE_REGISTER_MEMBER) { $model->email = Yii::app()->user->email_not_login; } $model->phone = Yii::app()->user->phone; $model->country_id = Yii::app()->user->country; } if (isset(Yii::app()->user->id)) { $cmsFormater = new CmsFormatter(); $mUser = Users::model()->findByPk(Yii::app()->user->id); $model->name = $cmsFormater->formatFullNameRegisteredUsers($mUser); $model->email = $mUser->email; $model->nric = $mUser->nric_passportno_roc; $model->phone = $mUser->phone; if (Yii::app()->user->role_id == ROLE_LANDLORD || Yii::app()->user->role_id == ROLE_TENANT) { $model->phone = $mUser->contact_no; $model->email = $mUser->email_not_login; } if (Yii::app()->user->role_id == ROLE_AGENT) { $model->email = $mUser->email_not_login; } } // $model->type_selling= 'Tenancy'; $box = Pages::getPageById(PAGE_ENGAGE_US_BOX); $this->render("global_enquiry", array('model' => $model, 'box' => $box)); }