Esempio n. 1
0
 public static function rubrics()
 {
     /* if (mysql_num_rows($result) > 0) {
                  echo("<UL>\n");
                  while ( $row = mysql_fetch_array($result) ) {
                      $ID1 = $row["id"];
                      echo("<LI>\n");
                      echo("<A HREF=\"" . "?ID=" . $ID1 . "\">" . $row["title"] . "</A>" . "&nbsp;&nbsp;\n");
                      ShowTree($ID1, $lvl);
                      $lvl--;
                  }
                  echo("</UL>\n");
              }
     
     
             Array
     (
         [0] => Array
             (
                 [text] =>  История
                 [expanded] => 1
                 [children] => Array
                     (
                         [0] => Array
                             (
                                 [text] =>  Мировая
                                 [expanded] => 1
                             )
     
                         [1] => Array
                             (
                                 [text] =>  Средних веков
                                 [expanded] => 1
                                 [children] => Array
                                     (
                                         [0] => Array
                                             (
                                                 [text] =>  Страны
                                                 [expanded] => 1
                                                 [children] => Array
                                                     (
                                                         [0] => Array
                                                             (
                                                                 [text] =>  Россия
                                                                 [expanded] => 1
                                                             )
     
                                                         [1] => Array
                                                             (
                                                                 [text] =>  Украина
                                                                 [expanded] => 1
                                                             )
     
                                                     )
     
                                             )
     
                                     )
     
                             )
     
                     )
     
             )
     
         [1] => Array
             (
                 [text] =>  Программирование
                 [expanded] => 1
                 [children] => Array
                     (
                         [0] => Array
                             (
                                 [text] => PHP
                                 [expanded] => 1
                             )
     
                         [1] => Array
                             (
                                 [text] => C++
                             )
     
                     )
     
             )
     
     )
     
     
     
     
     
     
             */
     //return (Rubric::model()->findAll());
     $d = array('ch' => 1);
     for ($i = 1; $i < 3; $i++) {
         $d = array('ch' => $d);
     }
     /*        echo "<pre>";
             print_r($d);
             echo "</pre>";
             die();*/
     $k = array();
     $a = array("ch" => 1);
     $a = 'array("ch"=>array("ch"=>1))';
     array_push($k, "dkfdf");
     //$k = array_fill_keys($k, 'banana');
     //$k= $a;
     /*        echo "<pre>";
             print_r($k);
             echo "</pre>";
             die();*/
     $level = 1;
     $rubricArray = array();
     $idArray = array();
     $children = array();
     $i = 0;
     $rubric = Rubric::model()->findAll();
     foreach ($rubric as $rubricEach) {
         $idArray[$rubricEach->level] = 0;
         if ($level == $rubricEach->level) {
             if ($rubricEach->level > 1) {
                 for ($x = 1; $x < $rubricEach->level; $x++) {
                     $children = array('children' => array($idArray[$x] => $children));
                 }
                 $rubricArray = array('children' => array($idArray[$rubricEach->level] => $rubricEach->rubric_title));
                 //$rubricArray[] = array('text' => $rubricEach->rubric_title, 'expanded' => true);
                 $idArray[$rubricEach->level]++;
             } else {
                 $rubricArray[$idArray[$rubricEach->level]] = array('text' => $rubricEach->rubric_title, 'expanded' => true);
                 $idArray[$rubricEach->level]++;
             }
         } else {
             $level++;
             /*                $rubricArray[] = array('text' => $rubricEach->rubric_title, 'expanded' => true);
                             $idArray[$rubricEach->level]++;*/
         }
     }
     echo "<pre>";
     print_r($rubricArray);
     echo "</pre>";
     die;
     return $rubricArray;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Rubric the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Rubric::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
    /**
     * Returns the data model based on the primary key given in the GET variable.
     * If the data model is not found, an HTTP exception will be raised.
     * @param integer $id the ID of the model to be loaded
     * @return Book the loaded model
     * @throws CHttpException
     */
    public function loadModel($id)
    {
        $model = Book::model()->findByPk($id);
        $rubrics = Rubric::model()->findAllBySql('
		SELECT r.title
		FROM db_rubric AS r
		INNER JOIN db_rubrics_books AS rb
		ON rb.rubric_id = r.id
		WHERE rb.book_id = ' . $id);
        $string = '';
        foreach ($rubrics as $rubric) {
            $string .= $rubric->title . ', ';
        }
        $model['rubric'] = substr($string, 0, strlen($string) - 2);
        unset($string);
        $model['comments'] = Comment::model()->findAllBySql('
		SELECT *
		FROM db_comment AS c
		INNER JOIN db_comments_books AS cb
		ON cb.commnet_id = c.id
		WHERE cb.book_id = ' . $id);
        $model['review'] = Review::model()->findAllBySql('
		SELECT *
		FROM db_review AS r
		INNER JOIN db_reviews_books AS rb
		ON rb.review_id = r.id
		WHERE rb.book_id = ' . $id);
        $model['files'] = Files::model()->findAllBySql('
		SELECT f.type, f.title
		FROM db_files AS f
		WHERE f.book_id = ' . $id);
        if ($model === null) {
            throw new CHttpException(404, 'The requested page does not exist.');
        }
        return $model;
    }