本文整理汇总了PHP中array_flat函数的典型用法代码示例。如果您正苦于以下问题:PHP array_flat函数的具体用法?PHP array_flat怎么用?PHP array_flat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_flat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array_flat
function array_flat($a, $s = array(), $l = 0)
{
# check if this is an array
if (!is_array($a)) {
return $s;
}
# go through the array values
foreach ($a as $k => $v) {
# check if the contained values are arrays
if (!is_array($v)) {
# store the value
$s[] = $v;
# move to the next node
continue;
}
# increment depth level
$l++;
# replace the content of stored values
$s = array_flat($v, $s, $l);
# decrement depth level
$l--;
}
# get only unique values
if ($l == 0) {
$s = array_values(array_unique($s));
}
# return stored values
return $s;
}
示例2: flatten
/**
* Takes a multidimensional array and flattens it
* @param array $array
* @return array
*/
public function flatten(array $array)
{
$tmp = array();
foreach ($array as $a) {
if (is_array($a)) {
$tmp = array_merge($tmp, array_flat($a));
} else {
$tmp[] = $a;
}
}
return $tmp;
}
示例3: array_flat
function array_flat($array)
{
$output = array();
if (is_array($array)) {
foreach ($array as $element) {
$output = array_merge($output, array_flat($element));
}
} else {
$output[] = $array;
}
return $output;
}
示例4: core_dimensions_update_7_8
/**
* Contact member cache
*
*/
function core_dimensions_update_7_8()
{
//UPDATE depth for all members
//update root members
DB::execute("UPDATE " . TABLE_PREFIX . "members SET depth = 1 WHERE parent_member_id = 0;");
//clean root members
DB::execute("UPDATE " . TABLE_PREFIX . "members SET depth = 2 WHERE parent_member_id != 0 AND depth = 1;");
$members_depth = DB::executeAll("SELECT id FROM " . TABLE_PREFIX . "members WHERE parent_member_id =0 ORDER BY id");
$members_depth = array_flat($members_depth);
$members_depth = implode(",", $members_depth);
$depth = 2;
$max_depth = DB::executeOne("SELECT MAX(depth) AS depth FROM `" . TABLE_PREFIX . "members`");
//update all depths
for ($i = $depth; $i <= $max_depth['depth']; $i++) {
//update members depth
DB::execute("UPDATE " . TABLE_PREFIX . "members SET depth = " . $depth . " WHERE parent_member_id IN (" . $members_depth . ");");
//Get member from next depth
$members_depth = DB::executeAll("SELECT id FROM " . TABLE_PREFIX . "members WHERE depth= " . $depth . " ORDER BY id");
$members_depth = array_flat($members_depth);
$members_depth = implode(",", $members_depth);
$depth++;
}
//END UPDATE depth for all members
//Load the contact member cache
set_time_limit(0);
ini_set('memory_limit', '512M');
$users = Contacts::getAllUsers();
$dimensions = Dimensions::findAll();
$dimensions_ids = array();
foreach ($dimensions as $dimension) {
if ($dimension->getDefinesPermissions()) {
$dimensions_ids[] = $dimension->getId();
}
}
$dimensions_ids = implode(",", $dimensions_ids);
$root_members = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "members WHERE dimension_id IN (" . $dimensions_ids . ") AND parent_member_id=0 ORDER BY id");
foreach ($users as $user) {
try {
DB::beginWork();
foreach ($root_members as $member) {
ContactMemberCaches::updateContactMemberCache($user, $member['id'], $member['parent_member_id']);
}
DB::commit();
} catch (Exception $e) {
DB::rollback();
throw $e;
}
}
//END Load the contact member cache
}
示例5: contactCanAccessMemberAll
/**
*
* Checks if user can access the member for a specified access level
* @param $permission_group_ids - string array: User permission group ids
* @param $member_id - integer: Member Id
* @param $user - Contact
* @param $access_level - enum: ACCESS_LEVEL_READ, ACCESS_LEVEL_WRITE, ACCESS_LEVEL_DELETE
* @param $check_administrator bool - if user is super administrator do not check permission
*/
function contactCanAccessMemberAll($permission_group_ids, $member_id, $user, $access_level, $check_administrator = true)
{
if ($user instanceof Contact && $user->isAdministrator() && $check_administrator) {
return true;
}
$member = Members::findById($member_id);
if ($member instanceof Member && !$member->getDimension()->getDefinesPermissions()) {
return true;
}
$disabled_ots = array();
$disableds = DB::executeAll("SELECT object_type_id FROM " . TABLE_PREFIX . "tab_panels WHERE object_type_id>0 AND enabled=0");
if (is_array($disableds)) {
$disabled_ots = array_flat($disableds);
}
$ws_ot = ObjectTypes::findByName('workspace')->getId();
$comment_ot = ObjectTypes::findByName('comment')->getId();
$disabled_ots[] = $ws_ot;
$disabled_ots[] = $comment_ot;
$disabled_ot_cond = "";
if (count($disabled_ots) > 0) {
$disabled_ot_cond = "AND object_type_id NOT IN (" . implode(",", $disabled_ots) . ")";
}
if ($access_level == ACCESS_LEVEL_READ) {
if (!isset(self::$readable_members["{$permission_group_ids}"])) {
$res = DB::execute("SELECT DISTINCT member_id FROM " . TABLE_PREFIX . "contact_member_permissions WHERE permission_group_id IN (" . $permission_group_ids . ") {$disabled_ot_cond}");
$rows = $res->fetchAll();
if (is_array($rows)) {
self::$readable_members["{$permission_group_ids}"] = array();
foreach ($rows as $row) {
self::$readable_members["{$permission_group_ids}"][] = $row['member_id'];
}
}
}
return in_array($member_id, self::$readable_members["{$permission_group_ids}"]);
} else {
if (!isset(self::$writable_members["{$permission_group_ids}"])) {
$res = DB::execute("SELECT DISTINCT member_id FROM " . TABLE_PREFIX . "contact_member_permissions WHERE can_write=1 AND permission_group_id IN (" . $permission_group_ids . ") {$disabled_ot_cond}");
$rows = $res->fetchAll();
if (is_array($rows)) {
self::$writable_members["{$permission_group_ids}"] = array();
foreach ($rows as $row) {
self::$writable_members["{$permission_group_ids}"][] = $row['member_id'];
}
}
}
return in_array($member_id, self::$writable_members["{$permission_group_ids}"]);
}
}
示例6: removeObjectFromMembers
/**
* Removes the object from those members where the user can see the object(and its corresponding parents)
*
*/
static function removeObjectFromMembers(ContentDataObject $object, Contact $contact, $context_members, $members_to_remove = null, $check_permissions = true)
{
if (is_null($members_to_remove)) {
$member_ids = array_flat(DB::executeAll("SELECT om.member_id FROM " . TABLE_PREFIX . "object_members om\r\n \t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "members m ON m.id=om.member_id\r\n \t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "dimensions d On d.id=m.dimension_id \r\n \t\t\t\t\t\tWHERE d.is_manageable=1 AND om.object_id = " . $object->getId()));
} else {
$member_ids = $members_to_remove;
}
$memebers_deleted_ids = array();
foreach ($member_ids as $id) {
$member = Members::findById($id);
if (!$member instanceof Member) {
continue;
}
if ($check_permissions) {
//can write this object type in the member
$can_write = $object->canAddToMember($contact, $member, $context_members);
} else {
$can_write = true;
}
if ($can_write) {
$om = self::findById(array('object_id' => $object->getId(), 'member_id' => $id));
if ($om instanceof ObjectMember) {
$om->delete();
$memebers_deleted_ids[] = $id;
}
$stop = false;
while ($member->getParentMember() != null && !$stop) {
$member = $member->getParentMember();
$obj_member = ObjectMembers::findOne(array("conditions" => array("`object_id` = ? AND `member_id` = ? AND \r\n\t\t\t\t\t\t\t\t\t`is_optimization` = 1", $object->getId(), $member->getId())));
if (!is_null($obj_member)) {
$obj_member->delete();
} else {
$stop = true;
}
}
}
}
return $memebers_deleted_ids;
}
示例7: removeObjectFromMembers
/**
* Removes the object from those members where the user can see the object(and its corresponding parents)
*
*/
static function removeObjectFromMembers(ContentDataObject $object, Contact $contact, $context_members, $members_to_remove = null){
if (is_null($members_to_remove)) {
$member_ids = array_flat(DB::executeAll("SELECT member_id FROM ".TABLE_PREFIX."object_members WHERE object_id = " . $object->getId()));
} else {
$member_ids = $members_to_remove;
}
foreach($member_ids as $id){
$member = Members::findById($id);
if (!$member instanceof Member) continue;
//can write this object type in the member
$can_write = $object->canAddToMember($contact, $member, $context_members);
if ($can_write){
$om = self::findById(array('object_id' => $object->getId(), 'member_id' => $id));
if ($om instanceof ObjectMember) {
$om->delete();
}
$stop = false;
while ($member->getParentMember() != null && !$stop){
$member = $member->getParentMember();
$obj_member = ObjectMembers::findOne(array("conditions" => array("`object_id` = ? AND `member_id` = ? AND
`is_optimization` = 1", $object->getId(),$member->getId())));
if (!is_null($obj_member)) {
$obj_member->delete();
}
else $stop = true;
}
}
}
}
示例8: array
$read_events[$rr['rel_object_id']] = 1;
}
}
}
// generate repetitive event instances
$repeated_instances = array();
foreach ($all_events as $k => $aev) {
if ($aev->isRepetitive()) {
$rep = $aev->getRepetitiveInstances($date_start, $date_end);
if (count($rep) > 0) {
$repeated_instances[] = $rep;
unset($all_events[$k]);
}
}
}
$all_events = array_merge($all_events, array_flat($repeated_instances));
$can_add_events = ProjectEvent::canAdd(logged_user(), active_context());
// Loop to render the calendar
for ($week_index = 0;; $week_index++) {
$month_aux = $month;
$year_aux = $year;
$day_of_month = $week_index * 7 + 2 - $firstday;
$weeknumber = date("W", mktime(0, 0, 0, $month, $day_of_month, $year));
?>
<tr>
<?php
if (user_config_option("show_week_numbers")) {
?>
<td style="width:20px" class="weeknumber" valign="top"><?php
echo $weeknumber;
?>
示例9: array_flat
function array_flat($array)
{
foreach ($array as $a) {
if (is_array($a)) {
$tmp = array_merge($tmp, array_flat($a));
} else {
$tmp[] = $a;
}
}
return $tmp;
}
示例10: setTags
/**
* Set object tags. This function accepts tags as params
*
* @access public
* @param void
* @return boolean
*/
function setTags()
{
if (!plugin_active('tags')) {
return null;
}
if (!$this->isTaggable()) {
throw new Error('Object not taggable');
}
$args = array_flat(func_get_args());
return Tags::setObjectTags($args, $this, get_class($this->manager()), $this->getProject());
}
示例11: select_values
static function select_values()
{
$results = call_user_func_array('DB::select', func_get_args());
return array_flat($results);
}
示例12: executeAll
/**
* Execute query and return all rows
*
* @access public
* @param string $sql
* @return array
* @throws DBQueryError
*/
static function executeAll($sql)
{
$arguments = func_get_args();
array_shift($arguments);
$arguments = count($arguments) ? array_flat($arguments) : null;
return self::connection()->executeAll($sql, $arguments);
}
示例13: array_flat
function array_flat($arr)
{
$result = array();
foreach ($arr as $value) {
if (!is_array($value)) {
$result[] = $value;
} else {
array_splice($result, count($result), 0, array_flat($value));
}
}
return $result;
}
示例14: getLastActivities
static function getLastActivities()
{
$members = active_context_members(false);
// Context Members Ids
$options = explode(",", user_config_option("filters_dashboard", null, null, true));
$extra_conditions = "action <> 'login' AND action <> 'logout' AND action <> 'subscribe' AND created_by_id > '0'";
if ($options[1] == 0) {
//do not show timeslots
$extra_conditions .= "AND action <> 'open' AND action <> 'close' AND ((action <> 'add' OR action <> 'edit' OR action <> 'delete') AND object_name NOT LIKE 'Time%')";
}
// task assignment conditions
if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) {
$extra_conditions .= " AND IF((SELECT o.object_type_id FROM " . TABLE_PREFIX . "objects o WHERE o.id=rel_object_id)=(SELECT ot.id FROM " . TABLE_PREFIX . "object_types ot WHERE ot.name='task'),\r\n\t\t\t\t(SELECT t.assigned_to_contact_id FROM " . TABLE_PREFIX . "project_tasks t WHERE t.object_id=rel_object_id) = " . logged_user()->getId() . ",\r\n\t\t\t\ttrue)";
}
//do not display template tasks logs
$extra_conditions .= " AND IF((SELECT o.object_type_id FROM " . TABLE_PREFIX . "objects o WHERE o.id=rel_object_id)=(SELECT ot.id FROM " . TABLE_PREFIX . "object_types ot WHERE ot.name='template_task'), false, true)";
// if logged user is guest dont show other users logs
if (logged_user()->isGuest()) {
$extra_conditions .= " AND `created_by_id`=" . logged_user()->getId();
}
$members_sql = "";
$is_member_child = "";
if (count($members) > 0) {
$members_sql = "(EXISTS(\r\n\t\t\t\tSELECT om.object_id FROM " . TABLE_PREFIX . "object_members om\r\n\t\t\t\tWHERE om.member_id IN (" . implode(',', $members) . ") AND rel_object_id = om.object_id\r\n\t\t\t\tGROUP BY object_id\r\n\t\t\t\tHAVING count(member_id) = " . count($members) . "\r\n\t\t\t))";
$is_member_child = "AND mem.parent_member_id IN (" . implode(',', $members) . ")";
}
//permissions
$logged_user_pgs = implode(',', logged_user()->getPermissionGroupIds());
$permissions_condition = "al.rel_object_id IN (\r\n\t\tSELECT sh.object_id FROM " . TABLE_PREFIX . "sharing_table sh\r\n\t\tWHERE al.rel_object_id = sh.object_id AND sh.object_id > 0\r\n\t\tAND sh.group_id IN ({$logged_user_pgs})\r\n\t\t)";
$sql = "SELECT al.id FROM " . TABLE_PREFIX . "application_logs al \r\n\t\t\t\tWHERE {$permissions_condition} AND {$extra_conditions}";
if ($members_sql != "") {
$sql .= " AND {$members_sql}";
//do not display users logs
$sql .= " AND NOT EXISTS(SELECT con.object_id FROM " . TABLE_PREFIX . "contacts con WHERE con.object_id=rel_object_id AND user_type > 0)";
}
$sql .= " ORDER BY created_on DESC LIMIT 100";
$id_rows = array_flat(DB::executeAll($sql));
// if logged user is guest dont show other users logs
$user_condition = "";
if (logged_user()->isGuest()) {
$user_condition .= " AND `created_by_id`=" . logged_user()->getId();
}
$member_logs_sql = "SELECT al.id FROM " . TABLE_PREFIX . "application_logs al\r\n\t\t\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "members mem ON mem.id=al.member_id \r\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "contact_member_cache cmcache ON cmcache.member_id=mem.id AND cmcache.contact_id = " . logged_user()->getId() . "\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE al.member_id>0\r\n\t\t\t\t\t\t\t\t\t\t\t{$user_condition}\r\n\t\t\t\t\t\t\t\t\t\t\t{$is_member_child}\r\n\t\t\t\t\t\t\tORDER BY created_on DESC LIMIT 100";
$m_id_rows = array_flat(DB::executeAll($member_logs_sql));
$id_rows = array_filter(array_merge($id_rows, $m_id_rows));
$logs = array();
if (count($id_rows) > 0) {
$logs = ApplicationLogs::findAll(array("condition" => "id IN (" . implode(',', $id_rows) . ")", "order" => "created_on DESC"));
}
return $logs;
}
示例15: array_flat
/**
* Make Array Flat
*/
function array_flat($array)
{
$out = array();
foreach ($array as $k => $v) {
if (is_array($array[$k])) {
$out = array_merge($out, array_flat($array[$k]));
} else {
$out[] = $v;
}
}
return $out;
}