function runHydrate($i) { $books = \Model_Book::find('all', array('limit' => 5, 'where' => array(array('price', '>', $i)))); foreach ($books as $book) { } Cache::delete_all(); }
public function action_index() { $data['files'] = Model_File::find('all'); $books = Model_Book::find('all'); $book_arr = array(); foreach ($books as $value) { array_push($book_arr, $value->book_url); array_push($book_arr, $value->cover_photo); } sort($book_arr); $data['books'] = $book_arr; $this->template->title = "Files"; $this->template->content = View::forge('site/files/index', $data); }
public function get_by_user($user_id) { $user = Model_User::find($user_id); $success = false; if (!$user) { return $this->error(['Cannot find user.']); } $data = null; if ($user->isRoleTeacher()) { $data = Model_Book::find('all', ['related' => ['subject' => ['where' => ['user_id' => $user->id]]]]); } else { if ($user->isRoleStudent()) { $data = Model_Book::find('all', ['related' => ['student_course' => ['where' => ['user_id' => $user->id]]]]); } } if ($data) { $success = true; } return $this->response(['data' => $data, 'success' => $success]); }
public function action_delete($id = null) { $where = ['id' => $id]; if (Model_User::is_current_user('teacher')) { $where['subject.user_id'] = Auth::get('id'); } if ($book = Model_Book::find('first', ['where' => $where, 'related' => ['subject']])) { $book->delete(); Session::set_flash('success', e('Deleted book #' . $id)); } else { Session::set_flash('error', e('Could not delete book #' . $id)); } Response::redirect('site/book'); }