示例#1
0
 public function action_index()
 {
     $id = $this->request->param('id', 0);
     //SEO. закрываем сортировку
     if ($id != 0) {
         $sort = 1;
         Kotwig_View::set_global('sort', $sort);
     }
     //end_SEO
     $category = ORM::factory('Category', $id);
     $video = ORM::factory('Video')->where('published', '=', 1)->and_where('language', '=', $this->language);
     if ($category->loaded()) {
         $video = $video->and_where_open()->and_where('category_id', '=', $id);
         if ($category->has_children()) {
             $video = $video->or_where('category_id', 'IN', $category->children->as_array('id'));
         }
         $video = $video->and_where_close();
         $this->add_cumb('Video', 'video');
         $this->add_cumb($category->name, '');
     } else {
         $this->add_cumb('Video', '');
     }
     $video = $video->order_by('date', 'DESC');
     $paginate = Paginate::factory($video)->paginate(NULL, NULL, 12)->render();
     $video = $video->find_all();
     $categories = ORM::factory('Category')->find_all();
     $mas_categories = array();
     foreach ($categories as $item) {
         $video_count = ORM::factory('Video')->where('published', '=', 1)->and_where('language', '=', $this->language)->and_where_open()->and_where('category_id', '=', $item->id);
         /* if ($item->has_children())
            {
                $video_count = $video_count->or_where('category_id', 'IN', $item->children->as_array('id'));
            }
            $video_count = $video_count->and_where_close()->count_all(); */
         if ($video_count) {
             $mas_categories[] = $item;
         }
     }
     $cat = ORM::factory('Category')->fulltree;
     $count_comments = Comments::instance();
     $this->set('cat', $cat);
     $this->set('video', $video)->set('categories', $mas_categories)->set('select_id', $id);
     $this->set('paginate', $paginate)->set('count_comments', $count_comments);
 }
示例#2
0
 public function action_form()
 {
     if (Auth::instance()->logged_in()) {
         $array = $this->request->param('id', false);
         $param = explode("-", $array);
         $table = isset($param[0]) ? $param[0] : '';
         $object_id = (int) isset($param[1]) ? $param[1] : '';
         $user = Auth::instance()->get_user();
         if (Request::$initial->method() == Request::POST) {
             $message = Arr::get($_POST, 'message');
             $save = Comments::instance()->save($message, $table, $object_id);
             $this->response->body(Comments::instance()->form($user));
             header('Location: ' . URL::base() . Request::$initial->uri());
             die;
             //HTTP::redirect(Request::$initial->uri());
         } else {
             $this->response->body(Comments::instance()->form($user));
         }
     } else {
         $this->response->body('<div style="margin: 15px 0 15px 0; text-align: center;">' . __('Для добавления комментариев необходимо авторизоваться.') . '</div>');
     }
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'Comments')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return Comments::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& Comments::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
示例#4
0
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return Comments 
 */
 function manager() {
   if(!($this->manager instanceof Comments)) $this->manager = Comments::instance();
   return $this->manager;
 } // manager
 /**
  * Return entries related to specific object
  *
  * If $include_private is set to true private entries will be included in result. If $include_silent is set to true
  * logs marked as silent will also be included. $limit and $offset are there to control the range of the result,
  * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored
  *
  * @param ApplicationDataObject $object
  * @param boolean $include_private
  * @param boolean $include_silent
  * @param integer $limit
  * @param integer $offset
  * @return array
  */
 static function getObjectLogs($object, $include_private = false, $include_silent = false, $limit = null, $offset = null)
 {
     $private_filter = $include_private ? 1 : 0;
     $silent_filter = $include_silent ? 1 : 0;
     if (get_class($object->manager()) == 'Users') {
         $private_filter = $include_private ? 1 : 0;
         $silent_filter = $include_silent ? 1 : 0;
         $userCond = " AND `taken_by_id` = " . $object->getId();
         if (isset($project_ids) && $project_ids != null) {
             $conditions = array('`is_private` <= ? AND `is_silent` <= ? AND ' . self::getWorkspaceString($project_ids) . $userCond, $private_filter, $silent_filter);
         } else {
             $conditions = array('`is_private` <= ? AND `is_silent` <= ?' . $userCond, $private_filter, $silent_filter);
         }
         // if
         return self::findAll(array('conditions' => $conditions, 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset));
         // findAll
     } else {
         $logs = self::findAll(array('conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) AND `rel_object_manager` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND `rel_object_id`IN (SELECT `id` FROM ' . Comments::instance()->getTableName(true) . ' WHERE `rel_object_id` = (?) AND `rel_object_manager` = (?)) AND `rel_object_manager` = "Comments"', $private_filter, $silent_filter, $object->getId(), get_class($object->manager()), $private_filter, $silent_filter, $object->getId(), get_class($object->manager())), 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset));
         // findAll
     }
     $next_offset = $offset + $limit;
     do {
         // Look for objects that user cannot see
         $removed = 0;
         foreach ($logs as $k => $log) {
             if ($log->getAction() == 'link') {
                 $id = explode(":", $log->getLogData());
                 $lobj = get_object_by_manager_and_id($id[1], $id[0]);
                 if (!$lobj instanceof ApplicationDataObject || !can_access(logged_user(), $lobj, ACCESS_LEVEL_READ)) {
                     $removed++;
                     unset($logs[$k]);
                 }
             }
         }
         // Get more objects to substitute the removed ones
         if ($limit && $removed > 0) {
             $other_logs = self::findAll(array('conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) AND `rel_object_manager` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND `rel_object_id`IN (SELECT `id` FROM ' . Comments::instance()->getTableName(true) . ' WHERE `rel_object_id` = (?) AND `rel_object_manager` = (?)) AND `rel_object_manager` = "Comments"', $private_filter, $silent_filter, $object->getId(), get_class($object->manager()), $private_filter, $silent_filter, $object->getId(), get_class($object->manager())), 'order' => '`created_on` DESC', 'limit' => $next_offset + $removed, 'offset' => $next_offset));
             // findAll
             $logs = array_merge($logs, $other_logs);
             $next_offset += $removed;
             if (count($logs) > $limit) {
                 $logs = array_slice($logs, 0, $limit);
             }
         }
     } while ($removed > 0);
     return $logs;
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return Comments 
  */
 function manager()
 {
     if (!$this->manager instanceof Comments) {
         $this->manager = Comments::instance();
     }
     return $this->manager;
 }
	/**
	 * Return entries related to specific object
	 *
	 * If $include_private is set to true private entries will be included in result. If $include_silent is set to true
	 * logs marked as silent will also be included. $limit and $offset are there to control the range of the result,
	 * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored
	 *
	 * @param ApplicationDataObject $object
	 * @param boolean $include_private
	 * @param boolean $include_silent
	 * @param integer $limit
	 * @param integer $offset
	 * @return array
	 */
	static function getObjectLogs($object, $include_private = false, $include_silent = false, $limit = null, $offset = null) {
		$private_filter = $include_private ? 1 : 0;
		$silent_filter = $include_silent ? 1 : 0;		
		
		// User History
		if ($object instanceof Contact && $object->isUser()){		
			$private_filter = $include_private ? 1 : 0;
			$silent_filter = $include_silent ? 1 : 0;		
			$userCond = " AND `taken_by_id` = " . $object->getId();
			
			$conditions =  array(
				'`is_private` <= ? AND `is_silent` <= ? '.$userCond, 
				$private_filter, 
				$silent_filter); 
				
			return self::findAll(array(
				'conditions' => $conditions,
				'order' => '`created_on` DESC',
				'limit' => $limit,
				'offset' => $offset,
			)); // findAll				
		} else {	
			$logs = self::findAll(array(
                            'conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND (`rel_object_id`IN (SELECT `object_id` FROM '.Comments::instance()->getTableName(true).' WHERE `rel_object_id` = (?)) OR `rel_object_id`IN (SELECT `object_id` FROM '.Timeslots::instance()->getTableName(true).' WHERE `rel_object_id` = (?)))', $private_filter, $silent_filter, $object->getId(),$private_filter, $silent_filter, $object->getId(), $object->getId()),
                            'order' => '`created_on` DESC',
                            'limit' => $limit,
                            'offset' => $offset,
			)); // findAll
		}
		
		$next_offset = $offset + $limit;
		do {
			// Look for objects that user cannot see
			$removed = 0;
			foreach ($logs as $k => $log) {
				if ($log->getAction() == 'link') {
					$id = explode(":", $log->getLogData());
					$lobj = Objects::findObject($id[1]);
					if (!$lobj instanceof ApplicationDataObject || !can_access(logged_user(), $lobj->getMembers(), $lobj->getObjectTypeId(), ACCESS_LEVEL_READ)) {
						$removed++;
						unset($logs[$k]);
					}
				}
			}
			// Get more objects to substitute the removed ones
			if ($limit && $removed > 0) {
				$other_logs = self::findAll(array(
			        'conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND (`rel_object_id`IN (SELECT `id` FROM '.Comments::instance()->getTableName(true).' WHERE `rel_object_id` = (?)) AND `rel_object_id`IN (SELECT `object_id` FROM '.Timeslots::instance()->getTableName(true).' WHERE `rel_object_id` = (?)))', $private_filter, $silent_filter, $object->getId(),$private_filter, $silent_filter, $object->getId(), $object->getId()),
			        'order' => '`created_on` DESC',
			        'limit' => $next_offset + $removed,
			        'offset' => $next_offset,
				)); // findAll
				$logs = array_merge($logs, $other_logs);
				$next_offset += $removed;
				if (count($logs) > $limit) $logs = array_slice($logs, 0, $limit);
			}
		} while ($removed > 0);
		
		return $logs;
	} // getObjectLogs
示例#8
0
<?php

$limit = 10;
$result = Comments::instance()->listing(array("order" => "created_on", "order_dir" => "desc", "start" => 0, "limit" => $limit));
$active_members = array();
$context = active_context();
foreach ($context as $selection) {
    if ($selection instanceof Member) {
        $active_members[] = $selection;
    }
}
if (count($active_members) > 0) {
    $mnames = array();
    $allowed_contact_ids = array();
    foreach ($active_members as $member) {
        $mnames[] = clean($member->getName());
    }
    $widget_title = lang('latest comments') . ' ' . lang('in') . ' ' . implode(", ", $mnames);
}
$total = $result->total;
$comments = $result->objects;
$genid = gen_id();
if ($total > 0) {
    include_once 'template.php';
}
示例#9
0
 /**
  * Empty implementation of static method.
  *
  * Add tag permissions are done through ProjectDataObject::canComment() method. This
  * will return comment permissions for specified object
  *
  * @param User $user
  * @param Project $project
  * @return boolean
  */
 function canAdd(User $user, Project $project)
 {
     return can_add($user, $project, get_class(Comments::instance()));
 }