当前位置: 首页>>代码示例>>PHP>>正文


PHP CActiveRecord类代码示例

本文整理汇总了PHP中CActiveRecord的典型用法代码示例。如果您正苦于以下问题:PHP CActiveRecord类的具体用法?PHP CActiveRecord怎么用?PHP CActiveRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CActiveRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save()
 {
     parent::save();
     /**
      * У сотрудников, которых нет приказов по
      * ГАК в году комиссии автоматически устанавливается
      * приказ от комиссии
      */
     if ($this->order_id !== 0) {
         $persons = new CArrayList();
         foreach ($this->members->getItems() as $person) {
             $persons->add($person->getId(), $person);
         }
         if (!is_null($this->manager)) {
             $persons->add($this->manager->getId(), $this->manager);
         }
         foreach ($persons->getItems() as $person) {
             if (is_null($person->getSABOrdersByYear($this->year))) {
                 $ar = new CActiveRecord(array("id" => null, "person_id" => $person->getId(), "year_id" => $this->year->getId(), "order_id" => $this->order_id));
                 $ar->setTable(TABLE_SAB_PERSON_ORDERS);
                 $ar->insert();
             }
         }
     }
 }
开发者ID:Rustam44,项目名称:ASUPortalPHP,代码行数:25,代码来源:CSABCommission.class.php

示例2: attach

 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     $validator = new yupe\components\validators\NumberValidator();
     $validator->attributes = array($this->priceAttribute, $this->priceEurAttribute, $this->priceOldAttribute);
     $owner->getValidatorList()->add($validator);
     parent::attach($owner);
 }
开发者ID:kuzmina-mariya,项目名称:unizaro-decor,代码行数:10,代码来源:PriceBehavior.php

示例3: update

 /**
  * @param CActiveRecord $model
  * @param $sortableAttribute
  * @param $sortOrderData
  *
  * @return string
  */
 private function update($model, $sortableAttribute, $sortOrderData)
 {
     $pk = $model->tableSchema->primaryKey;
     $pk_array = array();
     if (is_array($pk)) {
         // composite key
         $string_ids = array_keys($sortOrderData);
         $array_ids = array();
         foreach ($string_ids as $string_id) {
             $array_ids[] = explode(',', $string_id);
         }
         foreach ($array_ids as $array_id) {
             $pk_array[] = array_combine($pk, $array_id);
         }
     } else {
         // normal key
         $pk_array = array_keys($sortOrderData);
     }
     $models = $model->model()->findAllByPk($pk_array);
     $transaction = Yii::app()->db->beginTransaction();
     try {
         foreach ($models as $model) {
             $_key = is_array($pk) ? implode(',', array_values($model->primaryKey)) : $model->primaryKey;
             $model->{$sortableAttribute} = $sortOrderData[$_key];
             $model->save();
         }
         $transaction->commit();
     } catch (Exception $e) {
         // an exception is raised if a query fails
         $transaction->rollback();
     }
 }
开发者ID:zhaoyan158567,项目名称:YiiBooster,代码行数:39,代码来源:TbSortableAction.php

示例4: save

 public function save()
 {
     $this->grant->save();
     /**
      * Работа с участниками
      */
     $members = array();
     if (array_key_exists("members", $this->_fields)) {
         $members = $this->_fields["members"];
     }
     /**
      * Делаем руководителя тоже участником
      */
     if ($this->grant->manager_id != "0") {
         $members[] = $this->grant->manager_id;
     }
     /**
      * Удаляем старых участников
      */
     foreach (CActiveRecordProvider::getWithCondition(TABLE_GRANT_MEMBERS, "grant_id= " . $this->grant->getId())->getItems() as $ar) {
         $ar->remove();
     }
     /**
      * Добавляем новых
      */
     foreach ($members as $member) {
         $ar = new CActiveRecord(array("id" => null, "grant_id" => $this->grant->getId(), "person_id" => $member));
         $ar->setTable(TABLE_GRANT_MEMBERS);
         $ar->insert();
     }
 }
开发者ID:Rustam44,项目名称:ASUPortalPHP,代码行数:31,代码来源:CGrantForm.class.php

示例5: save

 public function save()
 {
     $group = $this->group;
     $roles = array();
     if (array_key_exists("roles", $group)) {
         $roles = $group["roles"];
         unset($group["roles"]);
     }
     $groupObj = new CUserGroup();
     $groupObj->setAttributes($group);
     /**
      * Удаляем старые задачи группы и пользователей
      */
     foreach (CActiveRecordProvider::getWithCondition(TABLE_USER_GROUP_HAS_ROLES, "user_group_id = " . $groupObj->getId())->getItems() as $ar) {
         $ar->remove();
     }
     $groupObj->save();
     /**
      * Создаем новые задачи группы и пользователей
      */
     foreach ($roles as $role => $level) {
         if ($level != 0) {
             $ar = new CActiveRecord(array("id" => null, "user_group_id" => $groupObj->getId(), "task_id" => $role, "task_rights_id" => $level));
             $ar->setTable(TABLE_USER_GROUP_HAS_ROLES);
             $ar->insert();
         }
     }
 }
开发者ID:Rustam44,项目名称:ASUPortalPHP,代码行数:28,代码来源:CUserGroupForm.class.php

示例6: attach

 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     $validator = new CSafeValidator();
     $validator->attributes = array($this->attribute);
     $owner->getValidatorList()->add($validator);
     parent::attach($owner);
 }
开发者ID:kuzmina-mariya,项目名称:gallery,代码行数:10,代码来源:DMultiplyListBehavior.php

示例7: run

 public function run($action, $to, $id)
 {
     $to = CActiveRecord::model($this->getController()->CQtreeGreedView['modelClassName'])->findByPk((int) $to);
     $moved = CActiveRecord::model($this->getController()->CQtreeGreedView['modelClassName'])->findByPk((int) $id);
     if (!is_null($to) && !is_null($moved)) {
         try {
             switch ($action) {
                 case 'child':
                     $moved->moveAsLast($to);
                     break;
                 case 'before':
                     if ($to->isRoot()) {
                         $moved->moveAsRoot();
                     } else {
                         $moved->moveBefore($to);
                     }
                     break;
                 case 'after':
                     if ($to->isRoot()) {
                         $moved->moveAsRoot();
                     } else {
                         $moved->moveAfter($to);
                     }
                     break;
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash('CQTeeGridView', $e->getMessage());
         }
     }
     $this->getController()->redirect(array($this->getController()->CQtreeGreedView['adminAction']));
 }
开发者ID:kostya1017,项目名称:our,代码行数:31,代码来源:MoveNode.php

示例8: assertSaves

 /**
  * Assert thet the model can be saved without error and, if errors are present, print
  * out the corresponding error messages.
  * @param CActiveRecord $model
  */
 public function assertSaves(CActiveRecord $model)
 {
     $saved = $model->save();
     if ($model->hasErrors()) {
         VERBOSE_MODE && print_r($model->getErrors());
     }
     $this->assertTrue($saved);
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:13,代码来源:X2TestCase.php

示例9: usernameFieldsSet

 /**
  * Sets username fields of a model
  */
 public static function usernameFieldsSet(CActiveRecord $model, $username)
 {
     if ($model->hasAttribute('updatedBy')) {
         $model->updatedBy = $username;
     }
     if ($model->hasAttribute('createdBy') && $model->isNewRecord) {
         $model->createdBy = $username;
     }
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:12,代码来源:X2ChangeLogBehavior.php

示例10: saveFromPost

 /**
  * Attempts to save the specified model with attribute values from POST. If 
  * the saving fails or if no POST data is available it returns false.
  * @param CActiveRecord $model the model
  * @return boolean whether the model was saved
  */
 protected function saveFromPost(&$model)
 {
     if (isset($_POST[$this->getModelClass()])) {
         $model->attributes = $_POST[$this->getModelClass()];
         if ($model->save()) {
             return true;
         }
     }
     return false;
 }
开发者ID:pweisenburger,项目名称:xbmc-video-server,代码行数:16,代码来源:ModelController.php

示例11: saveActiveRecord

 public function saveActiveRecord(CActiveRecord $record)
 {
     try {
         if (!$record->save()) {
             new \Error(5, null, json_encode($record->getErrors()));
         }
     } catch (Exception $e) {
         new \Error(5, null, $e->getMesaage());
     }
 }
开发者ID:Yougmark,项目名称:TiCheck_Server,代码行数:10,代码来源:ModifyController.php

示例12: unSubscribe

 /**
  * @param \CActiveRecord $model
  *
  * @return bool
  */
 public function unSubscribe(\CActiveRecord $model)
 {
     try {
         if ($channel = $this->getChannel()) {
             return $channel->unSubscribe($model->getSubscriber());
         }
     } catch (\CException $e) {
     }
     return false;
 }
开发者ID:sim2github,项目名称:yii-node-socket,代码行数:15,代码来源:ArChannel.php

示例13: format

 /**
  * {@inheritDoc}
  * @see IExportFormat::format()
  */
 public function format(CActiveRecord $record, array $data, array $templates = array())
 {
     if (empty($data)) {
         throw new CDbException(Yii::t('yii', 'Can not generate multiple insert command with empty data set.'));
     }
     $templates = array_merge(array('main' => "INSERT INTO {{tableName}} ({{columnInsertNames}}) VALUES \n{{rowInsertValues}};\n", 'columnInsertValue' => '{{value}}', 'columnInsertValueGlue' => ', ', 'rowInsertValue' => '({{columnInsertValues}})', 'rowInsertValueGlue' => ",\n", 'columnInsertNameGlue' => ', '), $templates);
     $table = $record->tableSchema;
     if ($table === null) {
         throw new CDbException(Yii::t('yii', 'Table "{table}" does not exist.', array('{table}' => $record->tableName())));
     }
     $tableName = $table->rawName;
     $columns = array();
     foreach ($data as $rowData) {
         foreach ($rowData as $columnName => $columnValue) {
             if (!in_array($columnName, $columns, true)) {
                 if ($table->getColumn($columnName) !== null) {
                     $columns[] = $columnName;
                 }
             }
         }
     }
     $columnInsertNames = array();
     foreach ($columns as $name) {
         $columnInsertNames[$name] = $record->getDbConnection()->quoteColumnName($name);
     }
     $columnInsertNamesSqlPart = implode($templates['columnInsertNameGlue'], $columnInsertNames);
     $rowInsertValues = array();
     foreach ($data as $rowData) {
         $columnInsertValues = array();
         foreach ($columns as $columnName) {
             /* @var $column CDbColumnSchema */
             $column = $table->getColumn($columnName);
             $columnValue = array_key_exists($columnName, $rowData) ? $rowData[$columnName] : new CDbException('NULL');
             if ($columnValue instanceof CDbExpression) {
                 $columnInsertValue = $columnValue->expression;
                 // in reverse order to prevent precocious replacements on param values
                 foreach (array_reverse($columnValue->params) as $columnValueParamName => $columnValueParam) {
                     $secureColumnParamValue = $this->secureOutput($record->getDbConnection(), $columnValueParam);
                     $columnInsertValue = strtr(':' . $columnValueParamName, $secureColumnParamValue, $columnInsertValue);
                 }
             } else {
                 $columnInsertValue = $column->typecast($columnValue);
                 if ($columnInsertValue === '' && $column->allowNull) {
                     $columnInsertValue = null;
                 }
                 $columnInsertValue = $this->secureOutput($record->getDbConnection(), $columnInsertValue);
             }
             $columnInsertValues[] = strtr($templates['columnInsertValue'], array('{{column}}' => $columnInsertNames[$columnName], '{{value}}' => $columnInsertValue));
         }
         $rowInsertValues[] = strtr($templates['rowInsertValue'], array('{{tableName}}' => $tableName, '{{columnInsertNames}}' => $columnInsertNamesSqlPart, '{{columnInsertValues}}' => implode($templates['columnInsertValueGlue'], $columnInsertValues)));
     }
     $sql = strtr($templates['main'], array('{{tableName}}' => $tableName, '{{columnInsertNames}}' => $columnInsertNamesSqlPart, '{{rowInsertValues}}' => implode($templates['rowInsertValueGlue'], $rowInsertValues)));
     return $sql;
 }
开发者ID:anastaszor,项目名称:yii1-export,代码行数:58,代码来源:SqlExportFormat.php

示例14: listData

 /**
  * @param CActiveRecord $model
  * @param string $valueField defaults to primary key field
  * @param string $textField defaults to primary key field
  * @return array
  */
 public static function listData($model, $valueField = '', $textField = '')
 {
     $pk = $model->metaData->tableSchema->primaryKey;
     if ($valueField === '') {
         $valueField = $pk;
     }
     if ($textField === '') {
         $textField = $valueField;
     }
     return CHtml::listData($model->findAll(array('select' => $valueField == $textField ? $valueField : $valueField . ',' . $textField)), $valueField, $textField);
 }
开发者ID:DarkAiR,项目名称:test,代码行数:17,代码来源:EHtml.php

示例15: checkUpdatedAtField

 /**
  * @param CActiveRecord $record
  * @param string        $colName
  * @param string        $newValue
  */
 protected function checkUpdatedAtField(CActiveRecord $record, $colName = 'name', $newValue = 'xxxxx')
 {
     $oldColumnValue = $record->{$colName};
     // Modifier l'objet met le champ updated_at à jour
     $oldUpdatedAt = $record->updated_at;
     $record->{$colName} = $newValue;
     $this->assertTrue($record->save());
     $this->assertNotEquals($oldUpdatedAt, $record->updated_at);
     // restauration de la valeur de départ
     $record->{$colName} = $oldColumnValue;
     $this->assertTrue($record->save());
 }
开发者ID:ChristopheBrun,项目名称:hLib,代码行数:17,代码来源:DbTestCase.php


注:本文中的CActiveRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。