コード例 #1
0
ファイル: QuizModel.php プロジェクト: xjtuwangke/laravel-quiz
 public static function _schema(\Illuminate\Database\Schema\Blueprint $table)
 {
     $table = parent::_schema($table);
     $table->longText('desc')->nullable();
     $table->text('title')->nullable();
     $table->enum('type', ['调研', '测试'])->default('调研');
     return $table;
 }
コード例 #2
0
ファイル: User.php プロジェクト: TheDenisNovikov/teacher
 public static function create($info)
 {
     $info['name'] = $info['username'];
     $info['password = MD5(?)'] = $info['password'];
     unset($info['password']);
     $info['created=NOW()'] = null;
     return parent::create($info);
 }
コード例 #3
0
 /**
  * see parent
  */
 public function clearCacheData()
 {
     parent::clearCacheData();
     // delete log cache key as well
     $f3 = self::getF3();
     $character = $this->characterId;
     $character->clearCacheData();
     $f3->clear('LOGGED.user.character.id_' . $character->id);
     return true;
 }
コード例 #4
0
 public static function _schema(\Illuminate\Database\Schema\Blueprint $table)
 {
     $table = parent::_schema($table);
     $table->unsignedInteger('step');
     $table->unsignedInteger('quiz_user_results_id');
     $table->unsignedInteger('quiz_id');
     $table->text('options')->nullable();
     $table->longText('text')->nullable();
     return $table;
 }
コード例 #5
0
ファイル: MenuItem.php プロジェクト: rash012/cms
 /**
  * Custom actions before deleting a record
  * @return boolean
  */
 protected function beforeDelete()
 {
     if (parent::beforeDelete()) {
         if ($childs = $this->childs) {
             foreach ($childs as $child) {
                 $child->delete();
             }
         }
         return true;
     }
     return false;
 }
コード例 #6
0
ファイル: MeminfoModel.php プロジェクト: phpsmith/IS4C
 public function save()
 {
     $stack = debug_backtrace();
     $lane_push = false;
     if (isset($stack[1]) && $stack[1]['function'] == 'pushToLanes') {
         $lane_push = true;
     }
     if ($this->record_changed && !$lane_push) {
         $this->modified(date('Y-m-d H:i:s'));
     }
     return parent::save();
 }
コード例 #7
0
 public static function _schema(\Illuminate\Database\Schema\Blueprint $table)
 {
     $table = parent::_schema($table);
     $table->unsignedInteger('quiz_id');
     $table->unsignedInteger('user_id');
     $table->unsignedInteger('current_step')->default(0);
     $table->text('token')->nullable();
     $table->enum('status', ['未开始', '进行中', '完成', '中止']);
     $table->longText('result_text')->nullable();
     $table->longText('score')->nullable();
     $table->index(['user_id', 'quiz_id']);
     return $table;
 }
コード例 #8
0
 public static function _schema(Blueprint $table)
 {
     $table = parent::_schema($table);
     $table->string('name');
     $table->string('title');
     $table->text('desc')->nullable();
     $table->text('logo')->nullable();
     $table->text('partner_id')->nullable();
     $table->text('partner_key')->nullable();
     $table->text('seller_email')->nullable();
     $table->text('options')->nullable();
     return $table;
 }
コード例 #9
0
 public function actionList()
 {
     $cond = new CDbCriteria();
     $cond->order = 'orderby asc';
     $cond->with = array('resource');
     $model = BasicModel::model()->findAll($cond);
     $rows = array();
     foreach ($model as $value) {
         $children = array();
         foreach ($value['resource'] as $val) {
             $children[] = array('text' => mb_convert_encoding($val->resourcename, 'UTF8', 'GBK'), 'id' => $val->resourceid, 'leaf' => TRUE);
         }
         $rows[] = array('text' => mb_convert_encoding($value->modelname, 'UTF8', 'GBK'), 'id' => $value->modelid, 'leaf' => FALSE, 'children' => $children);
     }
     echo json_encode($rows);
 }
コード例 #10
0
 static function init()
 {
     BasicModel::$connect_function = BasicModel::$dbconfig['engine'] . 'i_connect';
     BasicModel::$connect_function_error = BasicModel::$dbconfig['engine'] . 'i_connect_error';
     BasicModel::$db_select_function = BasicModel::$dbconfig['engine'] . 'i_select_db';
     BasicModel::$db_query_function = BasicModel::$dbconfig['engine'] . 'i_query';
     BasicModel::$query_inserted_id = BasicModel::$dbconfig['engine'] . 'i_insert_id';
     BasicModel::$db_query_num_rows_function = BasicModel::$dbconfig['engine'] . 'i_num_rows';
     BasicModel::$query_fetch_assoc_function = BasicModel::$dbconfig['engine'] . 'i_fetch_assoc';
     $connect_function = BasicModel::$connect_function;
     BasicModel::$connection = $connect_function(BasicModel::$dbconfig['host'], BasicModel::$dbconfig['username'], BasicModel::$dbconfig['password']);
     if (!BasicModel::$connection) {
         die("Connection failed: " . $connect_function_error());
     }
     $db_select_function = BasicModel::$db_select_function;
     $db_select_function(BasicModel::$connection, BasicModel::$dbconfig['database']) or die("Unable to select database");
 }
コード例 #11
0
 public static function _schema(Blueprint $table)
 {
     $table = parent::_schema($table);
     $table->string('order_no', 100)->unique();
     //订单号
     $table->bigInteger('user_id');
     //用户id
     $table->integer('payment_id')->references('id')->on('payments');
     //支付方式
     $table->integer('need_pay');
     //应付价格
     $table->integer('total');
     //总价
     $table->longText('goods')->nullable();
     //商品详细信息
     return $table;
 }
コード例 #12
0
ファイル: ProdUpdateModel.php プロジェクト: phpsmith/IS4C
 public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = false)
 {
     $adds = 0;
     $this->name = 'prodUpdate';
     $chk = parent::normalize($db_name, $mode, $doCreate);
     if ($chk !== false) {
         $adds += $chk;
     }
     $this->connection = FannieDB::get($db_name);
     if ($this->connection->tableExists('prodUpdateArchive')) {
         $this->name = 'prodUpdateArchive';
         $chk = parent::normalize($db_name, $mode, false);
         if ($chk !== false) {
             $adds += $chk;
         }
     }
     return $adds;
 }
コード例 #13
0
ファイル: Attitude.php プロジェクト: TheDenisNovikov/teacher
 public static function create($info)
 {
     $s = self::search();
     foreach ($info as $k => $v) {
         if ($k !== '`like`') {
             $s->filterBy($k, $v);
         }
     }
     $as = $s->find();
     if ($as) {
         $a = $as[0];
         if ($a->like == $info['`like`']) {
             $a->del();
             return false;
             // cancel
         } else {
             $a->update('`like`', !$a->like);
             return $a;
         }
     } else {
         return parent::create($info);
     }
 }
コード例 #14
0
ファイル: ProductsModel.php プロジェクト: phpsmith/IS4C
 /**
   Log deletes to prodUpdate
   Delete corresponding records from other tables
 */
 public function delete()
 {
     $update = new ProdUpdateModel($this->connection);
     $update->upc($this->upc());
     $update->logUpdate(ProdUpdateModel::UPDATE_DELETE);
     $try = parent::delete();
     if ($try) {
         if ($this->connection->tableExists('prodExtra')) {
             $extra = new ProdExtraModel($this->connection);
             $extra->upc($this->upc());
             $extra->delete();
         }
         $user = new ProductUserModel($this->connection);
         $user->upc($this->upc());
         $user->delete();
     }
     return $try;
 }
コード例 #15
0
ファイル: Activity.php プロジェクト: TheDenisNovikov/teacher
 public static function create($info)
 {
     $info['created=NOW()'] = null;
     return parent::create($info);
 }
コード例 #16
0
ファイル: BasicModel.php プロジェクト: phpsmith/IS4C
     echo "Update Table Structure: php BasicModel.php --update <Database name> <Subclass Filename>\n";
     echo "Generate markdown documentation: php BasicModel.php --doc <Model Filename(s)>\n";
     return 1;
 }
 $obj = new BasicModel(null);
 // Create new Model
 if ($argc == 3) {
     $modelname = $argv[2];
     if (substr($modelname, -4) == '.php') {
         $modelname = substr($modelname, 0, strlen($modelname) - 4);
     }
     if (substr($modelname, -5) != 'Model') {
         $modelname .= 'Model';
     }
     echo "Generating Model '{$modelname}'\n";
     $obj = new BasicModel(null);
     $as_view = $argv[1] == '--new-view' ? true : false;
     $obj->newModel($modelname, $as_view);
     return 0;
 }
 $classfile = $argv[1];
 if ($argc == 4) {
     $classfile = $argv[3];
 }
 if (substr($classfile, -4) != '.php') {
     $classfile .= '.php';
 }
 if (!file_exists($classfile)) {
     echo "Error: file '{$classfile}' does not exist\n";
     return 1;
 }
コード例 #17
0
 /**
  * see parent
  */
 public function clearCacheData()
 {
     parent::clearCacheData();
     // clear map cache as well
     $this->mapId->clearCacheData();
 }
コード例 #18
0
ファイル: VendorItemsModel.php プロジェクト: phpsmith/IS4C
 public function save()
 {
     if ($this->record_changed) {
         $this->modified(date('Y-m-d H:i:s'));
     }
     return parent::save();
 }
コード例 #19
0
ファイル: mapmodel.php プロジェクト: mglinski/pathfinder
 /**
  * save a map
  * @return mixed
  */
 public function save()
 {
     $mapModel = parent::save();
     // check if map type has changed and clear access objects
     if (!$mapModel->dry()) {
         if ($mapModel->isPrivate()) {
             $mapModel->clearAccess(['corporation', 'alliance']);
         } elseif ($mapModel->isCorporation()) {
             $mapModel->clearAccess(['user', 'alliance']);
         } elseif ($mapModel->isAlliance()) {
             $mapModel->clearAccess(['user', 'corporation']);
         }
     }
     return $mapModel;
 }
コード例 #20
0
 public function createIfNeeded($db_name)
 {
     return parent::createIfNeeded($db_name);
 }
コード例 #21
0
ファイル: PurchaseOrderModel.php プロジェクト: phpsmith/IS4C
 /**
   A really, REALLY old version of this table might exist.
   If so, just delete it and start over with the new schema.
 */
 public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = False)
 {
     $dbc = FannieDB::get($db_name);
     $this->connection = $dbc;
     if (!$dbc->table_exists($this->name)) {
         return parent::normalize($db_name, $mode, $doCreate);
     }
     $def = $dbc->table_definition($this->name);
     if (count($def) == 3 && isset($def['stamp']) && isset($def['id']) && isset($def['name'])) {
         echo "==========================================\n";
         if ($mode == BasicModel::NORMALIZE_MODE_APPLY) {
             $dbc->query('DROP TABLE ' . $dbc->identifier_escape($this->name));
             $success = $this->create();
             echo "Recreating table " . $this->name . ": ";
             echo $success ? 'Succeeded' : 'Failed';
             echo "\n";
             echo "==========================================\n";
             return $success;
         } else {
             echo $this->name . " is very old. It needs to be re-created\n";
             echo "Any data in the current table will be lost\n";
             echo "==========================================\n";
             return count($this->columns);
         }
     } else {
         return parent::normalize($db_name, $mode, $doCreate);
     }
 }
コード例 #22
0
ファイル: AreaBlock.php プロジェクト: rash012/cms
 /**
  * Returns the static model of the specified AR class.
  * @return AreaBlock the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
コード例 #23
0
ファイル: BasicModel.php プロジェクト: phpsmith/IS4C
     echo "Create new Model: php BasicModel.php --new <Model Name>\n";
     echo "Update Table Structure: php BasicModel.php --update <Database name> <Subclass Filename>\n";
     echo "Generate markdown documentation: php BasicModel.php --doc <Model Filename(s)>\n";
     return 0;
 }
 // Create new Model
 if ($argc == 3) {
     $modelname = $argv[2];
     if (substr($modelname, -4) == '.php') {
         $modelname = substr($modelname, 0, strlen($modelname) - 4);
     }
     if (substr($modelname, -5) != 'Model') {
         $modelname .= 'Model';
     }
     echo "Generating Model '{$modelname}'\n";
     $obj = new BasicModel(null);
     $obj->newModel($modelname);
     return 0;
 }
 $classfile = $argv[1];
 if ($argc == 4) {
     $classfile = $argv[3];
 }
 if (substr($classfile, -4) != '.php') {
     $classfile .= '.php';
 }
 if (!file_exists($classfile)) {
     echo "Error: file '{$classfile}' does not exist\n";
     return 1;
 }
 $class = pathinfo($classfile, PATHINFO_FILENAME);
コード例 #24
0
ファイル: BasicModel.php プロジェクト: phpsmith/IS4C
                    return $carry;
                }
            }
            $obj = new $class(null);
            if (!is_a($obj, 'BasicModel')) {
                return $carry;
            }
            $table = $obj->getName();
            $doc = '### ' . $table . "\n";
            if (is_a($obj, 'ViewModel')) {
                $doc .= '**View**' . "\n\n";
            }
            $doc .= $obj->columnsDoc();
            $doc .= $obj->doc();
            $carry[$table] = $doc;
            return $carry;
        }, array());
        ksort($tables);
        echo array_reduce(array_keys($table), function ($carry, $item) {
            return $carry . '* [' . $item . '](#' . strtolower($item) . ')' . "\n";
        }, '');
        echo "\n";
        echo array_reduce($tables, function ($carry, $item) {
            return $doc . "\n";
        }, '');
    }
}
if (php_sapi_name() === 'cli' && basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
    $obj = new BasicModel(null);
    $obj->cli($argc, $argv);
}
コード例 #25
0
ファイル: ScaleItemsModel.php プロジェクト: phpsmith/IS4C
 /**
   Custom normalization:
   The original version of scaleItems contained a column named "class".
   "class" is not a valid PHP function name, so the model is unable
   to have a method corresponding to the column.
 
   This will rename the legacy "class" column to "reportingClass" if
   needed. Otherwise, it just calls BasicModel::normalize().
 */
 public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = False)
 {
     $this->connection = FannieDB::get($db_name);
     if (!$this->connection->table_exists($this->name)) {
         return parent::normalize($db_name, $mode, $doCreate);
     }
     $current_definition = $this->connection->tableDefinition($this->name);
     if (isset($current_definition['class']) && !isset($current_definition['reportingClass'])) {
         $alter = 'ALTER TABLE ' . $this->connection->identifier_escape($this->name) . '
                   CHANGE COLUMN ' . $this->connection->identifier_escape('class') . ' ' . $this->connection->identifier_escape('reportingClass') . ' ' . $this->getMeta($this->columns['reportingClass']['type']);
         printf("%s column class as reportingClass\n", $mode == BasicModel::NORMALIZE_MODE_CHECK ? "Need to rename" : "Renaming");
         printf("\tSQL Details: %s\n", $alter);
         if ($mode == BasicModel::NORMALIZE_MODE_APPLY) {
             $renamed = $this->connection->query($alter);
             return 0;
         } else {
             return 1;
         }
     } else {
         return parent::normalize($db_name, $mode, $doCreate);
     }
 }
コード例 #26
0
ファイル: DTransactionsModel.php プロジェクト: phpsmith/IS4C
 /**
   Overrides (extends) the base function to check multiple tables that should
   all have identical or similar structure
     after doing a normal run of the base.
 */
 public function normalize($db_name, $mode = BasicModel::NORMALIZE_MODE_CHECK, $doCreate = false)
 {
     $config = FannieConfig::factory();
     $FANNIE_TRANS_DB = $config->get('TRANS_DB');
     $FANNIE_ARCHIVE_DB = $config->get('ARCHIVE_DB');
     $FANNIE_ARCHIVE_METHOD = $config->get('ARCHIVE_METHOD');
     $trans_adds = 0;
     $log_adds = 0;
     //EL If this isn't initialized it is "dlog_15" on the 2nd, preview_only=false run
     $this->name = 'dtransactions';
     // check self first
     $chk = parent::normalize($db_name, $mode, $doCreate);
     if ($chk !== false) {
         $trans_adds += $chk;
     }
     $this->columns['store_row_id']['increment'] = false;
     $this->columns['store_row_id']['primary_key'] = false;
     $this->columns['store_row_id']['index'] = false;
     $this->columns['pos_row_id']['index'] = false;
     $this->name = 'transarchive';
     $chk = parent::normalize($db_name, $mode, $doCreate);
     if ($chk !== false) {
         $trans_adds += $chk;
     }
     $this->name = 'suspended';
     $tmp1 = $this->columns['store_row_id'];
     $tmp2 = $this->columns['pos_row_id'];
     unset($this->columns['store_row_id']);
     unset($this->columns['pos_row_id']);
     $chk = parent::normalize($db_name, $mode, $doCreate);
     if ($chk !== false) {
         $trans_adds += $chk;
     }
     $this->columns['pos_row_id'] = $tmp2;
     $this->columns['store_row_id'] = $tmp1;
     $this->connection = FannieDB::get($FANNIE_ARCHIVE_DB);
     if ($FANNIE_ARCHIVE_METHOD == 'partitions') {
         $this->name = 'bigArchive';
         $chk = parent::normalize($FANNIE_ARCHIVE_DB, $mode, $doCreate);
         if ($chk !== false) {
             $trans_adds += $chk;
         }
     } else {
         $pattern = '/^transArchive\\d\\d\\d\\d\\d\\d$/';
         $tables = $this->connection->get_tables($FANNIE_ARCHIVE_DB);
         foreach ($tables as $t) {
             if (preg_match($pattern, $t)) {
                 $this->name = $t;
                 $chk = parent::normalize($FANNIE_ARCHIVE_DB, $mode, $doCreate);
                 if ($chk !== False) {
                     $trans_adds += $chk;
                 }
             }
         }
     }
     // move on to dlog views.
     // dlog_15 is used for detection since it's the only
     // actual table.
     // In the model the datestamp field datetime is swapped out for tdate
     // and trans_num is tacked on the end
     $this->connection = FannieDB::get($FANNIE_TRANS_DB);
     $this->name = 'dlog_15';
     unset($this->columns['datetime']);
     $tdate = array('tdate' => array('type' => 'datetime', 'index' => True));
     $trans_num = array('trans_num' => array('type' => 'VARCHAR(25)'));
     $this->columns = $tdate + $this->columns + $trans_num;
     $chk = parent::normalize($db_name, $mode, $doCreate);
     if ($chk !== false) {
         $log_adds += $chk;
     }
     // rebuild views
     // use BasicModel::normalize in check mode to detect missing columns
     // the ALTER queries it suggests won't work but the return value is
     // still correct. If it returns > 0, the view needs to be rebuilt
     $this->name = 'dlog';
     ob_start();
     $chk = parent::normalize($db_name, BasicModel::NORMALIZE_MODE_CHECK);
     ob_end_clean();
     if ($chk !== false && $chk > 0) {
         $log_adds += $chk;
         $this->normalizeLog('dlog', 'dtransactions', $mode);
     }
     $this->name = 'dlog_90_view';
     ob_start();
     $chk = parent::normalize($db_name, BasicModel::NORMALIZE_MODE_CHECK);
     ob_end_clean();
     if ($chk !== false && $chk > 0) {
         $log_adds += $chk;
         $this->normalizeLog('dlog_90_view', 'transarchive', $mode);
     }
     $this->connection = FannieDB::get($FANNIE_ARCHIVE_DB);
     if ($FANNIE_ARCHIVE_METHOD == 'partitions') {
         $this->name = 'dlogBig';
         ob_start();
         $chk = parent::normalize($FANNIE_ARCHIVE_DB, BasicModel::NORMALIZE_MODE_CHECK);
         ob_end_clean();
         if ($chk !== false && $chk > 0) {
             $log_adds += $chk;
             $this->normalizeLog('dlogBig', 'bigArchive', $mode);
         }
     } else {
         $pattern = '/^dlog\\d\\d\\d\\d\\d\\d$/';
         $tables = $this->connection->get_tables($FANNIE_ARCHIVE_DB);
         foreach ($tables as $t) {
             if (preg_match($pattern, $t)) {
                 $this->name = $t;
                 ob_start();
                 $chk = parent::normalize($FANNIE_ARCHIVE_DB, BasicModel::NORMALIZE_MODE_CHECK);
                 ob_end_clean();
                 if ($chk !== false && $chk > 0) {
                     $log_adds += $chk;
                     $this->normalizeLog($t, 'transArchive' . substr($t, 4), $mode);
                 }
             }
         }
     }
     // EL: Need to restore $this-columns to original values.
     $this->connection = FannieDB::get($FANNIE_TRANS_DB);
     unset($this->columns['tdate']);
     unset($this->columns['trans_num']);
     $datetime = array('datetime' => array('type' => 'datetime', 'index' => true));
     $this->columns = $datetime + $this->columns;
     $this->columns['store_row_id']['increment'] = true;
     $this->columns['store_row_id']['primary_key'] = true;
     $this->columns['store_row_id']['index'] = false;
     $this->columns['pos_row_id']['index'] = true;
     return $log_adds + $trans_adds;
     // normalize()
 }
コード例 #27
0
ファイル: ModelTest.php プロジェクト: minond/model
 /**
  * @expectedException Exception
  * @expectedExceptionMessage Invalid static method test called on class Efficio\Tests\Dataset\BasicModel
  */
 public function testCallingInvalidStaticMethodsThrowsAnException()
 {
     BasicModel::test();
 }