| Server IP : 180.180.241.3 / Your IP : 216.73.216.35 Web Server : Microsoft-IIS/7.5 System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 User : IUSR ( 0) PHP Version : 5.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /AppServ/www/app/Model/ |
Upload File : |
<?php
/**
* Application model for Cake.
*
* This file is application-wide model file. You can put all
* application-wide model-related methods here.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.Model
* @since CakePHP(tm) v 0.2.9
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Model', 'Model');
/**
* Application model for Cake.
*
* Add your application-wide methods in the class below, your models
* will inherit them.
*
* @package app.Model
*/
class AppModel extends Model {
/**
* Filter the rows by `is_activated` field
*
* If the model has a field called `is_activated`, filter the rows by it (`is_activated => 1`), except if there is a condition that already says `is_axctivated => 0`
* Typically, the only times when there will be a condition `is_activated => 0` will be in the `admin_index` actions when the user wants to display the items that have been deleted
*
* @param array $queryData the conditions of the query
* @return array a new conditions array with `is_activated => 1` if needed
* @author Mike
* @since 2013-10-08
* @modified Mike - 2013-11-19 - Force refresh of _schema property by calling $this->schema()
*/
public function beforeFind( $queryData ) {
$this->schema();
if ( isset( $this->_schema['is_activated'] ) ) {
$defaultStatus = array($this->alias . '.is_activated' => 1);
// $conditions can be written with or without `AND`
// mostly admin filters set `AND` explicitly
// so here we need to merge default status array to the correct one
if ( isset($queryData['conditions']['AND']) ) {
$queryData['conditions']['AND'] = array_merge(
$defaultStatus,
(array) $queryData['conditions']['AND']
);
} else {
$queryData['conditions'] = array_merge(
$defaultStatus,
(array) $queryData['conditions']
);
}
}
return $queryData;
}
/**
* Applies a soft delete if possible
*
* The method will look for a field `is_activated`; If there is no field `is_activated`, the method will apply the normal `delete`
* from the parent Model; if there is a field `is_activated`, it will set its value to `0`
*
* @param int $id ID of the row to delete
* @param boolean $cascade delete all attached models (not used)
* @return boolean `true` if the row could be deleted; otherwise `false`
*
* @author Mike <michael.damoiseau@gmail.com>
* @since 2013-09-27
*/
public function delete($id = null, $cascade = true) {
// the table has no field `is_activated` so we use the normal delete method from the parent
if( !isset( $this->_schema['is_activated'] ) ) {
return parent::delete( $id, $cascade );
}
// there is a field `is_activated`, so update it to `0`
//if $id is given as parameter of the function, set it to the current model
if( $id != null ) {
$this->id = $id;
}
return $this->saveField( 'is_activated', 0 );
}
/**
* if they need to activate items.
*
* @param int $id items id
* @return boolean
* @author Ting <3Musketeersteam@gmail.com>
* @since 27 January 2014
*/
public function activate($id = null) {
//if $id is given as parameter of the function, set it to the current model
if( $id != null ) {
$this->id = $id;
}
return $this->saveField( 'is_activated', 1 );
}
/**
* override $model->find('list') to automatically order results by name
* so we have a nice alphabetically ordered <option> in <select>
*
* @param [string] $state `before` or `after` each find()
* @param [array] $query [cake's query options]
* @param array $results [query results]
*/
protected function _findList($state, $query, $results = array()) {
// only set `order` only when it doesn't exist in original $query
if ( ($state === 'before') && empty($query['order']) ) {
// $this->_schema is null in `before` state
// so i'm assuming current model has `name` field
$query['order'] = $this->name . '.name';
}
return parent::_findList($state, $query, $results);
}
}