Example #1
0
 public function read($fields = null, $id = null, $unify = true)
 {
     $category = parent::read($fields, $id);
     if (!empty($category) && $unify) {
         $category[is_string($unify) ? $unify : 'Category'] = $category[$this->alias];
     }
     return $category;
 }
Example #2
0
 /**
  *
  * @param AppModel $model
  * @param int $id
  */
 public function readCached($model, $id = null)
 {
     if (empty($id)) {
         $id = $model->getID();
     }
     $key = $model->Behaviors->enabled('Translate') ? Inflector::underscore($model->alias) . "_{$id}_" . SlConfigure::read('I18n.locale') : Inflector::underscore($model->alias) . "_{$id}";
     $data = Cache::read($key, 'models');
     if (empty($data)) {
         Cache::write($key, $data = $model->read(null, $id), 'models');
     }
     return $data;
 }
Example #3
0
 /**
  *  SetById method. Check is model innitialized.
  *
  *  If $id is defined read record from model with this primary key value
  *
  * @param AppModel $model
  * @param ID $id  - value of model primary key to read
  * @return boolean True if model initialized, false if no info in $model->data exists.
  * @access private
  */
 function __setById(&$model, $id = null, $checkId = true)
 {
     if (!isset($id)) {
         if ($checkId) {
             return isset($model->data[$model->alias]['id']);
         } else {
             return isset($model->data[$model->alias]);
         }
     } else {
         return $model->read(null, $id);
     }
 }
Example #4
0
 function read($fields = null, $id = null)
 {
     $data = parent::read($fields, $id);
     if ($data) {
         if (!empty($data['CmsNode']['model'])) {
             $data2 = ClassRegistry::init("{$data['CmsNode']['plugin']}.{$data['CmsNode']['model']}")->read(null, $data['CmsNode']['foreign_key']);
             if ($data2) {
                 $data += $data2;
             } else {
                 $data = null;
             }
         }
     }
     return $data;
 }
Example #5
0
 function testTwitterSaveToken()
 {
     $this->loadFixtures('UserToken');
     $this->TestModel = ClassRegistry::init('UserToken');
     $this->TestModel->Behaviors->attach('TwitterKit.Twitter');
     // --
     $this->TestModel->id = 4;
     $this->TestModel->twitterSetToken('dummy_token4', 'dummy_secret4');
     $result = $this->TestModel->twitterSaveToken();
     $this->assertTrue($result);
     $data = $this->TestModel->read();
     $this->assertEqual('dummy_token4', $data['UserToken']['oauth_token']);
     $this->assertEqual('dummy_secret4', $data['UserToken']['oauth_token_secret']);
     // --
     $this->TestModel->Behaviors->Twitter->DataSource->reset();
     $this->TestModel->Behaviors->detach('TwitterKit.Twitter');
     $this->TestModel->Behaviors->attach('TwitterKit.Twitter', array('fields' => array('oauth_token' => 'access_token', 'oauth_token_secret' => 'access_token_secret')));
     $this->TestModel->twitterSetToken('dummy_token5', 'dummy_secret5');
     $result = $this->TestModel->twitterSaveToken(5);
     $this->assertTrue($result);
     $data = $this->TestModel->read();
     $this->assertEqual('dummy_token5', $data['UserToken']['access_token']);
     $this->assertEqual('dummy_secret5', $data['UserToken']['access_token_secret']);
 }
Example #6
0
 /**
  * Callback
  * Populates the $Model->data with the current register that will be deleted
  * for the callback afterDelete
  *
  * @access public
  *
  * @param AppModel $Model
  * @param bool     $cascade
  *
  * @return bool|mixed
  */
 public function beforeDelete(&$Model, $cascade)
 {
     $Model->read();
     return true;
 }
<?php

$obj = new AppModel($id);
$obj->useTable = 'pl_miejscowosci';
$obj->alias = 'Miejscowosc';
$obj->read();
return $this->DB->query('SELECT Powiat.id,Powiat.nazwa, Wojewodztwo.id, Wojewodztwo.nazwa FROM pl_powiaty Powiat, wojewodztwa Wojewodztwo WHERE Powiat.id = ' . $obj->data['Miejscowosc']['powiat_id'] . ' AND Wojewodztwo.id=' . $obj->data['Miejscowosc']['woj_id']);
Example #8
0
 /**
  * Get the parent node
  *
  * reads the parent id and returns this node
  *
  * @param AppModel $model
  * @param mixed $id The ID of the record to read
  * @param integer $recursive The number of levels deep to fetch associated records
  * @return array Array of data for the parent node
  * @access public
  */
 function getparentnode(&$model, $id = null, $fields = null, $recursive = -1)
 {
     if (empty($id)) {
         $id = $model->id;
     }
     extract($this->settings[$model->alias]);
     $parentId = $model->read($parent, $id);
     if ($parentId) {
         $parentId = $parentId[$model->alias][$parent];
         $parent = $model->find('first', array('conditions' => array($model->escapeField() => $parentId), 'fields' => $fields, 'recursive' => $recursive));
         return $parent;
     } else {
         return false;
     }
 }
Example #9
0
 /**
  * set OAuth Access Token By Id
  *
  * @param AppModel $model
  * @param mixed    $id
  * @return true|false
  */
 public function twitterSetTokenById($model, $id = null)
 {
     if (is_null($id)) {
         $id = $model->id;
     }
     $data = $model->read($this->settings[$model->alias]['fields'], $id);
     if (empty($data[$model->alias])) {
         return false;
     }
     return $this->twitterSetToken($model, $data[$model->alias]);
 }
 /**
  *  SetById method. Check is model innitialized.
  *
  *  If $id is defined read record from model with this primary key value
  *
  * @param AppModel $model
  * @param ID $id  - value of model primary key to read
  * @return boolean True if model initialized, false if no info in $model->data exists.
  */
 private function __setById($model, $id = null, $checkId = true)
 {
     if (!isset($id)) {
         if ($checkId) {
             return isset($model->data[$model->alias][$model->primaryKey]);
         } else {
             return isset($model->data[$model->alias]);
         }
     } else {
         return $model->read(null, $id);
     }
 }
Example #11
0
 /**
  * undocumented function
  *
  * @param string $fields
  * @param string $id
  * @return void
  */
 function read($fields = null, $id = null)
 {
     $data = parent::read($fields, $id);
     $data['Project']['config'] = unserialize($data['Project']['config']);
     return $data;
 }
Example #12
0
 /**
  * Move up element
  *
  * @param AppModel $Model Model instance
  * @param mixed $id The ID of the record to move
  * @param mixed $number how many places to move the node, or true to move to first position
  * @return boolean true on success, false on failure
  */
 public function moveup(&$Model, $id = null, $number = 1)
 {
     if (is_array($id)) {
         extract(array_merge(array('id' => null), $id));
     }
     if (!$number) {
         return false;
     }
     if (empty($id)) {
         $id = $Model->id;
     }
     $data = $Model->read(am($this->settings[$Model->alias]['order_field'], $this->settings[$Model->alias]['group_fields']), $id);
     $order = $data[$Model->alias][$this->settings[$Model->alias]['order_field']];
     if (is_int($number)) {
         $order -= abs($number);
     } elseif ($number === true) {
         $order = $this->settings[$Model->alias]['start_at'];
     } else {
         return false;
     }
     if ($order < $this->settings[$Model->alias]['start_at']) {
         $order = $this->settings[$Model->alias]['start_at'];
     }
     $Model->id = $id;
     return $Model->saveField($this->settings[$Model->alias]['order_field'], $order);
 }
Example #13
0
 /**
  *
  * @param AppModel $model 
  * @return array
  */
 protected function _getData($model)
 {
     $_recursive = $model->recursive;
     $model->recursive = -1;
     $data = $model->read(null, $model->id);
     $model->recursive = $_recursive;
     return $data[$model->alias];
 }
Example #14
0
 /**
  * Get the parent node
  *
  * reads the parent id and returns this node
  *
  * @param AppModel $model
  * @param mixed $id The ID of the record to read
  * @param integer $recursive The number of levels deep to fetch associated records
  * @return array Array of data for the parent node
  * @access public
  */
 function getparentnode(&$model, $id = null, $fields = null, $recursive = -1)
 {
     if (empty($id)) {
         $id = $model->id;
     }
     extract($this->settings[$model->name]);
     $parentId = $model->read($parent, $id);
     if ($parentId) {
         $parentId = $parentId[$model->name][$parent];
         $parent = $model->find(array($model->escapeField() => $parentId), $fields, null, $recursive);
         return $parent;
     } else {
         return false;
     }
 }
Example #15
0
 /**
  * Get the parent node
  *
  * reads the parent id and returns this node
  *
  * @param AppModel $Model Model instance
  * @param mixed $id The ID of the record to read
  * @param integer $recursive The number of levels deep to fetch associated records
  * @return array Array of data for the parent node
  * @access public
  */
 function getparentnode(&$Model, $id = null, $fields = null, $recursive = null)
 {
     if (is_array($id)) {
         extract(array_merge(array('id' => null), $id));
     }
     $overrideRecursive = $recursive;
     if (empty($id)) {
         $id = $Model->id;
     }
     extract($this->settings[$Model->alias]);
     if (!is_null($overrideRecursive)) {
         $recursive = $overrideRecursive;
     }
     $parentId = $Model->read($parent, $id);
     if ($parentId) {
         $parentId = $parentId[$Model->alias][$parent];
         $parent = $Model->find('first', array('conditions' => array($Model->escapeField() => $parentId), 'fields' => $fields, 'recursive' => $recursive));
         return $parent;
     }
     return false;
 }
Example #16
0
 /**
  * Before delete method. Called before all deletes
  *
  * Will delete the current node and all children using the deleteAll method and sync the table
  *
  * @param AppModel $Model Model instance
  * @return boolean true to continue, false to abort the delete
  * @access public
  */
 function beforeDelete(&$Model)
 {
     extract($this->settings[$Model->alias]);
     list($name, $data) = array($Model->alias, $Model->read());
     $data = $data[$name];
     if (!$data[$right] || !$data[$left]) {
         return true;
     }
     $diff = $data[$right] - $data[$left] + 1;
     if ($diff > 2) {
         if (is_string($scope)) {
             $scope = array($scope);
         }
         $scope[]["{$Model->alias}.{$left} BETWEEN ? AND ?"] = array($data[$left] + 1, $data[$right] - 1);
         $Model->deleteAll($scope);
     }
     $this->__sync($Model, $diff, '-', '> ' . $data[$right]);
     return true;
 }
Example #17
0
 /**
  * Get the path to the given node
  *
  * @since 1.2
  * @param AppModel $model
  * @param mixed $id The ID of the record to read
  * @param mixed $fields Either a single string of a field name, or an array of field names
  * @param int $recursive The number of levels deep to fetch associated records
  * @return array Array of nodes from top most parent to current node
  * @access public
  */
 function get_path(&$model, $id = null, $fields = null, $recursive = -1)
 {
     if (empty($id)) {
         $id = $model->id;
     }
     extract($this->settings[$model->name]);
     @(list($item) = array_values($model->read(array($left, $right), $id)));
     if (empty($item)) {
         return null;
     }
     $results = $model->findAll(array($scope, $model->escapeField($left) => '<= ' . $item[$left], $model->escapeField($right) => '>= ' . $item[$right]), $fields, array($model->escapeField($left) => 'asc'), null, null, $recursive);
     return $results;
 }