本文整理汇总了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;
}