Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RAuthItemDataProvider.php
1 <?php
2 /**
3  * Authorization item data provider class file.
4  *
5  * @author Christoffer Niska <cniska@live.com>
6  * @copyright Copyright &copy; 2010 Christoffer Niska
7  * @since 0.9.10
8  */
9 class RAuthItemDataProvider extends CDataProvider {
10 
11  public $type;
12  public $userId;
13  public $parent;
14  public $exclude = array();
15  public $items;
16  public $sortable;
17 
18  /**
19  * Constructs the data provider.
20  *
21  * @param string $id the data provider identifier.
22  * @param array $config configuration (name=>value) to be applied as the initial property values of this class.
23  *
24  * @return \RAuthItemDataProvider
25  */
26  public function __construct($id, $config = array())
27  {
28  $this->setId($id);
29 
30  foreach ($config as $key => $value) {
31  $this->$key = $value;
32  }
33  }
34 
35  /**
36  * Fetches the data from the persistent data storage.
37  *
38  * @return array list of data items
39  */
40  public function fetchData()
41  {
42  if ($this->sortable!==null) {
43  $this->processSortable();
44  }
45 
46  if ($this->items===null) {
47  $this->items = Rights::getAuthorizer()->getAuthItems($this->type, $this->userId, $this->parent, true, $this->exclude);
48  }
49 
50  $data = array();
51  foreach ($this->items as $name => $item) {
52  $data[] = $item;
53  }
54 
55  return $data;
56  }
57 
58  /**
59  * Fetches the data item keys from the persistent data storage.
60  *
61  * @return array list of data item keys.
62  */
63  public function fetchKeys()
64  {
65  $keys = array();
66  foreach ($this->getData() as $name => $item) {
67  $keys[] = $name;
68  }
69 
70  return $keys;
71  }
72 
73  /**
74  * Applies jQuery UI sortable on the target element.
75  *
76  * @return void
77  */
78  protected function processSortable()
79  {
80  if ($this->sortable!==null) {
81  if (isset($this->sortable['id'])===true && isset($this->sortable['element'])===true && isset($this->sortable['url'])===true) {
82  // Register the script to bind the sortable plugin to the role table
83  Yii::app()->getClientScript()->registerScript(
84  $this->sortable['id'],
85  "jQuery('".$this->sortable['element']."').rightsSortableTable({
86  url:'".$this->sortable['url']."',
87  csrfToken:'".Yii::app()->request->csrfToken."'
88  });"
89  );
90  }
91  }
92  }
93 
94  /**
95  * Calculates the total number of data items.
96  *
97  * @return integer the total number of data items.
98  */
99  protected function calculateTotalItemCount()
100  {
101  return count($this->getData());
102  }
103 }