コード例 #1
0
function counter($page)
{
    $count_home = Counter::wherePage($page)->where('created_at', '>=', new DateTime('today'));
    if ($count_home->count() > 0) {
        $update_count = $count_home->first();
        $update_count->count = $update_count->count + 1;
        $update_count->save();
    } else {
        $create_count = new Counter();
        $create_count->page = $page;
        $create_count->count = 1;
        $create_count->save();
    }
}
コード例 #2
0
 public function actionIndex()
 {
     $model = Counter::model()->find();
     if (empty($model)) {
         $model = new Counter();
     }
     if (!empty($_POST['Counter'])) {
         $model->attributes = $_POST['Counter'];
         $model->year = $_POST['Counter']['year'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', translate('Cập nhật thành công.'));
             $this->redirect(PIUrl::createUrl('/admin/counter'));
         }
     }
     $this->render('index', array('model' => $model));
 }
コード例 #3
0
ファイル: CountersSeeder.php プロジェクト: harixxy/CrowdTruth
 /**
  * Run the database counter seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->command->info('Seeding all activities...');
     $seeds = $this->getSeeds(Activity::distinct('_id')->get());
     foreach ($seeds as $name => $seed) {
         $this->command->info('Seed: ' . $name . ' = ' . $seed);
         $counter = new Counter();
         $counter['_id'] = $name;
         $counter['seq'] = $seed;
         $counter->save();
     }
     $this->command->info('Seeding all entities...');
     $seeds = $this->getSeeds(Entity::distinct('_id')->get());
     foreach ($seeds as $name => $seed) {
         $this->command->info('Seed: ' . $name . ' = ' . $seed);
         $counter = new Counter();
         $counter['_id'] = $name;
         $counter['seq'] = $seed;
         $counter->save();
     }
 }
コード例 #4
0
ファイル: Parser.php プロジェクト: smilexx/counter
 public function saveData()
 {
     $id = 0;
     $name = '';
     $counter_name = '';
     $date = '';
     $read = '';
     $type = '';
     foreach ($_REQUEST as $key => $value) {
         $id_row = preg_replace("/[^0-9]/", '', $key);
         if ($id != $id_row) {
             /*
              * @TODO Сделать проверку при вставке
              */
             $counter_isset = Counter::find('all', ['conditions' => ['YEAR(date) = ? and MONTH(date) = ? and counter =? and concetrator=?', explode('.', $date)[2], explode('.', $date)[1], $counter_name, $name]]);
             if (count($counter_isset) == 0) {
                 $counter = new Counter();
                 $counter->concetrator = $name;
                 $counter->counter = $counter_name;
                 $counter->date = $date;
                 $counter->reading = (int) $read;
                 $counter->type = $type;
                 $counter->save();
                 $id = $id_row;
                 $name = '';
                 $counter_name = '';
                 $date = '';
                 $read = '';
                 $type = '';
             }
         }
         $str = preg_replace("/[^a-zA-Z]/", '', $key);
         switch ($str) {
             case 'name':
                 $name = $value;
                 break;
             case 'counter':
                 $counter_name = $value;
                 break;
             case 'date':
                 $date = $value;
                 break;
             case 'read':
                 $read = $value;
                 break;
             case 'type':
                 $type = $value;
                 break;
             default:
                 break;
         }
     }
     Flight::redirect('/admin/update?success=1');
 }