public function getRouteArray($inputUrlRaw) { $config = array(); $inputUrl = rawurldecode(str_replace('_', ' ', $inputUrlRaw)); $arrayUrl = explode('/', $inputUrl, 2); if ($project = Model_Project::instance()->getBy('title', $arrayUrl[0])) { $config[] = array('/^(' . $project[0]['title'] . ')(.*)/iu', 'index/project/$1$2'); } elseif ($section = Model_Section::instance()->getBy('title', $arrayUrl[0])) { $config[] = array('/^(' . $section[0]['title'] . ')(.*)/iu', 'index/section/$1$2'); } //echo '1'; exit(); $pattern = array(); $replacement = array(); foreach ($config as $regexpArr) { $pattern[] = $regexpArr[0]; $replacement[] = $regexpArr[1]; } $url = preg_replace($pattern, $replacement, $inputUrl); $arrayUrl = explode('/', $url); if (isset($arrayUrl[0]) and $arrayUrl[0]) { $this->_route['controller'] = strtolower($arrayUrl[0]); } if (isset($arrayUrl[1]) and $arrayUrl[1]) { $this->_route['action'] = strtolower($arrayUrl[1]); } if (isset($arrayUrl[2]) and $arrayUrl[2]) { $this->_route['param1'] = $arrayUrl[2]; } if (isset($arrayUrl[3]) and $arrayUrl[3]) { $this->_route['param2'] = $arrayUrl[3]; } return $this->_route; }
private function _getModelByType($type) { switch ($type) { case self::TYPE_SAMPLE: $model = Model_Sample::instance(); break; case self::TYPE_SECTION: $model = Model_Section::instance(); break; case self::TYPE_PROJECT: $model = Model_Project::instance(); break; case self::TYPE_STATIC: $model = Model_Info::instance(); break; default: $model = false; } return $model; }
public function project($projectC, $sample_id = '') { $projectCurr = Model_Project::instance()->getAll(array('LEFT JOIN sections ON (projects.section_id = sections.id)', 'where' => 'projects.title ="' . $projectC . '" AND sections.status=' . Model_Section::STATUS_ON)); if (!isset($projectCurr[0])) { throw new AbstractException('Project‚ ' . $projectC . ' is not found'); } $projectC = $projectCurr[0]['title']; $sectionCurr = array('section_id' => $projectCurr[0]['section_id'], 'title' => $projectCurr[0]['section_title']); $projects = Model_Project::instance()->getAll(array('where' => 'sections.id =' . $sectionCurr['section_id'])); foreach ($projects as $project) { if ($project['title'] == $projectC) { $projectCurr = $project; } } $conditions = array('where' => 'project_id = ' . $projectCurr['id'], 'orderby' => 'id DESC'); if ($sample_id) { //$conditions['orderby']="FIELD(samples.id,".$sample_id.") desc"; } $samples = Model_Sample::instance()->getAll($conditions); if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { echo View::factory('element/project', array('samples' => $samples, 'sample_id' => $sample_id, 'projectCurr' => $projectCurr)); exit; } if (Helper_Js::isEnabledJs()) { header('Location: ' . Helper_Html::link(array('controller' => 'index', 'action' => 'section', 'param1' => $sectionCurr['title'], '#' => '/' . $projectC . '/' . $sample_id))); } $samplesCountMod = $this->_getSamplesCount($sectionCurr['section_id']); foreach ($projects as $projectKey => $project) { $projects[$projectKey]['count'] = isset($samplesCountMod[$project['id']]) ? $samplesCountMod[$project['id']] : '0'; } $pagination = array('prev' => Model_Project::instance()->getPagin($projectCurr['id'], $projectCurr['section_id'], 'prev'), 'next' => Model_Project::instance()->getPagin($projectCurr['id'], $projectCurr['section_id'], 'next')); $this->view->set('pagination', $pagination); //return View::factory('element/project',array('samples'=>$samples,'sample_id'=>$sample_id)); $this->view->setPageDescription($projectCurr['text']); $this->view->setPageTitle($sectionCurr['title'] . ' - ' . $projectCurr['title']); $this->view->set('sections', Model_Section::instance()->getAll()); $sapmlesCurrentArrayId = 0; if ($sample_id) { foreach ($samples as $arrayKey => $sample) { if ($sample['id'] == $sample_id) { $sapmlesCurrentArrayId = $arrayKey; } } } $this->view->set('sapmlesCurrentArrayId', $sapmlesCurrentArrayId); $this->view->set('samples', $samples); // $this->view->set('sectionCurr', $sectionCurr); $this->view->set('projectCurr', $projectCurr); // $this->view->set('projects', $projects); // }