コード例 #1
0
 public function actionRemove($a_id)
 {
     Yii::app()->db->createCommand()->delete('lt_books_authors', 'author_id=' . $a_id);
     //removing records from link table
     Authors::model()->deleteByPk($a_id);
     $this->actionIndex();
 }
コード例 #2
0
 public function actionIndex()
 {
     $book_model = Books::model();
     $authors_model = Authors::model();
     $params = array('book_model' => $book_model, 'authors_model' => $authors_model);
     $this->render('report', $params);
 }
コード例 #3
0
 private function getAuthorsFromBid($bid)
 {
     //все класы авторов, что привязаны к индификатору книги
     $book_author = BookAuthor::model()->with('books')->findAllByAttributes(array('bid' => $bid));
     $aids = array();
     foreach ($book_author as $class) {
         $aids[] = $class->aid;
     }
     $authors = Authors::model()->findAllByAttributes(array('aid' => $aids));
     //формирую красивый масив для результата функции
     $result = array();
     if (!empty($authors)) {
         foreach ($authors as $author) {
             $result['name'][] = $author->name;
             $result['surname'][] = $author->surname;
         }
     }
     return $result;
 }
コード例 #4
0
 public function actionAdd()
 {
     Yii::app()->getClientScript()->registerCoreScript('jquery');
     Yii::app()->getClientScript()->registerCoreScript('jquery.ui');
     $cs = Yii::app()->clientScript;
     $cs->registerCssFile('/js/datepicker/css/' . 'datepicker.css');
     $cs->registerScriptFile('/js/' . 'books.js');
     //
     $book = new Books();
     $command = Yii::app()->db->createCommand();
     if (isset($_POST['Books'])) {
         $book->attributes = $_POST['Books'];
         if ($book->validate()) {
             $book->save();
             if (isset($_POST['add_auth']) && !empty($_POST['add_auth'])) {
                 $criteria = new CDbCriteria();
                 $criteria->compare('lastname', $_POST['add_auth']);
                 $add_author = Authors::model()->find($criteria);
                 //If author exists
                 if (!empty($add_author)) {
                     //insert link book-author to link table
                     $command->insert('lt_books_authors', array('author_id' => $add_author->id, 'book_id' => $book->id));
                 }
             }
             $this->actionIndex();
             return true;
         }
     }
     $this->render('edit', array('model' => $book));
 }
コード例 #5
0
ファイル: main.php プロジェクト: hit-shappens/testapp
<div class="simple">
<?php 
echo CHtml::activeLabelEx($model, 'name');
echo CHtml::activeTextField($model, 'name', array('maxlength' => 255));
?>
</div>
<div class="simple">
<?php 
echo CHtml::activeLabelEx($model, 'date');
$this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'date', 'language' => 'ru', 'cssFile' => null, 'options' => array('dateFormat' => 'yy-mm-dd', 'changeMonth' => true, 'changeYear' => true)));
?>
</div>
<div class="simple">
<?php 
echo CHtml::activeLabelEx($model, 'author');
echo CHtml::activeDropDownList($model, 'author_id', Authors::model()->getOptions());
?>
</div>
コード例 #6
0
ファイル: SearchForm.php プロジェクト: hit-shappens/testapp
 public function rules()
 {
     return array(array('name', 'safe'), array('author', 'in', 'range' => array_keys(Authors::model()->getOptions()), 'message' => 'Указанного автора не существует'), array('startDate,endDate', 'date', 'format' => 'yyyy-mm-dd', 'message' => 'Не верный формат даты'));
 }
コード例 #7
0
 /**
  * Replace entries in database with new data from GitHub API
  *
  * This method will query the GitHub API for a list of recent commits.  If the query is
  * successful, the existing commits in the database will be removed and replaced with the
  * updated data.
  *
  * @return boolean Success or failure of the flush
  */
 public function flush()
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://api.github.com/repos/nodejs/node/commits');
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HEADER, true);
     curl_setopt($curl, CURLOPT_VERBOSE, true);
     curl_setopt($curl, CURLOPT_USERAGENT, 'Example PHP Challenge');
     $result = curl_exec($curl);
     $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($httpcode != 200) {
         return false;
     } else {
         $headersize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
         $result = substr($result, $headersize);
         $this->deleteAll();
         $commits = json_decode($result);
         $commits = array_slice($commits, 0, 25);
         foreach ($commits as $commit) {
             $model = new Commits();
             if (!($author = Authors::model()->findByPK($commit->author->id))) {
                 $author = new Authors();
                 $author->id = $commit->author->id;
                 $author->login = $commit->author->login;
                 $author->avatar_url = $commit->author->avatar_url;
                 $author->url = $commit->author->html_url;
                 $author->save();
             }
             if (!($committer = Authors::model()->findByPK($commit->committer->id))) {
                 $committer = new Authors();
                 $committer->id = $commit->committer->id;
                 $committer->login = $commit->committer->login;
                 $committer->avatar_url = $commit->committer->avatar_url;
                 $committer->url = $commit->committer->html_url;
                 $committer->save();
             }
             $model->hash = substr($commit->sha, 0, 6);
             $model->url = $commit->html_url;
             $model->message = $commit->commit->message;
             $model->author_id = $author->id;
             $model->committer_id = $committer->id;
             $model->modified = date('Y-m-d H:i:s');
             $model->save();
         }
         return true;
     }
 }
コード例 #8
0
 public function actionGetAuthorById($id)
 {
     $author_model = Authors::model();
     $result = $author_model->actionGetAuthorById($id);
     if ($result) {
         $params = array('model' => $author_model, 'name' => $result->author_name, 'request_url' => Yii::app()->createUrl('/library/library/updateAuthorByPk', array('id' => $id)));
         echo $this->renderPartial('_authorForm', $params, true);
     } else {
         echo "Нет информации....";
     }
 }
コード例 #9
0
ファイル: search_form.php プロジェクト: hit-shappens/testapp
<?php

echo CHtml::beginForm(Yii::app()->request->getRequestUri(), 'get');
?>

<div class="simple action">
<?php 
echo CHtml::submitButton('Искать');
?>
</div>

<div class="simple">
<?php 
echo CHtml::activeDropDownList($model, 'author', Authors::model()->getOptions(), array('prompt' => $model->getAttributeLabel('author')));
echo CHtml::activeTextField($model, 'name', array('maxlength' => 255, 'title' => $model->getAttributeLabel('name'), 'onkeyup' => 'if(this.value=="") {this.value=this.title;}', 'onkeydown' => 'if(this.value==this.title){this.value=null}'));
?>
</div>
<script type="text/javascript">
<!--
	jQuery(function($){
		var input = jQuery("#SearchForm_name");
		if(input.val()=='')
			input.val(input.attr('title'));
		input.parent().parent().submit(function(e){
			if(input.val()==input.attr('title'))
				input.val('');
		});
		
	});
//-->
</script>