/** * Generate the URL XML * * @param sfSympalContent $content * @return string $xml */ protected function _generateUrlXml(sfSympalContent $content) { return sprintf(' <url> <loc> %s </loc> </url>', $content->getUrl(array('absolute' => true))); }
/** * Set the current sfSympalContent instance for this sympal context * * @param sfSympalContent $content * @return void */ public function setCurrentContent(sfSympalContent $content) { $this->_currentContent = $content; if (!$this->_site) { $this->_site = $content->getSite(); } $this->_dispatcher->notify(new sfEvent($this->_currentContent, 'sympal.content.set_content')); }
/** * Set the current sfSympalContent instance for this sympal context * * @param sfSympalContent $content * @return void */ public function setCurrentContent(sfSympalContent $content) { $this->_currentContent = $content; if (!$this->_site) { $this->_site = $content->getSite(); } if ($menuItem = $content->getMenuItem()) { $this->_currentMenuItem = $menuItem; } }
/** * Check if this user has access to view the given content * * @param sfSympalContent $content * @return boolean */ public function hasAccessToViewContent($content) { $access = true; $allPermissions = $content->getAllPermissions(); if ($this->isAuthenticated() && !$this->hasCredential($allPermissions)) { $access = false; } if (!$this->isAuthenticated() && !empty($allPermissions)) { $access = false; } return $access; }
function get_sympal_content_slot_editor(sfSympalContent $content, sfSympalContentSlot $slot, $options = array()) { $content->setEditableSlotsExistOnPage(true); $slot->setContentRenderedFor($content); $name = $slot->getName(); $isColumn = $slot->getIsColumn(); $form = $slot->getEditForm(); $renderedValue = $slot->render(); if (!$renderedValue && sfSympalContext::getInstance()->shouldLoadFrontendEditor()) { $renderedValue = __('[Double click to enable inline edit mode.]'); } return ' <span title="' . __('[Double click to enable inline edit mode.]') . '" id="sympal_content_slot_' . $slot->getId() . '" class="sympal_content_slot"> <input type="hidden" class="content_slot_id" value="' . $slot->getId() . '" /> <input type="hidden" class="content_id" value="' . $slot->getContentRenderedFor()->getId() . '" /> <span class="editor">' . get_partial('sympal_edit_slot/slot_editor', array('form' => $form, 'contentSlot' => $slot)) . '</span> <span class="value toggle_edit_mode">' . $renderedValue . '</span> </span>'; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $database = $databaseManager->getDatabase($arguments['database']); $conn = $database->getDoctrineConnection(); $data = $conn->fetchAll('SELECT * FROM ' . $arguments['table']); $model = $arguments['model']; $modelTable = Doctrine_Core::getTable($model); $isContentType = $modelTable->hasTemplate('sfSympalContentType'); foreach ($data as $row) { if ($isContentType) { $record = sfSympalContent::createNew($model); $record->CreatedBy = Doctrine_Core::getTable(sfSympalConfig::get('user_model'))->findOneByIsSuperAdmin(true); $record->getRecord()->fromArray($row); $record->date_published = new Doctrine_Expression('NOW()'); $record->slug = (string) $record; } else { $record = new $model(); $record->fromArray($row); } $record->save(); } }
<?php /** * Testing the sympal_content actions class */ $app = 'sympal'; require_once dirname(__FILE__) . '/../../bootstrap/functional.php'; $browser = new sfSympalTestFunctional(new sfBrowser()); $browser->signinAsAdmin(); $types = Doctrine_Core::getTable('sfSympalContentType')->getAllContentTypes(); $pageType = Doctrine_Core::getTable('sfSympalContentType')->findOneBySlug('page'); $admin = Doctrine_Core::getTable('sfGuardUser')->findOneByUsername('admin'); $contents = Doctrine_Core::getTable('sfSympalContent')->createQuery()->execute(); $content = new sfSympalContent(); $content->setType($pageType); $contentForm = new sfSympalContentForm($content); $browser->info('1 - Test the new action')->info(' 1.1 - Going to the new action directly displays a menu of the content types')->get('/admin/content/manage/new')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'new')->end()->isForwardedTo('sympal_content', 'chooseNewType')->with('response')->begin()->isStatusCode(200)->checkElement('h1', '/Add new content/')->checkElement('ul.new-content-type li', 3)->end()->info(sprintf(' 1.2 - Click on the %s new content', $pageType->name))->click('Create ' . $pageType->label)->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'create_type')->isParameter('type', $pageType->id)->end()->with('response')->begin()->isStatusCode(200)->checkElement('h1', 'Create New ' . $pageType->label)->checkForm($contentForm)->end()->info(' 1.3 - Create a new piece of content')->click('Save')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'create')->end()->with('form')->begin()->hasErrors(1)->isError('TypeForm[title]')->end()->click('Save', array('sf_sympal_content' => array('page_title' => 'test page title', 'TypeForm' => array('title' => 'New page title')))); $createdContent = Doctrine_Core::getTable('sfSympalContent')->findOneByPageTitle('test page title'); $browser->info(' 1.4 - See that the sfSympalContent and sfSympalPage entries were created')->with('doctrine')->begin()->check('sfSympalContent', array(), count($contents) + 1)->check('sfSympalContent', array('content_type_id' => $pageType->id, 'created_by_id' => $admin->id, 'page_title' => 'test page title'))->check('sfSympalPage', array('content_id' => $createdContent->id, 'title' => 'New page title'))->end()->with('response')->begin()->isRedirected()->end()->followRedirect()->info(' 1.5 - Edit the form and save again')->click('Save', array('sf_sympal_content' => array('TypeForm' => array('title' => 'new test title'))))->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'update')->end()->with('doctrine')->begin()->check('sfSympalPage', array('title' => 'new test title'))->check('sfSympalContent', array(), count($contents) + 1)->end(); $createdContent->delete(); // refresh $contentTypeCount = count($types); $home = Doctrine_Core::getTable('sfSympalContent')->findOneBySlug('home'); $browser->info('2 - Test the content type index, click through the types and edit')->info(' 2.1 - Start at the content types index page')->get('/admin/content')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'content_types_index')->end()->with('response')->begin()->isStatusCode(200)->info(sprintf(' 2.2 There should be %s rows, one for each content type', $contentTypeCount))->checkElement('#sf_admin_content .sf_admin_list tbody tr', $contentTypeCount)->end()->info(' 2.3 - click the "Page" content type to see its index')->click('Page')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'list_type')->isParameter('type', 'page')->end()->with('response')->begin()->isStatusCode(200)->info(' 2.4 - There should be 3 pages: Home, Register, Sample Page')->checkElement('#sf_admin_content .sf_admin_list tbody tr', 3)->end()->info(' 2.5 - Click the "Page" entry, takes you to view that page')->click('Home')->with('request')->begin()->isParameter('module', 'sympal_content_renderer')->isParameter('action', 'index')->isParameter('sympal_content_type', 'sfSympalPage')->isParameter('sympal_content_id', $home->id)->end()->info(' 2.6 - Go back to the page index and click edit')->get('/admin/content/manage/type/page')->click('Edit')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'edit')->isParameter('id', $home->id)->end()->info(' 2.7 - Goto the content index page, it will show the page type')->get('/admin/content/manage')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'index')->end()->with('response')->begin()->isStatusCode(200)->checkElement('h1', '/Manage Page Content/')->end()->info(' 2.8 - goto the "view" action of a page, redirects you to the frontend')->get('/admin/content/manage/' . $home->id . '/view')->with('request')->begin()->isParameter('module', 'sympal_content')->isParameter('action', 'view')->end()->with('response')->begin()->isRedirected(true)->end()->followRedirect()->with('request')->begin()->isParameter('action', 'index')->isParameter('sympal_content_type', 'sfSympalPage')->isParameter('sympal_content_id', $home->id)->end(); // count the number of true (non-column) slots $trueSlots = 0; $trueSlot = null; foreach ($home->Slots as $slot) { if (!$slot->is_column) { $trueSlot = $slot; // just retrieve one of the true slots for use
/** * Build the route path for the given content record * * @param sfSympalContent $content * @return string $routePath */ protected function _buildRoutePath(sfSympalContent $content) { // If content has a custom path then lets use it if ($content->hasCustomPath()) { $path = $content->custom_path; if ($path != '/') { $path .= '.:sf_format'; } return $path; } else { if ($content->get('module', false) || $content->get('action', false)) { $values = $this->getCultureRouteValues(); $values['sf_culture'] = ':sf_culture'; $values['sf_format'] = ':sf_format'; return $this->getRouteObject()->generate($values); } else { if ($path = $content->getType()->getRoutePath()) { return $path; } else { if ($content->getSlug()) { return '/content/:slug'; } } } } }
<?php $app = 'sympal'; require_once dirname(__FILE__) . '/../../../../bootstrap/unit.php'; $t = new lime_test(2); $page = sfSympalContent::createNew('sfSympalPage'); $page->date_published = date('Y-m-d h:i:s', time() + 86400); // tomorrow $page->save(); $pageContentType = Doctrine_Core::getTable('sfSympalContentType')->findOneByName('sfSympalPage'); $contentList = sfSympalContent::createNew('sfSympalContentList'); $contentList->ContentType = $pageContentType; $contentList->save(); /** * This will test PluginsfSympalContentList, but buildDataGrid() currently * has an sfWebRequest dependency on it, which needs to be removed. * See ticket #23 */
public function newContent($contentType, $properties = array()) { if (is_string($contentType)) { $contentType = Doctrine_Core::getTable('sfSympalContentType')->findOneByName($contentType); } if (!$contentType instanceof sfSympalContentType) { throw new InvalidArgumentException('Invalid ContentType'); } $superAdmin = Doctrine_Core::getTable(sfSympalConfig::get('user_model'))->findOneByIsSuperAdmin(1); if (!$superAdmin) { throw new sfException('Could not find a super admin user'); } $siteSlug = sfConfig::get('sf_app'); $site = Doctrine_Core::getTable('sfSympalSite')->findOneBySlug($siteSlug); if (!$site) { throw new sfException(sprintf('Could not find site with slug "%s"', $siteSlug)); } $content = new sfSympalContent(); $content->Type = $contentType; $content->CreatedBy = $superAdmin; $content->Site = $site; $content->date_published = new Doctrine_Expression('NOW()'); $name = $contentType['name']; $content->{$name} = new $name(); $content->trySettingTitleProperty('Sample ' . $contentType['label']); $this->_setDoctrineProperties($content, $properties); $this->logSection('sympal', sprintf('...instantiating new %s "%s"', $contentType->getLabel(), $content), null, 'COMMENT'); return $content; }
8<?php $app = 'sympal'; require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(17); // Setup sample content record and menu item to test with $user = new sfGuardUser(); $user->first_name = 'test'; $user->last_name = 'test'; $user->email_address = '*****@*****.**'; $user->username = rand(); $user->password = '******'; $user->save(); $content = sfSympalContent::createNew('sfSympalPage'); $content->slug = 'testing-this-out'; $content->date_published = date('Y-m-d', time() - 3600); $content->CreatedBy = $user; $content->Site = Doctrine_Core::getTable('sfSympalSite')->findOneBySlug('sympal'); $content->title = 'Testing this out'; $content->save(); $menuItem = new sfSympalMenuItem(); $menuItem->name = 'test'; $menuItem->RelatedContent = $content; $menuItem->Site = Doctrine_Core::getTable('sfSympalSite')->findOneBySlug('sympal'); $menuItem->save(); $content->save(); // Test that $content was setup successfully $t->is($content->sfSympalPage instanceof sfSympalPage, true, 'Test that content type was instantiated properly'); $t->is($content->sfSympalPage->title, 'Testing this out', 'Test that content type instance title was set from content record'); // Query for new content $q = Doctrine_Core::getTable('sfSympalContent')->getFullTypeQuery('sfSympalPage')->andWhere('c.slug = ?', 'testing-this-out'); $content = $q->fetchOne();
/** * Handles the create processing, which submits from create_type */ public function executeCreate(sfWebRequest $request) { $content = $request->getParameter('sf_sympal_content'); $contentTypeId = $content['content_type_id']; $type = Doctrine_Core::getTable('sfSympalContentType')->find($contentTypeId); $this->sf_sympal_content = sfSympalContent::createNew($type); $this->sf_sympal_content->Site = $this->getSympalContext()->getSite(); $this->form = new sfSympalContentForm($this->sf_sympal_content); $this->processForm($request, $this->form); $this->setTemplate('new'); }
/** * Set the content that this is being rendered for */ public function setContent(sfSympalContent $content) { $this->_content = $content; // mark this content record as having content slots $content->setEditableSlotsExistOnPage(true); }
/** * Build the route path for the given content record * * @param sfSympalContent $content * @return string $routePath */ protected function _buildRoutePath(sfSympalContent $content) { // If content has a custom path then lets use it if ($content->hasCustomPath()) { $path = $content->custom_path; if ($path != '/') { $path .= '.:sf_format'; } return $path; } else { if ($content->get('module', false) || $content->get('action', false)) { $cloned = $content->copy(false); $cloned->module = null; $cloned->action = null; return $cloned->getContentRouteObject()->getEvaluatedRoutePath(); } else { if ($path = $content->getType()->getRoutePath()) { return $path; } else { if ($content->getSlug()) { return '/content/:slug'; } } } } }