diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3f2c5f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Eclipse +.project +.settings +/.buildpath + +# Composer +/vendor/ +composer.lock +composer-setup.php +composer.phar + +# Project +storage/tenant + +# KDE +.directory diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4064d0e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: php +php: + - '5.6' + - '7.0' + - '7.1' + +mysql: + database: test + username: root + encoding: utf8 + +before_install: + - sudo apt-get update > /dev/null + +install: + - composer install + +script: + - cd tests + - php run.php + - php coverage-checker.php clover.xml 70 + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a29c939 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Book \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cc139fd --- /dev/null +++ b/composer.json @@ -0,0 +1,43 @@ +{ + "name" : "pluf/book", + "description" : "Content management system fo pluf", + "type" : "library", + "license" : "MIT", + "authors" : [{ + "name" : "Mostafa Barmshory", + "email" : "mostafa.barmshory@dpq.co.ir", + "homepage" : "http://dpq.co.ir", + "role" : "developer" + }, { + "name" : "Mohammad Hadi Mansouri", + "email" : "mohammad.hadi.mansouri@dpq.co.ir", + "homepage" : "http://dpq.co.ir", + "role" : "developer" + } + ], + "minimum-stability" : "stable", + "require" : { + "pluf/core" : "^2.0.2" + }, + "require-dev" : { + "pluf/test" : "^2.1.0", + "pluf/user" : "^2.1.0" + }, + "include-path" : [ + "src/" + ], + "homepage" : "https://github.com/pluf/book", + "support" : { + "email" : "info@pluf.ir", + "issues" : "https://github.com/pluf/cms/issues", + "forum" : "https://github.com/pluf/cms", + "wiki" : "https://github.com/pluf/cms/wiki", + "source" : "https://github.com/pluf/cms" + }, + "keywords" : [ + "pluf", + "php", + "pluf-module", + "book" + ] +} \ No newline at end of file diff --git a/src/Book/Book.php b/src/Book/Book.php new file mode 100644 index 0000000..b09eb01 --- /dev/null +++ b/src/Book/Book.php @@ -0,0 +1,111 @@ + + * + */ +class Book_Book extends Pluf_Model +{ + + /** + * مدل داده‌ای را بارگذاری می‌کند. + * + * @see Pluf_Model::init() + */ + function init () + { + $this->_a['table'] = 'book'; + $this->_a['cols'] = array( + // شناسه‌ها + 'id' => array( + 'type' => 'Pluf_DB_Field_Sequence', + 'blank' => false, + 'editable' => false, + 'readable' => true + ), + // فیلدها + 'state' => array( + 'type' => 'Pluf_DB_Field_Integer', + 'blank' => false, + 'unique' => false + ), + 'title' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 250, + 'verbose' => __('title'), + 'help_text' => __( + 'the title of the page must only contain letters, digits or the dash character. For example: My-new-Wiki-Page.') + ), + 'language' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 50, + 'verbose' => __('language'), + 'help_text' => __( + 'the language of the page must only contain letters. for example: en.') + ), + 'summary' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 250, + 'verbose' => __('summary'), + 'help_text' => __( + 'a one line description of the page content.') + ), + 'creation_dtime' => array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('creation date') + ), + 'modif_dtime' => array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('modification date') + ), + // رابطه‌ها + 'interested' => array( + 'type' => 'Pluf_DB_Field_Manytomany', + 'model' => 'Pluf_User', + 'blank' => true, + 'relate_name' => 'interested', + 'verbose' => __('interested users'), + 'help_text' => __( + 'interested users will get an email notification when the wiki page is changed.') + ), + 'submitter' => array( + 'type' => 'Pluf_DB_Field_Foreignkey', + 'model' => 'Pluf_User', + 'blank' => false, + 'verbose' => __('submitter'), + 'relate_name' => 'submitted_wikipages' + ), + ); + } + + /** + * پیش ذخیره را انجام می‌دهد + * + * @param $create حالت + * ساخت یا به روز رسانی را تعیین می‌کند + */ + function preSave ($create = false) + { + if ($this->id == '') { + $this->creation_dtime = gmdate('Y-m-d H:i:s'); + } + $this->modif_dtime = gmdate('Y-m-d H:i:s'); + } + + /** + * حالت کار ایجاد شده را به روز می‌کند + * + * @see Pluf_Model::postSave() + */ + function postSave ($create = false) + { + // + } +} \ No newline at end of file diff --git a/src/Book/Exception/BookNotFound.php b/src/Book/Exception/BookNotFound.php new file mode 100644 index 0000000..876133b --- /dev/null +++ b/src/Book/Exception/BookNotFound.php @@ -0,0 +1,26 @@ + + * + */ +class Book_Exception_BookNotFound extends Pluf_Exception +{ + + /** + * یک نمونه از این کلاس ایجاد می‌کند. + * + * @param string $message + * @param Pluf_Exception $previous + * @param string $link + * @param string $developerMessage + */ + public function __construct ($message = "requested wiki book not found.", $previous = null, $link = null, + $developerMessage = null) + { + parent::__construct($message, 4302, $previous, 404, $link, + $developerMessage); + } +} \ No newline at end of file diff --git a/src/Book/Exception/PageNotFound.php b/src/Book/Exception/PageNotFound.php new file mode 100644 index 0000000..cfbad73 --- /dev/null +++ b/src/Book/Exception/PageNotFound.php @@ -0,0 +1,26 @@ + + * + */ +class Book_Exception_PageNotFound extends Pluf_Exception +{ + + /** + * یک نمونه از این کلاس ایجاد می‌کند. + * + * @param string $message + * @param Pluf_Exception $previous + * @param string $link + * @param string $developerMessage + */ + public function __construct ($message = "requested wiki page not found.", $previous = null, $link = null, + $developerMessage = null) + { + parent::__construct($message, 4301, $previous, 404, $link, + $developerMessage); + } +} \ No newline at end of file diff --git a/src/Book/Form/BookCreate.php b/src/Book/Form/BookCreate.php new file mode 100644 index 0000000..4b1886d --- /dev/null +++ b/src/Book/Form/BookCreate.php @@ -0,0 +1,63 @@ + + * + */ +class Book_Form_BookCreate extends Pluf_Form +{ + + public $user = null; + + public function initFields ($extra = array()) + { + $this->user = $extra['user']; + $initial = __('empty summary'); + $initname = (! empty($extra['name'])) ? $extra['name'] : __('PageName'); + $this->fields['title'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('page title'), + 'initial' => $initname, + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67 + ), + 'help_text' => __( + 'the page name must contains only letters, digits and the dash (-) character') + )); + $this->fields['summary'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('description'), + 'initial' => $initial, + 'help_text' => __( + 'this one line description is displayed in the list of pages'), + 'initial' => '', + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67 + ) + )); + } + + function save ($commit = true) + { + if (! $this->isValid()) { + throw new Pluf_Exception( + __('cannot save the book from an invalid form')); + } + // Create the book + $page = new Book_Book(); + $page->setFromFormData($this->cleaned_data); + $page->submitter = $this->user; + if ($commit) { + $page->create(); + } + return $page; + } +} diff --git a/src/Book/Form/BookUpdate.php b/src/Book/Form/BookUpdate.php new file mode 100644 index 0000000..e1bf138 --- /dev/null +++ b/src/Book/Form/BookUpdate.php @@ -0,0 +1,62 @@ + + * + */ +class Book_Form_BookUpdate extends Pluf_Form +{ + + public $user = null; + + public $book = null; + + public function initFields ($extra = array()) + { + $this->user = $extra['user']; + $this->book = $extra['book']; + $this->fields['title'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('page title'), + 'initial' => $this->book->title, + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67 + ), + 'help_text' => __( + 'the page name must contains only letters, digits and the dash (-) character') + )); + $this->fields['summary'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('description'), + 'initial' => $this->book->summary, + 'help_text' => __( + 'this one line description is displayed in the list of pages'), + 'initial' => '', + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67 + ) + )); + } + + function update ($commit = true) + { + if (! $this->isValid()) { + throw new Pluf_Exception( + __('cannot save the book from an invalid form')); + } + // Create the book + $this->book->setFromFormData($this->cleaned_data); + if ($commit) { + $this->book->update(); + } + return $this->book; + } +} diff --git a/src/Book/Form/PageCreate.php b/src/Book/Form/PageCreate.php new file mode 100644 index 0000000..a2264ec --- /dev/null +++ b/src/Book/Form/PageCreate.php @@ -0,0 +1,128 @@ + + * + */ +class Book_Form_PageCreate extends Pluf_Form +{ + + public $user = null; + + public $book = null; + + public function initFields ($extra = array()) + { + $this->user = $extra['user']; + $this->book = $extra['book']; + $initial = __('empty page'); + $initname = (! empty($extra['name'])) ? $extra['name'] : __('page name'); + $this->fields['title'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('page title'), + 'initial' => $initname, + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67 + ), + 'help_text' => __( + 'the page name must contains only letters, digits and the dash (-) character') + )); + $this->fields['summary'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('Description'), + 'help_text' => __( + 'this one line description is displayed in the list of pages'), + 'initial' => '', + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67 + ) + )); + $this->fields['content'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('content'), + 'initial' => $initial, + 'widget' => 'Pluf_Form_Widget_TextareaInput', + 'widget_attrs' => array( + 'cols' => 68, + 'rows' => 26 + ) + )); + $this->fields['content_type'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('content type'), + 'initial' => 'text/plain', + 'widget' => 'Pluf_Form_Widget_TextareaInput', + 'widget_attrs' => array( + 'cols' => 68, + 'rows' => 26 + ) + )); + } + + /** + * Save the model in the database. + * + * @param + * bool Commit in the database or not. If not, the object + * is returned but not saved in the database. + * @return Object Model with data set from the form. + */ + function save ($commit = true) + { + if (! $this->isValid()) { + throw new Pluf_Exception( + __('Cannot save the page from an invalid form')); + } + // // Add a tag for each label + // $tags = array(); + // if ($this->show_full) { + // for ($i = 1; $i < 4; $i ++) { + // if (strlen($this->cleaned_data['label' . $i]) > 0) { + // if (strpos($this->cleaned_data['label' . $i], ':') !== false) { + // list ($class, $name) = explode(':', + // $this->cleaned_data['label' . $i], 2); + // list ($class, $name) = array( + // trim($class), + // trim($name) + // ); + // } else { + // $class = 'Other'; + // $name = trim($this->cleaned_data['label' . $i]); + // } + // $tags[] = IDF_Tag::add($name, $this->project, $class); + // } + // } + // } + // Create the page + $page = new Book_Page(); + // $page->project = $this->project; + $page->setFromFormData($this->cleaned_data); + $page->submitter = $this->user; + $page->book = $this->book; + if ($commit) { + $page->create(); + } + // foreach ($tags as $tag) { + // $page->setAssoc($tag); + // } + // add the first revision + // $rev = new IDF_WikiRevision(); + // $rev->wikipage = $page; + // $rev->content = $this->cleaned_data['content']; + // $rev->submitter = $this->user; + // $rev->summary = __('Initial page creation'); + // $rev->create(); + // $rev->notify($this->project->getConf()); + return $page; + } +} diff --git a/src/Book/Form/PageDelete.php b/src/Book/Form/PageDelete.php new file mode 100644 index 0000000..f4b6b4b --- /dev/null +++ b/src/Book/Form/PageDelete.php @@ -0,0 +1,48 @@ + + * + */ +class Book_Form_PageDelete extends Pluf_Form +{ + + protected $page = null; + + public function initFields ($extra = array()) + { + $this->page = $extra['page']; + $this->fields['confirm'] = new Pluf_Form_Field_Boolean( + array( + 'required' => true, + 'label' => __( + 'yes, I understand that the page and all its revisions will be deleted'), + 'initial' => '' + )); + } + + /** + * Check the confirmation. + */ + public function clean_confirm () + { + if (! $this->cleaned_data['confirm']) { + throw new Pluf_Form_Invalid(__('you need to confirm the deletion')); + } + return $this->cleaned_data['confirm']; + } + + function save ($commit = true) + { + if (! $this->isValid()) { + throw new Exception( + __('cannot save the model from an invalid form')); + } + $this->page->delete(); + return true; + } +} diff --git a/src/Book/Form/PageUpdate.php b/src/Book/Form/PageUpdate.php new file mode 100644 index 0000000..ed7a000 --- /dev/null +++ b/src/Book/Form/PageUpdate.php @@ -0,0 +1,62 @@ + + * + */ +class Book_Form_PageUpdate extends Book_Form_PageCreate +{ + + public $user = null; + + public $page = null; + + public function initFields ($extra = array()) + { + $this->page = $extra['page']; + $this->user = $extra['user']; + + $this->fields['title'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('Page title'), + 'initial' => $this->page->title + )); + $this->fields['summary'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('Summary'), + 'initial' => $this->page->summary + )); + $this->fields['content'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('Content'), + 'initial' => $this->page->content, + 'widget' => 'Pluf_Form_Widget_TextareaInput' + )); + $this->fields['content_type'] = new Pluf_Form_Field_Varchar( + array( + 'required' => false, + 'label' => __('content type'), + 'initial' => $this->page->content_type + )); + } + + function update ($commit = true) + { + if (! $this->isValid()) { + throw new Exception( + __('Cannot update the page from an invalid form')); + } + $this->page->setFromFormData($this->cleaned_data); + if ($commit) { + $this->page->update(); + } + return $this->page; + } +} diff --git a/src/Book/Page.php b/src/Book/Page.php new file mode 100644 index 0000000..4ded3d4 --- /dev/null +++ b/src/Book/Page.php @@ -0,0 +1,161 @@ + + * + */ +class Book_Page extends Pluf_Model +{ + + /** + * مدل داده‌ای را بارگذاری می‌کند. + * + * @see Pluf_Model::init() + */ + function init () + { + $this->_a['table'] = 'book_page'; + $this->_a['cols'] = array( + // کلید + 'id' => array( + 'type' => 'Pluf_DB_Field_Sequence', + 'blank' => true + ), + // فیلدها + 'priority' => array( + 'type' => 'Pluf_DB_Field_Integer', + 'blank' => false, + 'unique' => false + ), + 'state' => array( + 'type' => 'Pluf_DB_Field_Integer', + 'blank' => false, + 'unique' => false + ), + 'title' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 250, + 'verbose' => __('title'), + 'help_text' => __( + 'the title of the page must only contain letters, digits or the dash character. For example: My-new-Wiki-Page.') + ), + 'language' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 50, + 'verbose' => __('language'), + 'help_text' => __( + 'the language of the page must only contain letters. For example: en.') + ), + 'summary' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 250, + 'verbose' => __('summary'), + 'help_text' => __( + 'a one line description of the page content.') + ), + 'content' => array( + 'type' => 'Pluf_DB_Field_Compressed', + 'blank' => false, + 'verbose' => __('content') + ), + 'content_type' => array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 50, + 'verbose' => __('content type'), + 'help_text' => __( + 'the content type of the page is a mime type. For example: text/plain.') + ), + 'creation_dtime' => array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('creation date') + ), + 'modif_dtime' => array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('modification date') + ), + // رابطه‌ها + 'submitter' => array( + 'type' => 'Pluf_DB_Field_Foreignkey', + 'model' => 'Pluf_User', + 'blank' => false, + 'verbose' => __('submitter') + ), + 'book' => array( + 'type' => 'Pluf_DB_Field_Foreignkey', + 'model' => 'Pluf_Book', + 'blank' => true, + 'verbose' => __('book') + ) + ); + $this->_a['views'] = array( +// 'page_list' => array( +// 'select' => $this->getCustomSelect('page_list', +// array( +// 'id', +// 'title', +// 'priority' +// )) +// ), +// 'page_list_summary' => array( +// 'select' => $this->getCustomSelect('page_list', +// array( +// 'id', +// 'title', +// 'priority', +// 'state', +// 'language', +// 'summary' +// )) +// ) + ); + } + +// function getCustomSelect ($cache_key, $keys = array()) +// { +// if (isset($this->_cache[$cache_key])) +// return $this->_cache[$cache_key]; +// $select = array(); +// $table = $this->getSqlTable(); +// foreach ($keys as $col) { +// $val = $this->_a['cols'][$col]; +// if ($val['type'] != 'Pluf_DB_Field_Manytomany') { +// $select[] = $table . '.' . $this->_con->qn($col) . ' AS ' . +// $this->_con->qn($col); +// } +// } +// $this->_cache['getSelect'] = implode(', ', $select); +// return $this->_cache['getSelect']; +// } + + /** + * پیش ذخیره را انجام می‌دهد + * + * @param $create حالت + * ساخت یا به روز رسانی را تعیین می‌کند + */ + function preSave ($create = false) + { + if ($this->id == '') { + $this->creation_dtime = gmdate('Y-m-d H:i:s'); + } + $this->modif_dtime = gmdate('Y-m-d H:i:s'); + } + + /** + * حالت کار ایجاد شده را به روز می‌کند + * + * @see Pluf_Model::postSave() + */ + function postSave ($create = false) + { + // + } +} \ No newline at end of file diff --git a/src/Book/Precondition.php b/src/Book/Precondition.php new file mode 100644 index 0000000..243c3ef --- /dev/null +++ b/src/Book/Precondition.php @@ -0,0 +1,54 @@ + 0 && $item->id == $id) { +// return $item; +// } +// throw new Book_Exception_PageNotFound( +// "Wiki page not found (Page id:" . $id . ")"); +// } + +/** + * کتاب با شناسه تعیین شده را بر می‌گرداند. + * + * در صورتی که کتاب پیدا نشود خطا ۴۰۴ را به عنوان نتیجه متشر خواهد کرد. + * + * @param unknown $id + * @throws Book_Exception_BookNotFound + * @return Book_Book معاد با شناسه ورودی + */ +// function Book_Shortcuts_GetBookOr404 ($id) +// { +// $item = new Book_Book($id); +// if ((int) $id > 0 && $item->id == $id) { +// return $item; +// } +// throw new Book_Exception_PageNotFound( +// "Wiki book not found (Page id:" . $id . ")"); +// } + +// function Book_Shortcuts_GetBookListCount ($request) +// { +// $count = 20; +// if (array_key_exists('_px_count', $request->REQUEST)) { +// $count = $request->GET['_px_count']; +// if ($count > 20) { +// $count = 20; +// } +// } +// return $count; +// } + +// function Book_Shortcuts_GetPageListCount ($request) +// { +// $count = 20; +// if (array_key_exists('_px_count', $request->GET)) { +// $count = $request->GET['_px_count']; +// if ($count > 20) { +// $count = 20; +// } +// } +// return $count; +// } diff --git a/src/Book/Views.php b/src/Book/Views.php new file mode 100644 index 0000000..25db6eb --- /dev/null +++ b/src/Book/Views.php @@ -0,0 +1,130 @@ + + */ +class Book_Views +{ + + /** + * فهرست کتاب‌ها را تعیین می‌کند. + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function find ($request, $match) + { + // maso, 1394: گرفتن فهرست مناسبی از پیام‌ها + $pag = new Pluf_Paginator(new Book_Book()); + $pag->list_filters = array( + 'id', + 'title' + ); + $list_display = array( + 'title' => __('title'), + 'summary' => __('summary') + ); + $search_fields = array( + 'title', + 'summary' + ); + $sort_fields = array( + 'id', + 'title', + 'creation_date', + 'modif_dtime' + ); + $pag->configure($list_display, $search_fields, $sort_fields); + $pag->setFromRequest($request); + return new Pluf_HTTP_Response_Json($pag->render_object()); + } + + /** + * یک کتاب جدید ایجاد می‌کند. + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function create ($request, $match) + { + // initial page data + $extra = array( + 'user' => $request->user + ); + $form = new Book_Form_BookCreate( + array_merge($request->REQUEST, $request->FILES), $extra); + $book = $form->save(); + $request->user->setMessage( + sprintf(__('new book \'%s\' is created.'), + (string) $book->title)); + return new Pluf_HTTP_Response_Json($book); + } + + /** + * اطلاعات یک کتاب را می‌گیرد + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function get ($request, $match) + { + // تعیین داده‌ها + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // بررسی حق دسترسی + Book_Precondition::userCanAccessBook($request, $book); + // اجرای درخواست + return new Pluf_HTTP_Response_Json($book); + } + + /** + * یک کتاب را به روز می‌کند. + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function update ($request, $match) + { + // تعیین داده‌ها + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // حق دسترسی + Book_Precondition::userCanUpdateBook($request, $book); + // اجرای درخواست + $extra = array( + 'user' => $request->user, + 'book' => $book + ); + $form = new Book_Form_BookUpdate( + array_merge($request->REQUEST, $request->FILES), $extra); + $book = $form->update(); + $request->user->setMessage( + sprintf(__('new book \'%s\' is created.'), + (string) $book->title)); + return new Pluf_HTTP_Response_Json($book); + } + + /** + * یک کتاب را حذف می‌کند. + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function delete ($request, $match) + { + // تعیین داده‌ها + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // بررسی حق دسترسی + Book_Precondition::userCanDeleteBook($request, $book); + // اجرای درخواست + $book2 = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + $book2->delete(); + return new Pluf_HTTP_Response_Json($book); + } +} \ No newline at end of file diff --git a/src/Book/Views/Page.php b/src/Book/Views/Page.php new file mode 100644 index 0000000..62d19ab --- /dev/null +++ b/src/Book/Views/Page.php @@ -0,0 +1,143 @@ + + * @date 1394 + */ +class Book_Views_Page +{ + + /** + * یک صفحه جدید را ایجاد می‌کند + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function create ($request, $match) + { + // تعیین دسترسی + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + Book_Precondition::userCanCreatePage($request, $book); + // اجرای درخواست + $extra = array( + 'user' => $request->user, + 'book' => $book + ); + $form = new Book_Form_PageCreate( + array_merge($request->REQUEST, $request->FILES), $extra); + $page = $form->save(); + $request->user->setMessage( + sprintf(__('new page \'%s\' is created.'), + (string) $page->title)); + // Return response + return new Pluf_HTTP_Response_Json($page); + } + + /** + * یک صفحه را با شناسه تعیین می‌کند + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function get ($request, $match) + { + // تعیین داده‌ها + $page = Pluf_Shortcuts_GetObjectOr404('Book_Page', $match['pageId']); + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // حق دسترسی + Book_Precondition::userCanAccessPage($request, $page, $book); + // اجرای درخواست + return new Pluf_HTTP_Response_Json($page); + } + + /** + * صفحه را به روز می‌کند + * + * @param unknown $request + * @param unknown $match + */ + public function update ($request, $match) + { + // تعیین داده‌ها + $page = Pluf_Shortcuts_GetObjectOr404('Book_Page', $match['pageId']); + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // حق دسترسی + Book_Precondition::userCanUpdatePage($request, $page, $book); + // اجرای درخواست + $extra = array( + 'user' => $request->user, + 'page' => $page + ); + $form = new Book_Form_PageUpdate( + array_merge($request->REQUEST, $request->FILES), $extra); + $page = $form->update(); + return new Pluf_HTTP_Response_Json($page); + } + + /** + * صفحه را حذف می‌کند. + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function delete ($request, $match) + { + // تعیین داده‌ها + $page = Pluf_Shortcuts_GetObjectOr404('Book_Page', $match['pageId']); + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // دسترسی + Book_Precondition::userCanDeletePage($request, $page); + // اجرا + $page2 = new Book_Page($page->id); + $page2->delete(); + return new Pluf_HTTP_Response_Json($page); + } + + /** + * جستجوی صفحه‌ها را انجام می‌دهد + * + * @param unknown $request + * @param unknown $match + * @return Pluf_HTTP_Response_Json + */ + public function find ($request, $match) + { + $book = Pluf_Shortcuts_GetObjectOr404('Book_Book', $match['bookId']); + // maso, 1394: گرفتن فهرست مناسبی از پیام‌ها + $pag = new Pluf_Paginator(new Book_Page()); + $sql = new Pluf_SQL('book=%s', + array( + $book->id, + )); + $pag->forced_where = $sql; + $pag->list_filters = array( + 'id', + 'title' + ); + $list_display = array( + 'title' => __('title'), + 'summary' => __('summary') + ); + $search_fields = array( + 'title', + 'summary', + 'content' + ); + $sort_fields = array( + 'id', + 'title', + 'creation_date', + 'modif_dtime' + ); + $pag->configure($list_display, $search_fields, $sort_fields); + $pag->setFromRequest($request); + return new Pluf_HTTP_Response_Json($pag->render_object()); + } +} \ No newline at end of file diff --git a/src/Book/conf/wiki.translate.php b/src/Book/conf/wiki.translate.php new file mode 100644 index 0000000..f612a85 --- /dev/null +++ b/src/Book/conf/wiki.translate.php @@ -0,0 +1,9 @@ +, YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Pluf Wiki\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-07 21:24+0330\n" +"PO-Revision-Date: 2015-11-07 21:37+0330\n" +"Last-Translator: Mostafa Barmshory \n" +"Language-Team: http://dpq.co.ir \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" +"Language: en\n" +"X-Poedit-SourceCharset: UTF-8\n" + +#: Wiki/Form/PageCreate.php:27 +msgid "empty page" +msgstr "" + +#: Wiki/Form/PageCreate.php:28 Wiki/Form/BookCreate.php:20 +msgid "PageName" +msgstr "" + +#: Wiki/Form/PageCreate.php:32 Wiki/Form/PageUpdate.php:35 +#: Wiki/Form/BookCreate.php:24 Wiki/Form/BookUpdate.php:24 +msgid "Page title" +msgstr "" + +#: Wiki/Form/PageCreate.php:39 Wiki/Form/PageUpdate.php:42 +#: Wiki/Form/BookCreate.php:31 Wiki/Form/BookUpdate.php:31 +msgid "" +"The page name must contains only letters, digits and the dash (-) character." +msgstr "" + +#: Wiki/Form/PageCreate.php:44 Wiki/Form/PageUpdate.php:47 +#: Wiki/Form/BookCreate.php:36 Wiki/Form/BookUpdate.php:36 +msgid "Description" +msgstr "" + +#: Wiki/Form/PageCreate.php:46 Wiki/Form/PageUpdate.php:49 +#: Wiki/Form/BookCreate.php:39 Wiki/Form/BookUpdate.php:39 +msgid "This one line description is displayed in the list of pages." +msgstr "" + +#: Wiki/Form/PageCreate.php:56 Wiki/Form/PageUpdate.php:61 +msgid "Content" +msgstr "" + +#: Wiki/Form/PageCreate.php:67 +msgid "Content type" +msgstr "" + +#: Wiki/Form/PageCreate.php:177 Wiki/Form/PageDelete.php:43 +#: Wiki/Form/PageUpdate.php:192 +msgid "Cannot save the model from an invalid form." +msgstr "" + +#: Wiki/Form/PageDelete.php:23 +msgid "Yes, I understand that the page and all its revisions will be deleted." +msgstr "" + +#: Wiki/Form/PageDelete.php:34 +msgid "You need to confirm the deletion." +msgstr "" + +#: Wiki/Form/PageUpdate.php:72 +msgid "Comment" +msgstr "" + +#: Wiki/Form/PageUpdate.php:74 +msgid "One line to describe the changes you made." +msgstr "" + +#: Wiki/Form/PageUpdate.php:96 +msgid "Labels" +msgstr "" + +#: Wiki/Form/PageUpdate.php:112 +msgid "The title contains invalid characters." +msgstr "" + +#: Wiki/Form/PageUpdate.php:125 +msgid "A page with this title already exists." +msgstr "" + +#: Wiki/Form/PageUpdate.php:172 +#, php-format +msgid "You cannot provide more than label from the %s class to a page." +msgstr "" + +#: Wiki/Form/PageUpdate.php:174 +msgid "You provided an invalid label." +msgstr "" + +#: Wiki/Form/BookCreate.php:19 +msgid "empty summary" +msgstr "" + +#: Wiki/Form/BookCreate.php:52 Wiki/Form/BookUpdate.php:52 +msgid "Cannot save the book from an invalid form." +msgstr "" + +#: Wiki/Views/Page.php:52 +msgid "requeisted page not found." +msgstr "" + +#: Wiki/Views/Page.php:67 +#, php-format +msgid "new page '%s' is created." +msgstr "" + +#: Wiki/Views/Page.php:104 Wiki/Views/Book.php:81 Wiki/Page.php:44 +#: Wiki/Book.php:39 +msgid "title" +msgstr "" + +#: Wiki/Views/Page.php:105 Wiki/Views/Book.php:82 Wiki/Page.php:60 +#: Wiki/Book.php:55 +msgid "summary" +msgstr "" + +#: Wiki/Views/Book.php:25 Wiki/Views/Book.php:55 +#, php-format +msgid "new book '%s' is created." +msgstr "" + +#: Wiki/Page.php:46 Wiki/Book.php:41 +msgid "" +"the title of the page must only contain letters, digits or the dash " +"character. For example: My-new-Wiki-Page." +msgstr "" + +#: Wiki/Page.php:52 Wiki/Book.php:47 +msgid "language" +msgstr "" + +#: Wiki/Page.php:54 +msgid "the language of the page must only contain letters. For example: en." +msgstr "" + +#: Wiki/Page.php:62 Wiki/Book.php:57 +msgid "a one line description of the page content." +msgstr "" + +#: Wiki/Page.php:67 +msgid "content" +msgstr "" + +#: Wiki/Page.php:73 +msgid "content type" +msgstr "" + +#: Wiki/Page.php:75 +msgid "the content type of the page is a mime type. For example: text/plain." +msgstr "" + +#: Wiki/Page.php:80 Wiki/Book.php:62 +msgid "creation date" +msgstr "" + +#: Wiki/Page.php:85 Wiki/Book.php:67 +msgid "modification date" +msgstr "" + +#: Wiki/Page.php:92 Wiki/Book.php:83 +msgid "submitter" +msgstr "" + +#: Wiki/Page.php:98 +msgid "book" +msgstr "" + +#: Wiki/Page.php:105 Wiki/Book.php:90 +msgid "labels" +msgstr "" + +#: Wiki/Page.php:106 Wiki/Book.php:91 +msgid "lables" +msgstr "" + +#: Wiki/Page.php:113 Wiki/Page.php:114 Wiki/Book.php:97 Wiki/Book.php:98 +msgid "categories" +msgstr "" + +#: Wiki/Book.php:49 +msgid "the language of the page must only contain letters. for example: en." +msgstr "" + +#: Wiki/Book.php:75 +msgid "interested users" +msgstr "" + +#: Wiki/Book.php:77 +msgid "" +"interested users will get an email notification when the wiki page is " +"changed." +msgstr "" diff --git a/src/Book/locale/fa/wiki.mo b/src/Book/locale/fa/wiki.mo new file mode 100644 index 0000000..47e6f98 Binary files /dev/null and b/src/Book/locale/fa/wiki.mo differ diff --git a/src/Book/locale/fa/wiki.po b/src/Book/locale/fa/wiki.po new file mode 100644 index 0000000..3c62b76 --- /dev/null +++ b/src/Book/locale/fa/wiki.po @@ -0,0 +1,201 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Pluf Wiki\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-07 21:49+0330\n" +"PO-Revision-Date: 2015-11-07 21:50+0330\n" +"Last-Translator: Mostafa Barmshory \n" +"Language-Team: http://dpq.co.ir \n" +"Language: fa\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" +"X-Poedit-SourceCharset: UTF-8\n" + +#: Wiki/Form/PageCreate.php:27 +msgid "empty page" +msgstr "صفحه خالی" + +#: Wiki/Form/PageCreate.php:28 +msgid "page name" +msgstr "نام صفحه" + +#: Wiki/Form/PageCreate.php:32 Wiki/Form/PageUpdate.php:35 +#: Wiki/Form/BookUpdate.php:25 +msgid "page title" +msgstr "عنوان صفحه" + +#: Wiki/Form/PageCreate.php:39 Wiki/Form/PageUpdate.php:42 +#: Wiki/Form/BookCreate.php:31 Wiki/Form/BookUpdate.php:32 +msgid "" +"the page name must contains only letters, digits and the dash (-) character" +msgstr "" + +#: Wiki/Form/PageCreate.php:44 Wiki/Form/PageUpdate.php:47 +msgid "Description" +msgstr "" + +#: Wiki/Form/PageCreate.php:46 Wiki/Form/PageUpdate.php:49 +#: Wiki/Form/BookCreate.php:39 Wiki/Form/BookUpdate.php:40 +msgid "this one line description is displayed in the list of pages" +msgstr "" + +#: Wiki/Form/PageCreate.php:56 Wiki/Form/PageUpdate.php:61 Wiki/Page.php:67 +msgid "content" +msgstr "" + +#: Wiki/Form/PageCreate.php:67 Wiki/Page.php:73 +msgid "content type" +msgstr "" + +#: Wiki/Form/PageCreate.php:177 Wiki/Form/PageDelete.php:43 +#: Wiki/Form/PageUpdate.php:192 +msgid "cannot save the model from an invalid form" +msgstr "" + +#: Wiki/Form/PageDelete.php:23 +msgid "yes, I understand that the page and all its revisions will be deleted" +msgstr "" + +#: Wiki/Form/PageDelete.php:34 +msgid "you need to confirm the deletion" +msgstr "" + +#: Wiki/Form/PageUpdate.php:72 +msgid "comment" +msgstr "" + +#: Wiki/Form/PageUpdate.php:74 +msgid "one line to describe the changes you made" +msgstr "" + +#: Wiki/Form/PageUpdate.php:96 Wiki/Page.php:105 Wiki/Book.php:90 +msgid "labels" +msgstr "" + +#: Wiki/Form/PageUpdate.php:112 +msgid "the title contains invalid characters" +msgstr "" + +#: Wiki/Form/PageUpdate.php:125 +msgid "a page with this title already exists" +msgstr "" + +#: Wiki/Form/PageUpdate.php:172 +#, php-format +msgid "you cannot provide more than label from the %s class to a page" +msgstr "" + +#: Wiki/Form/PageUpdate.php:174 +msgid "you provided an invalid label" +msgstr "" + +#: Wiki/Form/BookCreate.php:19 +msgid "empty summary" +msgstr "" + +#: Wiki/Form/BookCreate.php:20 +msgid "PageName" +msgstr "" + +#: Wiki/Form/BookCreate.php:24 +msgid "حage title" +msgstr "" + +#: Wiki/Form/BookCreate.php:36 Wiki/Form/BookUpdate.php:37 +msgid "description" +msgstr "" + +#: Wiki/Form/BookCreate.php:52 Wiki/Form/BookUpdate.php:53 +msgid "cannot save the book from an invalid form" +msgstr "" + +#: Wiki/Views/Page.php:52 +msgid "requeisted page not found." +msgstr "" + +#: Wiki/Views/Page.php:67 +#, php-format +msgid "new page '%s' is created." +msgstr "" + +#: Wiki/Views/Page.php:104 Wiki/Views/Book.php:81 Wiki/Page.php:44 +#: Wiki/Book.php:39 +msgid "title" +msgstr "" + +#: Wiki/Views/Page.php:105 Wiki/Views/Book.php:82 Wiki/Page.php:60 +#: Wiki/Book.php:55 +msgid "summary" +msgstr "" + +#: Wiki/Views/Book.php:25 Wiki/Views/Book.php:55 +#, php-format +msgid "new book '%s' is created." +msgstr "" + +#: Wiki/Page.php:46 Wiki/Book.php:41 +msgid "" +"the title of the page must only contain letters, digits or the dash " +"character. For example: My-new-Wiki-Page." +msgstr "" + +#: Wiki/Page.php:52 Wiki/Book.php:47 +msgid "language" +msgstr "" + +#: Wiki/Page.php:54 +msgid "the language of the page must only contain letters. For example: en." +msgstr "" + +#: Wiki/Page.php:62 Wiki/Book.php:57 +msgid "a one line description of the page content." +msgstr "" + +#: Wiki/Page.php:75 +msgid "the content type of the page is a mime type. For example: text/plain." +msgstr "" + +#: Wiki/Page.php:80 Wiki/Book.php:62 +msgid "creation date" +msgstr "" + +#: Wiki/Page.php:85 Wiki/Book.php:67 +msgid "modification date" +msgstr "" + +#: Wiki/Page.php:92 Wiki/Book.php:83 +msgid "submitter" +msgstr "" + +#: Wiki/Page.php:98 +msgid "book" +msgstr "" + +#: Wiki/Page.php:106 Wiki/Book.php:91 +msgid "lables" +msgstr "" + +#: Wiki/Page.php:113 Wiki/Page.php:114 Wiki/Book.php:97 Wiki/Book.php:98 +msgid "categories" +msgstr "" + +#: Wiki/Book.php:49 +msgid "the language of the page must only contain letters. for example: en." +msgstr "" + +#: Wiki/Book.php:75 +msgid "interested users" +msgstr "" + +#: Wiki/Book.php:77 +msgid "" +"interested users will get an email notification when the wiki page is " +"changed." +msgstr "" diff --git a/src/Book/locale/wiki.pot b/src/Book/locale/wiki.pot new file mode 100644 index 0000000..d701988 --- /dev/null +++ b/src/Book/locale/wiki.pot @@ -0,0 +1,200 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-07 21:49+0330\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: Wiki/Form/PageCreate.php:27 +msgid "empty page" +msgstr "" + +#: Wiki/Form/PageCreate.php:28 +msgid "page name" +msgstr "" + +#: Wiki/Form/PageCreate.php:32 Wiki/Form/PageUpdate.php:35 +#: Wiki/Form/BookUpdate.php:25 +msgid "page title" +msgstr "" + +#: Wiki/Form/PageCreate.php:39 Wiki/Form/PageUpdate.php:42 +#: Wiki/Form/BookCreate.php:31 Wiki/Form/BookUpdate.php:32 +msgid "" +"the page name must contains only letters, digits and the dash (-) character" +msgstr "" + +#: Wiki/Form/PageCreate.php:44 Wiki/Form/PageUpdate.php:47 +msgid "Description" +msgstr "" + +#: Wiki/Form/PageCreate.php:46 Wiki/Form/PageUpdate.php:49 +#: Wiki/Form/BookCreate.php:39 Wiki/Form/BookUpdate.php:40 +msgid "this one line description is displayed in the list of pages" +msgstr "" + +#: Wiki/Form/PageCreate.php:56 Wiki/Form/PageUpdate.php:61 Wiki/Page.php:67 +msgid "content" +msgstr "" + +#: Wiki/Form/PageCreate.php:67 Wiki/Page.php:73 +msgid "content type" +msgstr "" + +#: Wiki/Form/PageCreate.php:177 Wiki/Form/PageDelete.php:43 +#: Wiki/Form/PageUpdate.php:192 +msgid "cannot save the model from an invalid form" +msgstr "" + +#: Wiki/Form/PageDelete.php:23 +msgid "yes, I understand that the page and all its revisions will be deleted" +msgstr "" + +#: Wiki/Form/PageDelete.php:34 +msgid "you need to confirm the deletion" +msgstr "" + +#: Wiki/Form/PageUpdate.php:72 +msgid "comment" +msgstr "" + +#: Wiki/Form/PageUpdate.php:74 +msgid "one line to describe the changes you made" +msgstr "" + +#: Wiki/Form/PageUpdate.php:96 Wiki/Page.php:105 Wiki/Book.php:90 +msgid "labels" +msgstr "" + +#: Wiki/Form/PageUpdate.php:112 +msgid "the title contains invalid characters" +msgstr "" + +#: Wiki/Form/PageUpdate.php:125 +msgid "a page with this title already exists" +msgstr "" + +#: Wiki/Form/PageUpdate.php:172 +#, php-format +msgid "you cannot provide more than label from the %s class to a page" +msgstr "" + +#: Wiki/Form/PageUpdate.php:174 +msgid "you provided an invalid label" +msgstr "" + +#: Wiki/Form/BookCreate.php:19 +msgid "empty summary" +msgstr "" + +#: Wiki/Form/BookCreate.php:20 +msgid "PageName" +msgstr "" + +#: Wiki/Form/BookCreate.php:24 +msgid "حage title" +msgstr "" + +#: Wiki/Form/BookCreate.php:36 Wiki/Form/BookUpdate.php:37 +msgid "description" +msgstr "" + +#: Wiki/Form/BookCreate.php:52 Wiki/Form/BookUpdate.php:53 +msgid "cannot save the book from an invalid form" +msgstr "" + +#: Wiki/Views/Page.php:52 +msgid "requeisted page not found." +msgstr "" + +#: Wiki/Views/Page.php:67 +#, php-format +msgid "new page '%s' is created." +msgstr "" + +#: Wiki/Views/Page.php:104 Wiki/Views/Book.php:81 Wiki/Page.php:44 +#: Wiki/Book.php:39 +msgid "title" +msgstr "" + +#: Wiki/Views/Page.php:105 Wiki/Views/Book.php:82 Wiki/Page.php:60 +#: Wiki/Book.php:55 +msgid "summary" +msgstr "" + +#: Wiki/Views/Book.php:25 Wiki/Views/Book.php:55 +#, php-format +msgid "new book '%s' is created." +msgstr "" + +#: Wiki/Page.php:46 Wiki/Book.php:41 +msgid "" +"the title of the page must only contain letters, digits or the dash " +"character. For example: My-new-Wiki-Page." +msgstr "" + +#: Wiki/Page.php:52 Wiki/Book.php:47 +msgid "language" +msgstr "" + +#: Wiki/Page.php:54 +msgid "the language of the page must only contain letters. For example: en." +msgstr "" + +#: Wiki/Page.php:62 Wiki/Book.php:57 +msgid "a one line description of the page content." +msgstr "" + +#: Wiki/Page.php:75 +msgid "the content type of the page is a mime type. For example: text/plain." +msgstr "" + +#: Wiki/Page.php:80 Wiki/Book.php:62 +msgid "creation date" +msgstr "" + +#: Wiki/Page.php:85 Wiki/Book.php:67 +msgid "modification date" +msgstr "" + +#: Wiki/Page.php:92 Wiki/Book.php:83 +msgid "submitter" +msgstr "" + +#: Wiki/Page.php:98 +msgid "book" +msgstr "" + +#: Wiki/Page.php:106 Wiki/Book.php:91 +msgid "lables" +msgstr "" + +#: Wiki/Page.php:113 Wiki/Page.php:114 Wiki/Book.php:97 Wiki/Book.php:98 +msgid "categories" +msgstr "" + +#: Wiki/Book.php:49 +msgid "the language of the page must only contain letters. for example: en." +msgstr "" + +#: Wiki/Book.php:75 +msgid "interested users" +msgstr "" + +#: Wiki/Book.php:77 +msgid "" +"interested users will get an email notification when the wiki page is " +"changed." +msgstr "" diff --git a/src/Book/module.json b/src/Book/module.json new file mode 100644 index 0000000..848344d --- /dev/null +++ b/src/Book/module.json @@ -0,0 +1,10 @@ +{ + "name": "Wiki", + "version": "1.0.0", + "title": "Wiki framework", + "model": [ + "Book_Book", + "Book_Page" + ], + "permisson": [] +} \ No newline at end of file diff --git a/src/Book/relations.php b/src/Book/relations.php new file mode 100644 index 0000000..d45a573 --- /dev/null +++ b/src/Book/relations.php @@ -0,0 +1,16 @@ + array( + 'relate_to' => array( + 'Book_Book', + 'Pluf_User' + ), + 'relate_to_many' => array() + ), + 'Book_Book' => array( + 'relate_to' => array( + 'Pluf_User' + ), + 'relate_to_many' => array() + ) +); diff --git a/src/Book/urls.php b/src/Book/urls.php new file mode 100644 index 0000000..1e07fbc --- /dev/null +++ b/src/Book/urls.php @@ -0,0 +1,85 @@ + '#^/(?P\d+)/page/find$#', + 'model' => 'Book_Views_Page', + 'method' => 'find', + 'http-method' => 'GET' + ), + array( + 'regex' => '#^/(?P\d+)/page/new$#', + 'model' => 'Book_Views_Page', + 'method' => 'create', + 'precond' => array( + 'Pluf_Precondition::loginRequired', + 'Book_Precondition::userCanCreatePage' + ), + 'http-method' => 'POST' + ), + array( + 'regex' => '#^/(?P\d+)/page/(?P\d+)$#', + 'model' => 'Book_Views_Page', + 'method' => 'get', + 'http-method' => 'GET' + ), + array( + 'regex' => '#^/(?P\d+)/page/(?P\d+)$#', + 'model' => 'Book_Views_Page', + 'method' => 'delete', + 'http-method' => 'DELETE' + ), + array( + 'regex' => '#^/(?P\d+)/page/(?P\d+)$#', + 'model' => 'Book_Views_Page', + 'method' => 'update', + 'http-method' => 'POST' + ), + + /* + * کار با کتابها + */ + array( + 'regex' => '#^/find$#', + 'model' => 'Book_Views', + 'method' => 'find', + 'http-method' => 'GET' + ), + array( + 'regex' => '#^/new$#', + 'model' => 'Book_Views', + 'method' => 'create', + 'precond' => array( + 'Pluf_Precondition::loginRequired' + ), + 'http-method' => 'POST' + ), + array( + 'regex' => '#^/(?P\d+)$#', + 'model' => 'Book_Views', + 'method' => 'get', + 'http-method' => 'GET' + ), + array( + 'regex' => '#^/(?P\d+)$#', + 'model' => 'Book_Views', + 'method' => 'update', + 'http-method' => 'POST', + 'precond' => array( + 'Pluf_Precondition::loginRequired' + ) + ), + array( + 'regex' => '#^/(?P\d+)$#', + 'model' => 'Book_Views', + 'method' => 'delete', + 'http-method' => 'DELETE', + 'precond' => array( + 'Pluf_Precondition::loginRequired' + ) + ) +); + + diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..5c95cf7 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +/clover.xml +/tmp diff --git a/tests/conf/config.sqlite.php b/tests/conf/config.sqlite.php new file mode 100644 index 0000000..4934ab0 --- /dev/null +++ b/tests/conf/config.sqlite.php @@ -0,0 +1,75 @@ +. + */ +$cfg = array(); +$cfg['test'] = false; +$cfg['timezone'] = 'Europe/Berlin'; + +// Set the debug variable to true to force the recompilation of all +// the templates each time during development +$cfg['debug'] = true; +$cfg['installed_apps'] = array( + 'Pluf' +); + +// Temporary folder where the script is writing the compiled templates, +// cached data and other temporary resources. +// It must be writeable by your webserver instance. +// It is mandatory if you are using the template system. +$cfg['tmp_folder'] = dirname(__FILE__) . '/../tmp'; + +// The folder in which the templates of the application are located. +$cfg['templates_folder'] = array( + dirname(__FILE__) . '/../templates' +); + +$cfg['pluf_use_rowpermission'] = true; + +// Default mimetype of the document your application is sending. +// It can be overwritten for a given response if needed. +$cfg['mimetype'] = 'text/html'; + +// Some views for testing. +$cfg['app_views'] = dirname(__FILE__) . '/views.php'; + +// Default database configuration. The database defined here will be +// directly accessible from Pluf::db() of course it is still possible +// to open any other number of database connections through Pluf_DB +$cfg['db_login'] = 'testpluf'; +$cfg['db_password'] = 'testpluf'; +$cfg['db_server'] = 'localhost'; +$cfg['db_database'] = dirname(__FILE__) . '/../tmp/tmp.sqlite.db'; + +$cfg['app_base'] = '/testapp'; +$cfg['url_format'] = 'simple'; + +$cfg['template_tags'] = array( + 'mytag' => 'Pluf_Template_Tag_Mytag' +); + +// Must be shared by all the installed_apps and the core framework. +// That way you can have several installations of the core framework. +$cfg['db_table_prefix'] = 'pluf_unit_tests_'; + +// Starting version 4.1 of MySQL the utf-8 support is "correct". +// The reason of the db_version for MySQL is only for that. +$cfg['db_version'] = '5.0'; +$cfg['db_engine'] = 'SQLite'; + +return $cfg; + diff --git a/tests/conf/pluf.config.php b/tests/conf/pluf.config.php new file mode 100644 index 0000000..4934ab0 --- /dev/null +++ b/tests/conf/pluf.config.php @@ -0,0 +1,75 @@ +. + */ +$cfg = array(); +$cfg['test'] = false; +$cfg['timezone'] = 'Europe/Berlin'; + +// Set the debug variable to true to force the recompilation of all +// the templates each time during development +$cfg['debug'] = true; +$cfg['installed_apps'] = array( + 'Pluf' +); + +// Temporary folder where the script is writing the compiled templates, +// cached data and other temporary resources. +// It must be writeable by your webserver instance. +// It is mandatory if you are using the template system. +$cfg['tmp_folder'] = dirname(__FILE__) . '/../tmp'; + +// The folder in which the templates of the application are located. +$cfg['templates_folder'] = array( + dirname(__FILE__) . '/../templates' +); + +$cfg['pluf_use_rowpermission'] = true; + +// Default mimetype of the document your application is sending. +// It can be overwritten for a given response if needed. +$cfg['mimetype'] = 'text/html'; + +// Some views for testing. +$cfg['app_views'] = dirname(__FILE__) . '/views.php'; + +// Default database configuration. The database defined here will be +// directly accessible from Pluf::db() of course it is still possible +// to open any other number of database connections through Pluf_DB +$cfg['db_login'] = 'testpluf'; +$cfg['db_password'] = 'testpluf'; +$cfg['db_server'] = 'localhost'; +$cfg['db_database'] = dirname(__FILE__) . '/../tmp/tmp.sqlite.db'; + +$cfg['app_base'] = '/testapp'; +$cfg['url_format'] = 'simple'; + +$cfg['template_tags'] = array( + 'mytag' => 'Pluf_Template_Tag_Mytag' +); + +// Must be shared by all the installed_apps and the core framework. +// That way you can have several installations of the core framework. +$cfg['db_table_prefix'] = 'pluf_unit_tests_'; + +// Starting version 4.1 of MySQL the utf-8 support is "correct". +// The reason of the db_version for MySQL is only for that. +$cfg['db_version'] = '5.0'; +$cfg['db_engine'] = 'SQLite'; + +return $cfg; + diff --git a/tests/coverage-checker.php b/tests/coverage-checker.php new file mode 100644 index 0000000..d3e0566 --- /dev/null +++ b/tests/coverage-checker.php @@ -0,0 +1,31 @@ +xpath('//metrics'); +$totalElements = 0; +$checkedElements = 0; + +foreach ($metrics as $metric) { + $totalElements += (int) $metric['elements']; + $checkedElements += (int) $metric['coveredelements']; +} + +$coverage = ($checkedElements / $totalElements) * 100; + +if ($coverage < $percentage) { + echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL; + exit(1); +} + +echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL; diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..99cccd1 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,21 @@ + + + + + ./Cms/ + ./Cms_Contetn/ + ./Cms_REST/ + ./Cms_Monitor/ + + + + + + + ../src + + + + + + \ No newline at end of file diff --git a/tests/run.php b/tests/run.php new file mode 100755 index 0000000..a7eb826 --- /dev/null +++ b/tests/run.php @@ -0,0 +1,59 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main'); + +$files = array( + __DIR__ . '/../vendor/autoload.php', + __DIR__ . '/../../../autoload.php' +); + +foreach ($files as $file) { + if (file_exists($file)) { + require $file; + define('PHPUNIT_COMPOSER_INSTALL', $file); + break; + } +} + +if (! defined('PHPUNIT_COMPOSER_INSTALL')) { + die( + 'You need to set up the project dependencies using the following commands:' . + PHP_EOL . 'curl -s http://getcomposer.org/installer | php' . + PHP_EOL . 'php composer.phar install' . PHP_EOL); +} + +PHPUnit_TextUI_Command::main();