/** * Creates the list of objects. Sets the parameter $p_hasNextElements to * true if this list is limited and elements still exist in the original * list (from which this was truncated) after the last element of this * list. * * @param int $p_start * @param int $p_limit * @param array $p_parameters * @param int &$p_count * @return array */ protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count) { $sectionsList = Section::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count); $metaSectionsList = array(); foreach ($sectionsList as $section) { $metaSectionsList[] = new MetaSection($section->getPublicationId(), $section->getIssueNumber(), $section->getLanguageId(), $section->getSectionNumber() ); } return $metaSectionsList; }
/** * Creates the list of objects. Sets the parameter $p_hasNextElements to * true if this list is limited and elements still exist in the original * list (from which this was truncated) after the last element of this * list. * * @param int $p_start * @param int $p_limit * @param array $p_parameters * @param int &$p_count * @return array */ protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count) { $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheKey = $cacheService->getCacheKey(array('metaSectionList', implode('-', $this->m_constraints), implode('-', $this->m_order), $p_start, $p_limit, $p_count), 'section'); if ($cacheService->contains($cacheKey)) { return $cacheService->fetch($cacheKey); } $sectionsList = Section::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count); $metaSectionsList = array(); foreach ($sectionsList as $section) { $metaSectionsList[] = new MetaSection($section->getPublicationId(), $section->getIssueNumber(), $section->getLanguageId(), $section->getSectionNumber()); } $cacheService->save($cacheKey, $metaSectionsList); return $metaSectionsList; }
$correct= false; $f_number = ($f_number + 0); $errors[] = getGS('You must fill in the $1 field.','"'.getGS('Number').'"'); } if ($f_url_name == "") { $correct = false; $errors[] = getGS('You must fill in the $1 field.','"'.getGS('URL Name').'"'); } if (!$isValidShortName && trim($f_url_name) != "") { $correct = false; $errors[] = getGS('The $1 field may only contain letters, digits and underscore (_) character.', '"' . getGS('URL Name') . '"'); } $sectionsConstraints = array(new ComparisonOperation('idpublication', new Operator('is'), $f_publication_id), new ComparisonOperation('nrissue', new Operator('is'), $f_issue_number), new ComparisonOperation('number', new Operator('is'), $f_number)); $sections = Section::GetList($sectionsConstraints, null, 0, 0, $sectionsCount, true); if ($sectionsCount > 0) { $correct = false; $errors[] = getGS('The section number $1 was already in use.', $f_number); } if ($correct) { $newSection = new Section($f_publication_id, $f_issue_number, $f_language_id, $f_number); $columns = array(); $columns['Description'] = $f_description; $created = $newSection->create($f_name, $f_url_name, $columns); if ($created) { if ($f_add_subscriptions) { $numSubscriptionsAdded = Subscription::AddSectionToAllSubscriptions($f_publication_id, $f_number); if ($numSubscriptionsAdded == -1) { $errors[] = getGS('Error updating subscriptions.'); }
public function testGetListBadParameter() { global $g_ado_db; // builds the constraint $leftOperand = 'ShortName'; $rightOperand = 'opensource'; $operator = new Operator('is', 'sql'); $comparisonOperationObj = new ComparisonOperation($leftOperand, $operator, $rightOperand); // sets the params for Section::GetList() $params = array($comparisonOperationObj); $order = array('Name' => 'DESC'); $limitStart = 0; $limitOffset = 0; $this->assertEquals(null, Section::GetList($params, $order, $limitStart, $limitOffset)); } // fn testGetListBadParameter
/** * Campsite camp_select function plugin * * Type: function * Name: camp_select * Purpose: Provides a... * * @param string * $p_unixtime the date in unixtime format from $smarty.now * @param string * $p_format the date format wanted * * @return * string the formatted date * null in case a non-valid format was passed */ function smarty_function_camp_select($p_params, &$p_smarty) { global $g_ado_db; require_once $p_smarty->_get_plugin_filepath('function','html_options'); if (!isset($p_params['object']) || !isset($p_params['attribute'])) { return; } if (!isset($p_params['html_code']) || empty($p_params['html_code'])) { $p_params['html_code'] = ''; } // gets the context variable $campsite = $p_smarty->get_template_vars('gimme'); $html = ''; $object = strtolower($p_params['object']); $attribute = strtolower($p_params['attribute']); $selectTag = false; switch($object) { case 'user': $fieldValue = CampRequest::GetVar('f_user_'.$attribute); if ($attribute == 'gender') { if (is_null($fieldValue)) { $fieldValue = $campsite->user->$attribute; } $html = '<input type="radio" name="f_user_'.$attribute .'" value="M" '.(($fieldValue == 'M') ? 'checked' : '').' ' . $p_params['html_code'] . '/> ' .smarty_function_escape_special_chars($p_params['male_name']) .' <input type="radio" name="f_user_'.$attribute .'" value="F" '.(($fieldValue == 'F') ? 'checked' : '').' ' . $p_params['html_code'] . ' /> ' .smarty_function_escape_special_chars($p_params['female_name']); } elseif ($attribute == 'title') { require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php'); if (!isGS('Mr.')) { camp_load_translation_strings("users", $campsite->language->code); } if (is_null($fieldValue)) { $fieldValue = $campsite->user->$attribute; } $selectTag = true; $output = array(getGS('Mr.'), getGS('Mrs.'), getGS('Ms.'), getGS('Dr.')); $values = array('Mr.', 'Mrs.', 'Ms.', 'Dr.'); $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>'; } elseif ($attribute == 'country') { if (is_null($fieldValue)) { $fieldValue = $campsite->user->country_code; } $sqlQuery = 'SELECT Code, Name FROM Countries ' .'GROUP BY Code ASC ORDER BY Name ASC'; $data = $g_ado_db->GetAll($sqlQuery); foreach($data as $country) { $output[] = $country['Name']; $values[] = $country['Code']; } $selectTag = true; $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>'; } elseif ($attribute == 'age') { if (is_null($fieldValue)) { $fieldValue = $campsite->user->$attribute; } $selectTag = true; $output = array('0-17', '18-24', '25-39', '40-49', '50-65', '65 or over'); $values = array('0-17', '18-24', '25-39', '40-49', '50-65', '65-'); $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>'; } elseif ($attribute == 'employertype') { require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php'); if (!isGS('Corporate')) { camp_load_translation_strings("users", $campsite->language->code); } if (is_null($fieldValue)) { $fieldValue = $campsite->user->$attribute; } $selectTag = true; $output = array(getGS('Corporate'), getGS('Non-Governmental'), getGS('Government Agency'), getGS('Academic'), getGS('Media'), getGS('Other')); $values = array('Corporate', 'NGO', 'Government Agency', 'Academic', 'Media', 'Other'); $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>'; } elseif (substr($attribute, 0, 4) == 'pref') { if (is_null($fieldValue)) { $fieldValue = $campsite->user->$attribute; } $html = '<input type="checkbox" name="f_user_'.$attribute.'" ' .(($attrValue == 'Y') ? ' value="on" checked />' : ' />') .'<input type="hidden" name="f_has_pref' .substr($attribute, 4, 1).'" value="1" ' . $p_params['html_code'] . ' />'; } break; case 'login': if ($attribute == 'rememberuser') { if (is_null($fieldValue)) { $fieldValue = $campsite->user->$attribute; } $html = '<input type="checkbox" name="f_login_'.$attribute.'" ' . $p_params['html_code'] . ' />'; } break; case 'subscription': $subsType = strtolower(CampRequest::GetVar('SubsType')); if ($subsType != 'trial' && $subsType != 'paid') { return null; } if ($attribute == 'languages') { $publicationLanguages = $campsite->publication->languages_list(false); foreach ($publicationLanguages as $language) { $output[] = $language->name; $values[] = $language->number; } $selectTag = true; $html = '<select name="subscription_language[]" multiple size="3" '; if ($subsType == 'paid') { $html .= 'onchange="update_subscription_payment();" '; } $html .= 'id="select_language" ' . $p_params['html_code'] . '>'; } elseif ($attribute == 'alllanguages') { $html = '<input type="checkbox" name="subs_all_languages" ' .'onchange="ToggleElementEnabled(\'select_language\');'; if ($subsType == 'paid') { $html .= ' update_subscription_payment();'; } $html .= '" ' . $p_params['html_code'] . ' />'; } elseif ($attribute == 'section') { if ($campsite->subs_by_type == 'publication') { $html = '<input type="hidden" name="cb_subs[]" value="' .$campsite->section->number.'" />'; } elseif ($campsite->subs_by_type == 'section') { $html = '<input type="checkbox" name="cb_subs[]" value="' .$campsite->section->number.'" ' .'onchange="update_subscription_payment();" ' . $p_params['html_code'] . ' />'; } } break; case 'search': if ($attribute == 'mode') { $html = '<input type="checkbox" name="f_match_all" ' . $p_params['html_code'] . ' />'; } elseif ($attribute == 'level') { require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php'); if (!isGS('Publication')) { camp_load_translation_strings("globals", $campsite->language->code); } $html = '<select name="f_search_'.$attribute.'" ' . $p_params['html_code'] . '>' .'<option value="1" selected="selected">' . getGS('Publication') . '</option>' .'<option value="2">' . getGS('Issue') . '</option>' .'<option value="3">' . getGS('Section') . '</option>' .'</select>'; } elseif ($attribute == 'section') { require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php'); $constraints = array(); $operator = new Operator('is', 'integer'); if ($campsite->publication->defined) { $constraints[] = new ComparisonOperation('IdPublication', $operator, $campsite->publication->identifier); } if ($campsite->language->defined) { $constraints[] = new ComparisonOperation('IdLanguage', $operator, $campsite->language->number); } if ($campsite->issue->defined) { $constraints[] = new ComparisonOperation('NrIssue', $operator, $campsite->issue->number); } $sectionsList = Section::GetList($constraints, array('Name'=>'ASC'), 0, 0, $count); if (!isGS('-- ALL SECTIONS --')) { camp_load_translation_strings("user_subscription_sections", $campsite->language->code); } $html = '<select name="f_search_section" ' . $p_params['html_code'] . '>'; $html .= '<option value="0" selected="selected">' . getGS('-- ALL SECTIONS --') . '</option>'; foreach ($sectionsList as $section) { $html .= '<option value="' . $section->getSectionNumber() . '">' . htmlspecialchars($section->getName()) . '</option>'; } $html .= '</select>'; } elseif ($attribute == 'issue') { $constraints = array(); $operator = new Operator('is', 'integer'); if ($campsite->publication->defined) { $constraints[] = new ComparisonOperation('IdPublication', $operator, $campsite->publication->identifier); } if ($campsite->language->defined) { $constraints[] = new ComparisonOperation('IdLanguage', $operator, $campsite->language->number); } $constraints[] = new ComparisonOperation('published', $operator, 'true'); $issuesList = Issue::GetList($constraints, array(array('field'=>'bynumber', 'dir'=>'DESC')), 0, 0, $count); $html = '<select name="f_search_issue" ' . $p_params['html_code'] . '>'; $html .= '<option value="0" selected="selected"> </option>'; foreach ($issuesList as $issue) { $issueDesc = $issue->getIssueNumber() . '. ' . $issue->getName() . ' ('. $issue->getPublicationDate() . ')'; $html .= '<option value="' . $issue->getIssueNumber() . '">' . htmlspecialchars($issueDesc) . '</option>'; } $html .= '</select>'; } } if ($selectTag == true) { $html.= smarty_function_html_options(array('output' => $output, 'values' => $values, 'selected' => $fieldValue, 'print_result' => false), $p_smarty); $html.= '</select>'; } return $html; } // fn smarty_function_camp_select
/** * Get the section that this article is in. * @return object */ public function getSection() { $section = new Section($this->getPublicationId(), $this->getIssueNumber(), $this->getLanguageId(), $this->getSectionNumber()); if (!$section->exists()) { $params = array(new ComparisonOperation('idpublication', new Operator('is', 'integer'), $this->getPublicationId()), new ComparisonOperation('idlanguage', new Operator('is', 'integer'), $this->getLanguageId()), new ComparisonOperation('number', new Operator('is', 'integer'), $this->getSectionNumber())); if ($this->getIssueNumber()) { $params[] = new ComparisonOperation('nrissue', new Operator('is', 'integer'), $this->getIssueNumber()); } $sections = Section::GetList($params, null, 0, 1, $count = 0); if (!empty($sections)) { return $sections[0]; } } return $section; }