本文整理匯總了PHP中DataManager::prepareConditions方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataManager::prepareConditions方法的具體用法?PHP DataManager::prepareConditions怎麽用?PHP DataManager::prepareConditions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DataManager
的用法示例。
在下文中一共展示了DataManager::prepareConditions方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: combineConditions
/**
* Get multiple conditions and combine them into one condition string
*
* DataManager::combineConditions(array('project_id = ?', $project->getId()), 'is_visible = 1');
*
* Will result in:
*
* (project_id = '12') AND (is_visible = 1)
*
* Empty conditions are ignored
*
* @param void
* @return string
*/
function combineConditions()
{
$args = func_get_args();
if (!count($args)) {
return '';
}
// if
$conditions = array();
foreach ($args as $arg) {
$prepared = DataManager::prepareConditions($arg);
if ($prepared) {
$conditions[] = "({$prepared})";
}
// if
}
// foeach
return count($conditions) ? implode(' AND ', $conditions) : '';
}
示例2: delete
/**
* Delete records from attachments table that match given $conditions
*
* This function also deletes all files from /upload folder so this function
* is not 100% transaction safe
*
* @param mixed $conditions
* @return boolean
*/
function delete($conditions = null)
{
$attachments_table = TABLE_PREFIX . 'attachments';
$perpared_conditions = DataManager::prepareConditions($conditions);
$where_string = trim($perpared_conditions) == '' ? '' : "WHERE {$perpared_conditions}";
$rows = db_execute("SELECT id, location FROM {$attachments_table} {$where_string}");
if (is_foreachable($rows)) {
$attachments = array();
foreach ($rows as $row) {
if ($row['location']) {
$attachments[(int) $row['id']] = $row['location'];
}
// if
}
// foreach
// Delete attachments
$delete = db_execute("DELETE FROM {$attachments_table} WHERE id IN (?)", array_keys($attachments));
if ($delete && !is_error($delete)) {
foreach ($attachments as $location) {
@unlink(UPLOAD_PATH . '/' . $location);
}
// foreach
}
// if
return $delete;
}
// if
return true;
}