Example #1
0
 public function article($id)
 {
     if (!($id && ($article = Article::find('one', array('include' => array('sources'), 'conditions' => array('id = ? AND is_visibled = ? AND destroy_user_id IS NULL', $id, Article::IS_VISIBLED)))))) {
         return array();
     }
     if ($article->tags) {
         usort($article->tags, function ($a, $b) {
             return count($a->mappings) < count($b->mappings);
         });
     }
     if ($article->tags && ($article_ids = column_array(ArticleTagMapping::find('all', array('select' => 'article_id', 'order' => 'RAND()', 'limit' => 5, 'conditions' => array('article_id != ? AND article_tag_id = ?', $article->id, $article->tags[0]->id))), 'article_id'))) {
         Article::addConditions($conditions, 'id IN (?)', $article_ids);
     } else {
         Article::addConditions($conditions, 'id != ?', $article->id);
     }
     Article::addConditions($conditions, 'is_visibled = ? AND destroy_user_id IS NULL', Article::IS_VISIBLED);
     $others = Article::find('all', array('select' => 'id, title', 'limit' => 5, 'conditions' => $conditions));
     return array('article' => array_merge($article->to_array(array('only' => array('id', 'title', 'content', 'pv'), 'methods' => array('site_show_page_last_uri'))), array('mini_content' => array('150' => $article->mini_content(150), '300' => $article->mini_content(300)), 'cover_url' => array('1200x630c' => $article->cover->url('1200x630c')), 'updated_at' => array('c' => $article->updated_at->format('c'), 'Y-m-d H:i:s' => $article->updated_at->format('Y-m-d H:i:s')), 'created_at' => array('c' => $article->created_at->format('c'), 'Y-m-d H:i:s' => $article->created_at->format('Y-m-d H:i:s')))), 'tags' => array_map(function ($tag) {
         return $tag->to_array(array('only' => array('id', 'name')));
     }, $article->tags), 'others' => array_map(function ($article) {
         return $article->to_array(array('only' => array(), 'methods' => array('site_show_page_last_uri')));
     }, $others), 'sources' => array_map(function ($source) {
         return $source->to_array(array('only' => array('title', 'href'), 'methods' => array('mini_href')));
     }, $article->sources), 'user' => $article->user->to_array(array('only' => array('name'), 'methods' => array('facebook_link'))));
 }
Example #2
0
 public function sitmap()
 {
     $this->load->library('Sitemap');
     // 基礎設定
     $domain = 'http://www.zeusdesign.com.tw';
     $sit_map = new Sitemap($domain);
     $sit_map->setPath(FCPATH . 'sitemap' . DIRECTORY_SEPARATOR);
     $sit_map->setDomain($domain);
     // main pages
     $sit_map->addItem('/', '0.5', 'weekly', date('c'));
     $sit_map->addItem('/abouts/', '0.5', 'weekly', date('c'));
     $sit_map->addItem('/contacts/', '0.5', 'weekly', date('c'));
     $sit_map->addItem('/works/', '0.8', 'daily', date('c'));
     $sit_map->addItem('/articles/', '0.8', 'daily', date('c'));
     // all articles
     foreach (Article::find('all', array('select' => 'id, title, updated_at', 'order' => 'id DESC', 'conditions' => array('is_visibled = ? AND destroy_user_id IS NULL', Article::IS_VISIBLED))) as $article) {
         $sit_map->addItem('/article/' . $article->site_show_page_last_uri(), '1', 'daily', $article->updated_at->format('c'));
     }
     // all article tags
     foreach (ArticleTag::all(array('select' => 'id')) as $tag) {
         $sit_map->addItem('/article-tag/' . $tag->id . '/articles/', '0.8', 'daily', date('c'));
     }
     // all works
     foreach (Work::find('all', array('select' => 'id, title, updated_at', 'order' => 'id DESC', 'conditions' => array('is_enabled = ? AND destroy_user_id IS NULL', Work::ENABLE_YES))) as $work) {
         $sit_map->addItem('/work/' . $work->site_show_page_last_uri(), '1', 'daily', $work->updated_at->format('c'));
     }
     // all work tags
     foreach (WorkTag::all(array('select' => 'id')) as $tag) {
         $sit_map->addItem('/work-tag/' . $tag->id . '/works/', '0.8', 'daily', date('c'));
     }
     $sit_map->createSitemapIndex($domain . '/sitemap/', date('c'));
 }
Example #3
0
 public function index($tag_id, $offset = 0)
 {
     $columns = array();
     $configs = array('article-tag', $this->tag->id, 'articles', '%s');
     $conditions = conditions($columns, $configs);
     ArticleTagMapping::addConditions($conditions, 'article_tag_id = ?', $this->tag->id);
     $limit = 7;
     $total = ArticleTagMapping::count(array('conditions' => $conditions));
     $offset = $offset < $total ? $offset : 0;
     $this->load->library('pagination');
     $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 3, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li class="f">', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li class="p">', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li class="n">', 'next_tag_close' => '</li>', 'last_tag_open' => '<li class="l">', 'last_tag_close' => '</li>'), $configs))->create_links();
     $article_ids = column_array(ArticleTagMapping::find('all', array('select' => 'article_id', 'offset' => $offset, 'limit' => $limit, 'order' => 'article_id DESC', 'conditions' => $conditions)), 'article_id');
     $articles = $article_ids ? Article::find('all', array('order' => 'FIELD(id,' . implode(',', $article_ids) . ')', 'conditions' => array('is_visibled = ? AND id IN (?) AND destroy_user_id IS NULL', Article::IS_VISIBLED, $article_ids))) : array();
     if ($articles) {
         $this->add_meta(array('name' => 'keywords', 'content' => implode(',', column_array($articles, 'title')) . ',' . implode(',', Cfg::setting('site', 'site', 'keywords'))))->add_meta(array('name' => 'description', 'content' => $articles[0]->mini_content(150)))->add_meta(array('property' => 'og:title', 'content' => $this->tag->name . '文章' . ' - ' . Cfg::setting('site', 'site', 'title')))->add_meta(array('property' => 'og:description', 'content' => $articles[0]->mini_content(300)))->add_meta(array('property' => 'og:image', 'tag' => 'larger', 'content' => $img = $articles[0]->cover->url('1200x630c'), 'alt' => $this->tag->name . '文章' . ' - ' . Cfg::setting('site', 'site', 'title')))->add_meta(array('property' => 'og:image:type', 'tag' => 'larger', 'content' => 'image/' . pathinfo($img, PATHINFO_EXTENSION)))->add_meta(array('property' => 'og:image:width', 'tag' => 'larger', 'content' => '1200'))->add_meta(array('property' => 'og:image:height', 'tag' => 'larger', 'content' => '630'))->add_meta(array('property' => 'article:modified_time', 'content' => $articles[0]->updated_at->format('c')))->add_meta(array('property' => 'article:published_time', 'content' => $articles[0]->created_at->format('c')));
         if (($tags = column_array($articles[0]->tags, 'name')) || ($tags = Cfg::setting('site', 'site', 'keywords'))) {
             foreach ($tags as $i => $tag) {
                 if (!$i) {
                     $this->add_meta(array('property' => 'article:section', 'content' => $tag))->add_meta(array('property' => 'article:tag', 'content' => $tag));
                 } else {
                     $this->add_meta(array('property' => 'article:tag', 'content' => $tag));
                 }
             }
         }
     }
     return $this->set_title($this->tag->name . '文章' . ' - ' . Cfg::setting('site', 'site', 'title'))->set_class('articles')->set_method('index')->load_view(array('tag' => $this->tag, 'articles' => $articles, 'pagination' => $pagination, 'columns' => $columns));
 }
Example #4
0
 /**
  * Affiche l'article
  *
  * @access public
  * @return post.post
  */
 public function post($slug, $id)
 {
     // Find de right post
     $article = Article::find($id);
     // Get comments on this post
     $comments = $article->comments()->orderBy('created_at', 'DESC')->get();
     return View::make('article.article', array('article' => $article, 'comments' => $comments));
 }
Example #5
0
File: Cat.php Project: efueger/luya
 public function eventBeforeDelete($event)
 {
     $items = Article::find()->where(['cat_id' => $this->id])->all();
     if (count($items) > 0) {
         $this->addError('id', 'Diese Kategorie wird noch von einem oder mehreren Terminen benutzt und kann nicht gelöscht werden.');
         $event->isValid = false;
         return;
     }
     $event->isValid = true;
 }
Example #6
0
 public function index()
 {
     $result = Test::first();
     echo "<pre>";
     // var_dump($result);
     $first = Article::find(1);
     var_dump($first->content);
     echo '<h1>this is index</h1>';
     $this->view = View::make('home')->with('article', Article::first())->withTitle('MFFC :-D')->withFuck('Ok!');
 }
 /**
  * 填充评论数据
  * @return void
  */
 private function seedComment()
 {
     Comment::truncate();
     // 清空表
     for ($i = 1; $i < 30; $i++) {
         Comment::create(array('user_id' => $i, 'article_id' => 1 + $i % 5 + 28, 'content' => '评论内容' . $i));
         Article::find(1 + $i % 5 + 28)->increment('comments_count');
     }
     $this->command->info('随机评论数据填充完毕');
 }
/**
 * Print the content of an article specified by its id
 * 
 * @param {Int} $id
 */
function show($id)
{
    //retrive article from db
    $article = Article::find($id);
    //check if id correspond to an existing article
    if ($article) {
    } else {
        //retrive article author
        $author = User::findOrFail($article->author_id);
    }
}
Example #9
0
 public function postAdd()
 {
     $input = Input::all();
     $title = 'Agregar a carrito';
     $article = Article::find($input['id']);
     $cantidad = $input['cantidad'];
     self::addToCart($article, $cantidad);
     return Redirect::back();
     /*return View::make('carts.index')
     		//->with(compact('title'));*/
 }
Example #10
0
 public function test_multilingual_setting_by_reference()
 {
     $Article = new Article();
     $Article->set('headline', array('en' => 'New PHP Framework re-released', 'es' => 'Se ha re-liberado un nuevo Framework para PHP'));
     $Article->set('body', array('en' => 'The Akelos Framework has been re-released...', 'es' => 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...'));
     $Article->set('excerpt_limit', array('en' => 7, 'es' => 3));
     $this->assertTrue($Article->save());
     $Article =& $Article->find($Article->getId());
     $this->assertEqual($Article->get('en_headline'), 'New PHP Framework re-released');
     $this->assertEqual($Article->get('es_body'), 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...');
     $this->assertEqual($Article->get('en_excerpt_limit'), 7);
 }
Example #11
0
 public function createComment($article_id, Request $request)
 {
     $article_id = Article::find($article_id);
     $newcomment = new Comment();
     $message = $request->message;
     $newcomment->article_id = $article_id;
     $newcomment->message = $message;
     $newcomment->save();
     // $allcomments =Comment::where('article_id', $article_id)->get();
     // return view('articleviews.show', compact('article', 'allcomments'));
     return redirect('/article/' . $article_id);
 }
Example #12
0
 public function get_index($category, $title, $id, $idparent = null)
 {
     $id = !is_null($idparent) ? $idparent : $id;
     $article = Article::find($id);
     // || strcmp($title,$article->title)!=0
     if (is_null($article)) {
         return Redirect::error(404);
     }
     $article->categoryName = $article->Category()->first()->getCategoryFullName();
     $article->categoryUrl = $article->Category()->first()->getCategoryUrl();
     return View::make('visitor.article_content', array('article' => $article));
 }
Example #13
0
 public function getRead($id)
 {
     $article = Article::find($id);
     if ($article) {
         $article = DB::table('articles')->where('articles.id', '=', $id)->leftJoin('users', 'articles.user_id', '=', 'users.id')->leftJoin('nodes', 'articles.node_id', '=', 'nodes.id')->select('articles.*', 'users.name as user_name', 'nodes.name as node_name')->get();
         return view('layouts.home.read')->with('articles', $articles);
     } else {
         $returnInf = [];
         array_push($returnInf, '您查看的记录不存在');
         Session::flash('operationResult', 'am-alert-warning');
         Session::flash('returnInf', $returnInf);
         return redirect(url('home'));
     }
 }
Example #14
0
 /**
  * Deleted checked articles.
  */
 public function index_onDelete()
 {
     if (($checkedIds = article('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $articleId) {
             if (!($article = Article::find($articleId))) {
                 continue;
             }
             $article->delete();
         }
         Flash::success(Lang::get('abnmt.theaterpress::lang.articles.delete_selected_success'));
     } else {
         Flash::error(Lang::get('abnmt.theaterpress::lang.articles.delete_selected_empty'));
     }
     return $this->listRefresh();
 }
Example #15
0
 function index_put()
 {
     $data = $this->put();
     $article = Article::find($data['id']);
     if ($this->put('request') == 'update') {
         $article->title = $data['title'];
         $article->type = $data['type'];
         $article->body = $data['body'];
         $article->save();
         $this->response($article);
     } else {
         if ($this->put('request') == 'delete') {
             $article->forceDelete();
         }
     }
 }
Example #16
0
 /**
  * Ajoute un commentaire sur un article
  * 
  * @param $slug Slug de l'article
  * @param $id Id de l'article
  *
  */
 public function article($slug, $id)
 {
     $article = Article::find($id);
     $user = Auth::user();
     $comment = new Comment();
     $comment->content = Input::get('content');
     $comment->user_id = $user->id;
     $comment->article_id = $article->id;
     $v = Validator::make($comment->toArray(), array('content' => 'required', 'user_id' => 'required', 'article_id' => 'required'));
     if ($v->passes()) {
         $comment->save();
         Session::put('message', 'Your comment has been added');
     } else {
         Session::put('message', 'An error has occurred');
     }
     return Redirect::route('post', array('slug' => $article->slug, 'id' => $article->id));
 }
 public function initialize($entity = null, $options = null)
 {
     $article = new Select('articleid', Article::find(), array('using' => array('id', 'title'), 'useEmpty' => TRUE, 'emptyText' => $this->di->get('translate')->_('Select an Article'), 'class' => 'form-control'));
     $article->setLabel('Article');
     $this->add($article);
     $name = new Text('name', array('class' => 'form-control'));
     $name->setLabel('Name');
     $this->add($name);
     $email = new Text('email', array('class' => 'form-control'));
     $email->setLabel('Email');
     $this->add($email);
     $comment = new TextArea('comment', array('id' => 'summernote', 'name' => 'comment', 'class' => 'summernote'));
     $comment->setLabel('Comment');
     $this->add($comment);
     $active = new Select("active", array('Y' => $this->di->get('translate')->_('Yes'), 'N' => $this->di->get('translate')->_('No')), array('class' => 'form-control'));
     $active->setLabel('active');
     $this->add($active);
 }
Example #18
0
 public function index($offset = 0)
 {
     $columns = array(array('key' => 'user_id', 'title' => '作者', 'sql' => 'user_id = ?', 'select' => array_map(function ($user) {
         return array('value' => $user->id, 'text' => $user->name);
     }, User::all(array('select' => 'id, name')))), array('key' => 'is_visibled', 'title' => '是否公開', 'sql' => 'is_visibled = ?', 'select' => array_map(function ($key) {
         return array('value' => $key, 'text' => Article::$visibleNames[$key]);
     }, array_keys(Article::$visibleNames))), array('key' => 'title', 'title' => '標題', 'sql' => 'title LIKE ?'), array('key' => 'content', 'title' => '內容', 'sql' => 'content LIKE ?'));
     $configs = array('admin', $this->get_class(), '%s');
     $conditions = conditions($columns, $configs);
     Article::addConditions($conditions, 'destroy_user_id IS NULL');
     $limit = 25;
     $total = Article::count(array('conditions' => $conditions));
     $offset = $offset < $total ? $offset : 0;
     $this->load->library('pagination');
     $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links();
     $articles = Article::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('user'), 'conditions' => $conditions));
     Session::setData('admin_articles_index_url', current_url());
     return $this->set_tab_index(1)->set_subtitle('文章列表')->add_hidden(array('id' => 'is_visibled_url', 'value' => base_url('admin', $this->get_class(), 'is_visibled')))->load_view(array('articles' => $articles, 'pagination' => $pagination, 'columns' => $columns));
 }
 public function testEloquentORM()
 {
     // Insert
     $article = new Article();
     $article->title = static::ARTICLE_TITLE;
     $saved = $article->save();
     $this->assertTrue($saved);
     $this->assertEquals(1, $article->id);
     $id = $article->id;
     // Select
     $article = Article::find($id);
     $this->assertInstanceOf('Article', $article);
     $this->assertEquals(static::ARTICLE_TITLE, $article->title);
     // Delete
     $deleted = Article::destroy($id);
     $this->assertEquals(1, $deleted);
     // Count
     $count = Article::count();
     $this->assertEquals(0, $count);
 }
 public function fwdAction()
 {
     echo $this->security->hash($this->request->get('name'));
     // has('aba') == '$2a$08$qi2miDrEOg0m3DnPOLkfUeDkrvbRLbDe7PbNfdlX5XHj3DKG5TVi6'
     $hash = '$2a$08$qi2miDrEOg0m3DnPOLkfUeDkrvbRLbDe7PbNfdlX5XHj3DKG5TVi6';
     var_dump($this->security->checkHash($this->request->get('name'), $hash));
     print_r(get_class_methods($this->security));
     $res = Article::findFirst(array('id' => 11));
     $res = Article::find(array('id' => 11, 'limit' => 10));
     echo '<pre>';
     print_r(get_object_vars($res));
     //die;
     print_r(get_class_vars($res));
     print_r(get_class_methods($res));
     die;
     $arr = $res->toArray();
     //        print_r($res);die;
     $this->dispatcher->forward(array('controller' => 'microapp', 'action' => 'routes'));
     $this->view->disable();
 }
Example #21
0
function amp_articles_tagged($tagname = false)
{
    if (!$tagname) {
        return false;
    }
    $tag_ids = AMP_lookup('tagsSimple');
    $found_id = array_keys($tag_ids, strtolower($tagname));
    if (!$found_id) {
        return;
    }
    $tag_id = $found_id[0];
    require_once 'AMP/Content/Article.inc.php';
    $source = new Article(AMP_Registry::getDbcon());
    $article_set = $source->find(array('tag' => $tag_id));
    $source->sort($article_set, 'itemDate', AMP_SORT_DESC);
    $renderer = AMP_get_renderer();
    foreach ($article_set as $item) {
        $output .= $renderer->link($item->getURL(), AMP_trimText($item->getName(), 50, false), array('class' => 'sidelist')) . $renderer->newline();
    }
    return $output;
}
 public function update($id)
 {
     $article = Article::find($id);
     if (Input::has('published')) {
         $article->published = Input::get('published');
     }
     if (Input::has('title')) {
         $article->title = Input::get('title');
     }
     if (Input::has('text')) {
         $article->text = Input::get('text');
     }
     if (Input::has('category')) {
         $article->category = Input::get('category');
     }
     if (Input::has('img')) {
         $article->img = Input::get('img');
     }
     $article->save();
     return Response::json(array('success' => true));
 }
Example #23
0
	public function actionIndex()
	{
		$focusmap = Yii::app()->cache->get('aboutusfocusmap');
		if($focusmap == false){
			$focusmap = Img::model()->find(array(
					'select'=>'path',
					'condition'=>'typeid=5',
					'order'=>'createtime desc',
					'limit'=>'1',
			));
			Yii::app()->cache->set('aboutusfocusmap',$focusmap,3600*24*30);
		}
		
		$aModel = new Article;
		//查询5条最新的莱斯新闻
		$news = $aModel->findAll(array(
				'select'=>'id,title',
				'order'=>'sort desc,updatetime desc',
				'limit'=>10,
				));
		
		//根据ID 查询当前文章内容
		$nid = isset($_GET['id'])?intval($_GET['id']):0;
		
		if($nid!=0){
			$onenews = $aModel->find(array(
					'select'=>'operator,title,content,updatetime',
					'condition'=>"id=$nid",
					));
		}else{
			$this->render('404',array('msg'=>'你没有选择具体的新闻!'));
			exit;
		}
		
		$this->render('index',array(
				'news'=>$news,
				'focusmap'=>$focusmap,
				'onenews'=>$onenews,
				));
	}
 /**
  * @文章详情页
  */
 public function detail($id)
 {
     try {
         $aid = intval($id);
     } catch (Exception $e) {
         echo 'error request!';
         exit;
     }
     //查询文章信息
     $article = Article::find($aid);
     if (!is_object($article)) {
         return Response::make('article not exist', '404');
     }
     //获取用户id
     $uid = $article->uid;
     //获取用户信息
     $user = User::find($uid);
     //获取当前用户分类信息
     $cates = $user->getCate;
     //获取当前用户推荐文章5篇
     $recoment = Article::where('uid', $uid)->where('status', 1)->orderBy('updated_at', 'desc')->take(5)->get();
     return View::make('blog.detail', compact('article'))->with('user', $user)->with('cates', $cates)->with('recoment', $recoment);
 }
Example #25
0
 public function putAction()
 {
     if ($this->request()->isPost() == true) {
         $ans = [];
         try {
             $id = $this->request->getPost("id");
             $sectionNewName = $this->request->getPost("name");
             $existArticle = Article::find(array("conditions" => "id=?1", "bind" => array(1 => $id)));
             if (count($existArticle) == 0) {
                 $ans['ret'] = -1;
                 $ans['error'] = 204;
                 echo json_encode($ans);
                 throw new BaseException('文章不存在', 204);
             } else {
                 $existSection = Section::find(array("conditions" => "name=?1", "bind" => array(1 => $sectionNewName)));
                 if (count($existSection) == 0) {
                     $ans['ret'] = -1;
                     $ans['error'] = 105;
                     echo json_encode($ans);
                     throw new BaseException('栏目不存在', 105);
                 } else {
                     $existArticle->section_id = $existSection->id;
                     if ($existArticle->save() == true) {
                         $ans['ret'] = 0;
                         echo json_encode($ans);
                     } else {
                         $ans['ret'] = -1;
                         $ans['error'] = 102;
                         echo json_encode($ans);
                         throw new BaseException('参数存在非法数据', 102);
                     }
                 }
             }
         } catch (BaseException $e) {
         }
     }
 }
 /**
  * test to assert that != in key together with a single element array will work
  *
  * @return void
  */
 public function testNotEqualsInArrayWithOneValue()
 {
     $this->loadFixtures('Article');
     $Article = new Article();
     $Article->recursive = -1;
     $result = $Article->find('all', array('conditions' => array('Article.id !=' => array(1))));
     $this->assertTrue(is_array($result) && !empty($result));
 }
 /**
  * testSaveAssociatedValidateFirst method
  *
  * @return void
  */
 public function testSaveAssociatedValidateFirst()
 {
     $this->loadFixtures('Article', 'Comment', 'Attachment');
     $model = new Article();
     $model->deleteAll(true);
     $model->Comment->validate = array('comment' => 'notEmpty');
     $result = $model->saveAssociated(array('Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved author'), 'Comment' => array(array('comment' => 'First new comment'), array('comment' => ''))), array('validate' => 'first'));
     $this->assertFalse($result);
     $result = $model->find('all');
     $this->assertSame(array(), $result);
     $expected = array('Comment' => array(1 => array('comment' => array('This field cannot be left blank'))));
     $this->assertEquals($expected['Comment'], $model->Comment->validationErrors);
     $this->assertSame($model->Comment->find('count'), 0);
     $result = $model->saveAssociated(array('Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array(array('comment' => 'Only new comment', 'user_id' => 2))), array('validate' => 'first'));
     $this->assertSame($result, true);
     $result = $model->Comment->find('all');
     $this->assertSame(count($result), 1);
     $result = Hash::extract($result, '{n}.Comment.article_id');
     $this->assertEquals(4, $result[0]);
     $model->deleteAll(true);
     $data = array('Article' => array('title' => 'Post with Author saveAlled from comment', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array('comment' => 'Only new comment', 'user_id' => 2));
     $result = $model->Comment->saveAssociated($data, array('validate' => 'first'));
     $this->assertFalse(empty($result));
     $result = $model->find('all');
     $this->assertEquals('Post with Author saveAlled from comment', $result[0]['Article']['title']);
     $this->assertEquals('Only new comment', $result[0]['Comment'][0]['comment']);
 }
 /**
  * test that saveAll works even with conditions that lack a model name.
  *
  * @return void
  */
 public function testUpdateAllWithNonQualifiedConditions()
 {
     $this->loadFixtures('Article');
     $Article = new Article();
     $result = $Article->updateAll(array('title' => "'Awesome'"), array('title' => 'Third Article'));
     $this->assertTrue($result);
     $result = $Article->find('count', array('conditions' => array('Article.title' => 'Awesome')));
     $this->assertEquals(1, $result, 'Article count is wrong or fixture has changed.');
 }
 /**
  * testRecursiveDel method
  *
  * @return void
  */
 public function testRecursiveDel()
 {
     $this->loadFixtures('Article', 'Comment', 'Attachment');
     $TestModel = new Article();
     $result = $TestModel->delete(2);
     $this->assertTrue($result);
     $TestModel->recursive = 2;
     $result = $TestModel->read(null, 2);
     $this->assertFalse($result);
     $result = $TestModel->Comment->read(null, 5);
     $this->assertFalse($result);
     $result = $TestModel->Comment->read(null, 6);
     $this->assertFalse($result);
     $result = $TestModel->Comment->Attachment->read(null, 1);
     $this->assertFalse($result);
     $result = $TestModel->find('count');
     $this->assertEquals(2, $result);
     $result = $TestModel->Comment->find('count');
     $this->assertEquals(4, $result);
     $result = $TestModel->Comment->Attachment->find('count');
     $this->assertEquals(0, $result);
 }
 /**
  * testDynamicAssociations method
  *
  * @return void
  */
 public function testDynamicAssociations()
 {
     $this->loadFixtures('Article', 'Comment');
     $TestModel = new Article();
     $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = $TestModel->hasOne = array();
     $TestModel->hasMany['Comment'] = array_merge($TestModel->hasMany['Comment'], array('foreignKey' => false, 'conditions' => array('Comment.user_id =' => '2')));
     $result = $TestModel->find('all');
     $expected = array(array('Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), array('Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))));
     $this->assertEquals($expected, $result);
 }