コード例 #1
0
ファイル: json.php プロジェクト: raeldc/com_learn
    protected function _getList(KModelAbstract $model)
    {
    	// Save state data for later
        $state_data = $model->getState()->getData();

        $nodes = KFactory::get('com://admin/files.model.nodes')->set($state_data)->getList();

        $needed  = array();
        foreach ($nodes as $row)
        {
        	if ($row->isImage()) {
        		$needed[] = $row->name;	
        	}
        }

		$model->reset();
		$model->set('files', $needed);
		$list  = array_values($model->getList()->toArray());

    	$found = array();
        foreach ($list as $row) {
        	$found[] = $row['filename'];
        }

        if ($found !== $needed) 
        {
        	$new = array();
        	foreach ($nodes as $row) 
        	{
        		if ($row->isImage() && !in_array($row->name, $found)) 
        		{
	        		$result = $row->saveThumbnail(null);
	        		if ($result) {
	        			$new[] = $row->name;
	        		}
        		}
        	}
        	if (count($new))
        	{
				$model->reset();
				$model->set('files', $new);
				$list  = array_merge($list, array_values($model->getList()->toArray()));
        	}
        }
       
        $results = array();
        foreach ($list as $item) {
        	$key = $item['filename'];
        	$results[$key] = $item;
        }
        ksort($results);

        $output = new stdclass;
        $output->total  = count($list);
        $output->limit  = $state_data['limit'];
        $output->offset = $state_data['offset'];
        $output->items  = $results;

        return $output;
    }
コード例 #2
0
ファイル: document.php プロジェクト: raeldc/nooku-mongodb
 /**
  * Set the model state properties
  *
  * This function overloads the KDatabaseDocumentAbstract::set() function and only acts on state properties.
  *
  * @param   string|array|object The name of the property, an associative array or an object
  * @param   mixed               The value of the property
  * @return  KModelDocument
  */
 public function set($property, $value = null)
 {
     parent::set($property, $value);
     // If limit has been changed, adjust offset accordingly
     if ($limit = $this->_state->limit) {
         $this->_state->offset = $limit != 0 ? floor($this->_state->offset / $limit) * $limit : 0;
     }
     return $this;
 }