суббота, 19 апреля 2008 г.

Исходные коды к блогу Вопрос - ответ

data\fixtures test_data.yml


User:
anonymous:
nickname: anonymous
first_name: Anonymous
last_name: Coward

fabien:
nickname: fabpot
first_name: Fabien
last_name: Potencier

francois:
nickname: francoisz
first_name: François
last_name: Zaninotto

Question:
q1:
title: What shall I do tonight with my girlfriend?
user_id: fabien
body: |
We shall meet in front of the Dunkin'Donuts before dinner,
and I haven't the slightest idea of what I can do with her.
She's not interested in programming, space opera movies nor insects.
She's kinda cute, so I really need to find something
that will keep her to my side for another evening.

q2:
title: What can I offer to my step mother?
user_id: anonymous
body: |
My stepmother has everything a stepmother is usually offered
(watch, vacuum cleaner, earrings, del.icio.us account).
Her birthday comes next week, I am broke, and I know that
if I don't offer her something sweet, my girlfriend
won't look at me in the eyes for another month.

q3:
title: How can I generate traffic to my blog?
user_id: francois
body: |
I have a very swell blog that talks
about my class and mates and pets and favorite movies.

Interest:
i1: { user_id: fabien, question_id: q1 }
i2: { user_id: francois, question_id: q1 }
i3: { user_id: francois, question_id: q2 }
i4: { user_id: fabien, question_id: q2 }



batch/load_data.php

<?php


define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));

define('SF_APP', 'frontend');

define('SF_ENVIRONMENT', 'dev');

define('SF_DEBUG', true);


require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');


// initialize database manager

$databaseManager = new sfDatabaseManager();

$databaseManager->initialize();


$data = new sfPropelData();

$data->loadData(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures');


?>




schema.xml

  <?xml version="1.0" encoding="UTF-8" ?>


- <database name="propel" defaultIdMethod="native" noxsd="true">



- <table name="ask_question" phpName="Question">



  <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />



  <column name="user_id" type="integer" />



- <foreign-key foreignTable="ask_user">



  <reference local="user_id" foreign="id" />


  </foreign-key>




  <column name="title" type="longvarchar" />



  <column name="body" type="longvarchar" />



  <column name="created_at" type="timestamp" />



  <column name="updated_at" type="timestamp" />


  </table>




- <table name="ask_answer" phpName="Answer">



  <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />



  <column name="question_id" type="integer" />



- <foreign-key foreignTable="ask_question">



  <reference local="question_id" foreign="id" />


  </foreign-key>




  <column name="user_id" type="integer" />



- <foreign-key foreignTable="ask_user">



  <reference local="user_id" foreign="id" />


  </foreign-key>




  <column name="body" type="longvarchar" />



  <column name="created_at" type="timestamp" />


  </table>




- <table name="ask_user" phpName="User">



  <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />



  <column name="nickname" type="varchar" size="50" />



  <column name="first_name" type="varchar" size="100" />



  <column name="last_name" type="varchar" size="100" />



  <column name="created_at" type="timestamp" />


  </table>




- <table name="ask_interest" phpName="Interest">



  <column name="question_id" type="integer" primaryKey="true" />



- <foreign-key foreignTable="ask_question">



  <reference local="question_id" foreign="id" />


  </foreign-key>




  <column name="user_id" type="integer" primaryKey="true" />



- <foreign-key foreignTable="ask_user">



  <reference local="user_id" foreign="id" />


  </foreign-key>




  <column name="created_at" type="timestamp" />


  </table>




- <table name="ask_relevancy" phpName="Relevancy">



  <column name="answer_id" type="integer" primaryKey="true" />



- <foreign-key foreignTable="ask_answer">



  <reference local="answer_id" foreign="id" />


  </foreign-key>




  <column name="user_id" type="integer" primaryKey="true" />



- <foreign-key foreignTable="ask_user">



  <reference local="user_id" foreign="id" />


  </foreign-key>




  <column name="score" type="integer" />



  <column name="created_at" type="timestamp" />


  </table>



  </database>





actions.class.php


<?php

// auto-generated by sfPropelCrud

// date: 2006/05/18 11:06:58

?>

<?php


/**

* question actions.

*

* @package ##PROJECT_NAME##

* @subpackage question

* @author Your name here

* @version SVN: $Id: actions.class.php 11 2006-05-18 10:00:25Z fabien $

*/

class questionActions extends sfActions

{

public function executeList ()

{

$this->questions = QuestionPeer::doSelect(new Criteria());

}


public function executeShow ()

{

$this->question = Que

listSuccess.php


<?php use_helper('Text') ?>


<h1>popular questions</h1>


<?php foreach($questions as $question): ?>

<div class="question">

<div class="interested_block">

<div class="interested_mark" id="interested_in_<?php echo $question->getId() ?>">

<?php echo count($question->getInterests()) ?>

</div>

</div>


<h2><?php echo link_to($question->getTitle(), 'question/show?id='.$question->getId()) ?></h2>


<div class="question_body">

<?php echo truncate_text($question->getBody(), 200) ?>

</div>

</div>

<?php endforeach; ?>


stionPeer::retrieveByPk($this->getRequestParameter('id'));

$this->forward404Unless($this->question);

}

}


?>




showSuccess.php


<?php

// auto-generated by sfPropelCrud

// date: 2006/05/18 11:06:58

?>

<table>

<tbody>

<tr>

<th>Id: </th>

<td><?php echo $question->getId() ?></td>

</tr>

<tr>

<th>User: </th>

<td><?php echo $question->getUserId() ?></td>

</tr>

<tr>

<th>Title: </th>

<td><?php echo $question->getTitle() ?></td>

</tr>

<tr>

<th>Body: </th>

<td><?php echo $question->getBody() ?></td>

</tr>

<tr>

<th>Created at: </th>

<td><?php echo $question->getCreatedAt() ?></td>

</tr>

<tr>

<th>Updated at: </th>

<td><?php echo $question->getUpdatedAt() ?></td>

</tr>

</tbody>

</table>

<hr />

<?php echo link_to('edit', 'question/edit?id='.$question->getId()) ?>

&nbsp;<?php echo link_to('list', 'question/list') ?>

Комментариев нет: