Ejemplo n.º 1
0
 public function testToArray()
 {
     $authors = new Authors();
     $authors[] = new Author('James Bond <*****@*****.**>');
     $authors[] = new Author('Indiana Jones <*****@*****.**>');
     $this->assertSame([['name' => 'James Bond', 'email' => '*****@*****.**'], ['name' => 'Indiana Jones', 'email' => '*****@*****.**']], $authors->toArray());
 }
Ejemplo n.º 2
0
function authors_directory()
{
    global $authors;
    $author = new Authors();
    $authors = $author->find("WHERE directory = '1'");
    global $staff;
    $staff = $author->find("WHERE directory = '2'");
    render();
}
Ejemplo n.º 3
0
 public function testAction()
 {
     $authors = new Authors();
     $me = $authors->find(1)->current();
     echo '<span>' . $me->name() . '</span>';
     $meAgain = $authors->fetchRow('id = 3');
     $pubs = $meAgain->findDependentRowset('Entry')->toArray();
     //Zend_Debug::dump($pubs);
     // list of entries by tag "Test tag 1"
     $tags = new Tags();
     $firstTag = $tags->fetchRow('id = 2');
     $tagEntries = $firstTag->findManyToManyRowset('Entry', 'TagsLinks')->toArray();
     //Zend_Debug::dump($tagEntries);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 public function delete($id)
 {
     if (!($feedback = Authors::find($id))) {
         throw new RestException(404, 'feedback not found');
     }
     $feedback->delete();
     return ['success' => true];
 }
Ejemplo n.º 7
0
 public function checkColumns($book, $row_number, CheckLinks &$check_links, Authors $authors)
 {
     $this->onRow($row_number + 2);
     $this->checkColumnCount($book);
     $book_title = $book['title'];
     $this->checkCharacters($book_title, 'A-Title');
     $book_author = $book['author'];
     $this->checkCharacters($book_author, 'B-Author');
     $story_link = $book['story_link_on_wikipedia'];
     $this->checkWikipediaLink($story_link, 'C-Story Link on Wikipedia');
     $check_links->addUrl($story_link);
     $author_link = $book['author_wikipedia_entry'];
     $this->checkWikipediaLink($author_link, 'D-Author Wikipedia Entry');
     $check_links->addUrl($author_link);
     $authors->addAuthorCollapsed($book_author, $author_link);
     $this->checkPdfColumns($book, $check_links);
 }
Ejemplo n.º 8
0
 public function index()
 {
     //Set keyword to proper format using Str::lower - it's the same as strtolower
     $keyword = Str::lower(Input::get('keyword'));
     //Use Query builder to look for the keyword in various category
     $data['comics'] = Comicbooks::where('book_name', 'LIKE', '%' . $keyword . '%')->select('book_name')->distinct()->get();
     $data['characters'] = Characters::where('character_name', 'LIKE', '%' . $keyword . '%')->select('character_name')->distinct()->get();
     $data['authors'] = Authors::where('author_name', 'LIKE', '%' . $keyword . '%')->select('author_name')->distinct()->get();
     $data['artists'] = Artists::where('artist_name', 'LIKE', '%' . $keyword . '%')->select('artist_name')->distinct()->get();
     $data['publishers'] = Publishers::where('publisher_name', 'LIKE', '%' . $keyword . '%')->select('publisher_name')->distinct()->get();
     $this->layout->content = View::make('search', $data);
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 public function getBrowse($category)
 {
     //Get browse category
     $category_filtered = strtoupper(trim($category));
     //Page Title
     $data['title'] = $category_filtered;
     //Switch to get appropriate data, redirect to error if options aren't listed
     switch ($category_filtered) {
         case 'SERIES':
             $data['comics'] = Comicbooks::orderBy('book_name', 'asc')->get();
             break;
         case 'AUTHORS':
             $data['comics'] = Authors::select('author_name')->orderBy('author_name', 'asc')->distinct()->get();
             break;
         case 'ARTISTS':
             $data['comics'] = Artists::select('artist_name')->orderBy('artist_name', 'asc')->distinct()->get();
             break;
         case 'CHARACTERS':
             $data['comics'] = Characters::select('character_name')->orderBy('character_name', 'asc')->distinct()->get();
             break;
         case 'PUBLISHERS':
             $data['comics'] = Publishers::select('publisher_name')->orderBy('publisher_name', 'asc')->distinct()->get();
             break;
         case 'GENRES':
             $data['comics'] = Genres::orderBy('genre_name', 'asc')->get();
             break;
         case 'YEARS':
             //This needed to be a raw query because of the date
             $data['comics'] = Comicissues::select(DB::raw('year(published_date) as year'))->orderBy('published_date', 'asc')->distinct()->get();
             break;
         default:
             return Redirect::to('error');
             break;
     }
     $this->layout->content = View::make('browse', $data);
 }
Ejemplo n.º 11
0
 public function matchingBooks($pdf_url_folder, $search = '')
 {
     $filtered_search = $this->filterSearch($search);
     $initial_pdf_books = $this->sortableTitleKeys($this->pdf_books);
     $authors = new Authors();
     $html_books = array();
     foreach ($initial_pdf_books as $sort_title => $book) {
         if ($this->bookInSearch($book, $filtered_search)) {
             $this->title_html = $this->titleHtml($book['title'], $book['story_link_on_wikipedia']);
             $sort_author_lastname = $authors->lastAuthorName($book['author']);
             $this->author_title_sort = "{$sort_author_lastname}-{$sort_title}";
             $this->author_html = $this->authorHtml($book['author'], $sort_author_lastname);
             $pdfs_book = self::pdfsOnlyList($book);
             $this->pdfs_html = $this->pdfsHtml($pdf_url_folder, $pdfs_book);
             $html_books[] = $this->tableRow($sort_title);
         }
     }
     $html = implode("\n", $html_books);
     return $html;
 }
Ejemplo n.º 12
0
 protected function mormTearDown()
 {
     $this->sql->queryDB(Authors::dropTable());
 }
Ejemplo n.º 13
0
 public function getAdmin()
 {
     //Get info
     $data['users'] = User::paginate(5);
     $data['recent_books'] = Comicbooks::select('book_name', 'updated_at')->orderBy('updated_at', 'desc')->paginate(3);
     $data['user_count'] = User::where('id', '>', 0)->count();
     $data['publisher_count'] = Publishers::where('id', '>', 0)->count();
     $data['books_count'] = Comicbooks::where('id', '>', 0)->count();
     $data['issue_count'] = Comicissues::where('issue_id', '>', 0)->where('book_id', '>', 0)->count();
     $data['artist_count'] = Artists::count();
     $data['author_count'] = Authors::count();
     $data['books_created'] = Comicbooks::select(DB::raw('count(*) as count'), 'created_at')->groupby(DB::raw('date_format(created_at, "%b %Y")'))->orderby('created_at', 'asc')->get();
     $data['issues_created'] = Comicissues::select(DB::raw('count(*) as count'), 'created_at')->groupby(DB::raw('date_format(created_at, "%b %Y")'))->orderby('created_at', 'asc')->get();
     //Check if there are any comicbook series
     if (count($data['books_created']) > 0) {
         //Get the count of books per the month/year then return the json encoded string
         foreach ($data['books_created'] as $created) {
             $created_books[] = $created->count;
             $created_books_date[] = date_format($created->created_at, "M Y");
         }
         $data['created_books'] = json_encode($created_books);
     }
     //Check if there are any comicbook issue
     if (count($data['issues_created']) > 0) {
         //Get the count of issues per the month/year then return the json encoded string
         foreach ($data['issues_created'] as $created) {
             $created_issues[] = $created->count;
             $created_issues_date[] = date_format($created->created_at, "M Y");
         }
         $data['created_issues'] = json_encode($created_issues);
     }
     //Merge dates from comicbook series and issues created then return the json encoded string
     $data['created_dates'] = json_encode(array_unique(array_merge($created_issues_date, $created_books_date)));
     $this->layout->content = View::make('admin.index', $data);
 }
Ejemplo n.º 14
0
 /**
  * Declares an association between this object and a Authors object.
  *
  * @param      Authors $v
  * @return     Photos The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setAuthors(Authors $v = null)
 {
     if ($v === null) {
         $this->setAuthorId(NULL);
     } else {
         $this->setAuthorId($v->getId());
     }
     $this->aAuthors = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Authors object, it will not be re-added.
     if ($v !== null) {
         $v->addPhotos($this);
     }
     return $this;
 }
Ejemplo n.º 15
0
class Articles extends \EntityPHP\Entity
{
    protected $title;
    protected $content;
    protected $author;
    //__structure() method is mandatory and must return an array
    public static function __structure()
    {
        return array('title' => 'VARCHAR(255)', 'content' => 'TEXT', 'author' => 'Authors');
    }
}
//Init connection to the database
\EntityPHP\Core::connectToDB('localhost', 'entityphp', '3n7i7iPHP', 'entityphp');
//Generate the database (this method should be execute only once)
\EntityPHP\Core::generateDatabase();
//Create a new author
$author = new Authors(array('firstname' => 'Jean', 'lastname' => 'Peplu'));
//And store it to our table!
Authors::add($author);
//Create a new article
$article = new Articles(array('title' => 'It should work!', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.
					Ab assumenda dicta doloribus eaque earum, ex inventore libero
					odio perferendis possimus quaerat quidem quo ullam?', 'author' => $author));
//And store it to our table!
Articles::add($article);
//Create a second article
$article = new Articles(array('title' => 'It should work again!', 'content' => 'Ex inventore libero odio perferendis possimus quaerat quidem quo ullam?
					Lorem ipsum dolor sit amet, consectetur adipisicing elit.
					Ab assumenda dicta doloribus eaque earum...', 'author' => $author));
//And store it to our table!
Articles::add($article);
Ejemplo n.º 16
0
function admin_authors_new()
{
    $author = new Authors();
    if (isset($_POST['update'])) {
        foreach ($_POST['update'] as $k => $v) {
            $author->{$k} = $v;
        }
        $author->save();
        render('research_authors');
    }
    render();
}
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Authors $value A Authors object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Authors $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Ejemplo n.º 18
0
<?php

namespace app\models;

class Authors extends \lithium\data\Model
{
    public $hasMany = array('Books');
    public $validates = array('email' => array(array('notEmpty', 'message' => 'You must type a valid email address')), 'password' => array(array('notEmpty', 'message' => 'You must type a password')));
}
Authors::applyFilter('save', function ($self, $params, $chain) {
    if (!$params['entity']->id && !empty($params['entity']->password)) {
        $params['entity']->password = \lithium\util\String::hash($params['entity']->password);
    }
    return $chain->next($self, $params, $chain);
});
Ejemplo n.º 19
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));
 }
Ejemplo n.º 20
0
<?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>
Ejemplo n.º 21
0
 /**
  * Adding a comicbook series into the database
  * GET /content/store
  *
  * @return Response
  */
 public function store()
 {
     //Get string inputs
     $inputs = Input::only('book_name', 'publisher_name', 'author_name', 'artist_name');
     //Trim string inputs
     Input::merge(array_map('trim', $inputs));
     //Create session
     $this->createSession();
     //Set validation rules
     $rules = array('book_name' => 'required|alpha_num|unique:comicdb_books', 'publisher_name' => 'required|alpha_num|min:1', 'book_description' => 'max:2000', 'genres' => 'min:1', 'author_name' => 'required|alpha_num|min:1', 'artist_name' => 'required|alpha_num|min:1', 'published_date' => 'required|date_format:yy-m-d', 'cover_image' => 'required|image', 'characters' => 'min:1', 'issue_summary' => 'max:2000');
     //Laravel Validation class and make method takes the inputs in the first argument
     //then the rules on the data in the second
     $validator = Validator::make(Input::all(), $rules);
     //Validator instance use the pass method to continue
     if ($validator->passes()) {
         dd($validator->passes());
         //Instance of Comicbook model
         $comic = new Comicbooks();
         //Instance of Publisher model
         $publishers = new Publishers();
         //Setting variables
         $publisher = strtolower(Input::get('publisher_name'));
         $author = strtolower(Input::get('author_name'));
         $artist = strtolower(Input::get('artist_name'));
         $publisherExists = $publishers->where('publisher_name', $publisher)->select('id')->first();
         $authorExists = Authors::where('author_name', $author)->select('id')->first();
         $artistExists = Artists::where('artist_name', $artist)->select('id')->first();
         //Check if publisher already exist in the database
         if (isset($publisherExists->id)) {
             //if it does get the id
             $publisher_id = $publisherExists->id;
         } else {
             //else create it in the Publisher table using the instance of publisher model
             $publisher_id = $publishers->insertGetId(array('publisher_name' => $publisher));
         }
         //Check if author already exist in the database
         if (isset($authorExists)) {
             //if they do get the id
             $author_id = $authorExists->id;
         } else {
             //else create it in the Authors table using the instance of author model
             $author_id = Authors::insertGetId(array('author_name' => $author));
         }
         //Check if artist already exist in the database
         if (isset($artistExists)) {
             //if they do get the id
             $artist_id = $artistExists->id;
         } else {
             //else create it in the Artists table using the instance of artist model
             $artist_id = Artists::insertGetId(array('artist_name' => $artist));
         }
         //Add book series information to comicdb_books
         $comic->book_name = strtolower(Input::get('book_name'));
         $comic->book_description = Input::get('book_description');
         $comic->publisher_id_FK = $publisher_id;
         $comic->save();
         //Add genre and book ids in the comicdb_genrebook using Query Builder
         foreach (Input::get('genres') as $key => $genre) {
             DB::table('comicdb_genrebook')->insert(array('book_id_FK' => $comic->id, 'genre_id_FK' => $genre));
         }
         //Add cover image to local file and set location string into database
         if (Input::hasFile('cover_image')) {
             $fileName = strtolower(Input::get('book_name')) . '01_Cov_' . Str::random(10) . '.' . Input::file('cover_image')->getClientOriginalExtension();
             $cover_image = Input::file('cover_image')->move('public/img/comic_covers/', $fileName);
         }
         //Add issue character information into the comicdb_character table and keys into the comicdb_characterbook table using Query Builder
         foreach (Input::get('characters') as $key => $character) {
             $character_id = Characters::insertGetId(array('character_name' => $character));
             DB::table('comicdb_characterbook')->insert(array('book_id_FK' => $comic->id, 'character_id_FK' => $character_id));
         }
         //Add issues information to comicdb_issues
         Comicissues::insert(array('book_id' => $comic->id, 'issue_id' => 1, 'artist_id_FK' => $artist_id, 'author_id_FK' => $author_id, 'summary' => Input::get('issue_summary'), 'published_date' => Input::get('published_date'), 'cover_image' => 'img/comic_covers/' . $fileName, 'created_at' => date('Y-m-d H:i:s', time())));
         $this->destorySession();
         return Redirect::to('browse')->with('postMsg', 'Thanks for submiting!');
     } else {
         return Redirect::to('content/series')->with('postMsg', 'Whoops! Looks like you got some errors.')->withErrors($validator);
     }
 }
Ejemplo n.º 22
0
 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' => 'Не верный формат даты'));
 }
Ejemplo n.º 23
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;
     }
 }
Ejemplo n.º 24
0
 /**
  * funkce vylistuje autory
  * @param int $distributor_id optional
  * @return array
  */
 public function authorsList($distributor_id = null)
 {
     try {
         return Authors::authorsList($distributor_id);
     } catch (Exception $e) {
         throw new RPCFault($e->getMessage(), $e->getCode(), $e->getCode());
     }
 }
Ejemplo n.º 25
0
<?php

try {
    if (empty($_GET['page'])) {
        $_GET['page'] = '1';
    }
    // Create Class BlogPostsCollection
    $Collection = new BlogPostsCollection();
    // Return all BlogPost in one Array
    $BlogPosts = $Collection->ToArray($_GET['page'], 5);
    $BlogPostPagination = HelperSingleton::GetInstance()->GetPagination();
    // Create Author Class
    $AuthorsObj = new Authors();
    // Return all Authors
    $AuthorArray = $AuthorsObj->GetAuthors();
} catch (Exception $e) {
    // No Exception Management at this time
}
Ejemplo n.º 26
0
 public function testAuthorsLastNames()
 {
     $author_test_names_to_last = array("Madeline L'Engel " => "L'Engel", "Fitz-James O'Brien " => "O'Brien", "Sheridan Le Fanu " => "Le Fanu", "Lester del Rey " => "del Rey", "James De Mille " => "De Mille", "Charles De Vet " => "De Vet", ' Kurt Vonnegut Jr. ' => 'Vonnegut', " Gene Cross aka 'Arthur Jean Cox' " => 'Cox', ' Arthur Quiller-Couch ' => 'Quiller-Couch', ' Sam    Merwin     Jr. ' => 'Merwin', " jim Garis' " => 'Garis', 'Emily Brontë' => 'Brontë', 'Gottfried August Bürger ' => 'Bürger', 'hansen )' => 'hansen', 'Hansen)' => 'Hansen', 'H.G.Wells' => 'Wells', "Robert W.Chambers" => 'Chambers');
     $authors = new Authors();
     foreach ($author_test_names_to_last as $test_name => $expected_last) {
         $found_last = $authors->lastAuthorName($test_name);
         $this->assertEquals($found_last, $expected_last);
     }
 }
Ejemplo n.º 27
0
<?php

//We admit that Authors & Articles classes and their tables exist
//Get the article with id 1
$myArticle = Articles::getById(1);
//Check if character is found
if (!empty($myArticle)) {
    //Get the new author to link to the article
    $myAuthor = Authors::getById(2);
    if (!empty($myAuthor)) {
        //Update the "author" field of the article
        $myArticle->prop('author', $myAuthor);
        //And save the changes!
        Articles::update($myArticle);
    } else {
        echo 'The new author of the article is not found.';
    }
} else {
    echo 'The article to update is not found.';
}
Ejemplo n.º 28
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 "Нет информации....";
     }
 }
Ejemplo n.º 29
0
<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>
Ejemplo n.º 30
0
 /**
  * Update an issue in the database
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //Trim inputs
     Input::merge(array_map('trim', Input::all()));
     //Set rules
     $rules = array('author_name' => 'required|min:5', 'artist_name' => 'required|min:5', 'published_date' => 'required|date_format:yy-m-d', 'issue_summary' => 'max:2000');
     //Create session
     $this->createSession();
     //Set validator
     $validator = Validator::make(Input::all(), $rules);
     //Set variables
     $data['issue_id'] = $id;
     $comic_title = Comicbooks::find(Input::get('id'));
     $comic_issues = Comicissues::issues($comic_title->book_name, $id)->select('book_id', 'issue_id')->first();
     //If comicbook issue exists
     if (!is_null($comic_issues)) {
         //Validation check
         if ($validator->passes()) {
             //Instance of Comicissue model
             $comic_issues = new Comicissues();
             //Set variables
             $author = Str::lower(Input::get('author_name'));
             $artist = Str::lower(Input::get('artist_name'));
             $authorExists = Authors::where('author_name', $author)->select('id')->first();
             $artistExists = Artists::where('artist_name', $artist)->select('id')->first();
             //Check if author already exist in the database
             if (isset($authorExists)) {
                 //if they do get the id
                 $author_id = $authorExists->id;
             } else {
                 //else create it in the Authors table using the instance of author model
                 $author_id = Authors::insertGetId(array('author_name' => $author));
             }
             //Check if artist already exist in the database
             if (isset($artistExists)) {
                 //if they do get the id
                 $artist_id = $artistExists->id;
             } else {
                 //else create it in the Artists table using the instance of artist model
                 $artist_id = Artists::insertGetId(array('artist_name' => $artist));
             }
             //Set an array of update variables
             $update_array = array('author_id_FK' => $author_id, 'artist_id_FK' => $artist_id, 'summary' => Input::get('issue_summary'), 'published_date' => Input::get('published_date'), 'updated_at' => date('Y-m-d H:i:s', time()));
             //Add cover image to local file and set location string into database
             if (Input::hasFile('cover_image')) {
                 $fileName = $comic_title->book_name . $id . '_Cov_' . Str::random(10) . '.' . Input::file('cover_image')->getClientOriginalExtension();
                 $cover_image = Input::file('cover_image')->move('public/img/comic_covers/', $fileName);
                 $update_array['cover_image'] = 'img/comic_covers/' . $fileName;
             }
             //Add issue information to comicdb_books
             Comicissues::where('book_id', Input::get('id'))->where('issue_id', $id)->update($update_array);
             //Destroy session data
             $this->destorySession();
             return Redirect::to('browse/series/' . $comic_title->book_name)->with('postMsg', 'Thanks for submiting!');
         } else {
             return Redirect::to(URL::previous())->with('postMsg', 'Whoops! Looks like you got some errors.')->withErrors($validator)->withInput();
         }
     }
     $this->destorySession();
     return Redirect::to(URL::previous())->with('postMsg', 'Looks like that issue already exists!');
 }