Model PHP Class Code Examples

This page contains top rated real world PHP examples of class Model extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: AssignAction.php Project: Bagelllama/delphinium
0
 public function save(Model $parent, Model $parent_rule, $order)
 {
     $model = new ActionModel(['variable_name' => $this->lvariable->getName(), 'order' => $order]);
     $model->rule()->associate($parent);
     $model->save();
     $this->value->save($model, $parent_rule, 0);
 }
Example #2
Show file File: functions.php Project: PinGao/QQDemo
0
/**
 * 实例化模型类 格式 [资源://][模块/]模型
 * @param string $name 资源地址
 * @param string $layer 模型层名称
 * @return Think\Model
 */
function D($name = '', $layer = '')
{
    if (empty($name)) {
        return new Think\Model();
    }
    static $_model = array();
    $layer = $layer ?: C('DEFAULT_M_LAYER');
    if (isset($_model[$name . $layer])) {
        return $_model[$name . $layer];
    }
    $class = parse_res_name($name, $layer);
    if (class_exists($class)) {
        $model = new $class(basename($name));
    } elseif (false === strpos($name, '/')) {
        // 自动加载公共模块下面的模型
        if (!C('APP_USE_NAMESPACE')) {
            import('Common/' . $layer . '/' . $class);
        } else {
            $class = '\\Common\\' . $layer . '\\' . $name . $layer;
        }
        $model = class_exists($class) ? new $class($name) : new Think\Model($name);
    } else {
        Think\Log::record('D方法实例化没找到模型类' . $class, Think\Log::NOTICE);
        $model = new Think\Model(basename($name));
    }
    $_model[$name . $layer] = $model;
    return $model;
}
Example #3
Show file File: CategoriesController.php Project: alawnchen/blog-tutorial
0
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, "Categories", $_POST);
         $this->session->conditions = $query->getConditions();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
         if ($numberPage <= 0) {
             $numberPage = 1;
         }
     }
     $parameters = array();
     if ($this->session->conditions) {
         $parameters["conditions"] = $this->session->conditions;
     }
     $parameters["order"] = "id";
     $categories = Categories::find($parameters);
     if (count($categories) == 0) {
         $this->flash->notice("The search did not find any categories");
         return $this->dispatcher->forward(array("controller" => "categories", "action" => "index"));
     }
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $categories, "limit" => 10, "page" => $numberPage));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
 }
Example #4
Show file File: PostgresTest.php Project: MrGrigorev/reserva-de-salas
0
 /**
  * testCakeSchema method
  *
  * Test that schema generated postgresql queries are valid. ref #5696
  * Check that the create statement for a schema generated table is the same as the original sql
  *
  * @return void
  */
 public function testCakeSchema()
 {
     $db1 = ConnectionManager::getDataSource('test');
     $db1->cacheSources = false;
     $db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('datatype_tests') . ' (
id serial NOT NULL,
"varchar" character varying(40) NOT NULL,
"full_length" character varying NOT NULL,
"timestamp" timestamp without time zone,
"date" date,
CONSTRAINT test_data_types_pkey PRIMARY KEY (id)
');
     $model = new Model(array('name' => 'DatatypeTest', 'ds' => 'test'));
     $schema = new CakeSchema(array('connection' => 'test'));
     $result = $schema->read(array('connection' => 'test', 'models' => array('DatatypeTest')));
     $schema->tables = array('datatype_tests' => $result['tables']['missing']['datatype_tests']);
     $result = $db1->createSchema($schema, 'datatype_tests');
     $this->assertNotRegExp('/timestamp DEFAULT/', $result);
     $this->assertRegExp('/\\"full_length\\"\\s*text\\s.*,/', $result);
     $this->assertRegExp('/timestamp\\s*,/', $result);
     $db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
     $db1->query($result);
     $result2 = $schema->read(array('connection' => 'test', 'models' => array('DatatypeTest')));
     $schema->tables = array('datatype_tests' => $result2['tables']['missing']['datatype_tests']);
     $result2 = $db1->createSchema($schema, 'datatype_tests');
     $this->assertEquals($result, $result2);
     $db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
 }
Example #5
Show file File: ExtTranslateBehavior.php Project: thedrumz/music
0
 /**
  * Unbind translation for fields, optionally unbinds hasMany association for
  * fake field
  *
  * @param Model $Model using this behavior of model
  * @param string|array $fields string with field, or array(field1, field2=>AssocName, field3), or null for
  *    unbind all original translations
  * @return bool
  */
 public function unbindTranslation(Model $Model, $fields = null)
 {
     if (empty($fields) && empty($this->settings[$Model->alias])) {
         return false;
     }
     if (empty($fields)) {
         return $this->unbindTranslation($Model, $this->settings[$Model->alias]);
     }
     if (is_string($fields)) {
         $fields = array($fields);
     }
     $associations = array();
     foreach ($fields as $key => $value) {
         if (is_numeric($key)) {
             $field = $value;
             $association = null;
         } else {
             $field = $key;
             $association = $value;
         }
         $this->_removeField($Model, $field);
         if ($association !== null && (isset($Model->hasMany[$association]) || isset($Model->__backAssociation['hasMany'][$association]))) {
             $associations[] = $association;
         }
     }
     if (!empty($associations)) {
         $Model->unbindModel(array('hasMany' => $associations), false);
     }
     return true;
 }
Example #6
Show file File: ContainableBehaviorTest.php Project: manzapanza/cakephp-api-utils
0
 /**
  * _assertBindings method
  *
  * @param Model $Model
  * @param array $expected
  * @return void
  */
 protected function _assertBindings(Model $Model, $expected = array())
 {
     $expected = array_merge(array('belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array()), $expected);
     foreach ($expected as $binding => $expect) {
         $this->assertEquals(array_keys($Model->{$binding}), $expect);
     }
 }
Example #7
Show file File: MultiContentOverviewFilter.php Project: KristofSerre/ride-web-cms-orm
0
 /**
  * Applies the filter to the provided query
  * @param \ride\library\orm\model\Model $model
  * @param \ride\library\orm\query\ModelQuery $query
  * @param string $fieldName Name of the filter field
  * @param string|array $value Submitted value
  * @return string|array Value of the filter
  */
 public function applyQuery(Model $model, ModelQuery $query, $fieldName, $value = null)
 {
     $isArray = is_array($value);
     if ($value === null || $value === '' || $isArray && !$value) {
         return null;
     }
     $conditionField = '';
     if (!$this->prepareQuery($model, $query, $fieldName, $conditionField)) {
         return null;
     }
     if (!$isArray) {
         $value = array($value);
     }
     if ($this->operator == 'AND') {
         $conditions = array();
         foreach ($value as $index => $v) {
             if ($v === '') {
                 continue;
             }
             $conditions[] = '{' . $conditionField . '} = %' . $index . '%';
         }
         if ($conditions) {
             $query->addConditionWithVariables(implode(' ' . $this->operator . ' ', $conditions), $value);
         }
     } else {
         $query->addCondition('{' . $conditionField . '} IN %1%', $value);
     }
     return $value;
 }
Example #8
Show file File: CakeMigrationTest.php Project: dlpc/CakeWX
0
 /**
  * testRenameField method
  *
  * @return void
  */
 public function testRenameField()
 {
     $this->loadFixtures('User', 'Post');
     $model = new Model(array('table' => 'posts', 'ds' => 'test'));
     $migration = new TestCakeMigration(array('up' => array('rename_field' => array('posts' => array('updated' => 'renamed_updated'))), 'down' => array('rename_field' => array('posts' => array('renamed_updated' => 'updated')))));
     $fields = $this->db->describe($model);
     $this->assertTrue(isset($fields['updated']));
     $this->assertFalse(isset($fields['renamed_updated']));
     $this->assertTrue($migration->run('up'));
     $fields = $this->db->describe($model);
     $this->assertFalse(isset($fields['updated']));
     $this->assertTrue(isset($fields['renamed_updated']));
     try {
         $migration->run('up');
         $this->fail('No exception triggered');
     } catch (MigrationException $e) {
         $this->assertEqual('Field "updated" does not exists in "posts".', $e->getMessage());
     }
     $this->assertTrue($migration->run('down'));
     $fields = $this->db->describe($model);
     $this->assertTrue(isset($fields['updated']));
     $this->assertFalse(isset($fields['renamed_updated']));
     try {
         $migration->run('down');
         $this->fail('No exception triggered');
     } catch (MigrationException $e) {
         $this->assertEqual('Field "renamed_updated" does not exists in "posts".', $e->getMessage());
     }
 }
Example #9
Show file File: common.php Project: tmlsoft/main
0
/**
 +----------------------------------------------------------
* D函数用于实例化Model 格式 项目://分组/模块
+----------------------------------------------------------
* @param string name Model资源地址
 +----------------------------------------------------------
* @return Model
 +----------------------------------------------------------
*/
function D($name = '')
{
    if (empty($name)) {
        return new Model();
    }
    static $_model = array();
    if (isset($_model[$name])) {
        return $_model[$name];
    }
    if (strpos($name, '://')) {
        // 指定项目
        $name = str_replace('://', '/Model/', $name);
    } else {
        $name = C('DEFAULT_APP') . '/Model/' . $name;
    }
    import($name . 'Model');
    $class = basename($name . 'Model');
    if (class_exists($class)) {
        $model = new $class();
    } else {
        $model = new Model(basename($name));
    }
    $_model[$name] = $model;
    return $model;
}
Example #10
Show file File: InsertionController.php Project: devsnippet/city_site
0
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = \Phalcon\Mvc\Model\Criteria::fromInput($this->di, "Insertion", $_POST);
         $this->session->conditions = $query->getConditions();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
         if ($numberPage <= 0) {
             $numberPage = 1;
         }
     }
     $parameters = array();
     if ($this->session->conditions) {
         $parameters["conditions"] = $this->session->conditions;
     }
     $parameters["order"] = "id";
     $insertion = Insertion::find($parameters);
     if (count($insertion) == 0) {
         $this->flash->notice("The search did not find any insertion");
         return $this->dispatcher->forward(array("controller" => "insertion", "action" => "index"));
     }
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $insertion, "limit" => 10, "page" => $numberPage));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
 }
Example #11
Show file File: test_10_local_ensemble_prediction.php Project: antoniomachine/bigml-php
0
 public function test_scenario4()
 {
     $data = array(array("filename" => 'data/iris.csv', "params1" => array("input_fields" => array("000000", "000001", "000003", "000004")), "params2" => array("input_fields" => array("000000", "000001", "000002", "000004")), "params3" => array("input_fields" => array("000000", "000001", "000002", "000003", "000004")), "number_of_models" => 3, "field_importance" => array("000002" => 0.5269933333333333, "000003" => 0.38936, "000000" => 0.04662333333333333, "000001" => 0.037026666666666666)));
     foreach ($data as $item) {
         print "\nSuccessfully obtaining field importance from an Ensemble created from local models\n";
         print "I create a data source uploading a " . $item["filename"] . " file\n";
         $source = self::$api->create_source($item["filename"], $options = array('name' => 'local_test_source', 'project' => self::$project->resource));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
         $this->assertEquals(1, $source->object->status->code);
         print "And I wait until the source is ready\n";
         $resource = self::$api->_check_resource($source->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create dataset with local source\n";
         $dataset = self::$api->create_dataset($source->resource);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
         $this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
         print "And I wait until the dataset is ready\n";
         $resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create model with params " . json_encode($item["params1"]) . "\n";
         $model_1 = self::$api->create_model($dataset->resource, $item["params1"]);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $model_1->code);
         print "And I wait until the model is ready\n";
         $resource = self::$api->_check_resource($model_1->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "create model with params " . json_encode($item["params2"]) . "\n";
         $model_2 = self::$api->create_model($dataset->resource, $item["params2"]);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $model_2->code);
         print "And I wait until the model is ready\n";
         $resource = self::$api->_check_resource($model_2->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "create model with params " . json_encode($item["params3"]) . "\n";
         $model_3 = self::$api->create_model($dataset->resource, $item["params3"]);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $model_3->code);
         print "And I wait until the model is ready\n";
         $resource = self::$api->_check_resource($model_3->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         $model_1 = self::$api->get_model($model_1->resource);
         $model_2 = self::$api->get_model($model_2->resource);
         $model_3 = self::$api->get_model($model_3->resource);
         $local_model_1 = new Model($model_1);
         $local_model_2 = new Model($model_2);
         $local_model_3 = new Model($model_3);
         print "When I create a local Ensemble with the last " . $item["number_of_models"] . " local models\n";
         $local_ensemble = new Ensemble(array($local_model_1, $local_model_2, $local_model_3), self::$api);
         $field_importance_data = $local_ensemble->field_importance_data();
         print "Then the field importance text is " . json_encode($item["field_importance"]) . "\n";
         $this->assertEquals($item["field_importance"], $field_importance_data[0]);
     }
 }
Example #12
Show file File: ZNotification.php Project: xhoogland/Monique
0
 /**
  * To know on which command we have to reply on when someone wants to set a notification, we
  * have to register the command with the Commands-module.
  */
 private function registerTellCommand()
 {
     $moduleManager = ModuleManager::getInstance()->offsetGet('Commands');
     $moduleManager->registerCommand(new \Command(self::NOTIFICATION_COMMAND_NAME, function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) {
         if (stringH::IsNullOrWhiteSpace($sMessage)) {
             echo '7* Usage: nickname message';
             return;
         }
         list($sReceiver, $sNotification) = explode(' ', $sMessage, 2);
         if (strtolower($sReceiver) == strtolower($sNickname)) {
             echo '10* Info: You cannot send notifications to yourself.';
             return;
         }
         $oNotification = new Model(self::NOTIFICATION_TABLE, 'sReceiver', $sReceiver);
         if (count($oNotification->getAll()) >= self::NOTIFICATION_MESSAGE_LIMIT) {
             echo '10* Info: The message could not be stored, because there are already ' . self::NOTIFICATION_MESSAGE_LIMIT . ' messages waiting for ' . $sReceiver;
             return;
         }
         $oNotification = new Model(self::NOTIFICATION_TABLE, 'iTimestamp', time());
         $oNotification->sReceiver = $sReceiver;
         $oNotification->sSender = $sNickname;
         $oNotification->sMessage = $sNotification;
         $oNotification->iTimestamp = time();
         $oNotification->sNetwork = $pBot['Network'];
         $oNotification->sChannel = $sChannel;
         if ($oNotification->save()) {
             $sReceiver = strtolower($oNotification->sReceiver);
             if (!in_array($sReceiver, $this->notifiedUsers)) {
                 $this->notifiedUsers[] = $sReceiver;
             }
             echo 'Sure ' . $sNickname . '!';
         }
         return;
     }));
 }
Example #13
Show file File: eloquent.test.php Project: gigikiri/masjid-l3
0
 /**
  * Test the Model::to_array method.
  *
  * @group laravel
  */
 public function testConvertingToArray()
 {
     Model::$hidden = array('password', 'hidden');
     $array = array('name' => 'Taylor', 'age' => 25, 'password' => 'laravel', 'null' => null);
     $model = new Model($array);
     $first = new Model(array('first' => 'foo', 'password' => 'hidden'));
     $second = new Model(array('second' => 'bar', 'password' => 'hidden'));
     $third = new Model(array('third' => 'baz', 'password' => 'hidden'));
     $model->relationships['one'] = new Model(array('foo' => 'bar', 'password' => 'hidden'));
     $model->relationships['many'] = array($first, $second, $third);
     $model->relationships['hidden'] = new Model(array('should' => 'not_visible'));
     $model->relationships['null'] = null;
     $this->assertEquals(array('name' => 'Taylor', 'age' => 25, 'null' => null, 'one' => array('foo' => 'bar'), 'many' => array(array('first' => 'foo'), array('second' => 'bar'), array('third' => 'baz')), 'null' => null), $model->to_array());
 }
Example #14
Show file File: IndexController.class.php Project: wuyouzi/expweb-v1.0
0
 function listall()
 {
     $projects = new Model('project');
     @($res = $projects->field('project_name,project_desc,project_hash,time,status')->where("user_hash = '" . $_SESSION['user_hash'] . "'")->select());
     //封装数组处理
     $url = new Model('url');
     foreach ($res as $key => &$value) {
         $value['shellnum'] = $url->where("project_hash = '" . $value['project_hash'] . "'")->count();
         $value['time'] = date('Y-m-d', $value['time']);
     }
     return $res;
 }
Example #15
Show file File: helpers.php Project: andersonsousa/Diferente.tv
0
function liturgia()
{
    $d = new Model("_dias");
    $l = new Model("_liturgia");
    $ref = isset($_GET['id']) ? $_GET['id'] : date("j_n_Y");
    $d = $d->Read("*", "titulo='{$ref}'");
    $l = $l->Read("*", "dia=" . $d['id']);
    $r = array();
    $r['dias'] = $d;
    $r['liturgia'] = $l;
    return $r;
}
Example #16
Show file File: CashAction.class.php Project: kwdwkiss/kongbao
0
 public function deal_change()
 {
     if (!IS_POST) {
         $this->message2('无效请求!', __APP__ . '/Index');
     }
     $money = I('money', 0);
     if ($money <= 0) {
         $this->message2('转换金额必须大于0', __APP__ . '/User/Home');
     }
     if ($money % 1 != 0) {
         $this->message2('转换金额必须为整数!', __APP__ . '/User/Home');
     }
     $userid = session('userid');
     $user_model = new Model('user');
     $user = $user_model->where('id=' . $userid)->find();
     if (empty($user)) {
         $this->message2('获取用户信息出错!', __APP__ . '/User/Home');
     }
     $refer_money = $user['refer_money'];
     if ($refer_money < $money) {
         $this->message2('转换金额不能高于当前可用佣金!', __APP__ . '/User/Home');
     }
     $userdata['id'] = $userid;
     $userdata['refer_money'] = $user['refer_money'] - $money;
     $userdata['money'] = $user['money'] + $money;
     $user_model->startTrans();
     $result = $user_model->data($userdata)->save();
     if ($result) {
         $account_log_model = new Model('account_log');
         $reason = '佣金转换成账户余额-佣金减少';
         $account_log = array();
         $account_log['user_id'] = $userid;
         $account_log['stage'] = 'change';
         $account_log['money'] = 0 - $money;
         $account_log['comm'] = $reason;
         $account_log['addtime'] = $this->getDate();
         $account_log['remain_money'] = $userdata['money'];
         $account_log['remain_refer_money'] = $userdata['refer_money'];
         $result_1 = D('account_log')->data($account_log)->add();
         $reason = '佣金转换成账户余额-账户余额增加';
         $account_log['money'] = $money;
         $account_log['comm'] = $reason;
         $result_2 = D('account_log')->data($account_log)->add();
         if ($result_1 && $result_2) {
             $user_model->commit();
             $this->message2('转换成功!', __APP__ . '/User/Home');
         } else {
             $user_model->rollback();
             $this->message2('佣金转换失败:' . $user_model->getError(), __APP__ . '/User/Home');
         }
     } else {
         $user_model->rollback();
         $this->message2('佣金转换失败:' . $user_model->getError(), __APP__ . '/User/Home');
     }
 }
Example #17
Show file File: HyperEdge.php Project: pin-cnx/orientdb-laravel-5
0
 /**
  * Create a new HyperEdge instance.
  *
  * @param Sgpatil\Orientdb\Eloquent\Builder $query
  * @param Sgpatil\Orientdb\Eloquent\Model   $parent
  * @param string  $type
  * @param Sgpatil\Orientdb\Eloquent\Model   $related
  * @param string  $morphType
  * @param Sgpatil\Orientdb\Eloquent\Model   $morph
  */
 public function __construct(Builder $query, Model $parent, $type, Model $related, $morphType, Model $morph, $attributes = array())
 {
     $this->morph = $morph;
     $this->morphType = $morphType;
     // This is not a unique relationship since it involves multiple models.
     $unique = false;
     parent::__construct($query, $parent, $related, $type, $attributes, $unique);
 }
Example #18
Show file File: ModelTaskTest.php Project: abhinand4858/ProgrammedV
0
 /**
  * test that odd tablenames arent inflected back from modelname
  *
  * @return void
  */
 public function testExecuteIntoBakeOddTables()
 {
     $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
     $in = $this->getMock('ConsoleInput', array(), array(), '', false);
     $this->Task = $this->getMock('ModelTask', array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'), array($out, $out, $in));
     $this->_setupOtherMocks();
     $this->Task->connection = 'test';
     $this->Task->path = '/my/path/';
     $this->Task->args = array('BakeOdd');
     $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
     $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
     $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
     $this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
     $this->Task->expects($this->once())->method('bake')->with($object, false)->will($this->returnValue(true));
     $this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
     $this->Task->execute();
     $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
     $in = $this->getMock('ConsoleInput', array(), array(), '', false);
     $this->Task = $this->getMock('ModelTask', array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'createFile'), array($out, $out, $in));
     $this->_setupOtherMocks();
     $this->Task->connection = 'test';
     $this->Task->path = '/my/path/';
     $this->Task->args = array('BakeOdd');
     $this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
     $this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
     $object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
     $this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
     $this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
     $this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
     $filename = '/my/path/BakeOdd.php';
     $this->Task->expects($this->once())->method('createFile')->with($filename, $this->stringContains('class BakeOdd'));
     $filename = '/my/path/BakeOdd.php';
     $this->Task->expects($this->once())->method('createFile')->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
     $this->Task->execute();
 }
Example #19
Show file File: ContactAction.class.php Project: yunsite/smeoa
0
 function ajaxRead()
 {
     $type = $_REQUEST['type'];
     $id = $_REQUEST['id'];
     switch ($type) {
         case "company":
             $model = M("Dept");
             $dept = tree_to_list(list_to_tree(M("Dept")->select(), $id));
             $dept = rotate($dept);
             $dept = implode(",", $dept['id']) . ",{$id}";
         case "emp":
             $model = M("Dept");
             $dept = tree_to_list(list_to_tree(M("Dept")->select(), $id));
             $dept = rotate($dept);
             $dept = implode(",", $dept['id']) . ",{$id}";
             $sql = D("UserView")->buildSql();
             $model = new Model();
             $where['dept_id'] = array('in', $dept);
             $data = $model->table($sql . "a")->where($where)->select();
             break;
         case "rank":
             $sql = D("UserView")->buildSql();
             $model = new Model();
             $where['rank_id'] = array('eq', $id);
             $data = $model->table($sql . "a")->where($where)->select();
             break;
         case "position":
             $sql = D("UserView")->buildSql();
             $model = new Model();
             $where['position_id'] = array('eq', $id);
             $data = $model->table($sql . "a")->where($where)->select();
             break;
         case "personal":
             $model = D("Tag");
             if ($id == "#") {
                 $data = $model->get_data_list();
                 $data = rotate($data);
                 $data = $data['row_id'];
                 $where['id'] = array('not in', implode(",", $data));
             } else {
                 $data = $model->get_data_list(MODULE_NAME, $id);
                 $data = rotate($data);
                 $data = $data['row_id'];
                 $where['id'] = array('in', implode(",", $data));
             }
             $model = M("Contact");
             $data = $model->where($where)->field('id,name,email')->select();
             //echo $model->getLastSql();
             break;
         default:
     }
     $new = array();
     //foreach ($data as $val) {
     //	$new[] = $this -> _conv_data($val);
     //}
     if (true) {
         // 读取成功
         $this->ajaxReturn($data, dump($data, false), 1);
     }
 }
Example #20
Show file File: belongstomany.php Project: bigjoevtrj/CodeIgniter-3.0.0-ORM-Twig
0
 function __construct(Model $parent, Model $related, $pivot_builder, $foreign_key, $other_key)
 {
     parent::__construct($parent, $related);
     $this->pivot_builder = $pivot_builder;
     $this->foreign_key = $foreign_key;
     $this->other_key = $other_key;
 }
Example #21
Show file File: FixtureTask.php Project: galabyca/nostalgames
0
 /**
  * Interact with the user to get a custom SQL condition and use that to extract data
  * to build a fixture.
  *
  * @param string $modelName name of the model to take records from.
  * @param string $useTable Name of table to use.
  * @return array Array of records.
  */
 protected function _getRecordsFromTable($modelName, $useTable = null)
 {
     $modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
     if ($this->interactive) {
         $condition = null;
         $prompt = __d('cake_console', "Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1");
         while (!$condition) {
             $condition = $this->in($prompt, null, 'WHERE 1=1');
         }
         $recordsFound = $modelObject->find('count', array('conditions' => $condition, 'recursive' => -1));
         $prompt = __d('cake_console', "How many records do you want to import?");
         $recordCount = $this->in($prompt, null, $recordsFound < 10 ? $recordsFound : 10);
     } else {
         $condition = 'WHERE 1=1';
         $recordCount = isset($this->params['count']) ? $this->params['count'] : 10;
     }
     $records = $modelObject->find('all', array('conditions' => $condition, 'recursive' => -1, 'limit' => $recordCount));
     $schema = $modelObject->schema(true);
     $out = array();
     foreach ($records as $record) {
         $row = array();
         foreach ($record[$modelObject->alias] as $field => $value) {
             if ($schema[$field]['type'] === 'boolean') {
                 $value = (int) (bool) $value;
             }
             $row[$field] = $value;
         }
         $out[] = $row;
     }
     return $out;
 }
Frequently Used Methods