Permalink
Browse files

добавил блок с последними просмотренными проектами

  • Loading branch information...
FladeX committed Jan 5, 2012
1 parent c6d7b53 commit 33fe3c877c1b62b9150c51686d80a7583020721e
@@ -3,4 +3,5 @@
# default values
all:
- projects_per_page: 5
+ projects_per_page: 5
+ last_viewed_projects: 3
@@ -2,4 +2,30 @@
class myUser extends sfBasicSecurityUser
{
+ public function addProjectToHistory(projects $project)
+ {
+ $ids = $this->getAttribute('projects_history', array());
+
+ if (!in_array($project->getId(), $ids))
+ {
+ array_unshift($ids, $project->getId());
+ $this->setAttribute('projects_history', array_slice($ids, 0, sfConfig::get('app_last_viewed_projects')));
+ }
+ }
+
+ public function getProjectsHistory()
+ {
+ $ids = $this->getAttribute('projects_history', array());
+
+ if (!empty($ids))
+ {
+ return Doctrine_Core::getTable('projects')
+ ->createQuery('a')
+ ->whereIn('a.id', $ids)
+ ->execute()
+ ;
+ }
+
+ return array();
+ }
}
@@ -27,6 +27,8 @@ public function executeShow(sfWebRequest $request)
{
$this->projects = Doctrine_Core::getTable('projects')->find(array($request->getParameter('id')));
+ $this->getUser()->addProjectToHistory($this->projects);
+
// находим количество оставшихся дней
$timeleft_days = $timeleft_hours = $timeleft_minutes = 0;
$project_timeleft = time($this->projects['expired_at']) - time($this->projects['created_at']);
@@ -7,6 +7,17 @@
<a id="addTaskLink" href="<?php echo url_for('projects/new') ?>">добавить задание</a>
</div>
+ <div id="projects_history" class="sidebarBlock">
+ <h3>Вы смотрели:</h3>
+ <ul class="userList">
+ <?php foreach ($sf_user->getProjectsHistory() as $project): ?>
+ <li>
+ <?php echo link_to($project->getTitle(), 'projects_show', $project) ?>
+ </li>
+ <?php endforeach ?>
+ </ul>
+ </div>
+
<div id="topCustomers" class="sidebarBlock">
<h3>Лучшие заказчики</h3>
<ul class="userList">
@@ -47,6 +47,17 @@
</table>
</div>
+ <div id="projects_history" class="sidebarBlock">
+ <h3>Вы смотрели:</h3>
+ <ul class="userList">
+ <?php foreach ($sf_user->getProjectsHistory() as $project): ?>
+ <li>
+ <?php echo link_to($project->getTitle(), 'projects_show', $project) ?>
+ </li>
+ <?php endforeach ?>
+ </ul>
+ </div>
+
</div>
<div id="primaryContent">
@@ -74,7 +74,7 @@
<?php if ($sf_user->hasFlash('error')): ?>
<div class="flash_error"><?php echo $sf_user->getFlash('error') ?></div>
<?php endif; ?>
-
+
<?php echo $sf_content ?>
</div><!-- #mainContent -->

0 comments on commit 33fe3c8

Please sign in to comment.