예제 #1
0
 /**
  * Lists all Todo models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Todo::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
 public function fooAction()
 {
     $list = Todo::find();
     $this->view->todoList = $list;
 }
예제 #3
0
 private function _indexList()
 {
     $userId = \Yii::$app->user->id;
     $key = $this->getParam('key', 1);
     $sort = $this->getParam('order');
     $start = $this->getParam('start', 1);
     $pageSize = $this->getParam('length', 10);
     $columns = $this->getParam('columns');
     switch ($key) {
         case 0:
             $startDate = $this->getParam('startDate', date('Y-m-d'));
             $endDate = $this->getParam('endDate', date('Y-m-d'));
             $andWhere = ['and', ['>=', 'todo_date', $startDate], ['<=', 'todo_date', $endDate]];
             break;
         case 1:
             $andWhere = ['todo_date' => date('Y-m-d')];
             break;
         case 2:
             $andWhere = ['todo_date' => date('Y-m-d', strtotime('-1 day'))];
             break;
         case 3:
             $andWhere = ['>=', 'todo_date', date('Y-m-d', strtotime('this week'))];
             break;
         case 4:
             $andWhere = ['and', ['>=', 'todo_date', date('Y-m-d', strtotime('last week'))], ['<', 'todo_date', date('Y-m-d', strtotime('this week'))]];
             break;
         case 5:
             $andWhere = ['>=', 'todo_date', date('Y-m-01')];
             break;
         case 6:
             $andWhere = ['and', ['>=', 'todo_date', date('Y-m-01', strtotime('-1 month'))], ['<', 'todo_date', date('Y-m-01')]];
             break;
         case 7:
             $season = ceil(date('n') / 3);
             $andWhere = ['>=', 'todo_date', date('Y-m-d', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')))];
             break;
         case 8:
             $andWhere = ['>=', 'todo_date', date('Y-01-01')];
             break;
         case 9:
             $andWhere = ['or', ['todo_date' => ''], ['todo_date' => null]];
             break;
         case 10:
             $andWhere = ['todo_status' => [Todo::STATUS_WAIT, Todo::STATUS_DOING]];
             break;
         case 11:
             $andWhere = '1=1';
             break;
         default:
             $andWhere = '1=1';
     }
     $order = $columns[$sort[0]['column']]['name'];
     $asc = $sort[0]['dir'] == 'asc' ? SORT_ASC : SORT_DESC;
     $list = Todo::find()->where(['todo_account' => $userId])->andWhere($andWhere)->offset($start)->limit($pageSize)->orderBy([$order => $asc])->asArray()->all();
     $total = Todo::find()->where(['todo_account' => $userId])->andWhere($andWhere)->count();
     echo Json::encode(['recordsTotal' => $total, 'recordsFiltered' => $total, 'data' => $list]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $todo = Todo::find($id);
     $todo->delete();
     return redirect()->route('admin.todos.index')->with('message', 'Se ha eliminado ' . $todo->name . ' de forma correcta.');
 }
 public function todoMoveDown(Request $request)
 {
     $todoItem = Todo::find($request->input('todoId'));
     $currentPriority = intval($todoItem->priority);
     if (1 == intval($currentPriority)) {
         return "false";
     } else {
         $newPriority = intval($currentPriority) - 1;
         $todoItem2 = Todo::where('priority', $newPriority)->first();
         $todoItem2->priority = $currentPriority;
         $todoItem2->save();
         $todoItem->priority = $newPriority;
         $todoItem->save();
         return "true";
     }
 }