public function test_multilingual_setting_an_specific_locale() { $Article = new Article(); $Article->set('headline', 'Happiness on developers boost productivity', 'en'); $Article->set('headline', 'La felicidad de los programadores mejora la productivdad', 'es'); $this->assertEqual($Article->en_headline, 'Happiness on developers boost productivity'); $this->assertEqual($Article->es_headline, 'La felicidad de los programadores mejora la productivdad'); }
function test_multilingual_setting() { $Article = new Article(); $Article->set('headline', array('en' => 'New PHP Framework released', 'es' => 'Se ha liberado un nuevo Framework para PHP')); $Article->set('body', array('en' => 'The Akelos Framework has been released...', 'es' => 'Un equipo de programadores españoles ha lanzado un entorno de desarrollo para PHP...')); $Article->set('excerpt_limit', array('en' => 7, 'es' => 3)); $this->assertTrue($Article->save()); $Article = $Article->find($Article->getId()); $this->assertEqual($Article->get('en_headline'), 'New PHP Framework released'); $this->assertEqual($Article->get('es_body'), 'Un equipo de programadores españoles ha lanzado un entorno de desarrollo para PHP...'); $this->assertEqual($Article->get('en_excerpt_limit'), 7); }
/** * test that saveAll still behaves like previous versions (does not necessarily need a first argument) * * @return void */ public function testSaveAllWithSet() { $this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag'); $data = array('Article' => array('user_id' => 1, 'title' => 'Article Has and belongs to Many Tags'), 'Tag' => array('Tag' => array(1, 2)), 'Comment' => array(array('comment' => 'Article comment', 'user_id' => 1))); $Article = new Article(); $Article->set($data); $result = $Article->saveAll(); $this->assertFalse(empty($result)); }
/** * testDeleteAll method * * @return void */ public function testDeleteAll() { $this->loadFixtures('Article'); $TestModel = new Article(); $data = array('Article' => array('user_id' => 2, 'id' => 4, 'title' => 'Fourth Article', 'published' => 'N')); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $data = array('Article' => array('user_id' => 2, 'id' => 5, 'title' => 'Fifth Article', 'published' => 'Y')); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $data = array('Article' => array('user_id' => 1, 'id' => 6, 'title' => 'Sixth Article', 'published' => 'N')); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'), 'order' => array('Article.id' => 'ASC'))); $expected = array(array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y')), array('Article' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'published' => 'Y')), array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y')), array('Article' => array('id' => 4, 'user_id' => 2, 'title' => 'Fourth Article', 'published' => 'N')), array('Article' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Article', 'published' => 'Y')), array('Article' => array('id' => 6, 'user_id' => 1, 'title' => 'Sixth Article', 'published' => 'N'))); $this->assertEquals($expected, $result); $result = $TestModel->deleteAll(array('Article.published' => 'N')); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'), 'order' => array('Article.id' => 'ASC'))); $expected = array(array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y')), array('Article' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'published' => 'Y')), array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y')), array('Article' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Article', 'published' => 'Y'))); $this->assertEquals($expected, $result); $data = array('Article.user_id' => array(2, 3)); $result = $TestModel->deleteAll($data, true, true); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'), 'order' => array('Article.id' => 'ASC'))); $expected = array(array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y')), array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y'))); $this->assertEquals($expected, $result); $result = $TestModel->deleteAll(array('Article.user_id' => 999)); $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); }
/** * testSaveHabtm method * * @return void */ public function testSaveHabtm() { $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); $TestModel = new Article(); $result = $TestModel->findById(2); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), 'Comment' => array(array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31')), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $data = array('Article' => array('id' => '2', 'title' => 'New Second Article'), 'Tag' => array('Tag' => array(1, 2))); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'))); $this->assertEquals($expected, $result); $data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3))); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array(1, 2, 3))); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array())); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $data = array('Tag' => array('Tag' => '')); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array()); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array(2, 3))); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article')); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'))); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article Title')); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article Title', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'))); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array(2, 3)), 'Article' => array('id' => '2', 'title' => 'Changed Second Article')); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $data = array('Tag' => array('Tag' => array(1, 3)), 'Article' => array('id' => '2')); $result = $TestModel->set($data); $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $data = array('Article' => array('id' => 10, 'user_id' => '2', 'title' => 'New Article With Tags and fieldList', 'body' => 'New Article Body with Tags and fieldList', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), 'Tag' => array('Tag' => array(1, 2, 3))); $result = $TestModel->create() && $TestModel->save($data, true, array('user_id', 'title', 'published')); $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->read(); $expected = array('Article' => array('id' => 4, 'user_id' => 2, 'title' => 'New Article With Tags and fieldList', 'body' => '', 'published' => 'N', 'created' => '', 'updated' => ''), 'Tag' => array(0 => array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), 1 => array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), 2 => array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $this->loadFixtures('JoinA', 'JoinC', 'JoinAC', 'JoinB', 'JoinAB'); $TestModel = new JoinA(); $TestModel->hasBelongsToMany = array('JoinC' => array('unique' => true)); $data = array('JoinA' => array('id' => 1, 'name' => 'Join A 1', 'body' => 'Join A 1 Body'), 'JoinC' => array('JoinC' => array(array('join_c_id' => 2, 'other' => 'new record'), array('join_c_id' => 3, 'other' => 'new record')))); $TestModel->save($data); $result = $TestModel->read(null, 1); $expected = array(4, 5); $this->assertEquals($expected, Set::extract('/JoinC/JoinAsJoinC/id', $result)); $expected = array('new record', 'new record'); $this->assertEquals($expected, Set::extract('/JoinC/JoinAsJoinC/other', $result)); }
/** * Test that 'required' and 'on' are not conflicting * * @return void */ public function testOnRequiredConflictValidation() { $this->loadFixtures('Article'); $Article = new Article(); // no title field present $data = array('Article' => array('body' => 'Extra Fields Body', 'published' => '1')); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'create', 'on' => 'create'))); $Article->create($data); $this->assertFalse($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'update', 'on' => 'create'))); $Article->create($data); $this->assertTrue($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'create', 'on' => 'update'))); $Article->create($data); $this->assertTrue($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'update', 'on' => 'update'))); $Article->create($data); $this->assertTrue($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'create', 'on' => 'create'))); $Article->save(null, array('validate' => false)); $data['Article']['id'] = $Article->id; $Article->set($data); $this->assertTrue($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'update', 'on' => 'create'))); $Article->set($data); $this->assertTrue($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'create', 'on' => 'update'))); $Article->set($data); $this->assertTrue($Article->validates()); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => 'update', 'on' => 'update'))); $Article->set($data); $this->assertFalse($Article->validates()); }
/** * testDeleteAll method * * @access public * @return void */ public function testDeleteAll() { $this->loadFixtures('Article'); $TestModel = new Article(); $data = array('Article' => array('user_id' => 2, 'id' => 4, 'title' => 'Fourth Article', 'published' => 'N')); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $data = array('Article' => array('user_id' => 2, 'id' => 5, 'title' => 'Fifth Article', 'published' => 'Y')); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $data = array('Article' => array('user_id' => 1, 'id' => 6, 'title' => 'Sixth Article', 'published' => 'N')); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'))); $expected = array(array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y')), array('Article' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'published' => 'Y')), array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y')), array('Article' => array('id' => 4, 'user_id' => 2, 'title' => 'Fourth Article', 'published' => 'N')), array('Article' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Article', 'published' => 'Y')), array('Article' => array('id' => 6, 'user_id' => 1, 'title' => 'Sixth Article', 'published' => 'N'))); $this->assertEqual($expected, $result); $result = $TestModel->deleteAll(array('Article.published' => 'N')); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'))); $expected = array(array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y')), array('Article' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'published' => 'Y')), array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y')), array('Article' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Article', 'published' => 'Y'))); $this->assertEqual($expected, $result); $data = array('Article.user_id' => array(2, 3)); $result = $TestModel->deleteAll($data, true, true); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'))); $expected = array(array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y')), array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y'))); $this->assertEqual($expected, $result); $result = $TestModel->deleteAll(array('Article.user_id' => 999)); $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); $this->expectError(); ob_start(); $result = $TestModel->deleteAll(array('Article.non_existent_field' => 999)); ob_get_clean(); $this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s'); }
/** * Test for 'on' => [create|update] in validation rules. * * @return void */ function testStateValidation() { $this->loadFixtures('Article'); $Article = new Article(); $data = array('Article' => array('title' => '', 'body' => 'Extra Fields Body', 'published' => '1')); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'on' => 'create'))); $Article->create($data); $this->assertFalse($Article->validates()); $Article->save(null, array('validate' => false)); $data['Article']['id'] = $Article->id; $Article->set($data); $this->assertTrue($Article->validates()); unset($data['Article']['id']); $Article->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'on' => 'update'))); $Article->create($data); $this->assertTrue($Article->validates()); $Article->save(null, array('validate' => false)); $data['Article']['id'] = $Article->id; $Article->set($data); $this->assertFalse($Article->validates()); }
<?php header('Content-Type: text/plain; charset=utf-8'); require_once __DIR__ . '/autoload.php'; require_once __DIR__ . '/classes.php'; use Orange\Database\Connection; $config = json_decode(file_get_contents(__DIR__ . '/config.json'), true); try { $connection = new Connection($config); // Initialize connection Article::install(); User::install(); $user = new User('login', 'admin'); if (!$user->id) { $data = array('login' => 'admin', 'name' => 'Administrator', 'email' => '*****@*****.**', 'status' => true); $user->setData($data)->save(); } $article = new Article(); $article->set('title', 'My article number one')->set('content', 'Text of my first article')->set('user_id', $user->id)->save(); } catch (\Orange\Database\DBException $e) { echo 'Orange database exception: ' . $e->getMessage() . (($query = $e->getQuery()) ? ". Query:\n" . $query . "\n" . $e->getTraceAsString() . "\n" : ''); }
/** * Override modResourceCreateProcessor::beforeSave to provide archiving * * {@inheritDoc} * @return boolean */ public function beforeSave() { $beforeSave = parent::beforeSave(); if (!$this->parentResource) { $this->parentResource = $this->object->getOne('Parent'); } if ($this->object->get('published')) { if (!$this->setArchiveUri()) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to set URI for new Article.'); } } /** @var ArticlesContainer $container */ $container = $this->modx->getObject('ArticlesContainer', $this->object->get('parent')); if ($container) { $settings = $container->getProperties('articles'); $this->object->setProperties($settings, 'articles'); $this->object->set('richtext', !isset($settings['articlesRichtext']) || !empty($settings['articlesRichtext'])); } $this->isPublishing = $this->object->isDirty('published') && $this->object->get('published'); return $beforeSave; }
/** * Override modResourceUpdateProcessor::beforeSave to provide archiving * * {@inheritDoc} * @return boolean */ public function beforeSave() { $afterSave = parent::beforeSave(); $container = $this->modx->getObject('ArticlesContainer', $this->object->get('parent')); if ($this->object->get('published') && ($this->object->isDirty('alias') || $this->object->isDirty('published'))) { if (!$this->setArchiveUri()) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to set date URI.'); } } else { if ($this->object->get('pub_date') && $this->object->isDirty('pub_date') || $this->object->isDirty('pub_date')) { if (!$this->setArchiveUri()) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to set date URI pub_date.'); } } else { if (!$this->object->get('published') && !$this->object->get('pub_date')) { // we need to always do this because the url may have been set previously by pub_date /*$containerUri = $container->get('uri'); if (empty($containerUri)) { $containerUri = $container->get('alias'); }*/ $uri = rtrim($this->object->get('alias')); $this->object->set('uri', $uri); $this->object->set('uri_override', true); } } } /** @var ArticlesContainer $container */ if ($container) { $this->object->setProperties($container->getProperties('articles'), 'articles'); } $this->isPublishing = $this->object->isDirty('published') && $this->object->get('published'); return $afterSave; }
function genererRss() { $article = new Article(); $article->set('pageNews', 'oui'); $arch = new Archiviste(); $articles = $arch->restituer($article); $rssGen = new RssGen(); $rssGen->setArtList($articles); $rssGen->generer(); }